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
OpenSim Plugins with MOCO
- Ross Miller
- Posts: 375
- Joined: Tue Sep 22, 2009 2:02 pm
Re: OpenSim Plugins with MOCO
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:
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
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>
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
- Ross Miller
- Posts: 375
- Joined: Tue Sep 22, 2009 2:02 pm
Re: OpenSim Plugins with MOCO
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
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
- Ton van den Bogert
- Posts: 166
- Joined: Thu Apr 27, 2006 11:37 am
Re: OpenSim Plugins with MOCO
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.
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.
- Ali Adil Lashari
- Posts: 5
- Joined: Tue May 18, 2021 7:12 am
Re: OpenSim Plugins with MOCO
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!