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

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
veerendra v
Posts: 6
Joined: Wed May 16, 2018 5:03 am

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

Post by veerendra v » 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: 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?
Attachments
Screenshot from 2018-07-18 17-06-43.png
Screenshot from 2018-07-18 17-06-43.png (40.87 KiB) Viewed 446 times

Tags:

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

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

Post by Thomas Uchida » Wed Jul 18, 2018 12:39 pm

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.

User avatar
veerendra v
Posts: 6
Joined: Wed May 16, 2018 5:03 am

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

Post by veerendra v » Mon Jul 23, 2018 11:50 pm

Thanks for the reply Thomas. Finally I am able to control the simulation with runtime control input from the keyboard.

POST REPLY