Controller that takes runtime input for forward dynamics simulation of simple arm example
Posted: Wed Jul 18, 2018 4:46 am
is there any predefined controller class which takes control inputs in runtime(from keyboard,network socket,etc when the simulation is running) and apply to its actuator? if none is available is there any possibility of achieving this by overriding computeControls() of Controller? I tried the below code but no success.
This is the custom controller implementation for simple arm example given in https://github.com/opensim-org/opensim- ... Example.md. This controller just calculates muscle activation as a ratio of current state time and final time.
Code in main function:
I'm getting this output. where did i go wrong?
This is the custom controller implementation for simple arm example given in https://github.com/opensim-org/opensim- ... Example.md. This controller just calculates muscle activation as a ratio of current state time and final time.
Code: Select all
class elbController : public Controller
{
OpenSim_DECLARE_CONCRETE_OBJECT(elbController, Controller);
double _finalTime = 0.0;
public:
elbController(double finalTime) : Controller(){
_finalTime = finalTime;
}
void computeControls(const SimTK::State& s, SimTK::Vector &controls) const
{
const Muscle* bicep = dynamic_cast<const Muscle*> ( &getActuatorSet().get(0) );
double mycontrol = 0.0;
mycontrol = (double)(s.getTime()/_finalTime); //_finalTime = final time of simulation
Vector muscleControl(1, mycontrol);
// Add in the controls computed for this muscle to the set of all model controls
bicep->addInControls(muscleControl, controls);
}
};
Code: Select all
// Create the controller.
elbController *controller = new elbController(finalTime);
// Give the controller the Model's actuators so it knows
// to control those actuators.
controller->setActuators( model.updActuators() );
model.addController(controller);