Page 1 of 1

get position segment in Controller (ComputeControls)

Posted: Sun Jan 08, 2017 3:05 am
by maaafsch
Hi,

I want to acces the position of a specific body inside the computeControls function of my controller class.
I tried this as follows

Code: Select all

void COM_MuscleController::computeControls(const SimTK::State& s, SimTK::Vector& controls) const
{	
	OpenSim::Body body_sel = getModel().getBodySet().get("calcn_l");		// get body
	getModel().getMultibodySystem().realize(s, Stage::Velocity);			// needed ?
	Vec3 p1 = Vec3(0, 0, 0);	Vec3 p2 = Vec3(0, 0, 0);
	getModel().getSimbodyEngine().getPosition(s, body_sel, p1, p2);			// compute position (p2)
	
};
There is something wrong with this code, but I have no idea why is doesn't want to compute the position information.
The code does not run on the line: [getModel().getSimbodyEngine().getPosition(s, body_sel, p1, p2);]. Can anyone help me ?

regards,
Maarten

Re: get position segment in Controller (ComputeControls)

Posted: Sun Jan 08, 2017 6:05 am
by mitkof6
I think the problem originates in this line:

Code: Select all

OpenSim::Body body_sel = getModel().getBodySet().get("calcn_l");
that should be:

Code: Select all

const OpenSim::Body& body_sel = getModel().getBodySet().get("calcn_l");
Also, you have to realize to position stage and not velocity, since this is a kinematic variable. Also you have to provide the offset of the station of interest define in the local frame of the body. You assumed Vec3(0).

Code: Select all

    _model->realizePosition(s);
    Vec3 temp;
    _model->getSimbodyEngine().getPosition(s, _model->getBodySet().get(body), offset, temp);

Re: get position segment in Controller (ComputeControls)

Posted: Sun Jan 08, 2017 9:25 am
by maaafsch
Hi Dimitar,

Thanks for you response.
Indeed, the problems originated in this line:

Code: Select all

const OpenSim::Body& body_sel = getModel().getBodySet().get("calcn_l");
Thanks,
Maarten