Page 1 of 1

OpenSim Plugins with MOCO

Posted: Fri Dec 10, 2021 10:51 am
by alashari
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

Re: OpenSim Plugins with MOCO

Posted: Sat Dec 11, 2021 8:30 am
by rosshm
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

Re: OpenSim Plugins with MOCO

Posted: Sat Dec 11, 2021 9:07 am
by rosshm
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

Re: OpenSim Plugins with MOCO

Posted: Sun Dec 12, 2021 11:51 am
by bogert
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.

Re: OpenSim Plugins with MOCO

Posted: Thu Dec 16, 2021 2:47 am
by alashari
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!