Page 1 of 1

Controller that takes runtime input for forward dynamics simulation of simple arm example

Posted: Wed Jul 18, 2018 4:46 am
by veerendra
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: 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 in main function:

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);
        
I'm getting this output. where did i go wrong?

Re: Controller that takes runtime input for forward dynamics simulation of simple arm example

Posted: Wed Jul 18, 2018 12:39 pm
by tkuchida
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?
The functionality you seek is not built into OpenSim, though others have done similar things. You might be able to build on the "Operational-Space Controller API Tutorial" (https://simtk-confluence.stanford.edu/d ... I+Tutorial), which takes input from the keyboard.

Re: Controller that takes runtime input for forward dynamics simulation of simple arm example

Posted: Mon Jul 23, 2018 11:50 pm
by veerendra
Thanks for the reply Thomas. Finally I am able to control the simulation with runtime control input from the keyboard.