OpenSim Plugins with MOCO

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Ali Adil Lashari
Posts: 5
Joined: Tue May 18, 2021 7:12 am

OpenSim Plugins with MOCO

Post by Ali Adil Lashari » Fri Dec 10, 2021 10:51 am

Hi,

I'm trying to run a simple marker tracking problem like the one included in MocoTrack. The OpenSim model I want to use includes a plugin that defines drag force. I can load the plugin okay through both the GUI and the Matlab API. However, when I try to run the matlab script that includes my model, Matlab crashes and I have to force quit. Can anyone help regarding what might be the Issue?

Using OpenSim 4.3 and the Moco distribution included with this version.

Thanks,
-Ali

User avatar
Ross Miller
Posts: 375
Joined: Tue Sep 22, 2009 2:02 pm

Re: OpenSim Plugins with MOCO

Post by Ross Miller » Sat Dec 11, 2021 8:30 am

Hi Ali,

It's likely there's something in the plug-in that's incompatible with Moco/IPOPT/CasADI.

Drag force is tricky to model. Ton van den Bogert has done it before, maybe he will see this thread.

If your model has pelvis translations, you could add a very crude approximation of drag using ExpressionBasedCoordinateForce. For example, if pelvis_tx is the direction of progression:

Code: Select all

<ExpressionBasedCoordinateForce name="PassiveLumbarDampingX">
	<!--Coordinate (name) to apply force to-->
	<coordinate>pelvis_tx</coordinate>
	<!--Expression of the force magnitude as a function of the coordinate value (q) and its time derivative (qdot)-->
	<expression>-b*qdot^2</expression>
</ExpressionBasedCoordinateForce>
where b is some constant. You would have to enter an actual numerical value for it in the <expression> tag above. It could be something like b = 1/2*Cd*A*rho where Cd = drag coeffient, A = frontal area, rho = fluid density.

This isn't modeling drag on each body segment but it's at least providing a drag-like force resisting the model's overall progression.

Ross

User avatar
Ross Miller
Posts: 375
Joined: Tue Sep 22, 2009 2:02 pm

Re: OpenSim Plugins with MOCO

Post by Ross Miller » Sat Dec 11, 2021 9:07 am

For example, typical drag equation is:

F = -0.5*rho*Cd*A*v^2

rho = 1.225 kg/m^3 (standard temperature and pressure)
Cd = 1.2 (in most wind-tunnel tests of upright humans it seems to be in the range of 1.0-1.2)
A = 0.45 m^2 for average-sized male (Shanebrook & Jaszcak, 1976)

This gives a drag force of -0.5 N for walking at 1.2 m/s and -33 N for sprinting at 10 m/s.

Ross

User avatar
Ton van den Bogert
Posts: 166
Joined: Thu Apr 27, 2006 11:37 am

Re: OpenSim Plugins with MOCO

Post by Ton van den Bogert » Sun Dec 12, 2021 11:51 am

If you know that the velocity is always positive, that expression should work. The drag force will always be negative.

But, the optimizer may sometimes evaluate a very weird trajectory, where a velocity is negative. If you get a negative drag force when the velocity is negative, your model will quickly explode towards negative infinity, if you did a forward simulation.

To prevent this, replace v^2 by v*abs(v).

If you want a 2D or 3D drag force model: Fx = -vx * sqrt(vx^2 + vy^2 + vz^2), etc.

Hopefully you can get this working with a minor change in your plugin code.

User avatar
Ali Adil Lashari
Posts: 5
Joined: Tue May 18, 2021 7:12 am

Re: OpenSim Plugins with MOCO

Post by Ali Adil Lashari » Thu Dec 16, 2021 2:47 am

Thank you for your responses. The BodyDragForce plugin in my model works when used through the GUI. It's getting it to work with MOCO that's proving to be a problem. I'll try this alternative. Thanks!

POST REPLY