Keeping track of a specific point during the motion with Kinematic Measures

Hi,
I'm using Mocap models and, I'm running a 20 frame analysis. I want to keep track of a specific point on the subject's hand during the movement. I have used AnyKinLinear class to do so. But there are some problems that I will explain.
Here is my code:

  AnyFolder HandPosition = {
     AnyKinLinear RightHandPos = {
       AnyRefFrame &origin = Main.EnvironmentModel.GlobalRef;
       AnyRefFrame &hand = Main.HumanModel.BodyModel.Right.ShoulderArm.Seg.Hand.Ref.I_Flexor_Digitorum_Superficialis_Digit3;
       Type = CartesianCoord;
     };
     
     AnyKinLinear LeftHandPos = {
       AnyRefFrame &origin = Main.EnvironmentModel.GlobalRef;
       AnyRefFrame &hand = Main.HumanModel.BodyModel.Left.ShoulderArm.Seg.Hand.Ref.I_Flexor_Digitorum_Superficialis_Digit3;
       Type = CartesianCoord;
     };
     
     AnyVec3 HandPos = (LeftHandPos.Pos + RightHandPos.Pos)/2;
  };

First of all, the result of each kinematic measure is a three-dimensional vector. However, I want to have the 3D coordinates of the point in each frame. Something like this: {{1,2,3},{4,5,6},{7,8,9}} (I don't know the name of this kind of variable in anyscript) But the result is something like this: {1,2,3}

Second, I want to calculate the average of the values of the right and left hand. But the result is always a three-dimensional zero vector ({0,0,0}).

Best regards,
Mohammad reza

Hi Mohammad Reza,

How are you viewing your results? Just looking at this variable in the Model Tree, or exporting into a CSV file? If you just view in the Model Tree - it will show you the value for a particular time step. Meaning that if you ran analysis - you will see the last value. Viewing these variables in the Chart View should supposedly show the right curves.
Secondly, please ensure that these values are included through referencing in the Study, otherwise they will not be updated and you may see zeros.

Kind regards,
Pavel

1 Like

Hi Pavel,

Thanks for your reply. I inserted this code into the InverseDynamicStudy, and the problem was solved. You were right; the problem was the lack of reference of those variables in the Study.

      AnyFolder &RightPos = Main.HandPosition.RightHandPos;
      AnyFolder &LeftPos = Main.HandPosition.LeftHandPos;
      AnyFloat AvgPos = (RightPos.Pos + LeftPos.Pos) / 2;

I have another question if you don’t mind. Now I want to draw a point with the coordinate that I have calculated in the AvgPos variable. I tried to define a node with AnyRefNode class and giving the value of Main.Studies.InverseDynamicStudy.AvgPos or Main.Studies.InverseDynamicStudy.Output.AvgPos to sRel of the node, but I got some errors each time. Would you please help me with this?

Best regards,
Mohammad reza

Hi @mrb9

It could be that you are using values that are not ready at the time of computing the sRel. Can you try and dump the errors you see here in the thread?

Best regards,
Bjørn

1 Like

Hi Bjørn,
Thanks for your reply. Here is the error that I receive when I load the model:

ERROR(SCR.EXP10) : EnvironmentModel.any(8) : 'AvgPointNode' : Expression evaluation failed at moment 'DesignVar' :
AnyMocapModel.any(33) : AvgHandPos : argument will not be ready for evaluation until moment 'PosVar'

I have defined a Node in the GlobalRef and assigned the position I calculate from getting the average of two specific points' positions on the hand. I calculated this position in the Main file, and the code is attached below:

  AnyFolder HandPosition = {
     AnyKinLinear RightHandPos = {
       AnyRefFrame &origin = Main.EnvironmentModel.GlobalRef;
       AnyRefFrame &hand = Main.HumanModel.BodyModel.Right.ShoulderArm.Seg.Hand.Ref.I_Flexor_Digitorum_Superficialis_Digit3;
       Type = CartesianCoord;
     };
     
     AnyKinLinear LeftHandPos = {
       AnyRefFrame &origin = Main.EnvironmentModel.GlobalRef;
       AnyRefFrame &hand = Main.HumanModel.BodyModel.Left.ShoulderArm.Seg.Hand.Ref.I_Flexor_Digitorum_Superficialis_Digit3;
       Type = CartesianCoord;
     };
     
     AnyFloat AvgHandPos = (LeftHandPos.Pos+RightHandPos.Pos)/2;
  };

I have also referenced it in the Studies, and there is no problem with the coordinates of the point itself, but it seems there is nothing to be assigned to the sRel of the Node at the beginning of the procedure. How can I visualize the point in any way during the simulation?

Best regards,
Mohammadreza

Hi @mrb9

Thanks for the info.
The error you get is because you are trying the initiate a AnyRefNode with a sRel that is not ready at that specific time (called PosVar)
Luckily you don't need to make it a ref node in order to draw it.

The snippet you send about the measures and calculating the AvgHandPos is correct and in order to draw it you can use a AnyDrawSphere like this:

AnyDrawSphere AvgHandPosDraw = {
  Position = .AvgHandPos;
  ScaleXYZ = {1.0,1.0,1.0}*0.05;
};

Bonus tip:
You can further simplify the process by eliminating the measures you made and use the existing.

AnyFloat RightHandPos  = Main.HumanModel.BodyModel.Right.ShoulderArm.Seg.Hand.Ref.I_Flexor_Digitorum_Superficialis_Digit2.r;
AnyFloat LeftHandPos = Main.HumanModel.BodyModel.Left.ShoulderArm.Seg.Hand.Ref.I_Flexor_Digitorum_Superficialis_Digit2.r;
AnyFloat AvgHandPos = (LeftHandPos + RightHandPos) / 2;

The .r parameter is the position w. respect to the global coordinate system. It uses the AnyKinLinear formulation you specified internally.

Best regards,
Bjørn

1 Like

Hi Bjørn,

Thank you so much from the bottom of my heart :heart_eyes: :hugs:
Your instructions really helped me.

Best regards,
Mohammadreza