Export Muscle Forces with AnyMechOutputFileForceExport

Hi everyone,

I’m new to AnyBody and trying to customize the MoCap Runner model. My goal is to extract the muscle forces (in x, y, z) for the following muscles:

  • TibialisAnterior1
  • FlexorHallucisLongus1
  • ExtensorHallucisLongus1

Here is my current adjustment added at the end of the InverseDynamics.any file:

AnyMechOutputFileForceExport ForcesOutput = {
  FileName = "MuscleForcesOutput.txt";
  AnyRefFrame &Ref = Main.EnvironmentModel.GlobalRef;  
  
  AnySeg &MuscleForce1 = Main.Studies.InverseDynamicStudy.Output.BodyModel.Right.Leg.Mus.TibialisAnterior1;
  AnySeg &MuscleForce2 = Main.Studies.InverseDynamicStudy.Output.BodyModel.Right.Leg.Mus.FlexorHallucisLongus1;
  AnySeg &MuscleForce3 = Main.Studies.InverseDynamicStudy.Output.BodyModel.Right.Leg.Mus.ExtensorHallucisLongus1;
  
  AllSegmentsInStudyOnOff = Off;
  OutputRefFrame.GlobalOnOff = On;
  OutputRefFrame.LocalOnOff = Off;
};

However, when I try to load the model, I get the following error message:

ERROR(SCR.PRS9) : C:/U..s/m..l/D..s/A..e/AMMR/A..n/E..s/M..r/M..l/InverseDynamics.any(50) : 'TibialisAnterior1' : Unresolved object
Model loading skipped

It seems like the muscle object names I used are not recognized, but I copied the muscle names directly from the model tree. Can anyone help me figure out what I’m doing wrong? Did I miss a step or reference? Any advice on how to correctly specify these muscles in the model?

Thanks in advance!

Hello Milena,

Is there any particular reason you are using AnyMechOutputFileForceExport?

You can export muscle force using AnyOutputFile class. This will be simpler than using AnyMechOutputFileForceExport. Please see the reference manual, which also has a demo model.

However, before you can use this, you must define the x,y,z components of the muscle force. Muscle force acts along the line of action of the muscle. Therefore, when you want to convert this to x,y,z force in the GlobalRef (as I understand from your code), you must ask yourself where your reference point for each muscle is. For example, do you want to convert the force at muscle origin or muscle insertion to the global system? This is important as these reference frames will have different orientation and will change your results.

In each muscle, you can see the RefFrameOutput.F. This object express the force in the x,y,z coordinate in the corresponding reference frame that you can find in the RefFrameOutput.RefFrameArr object, which lists the reference frames in the same sequence.

I can write some lines here are some lines to get you going:

Main.Studies.InverseDynamicStudy = {
    AnyOutputFile ForcesOutput = {
     FileName = "MuscleForcesOutput.txt";
     AnyFloat TibialisAnterior1Force = Main.HumanModel.BodyModel.Right.Leg.Mus.TibialisAnterior1.RefFrameOutput.F[0]*Main.HumanModel.BodyModel.Right.Leg.Seg.Shank.TibialisAnterior1Node.Axes'; // converts force to global
   };
};

Hope that helps.

Best regards
Dave