Code for switch muscle to driver.

Good morning.

I am currently using the mocap model. (Anybody 6.0)
I know that there is code that uses the driver of the joint instead of the muscle to calculate the inverse dynamics.
I want to know method and the code for that.

Thank you so much.

Hi JM,

You can use Body Model Parameters. Under AnyBody tutorials, look into Lesson 3/Body Model Parameters.
For example, in your main file before “Main = {”, you can use the following:
that takes out both legs’ muscles.

In general, if you need to use the joint torques instead of muscles, leave the driver’s reactions ON, which is the default case. If we want muscles to take over, we set “Reaction.Type = Off;”.

Lastly, even if you have muscles in your model, you can still access the net moment by muscles, which in the case that the inverse dynamics has completed successfully, those net moments would be equal to the torques that you expected from a torque-driven model. For example, in the model tree, under BodyModel\Right, look for MomentMeasure and you’d be able to see for example KneeNetMomentMuscle both in local and global reference frames. This might be what you’d like to do without disabling the muscles.

Hope this helps,

Thank you for your reply.
I used the code, but I do not know if this is correct.
As far as I know, if you define BM_LEG_MUSCLES_BOTH CONST_MUSCLES_NONE, the muscle will also disappear from the visualization. However, in this model, the muscle is still there.

In the case of the driver, it was turned on at JointsAndDriversOptimized.

Please let me know if I have any mistakes.
Thank you.


The structure of MoCap models is a little different. It uses an old approach, where the model was configured in the BodyPartsSetup.any file (you can find it in the Model subfolder).

If you want the muscles to be switched off, please find these lines and change:



I did it!
Thank you so much!