Measuring Contact Force Vectors in Forward Simulation

The Question and Answer and Support Forum for the 2017 Fall Virtual Workshop.
User avatar
Carmichael Ong
Posts: 401
Joined: Fri Feb 24, 2012 11:50 am

Re: Measuring Contact Force Vectors in Forward Simulation

Post by Carmichael Ong » Thu Oct 26, 2017 10:16 am

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.

User avatar
Ayman Habib
Posts: 2252
Joined: Fri Apr 01, 2005 12:24 pm

Re: Measuring Contact Force Vectors in Forward Simulation

Post by Ayman Habib » Thu Oct 26, 2017 10:26 am

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

User avatar
Ayman Habib
Posts: 2252
Joined: Fri Apr 01, 2005 12:24 pm

Re: Measuring Contact Force Vectors in Forward Simulation

Post by Ayman Habib » Thu Oct 26, 2017 12:57 pm

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

User avatar
Hide Kimpara
Posts: 135
Joined: Mon Sep 19, 2016 5:12 am

Re: Measuring Contact Force Vectors in Forward Simulation

Post by Hide Kimpara » Thu Oct 26, 2017 1:02 pm

Hello Ayman,

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

User avatar
Kenechukwu Mbanisi
Posts: 51
Joined: Fri Feb 10, 2017 2:50 pm

Re: Measuring Contact Force Vectors in Forward Simulation

Post by Kenechukwu Mbanisi » Thu Oct 26, 2017 5:35 pm

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.
Attachments
TwoLinkArmModel2.zip
(48.68 KiB) Downloaded 70 times

User avatar
Ajay Seth
Posts: 136
Joined: Thu Mar 15, 2007 10:39 am

Re: Measuring Contact Force Vectors in Forward Simulation

Post by Ajay Seth » Thu Oct 26, 2017 10:59 pm

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.

User avatar
Kenechukwu Mbanisi
Posts: 51
Joined: Fri Feb 10, 2017 2:50 pm

Re: Measuring Contact Force Vectors in Forward Simulation

Post by Kenechukwu Mbanisi » Fri Oct 27, 2017 12:54 am

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

POST REPLY