#include #include "LocomotorPrimitivesController.h" #define VERBOSE 1 // XXX extern clock_t ts_start; static const double TIME_DAMP = 0.1; static const unsigned int N_PRINT = 1000; void LocomotorPrimitivesController::computeControls(const SimTK::State &s, SimTK::Vector &controls) const { double t = s.getTime(); static double last_twitch = t; static unsigned int n = 0; /* Extract muscle activation for each of the muscles */ int act_set_siz = getActuatorSet().getSize(); int nc = _act.getSmallestNumberOfStates(); /* * 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++) { const OpenSim::Muscle *muscle = dynamic_cast(&getActuatorSet().get(i)); const OpenSim::Array indices = _act.getColumnIndicesForIdentifier(muscle->getName()); if (indices.getSize() != 0) { int idx = indices.get(0) - 1; if (n % N_PRINT == 0) std::cout << "[" << (1.e3 * clock() - ts_start) / CLOCKS_PER_SEC << "ms] " << t << " (" << idx << ") actuation data for '" << muscle->getName() << "' found: " << _muscle_act[idx] << std::endl; if (_muscle_act[idx] > 1.0) { std::cerr << "Error: muscle actuation larger than 1.0 (" << _muscle_act[idx] << "), truncating" << std::endl; _muscle_act[idx] = 1.0; } 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; continue; } } n++; }