Hello,
How can I retrieve contact forces and Lagrange multipliers after the problem has been solved?
Thank you in advance!
Retrieve contact forces and Lagrange multipliers
- Bach Quoc Hoa
- Posts: 24
- Joined: Thu Jul 13, 2017 7:03 am
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Retrieve contact forces and Lagrange multipliers
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.
Lagrange multipliers are available in the MocoSolution, via getMultiplier() and related functions.
- Bach Quoc Hoa
- Posts: 24
- Joined: Thu Jul 13, 2017 7:03 am
Re: Retrieve contact forces and Lagrange multipliers
With the snippet of code from example2DWalking, it doesn't work even the system was already realized at Dynamics stage.
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?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
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Retrieve contact forces and Lagrange multipliers
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?With the snippet of code from example2DWalking, it doesn't work even the system was already realized at Dynamics stage.
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.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?
In general, you need to stabilize the control using a feedback controller such as LQR.
- Bach Quoc Hoa
- Posts: 24
- Joined: Thu Jul 13, 2017 7:03 am
Re: Retrieve contact forces and Lagrange multipliers
I found the issue!
It was
while it should be
However, it only works with SmoothSphereHalfSpaceForce. The error remains with ElasticFoundationForce.
But why does that make the system not realized?
It was
Code: Select all
State& _state = _model.initSystem();
Code: Select all
_model.initSystem();
But why does that make the system not realized?
Last edited by Bach Quoc Hoa on Tue Feb 11, 2020 1:29 pm, edited 1 time in total.
- Bach Quoc Hoa
- Posts: 24
- Joined: Thu Jul 13, 2017 7:03 am
Re: Retrieve contact forces and Lagrange multipliers
I have encountered this problem while using Manager and a model containing SmoothSphereHalfSpaceForce (attached file).
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.
There is just no contact and the model falls right through the ground. How can I register this type of contact force?Encountered unrecognized Object typename SmoothSphereHalfSpaceForce while reading property components. There is no registered Object of this type; ignoring.
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.