Page 1 of 1

Units and expression for SpringGeneralizedForce

Posted: Tue Jan 05, 2021 7:05 am
by rosshm
Hi all,

For a simple model of walking with a transtibial prosthesis, I remove all the ankle muscles and replace them with a linear torsional spring-damper: F = k*q + b*qdot, where q and qdot are the coordinate and its speed and F is the moment at the coordinate. Previously I've done this with ExpressionBasedCoordinateForce, which works well (optimizer converges on good results):

Code: Select all

<ExpressionBasedCoordinateForce name="prosthetic_ankle_r">
	<coordinate>ankle_angle_r</coordinate>
	<expression>-400.0*q-1.0*qdot</expression>
</ExpressionBasedCoordinateForce>
In this example the spring stiffness k = -400 Nm/rad and the damping b = -1.0 Nm/(rad/s). I would like to have Moco optimize the values of these parameters (k and b), which I think can't be done using ExpressionBasedCoordinateForce, so I've switched to SpringGeneralizedForce and am struggling to get good results:

Code: Select all

<SpringGeneralizedForce name="prosthetic_ankle_r">
	<isDisabled>false</isDisabled>
	<coordinate>ankle_angle_r</coordinate>
	<stiffness>-400.0</stiffness>
	<rest_length>0</rest_length>
	<viscosity>-1.0</viscosity>
</SpringGeneralizedForce>
I first tried SpringGeneralizedForce with stiffness = 400 and viscosity = 1.0 and the optimizer would not converge. I then tried it with the values above, stiffness = -400 and viscosity = -1.0. This time the optimizer converged but the result was not good, bad tracking of the target data and too-high muscle activity.

For SpringGeneralizedForce, can anyone confirm what the units should be on stiffness and viscosity for rotational coordinates, e.g. Nm/rad vs. Nm/deg, and if the negative signs in the XML tags above are needed, i.e. is the expression that's implemented F = -k*q - b*qdot or F = k*q + b*qdot, or something else? I checked the SpringGeneralizedForce documentation but couldn't find this info.

Thanks much!
Ross

Re: Units and expression for SpringGeneralizedForce

Posted: Tue Jan 05, 2021 3:56 pm
by nbianco
Hi Ross,

Here's the source for reference: https://github.com/opensim-org/opensim- ... e.cpp#L234.

It is implemented as F = -k*q - b*qdot. So stiffness = 400 and viscosity = 1.0 should give you equivalent performance to the ExpressionBasedCoordinateForce. Not sure why it doesn't work though. Perhaps you could try using smaller stiffness values until it convergences. Or maybe create a simple motion to make sure the two components produce the same force.

-Nick

Re: Units and expression for SpringGeneralizedForce

Posted: Wed Jan 06, 2021 9:51 am
by rosshm
Thanks Nick. It worked when I used the solution from a model with ExpressionBasedCoordinateForce as the initial guess for a model with SpringGeneralizedForce. The former was produced using a solution from a "two intact legs" simulation. I was expecting they would both work identically when starting from the same initial guess but maybe there is some small difference in implementation that affects IPOPT.

Ross

Re: Units and expression for SpringGeneralizedForce

Posted: Wed Jan 06, 2021 4:54 pm
by nbianco
Glad that it works now. Yes, maybe there's a small difference in how the force is applied. I'm not familiar enough with the ExpressionBasedCoordinateForce to say for sure.