Page 2 of 2

Re: Measuring Contact Force Vectors in Forward Simulation

Posted: Thu Oct 26, 2017 10:16 am
by ongcf
One line in the code to get the contact force that worries me is the line that makes a copy of the ForceSet:

Code: Select all

ForceSet forces = _model->getForceSet();
Maybe something to try is to avoid any copying to intermediate variables, so your ForceValue() function looks something like this:

Code: Select all

_model->getMultibodySystem().realize(s, SimTK::Stage::Dynamics);
Array<double> F = _model->getForceSet().get(index).getRecordValues(s)
This would narrow down if making a copy to a ForceSet was the problem or not.

Re: Measuring Contact Force Vectors in Forward Simulation

Posted: Thu Oct 26, 2017 10:26 am
by aymanh
Thanks Carmichael, great find.

Definitely you don't want to make a copy here, instead you'd use a reference (ForceSet&) or const reference if you're not going to modify the contents of the ForceSet in your code.

Hope this helps,
-Ayman

Re: Measuring Contact Force Vectors in Forward Simulation

Posted: Thu Oct 26, 2017 12:57 pm
by aymanh
Hello,

Just tried to open the model you sent (TwoLinkArmModel) in Matlab and it failed to open because of missing meshfile foot_l_a3_01.obj

The file should live in the same folder as the model. Can you send it?

Thanks,
-Ayman

Re: Measuring Contact Force Vectors in Forward Simulation

Posted: Thu Oct 26, 2017 1:02 pm
by hkimpara
Hello Ayman,

Yes, here attached zip contains obj files. Thank you, Hide
foot_l_a3_01.zip
(77.08 KiB) Downloaded 68 times

Re: Measuring Contact Force Vectors in Forward Simulation

Posted: Thu Oct 26, 2017 5:35 pm
by kenechukwu
Hello,
Maybe something to try is to avoid any copying to intermediate variables, so your ForceValue() function looks something like this:
CODE: SELECT ALL
_model->getMultibodySystem().realize(s, SimTK::Stage::Dynamics);
Array<double> F = _model->getForceSet().get(index).getRecordValues(s)
This was definitely very helpful. But I noticed that when I try to realize to the state to the Dynamic stage, the program crashes and when I go line by line on the debugger, it keeps looping back once I get this line:

Code: Select all

_model->getMultibodySystem().realize(s, SimTK::Stage::Dynamics);
It's not realizing the stage.

Please what I can do about this? There are no errors or exceptions being thrown.

I added my model and code here.

Re: Measuring Contact Force Vectors in Forward Simulation

Posted: Thu Oct 26, 2017 10:59 pm
by aseth
I am not sure this is the issue in your case, but be aware that you cannot

Code: Select all

realizedDynamics
within

Code: Select all

computeControls
of a Controller. That will cause an infinite recursion because realizeDynamics invokes the

Code: Select all

Controller::computeControls
on all Model controllers. Actuators then access the computed control values in order to determine the forces that they apply to the MultibodySystem.

Re: Measuring Contact Force Vectors in Forward Simulation

Posted: Fri Oct 27, 2017 12:54 am
by kenechukwu
Hello Ajay,

Thank you for your comment.

I am designing a controller which considers the forces acting on the model in order to compute the controls in the next time step.

With the limitation (inability to call realizeDynamics in computeControls), how would you suggest I obtain and use contact forces within the controller class?

Thank you.

Kenechukwu