From 6ffc7871c090ab126353c918adcd5c4ef33dc261 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 25 Jan 2013 13:02:19 +0100 Subject: LocomotorPrimitives: Check availability of control data before running --- LocomotorPrimitivesController.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'LocomotorPrimitivesController.cpp') diff --git a/LocomotorPrimitivesController.cpp b/LocomotorPrimitivesController.cpp index 0c13336..2708162 100644 --- a/LocomotorPrimitivesController.cpp +++ b/LocomotorPrimitivesController.cpp @@ -10,6 +10,26 @@ extern clock_t ts_start; static const double TIME_DAMP = 0.1; static const unsigned int N_PRINT = 1000; +int LocomotorPrimitivesController::checkControls() +{ + const int act_set_siz = getActuatorSet().getSize(); + int ret = 0; + + /* Iterate over all controls in the model and check whether they're + * available in the loaded storage */ + for (int i = 0; i < act_set_siz; i++) { + const OpenSim::Muscle *muscle = dynamic_cast(&getActuatorSet().get(i)); + const OpenSim::Array indices = _act.getColumnIndicesForIdentifier(muscle->getName()); + + if (indices.getSize() == 0) { + std::cerr << "Error: no actuation data for muscle '" << muscle->getName() << "' found" << std::endl; + ret--; + } + } + + return ret; +} + void LocomotorPrimitivesController::computeControls(const SimTK::State &s, SimTK::Vector &controls) const { double t = s.getTime(); @@ -17,13 +37,11 @@ void LocomotorPrimitivesController::computeControls(const SimTK::State &s, SimTK static unsigned int n = 0; /* Extract muscle activation for each of the muscles */ - int act_set_siz = getActuatorSet().getSize(); - int nc = _act.getSmallestNumberOfStates(); + const int act_set_siz = getActuatorSet().getSize(); + const int nc = _act.getSmallestNumberOfStates(); - /* - * Get the first nc states at a specified time (_NOT_ the state at nc as - * with getData()). - */ + /* Get the first nc states at a specified time (_NOT_ the state at nc as + * with getData()). */ _act.getDataAtTime(t, nc, _muscle_act); for (int i = 0; i < act_set_siz; i++) { @@ -43,7 +61,7 @@ void LocomotorPrimitivesController::computeControls(const SimTK::State &s, SimTK SimTK::Vector ctrl(1, _muscle_act[idx]); muscle->addInControls(ctrl, controls); } else { - std::cerr << "Error: no actuation data for muscle '" << muscle->getName() << "' at time " << t << " found" << std::endl; + // std::cerr << "Error: no actuation data for muscle '" << muscle->getName() << "' at time " << t << " found" << std::endl; continue; } } -- cgit v1.2.3-54-g00ecf 8c3a461d16f0355ced3d56d6d1bb5923207a1'>block
AgeCommit message (Expand)AuthorFilesLines