Page 1 of 1
Retrieve contact forces and Lagrange multipliers
Posted: Tue Feb 04, 2020 5:55 am
by hbquoc
Hello,
How can I retrieve contact forces and Lagrange multipliers after the problem has been solved?
Thank you in advance!
Re: Retrieve contact forces and Lagrange multipliers
Posted: Tue Feb 04, 2020 9:22 am
by chrisdembia
See this snippet from example2DWalking:
https://github.com/opensim-org/opensim- ... #L288-L299
Lagrange multipliers are available in the MocoSolution, via getMultiplier() and related functions.
Re: Retrieve contact forces and Lagrange multipliers
Posted: Thu Feb 06, 2020 1:33 am
by hbquoc
With the snippet of code from example2DWalking, it doesn't work even the system was already realized at Dynamics stage.
terminate called after throwing an instance of 'SimTK::Exception::StageTooLow'
what(): SimTK Exception thrown at GeneralContactSubsystem.cpp:131:
Expected stage to be at least Dynamics in GeneralContactSubsystemImpl::getContacts() but current stage was Velocity
Another question : If I run a forward dynamics simulation with OpenSim::Manager and use the forces previously obtained as inputs, will the contact forces and the multipliers be the same as those in the previous optimal control simulation?
Re: Retrieve contact forces and Lagrange multipliers
Posted: Thu Feb 06, 2020 11:37 am
by chrisdembia
With the snippet of code from example2DWalking, it doesn't work even the system was already realized at Dynamics stage.
Without seieng your code, I'm not sure why you get this error. The example works as-is, so perhaps you are doing something different from the example?
If I run a forward dynamics simulation with OpenSim::Manager and use the forces previously obtained as inputs, will the contact forces and the multipliers be the same as those in the previous optimal control simulation?
For certain simple systems, yes. In general, no. Numerical errors due to differences between the integration schemes will cause the nonlinear chaotic system to diverge. We touch on this in the Moco bioRxiv preprint.
In general, you need to stabilize the control using a feedback controller such as LQR.
Re: Retrieve contact forces and Lagrange multipliers
Posted: Fri Feb 07, 2020 5:40 am
by hbquoc
I found the issue!
It was
Code: Select all
State& _state = _model.initSystem();
while it should be
However, it only works with SmoothSphereHalfSpaceForce. The error remains with ElasticFoundationForce.
But why does that make the system not realized?
Re: Retrieve contact forces and Lagrange multipliers
Posted: Fri Feb 07, 2020 10:40 am
by hbquoc
I have encountered this problem while using Manager and a model containing SmoothSphereHalfSpaceForce (attached file).
Encountered unrecognized Object typename SmoothSphereHalfSpaceForce while reading property components. There is no registered Object of this type; ignoring.
There is just no contact and the model falls right through the ground. How can I register this type of contact force?
Solution
It seems mandatory to use at least one feature of Moco library, such as declare a void MocoProblem or call visualize(model, storage), so that the MocoComponents can be taken into account.