Joint Reaction Goal

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Burak Kula
Posts: 31
Joined: Wed Dec 04, 2019 3:34 pm

Joint Reaction Goal

Post by Burak Kula » Mon Nov 16, 2020 4:16 am

Hello Everyone,

In my study, I want to minimize joint forces and moments. To do so I am using "MocoJointReactionGoal" function in MATLAB. But I have some problem regarding subfunctions of "MocoJointReactionGoal" which is called "setReactionMeasures()". In tutorial page of function "https://opensim-org.github.io/opensim-m ... _goal.html" it says "force-x","force-y","force-z","moment-x","moment-y","moment-z" can be minimized as it is desired.
When I run my below code,

% Joint Torque optimization
jointCost=MocoJointReactionGoal();
problem.addGoal(jointCost);
jointCost.setName("tibiofemoral_compressive_force");
jointCost.setJointPath("/jointset/knee_l");
jointCost.setLoadsFrame("child");
jointCost.setExpressedInFramePath("/bodyset/tibia_l");
jointCost.setReactionMeasures("force-x");


I am facing with below error,
Check for missing argument or incorrect argument data type in call to function 'setReactionMeasures'.

How can I correct this argument error in my code? What should I give this function as input? or Which type of data should I give ??

Best Regards,
Burak.

User avatar
Carlos Gonçalves
Posts: 139
Joined: Wed Jun 08, 2016 4:56 am

Re: Joint Reaction Goal

Post by Carlos Gonçalves » Mon Nov 16, 2020 6:51 am

Hello Burka,

The method "setReactionMeasures()" receives a list as an argument.

I Python it would be something like this: jointCost.setReactionMeasures(["force-x"]). It should be very similar in MATLAB.

Best regards.

Carlos

User avatar
Burak Kula
Posts: 31
Joined: Wed Dec 04, 2019 3:34 pm

Re: Joint Reaction Goal

Post by Burak Kula » Mon Nov 16, 2020 9:27 am

Hello Carlos,

I am appreciated for your help, but when I try your method unfortunately I got same error.
Check for missing argument or incorrect argument data type in call to function 'setReactionMeasures'.

Also there was a warning for syntax of "jointCost.setReactionMeasures(["force-x"])." It said that in order to specify the argument I must use parenthesis instead of brackets.

I am starting thinking about Moco does not know "force-x, force-y, force-z, moment-x, moment-y, moment-z" . Shall I identify them first in MATLAB or osim file ?

User avatar
Carlos Gonçalves
Posts: 139
Joined: Wed Jun 08, 2016 4:56 am

Re: Joint Reaction Goal

Post by Carlos Gonçalves » Mon Nov 16, 2020 11:33 am

Hello Burka,

You need to find out how the lists are used in MATLAB.

For example, in C++ the syntax is: cost->setReactionMeasures({"force-y"});

The command that I sent previously would only run in Python ( jointCost.setReactionMeasures(["force-x"]) ).

Since the function argument is not a list, the compiler (interpreter) is failing.

I used this Goal before in multiple ways, without argument, or with a list argument with multiple options.

Best regards.

Carlos

User avatar
Nicholas Bianco
Posts: 1057
Joined: Thu Oct 04, 2012 8:09 pm

Re: Joint Reaction Goal

Post by Nicholas Bianco » Mon Nov 16, 2020 1:30 pm

Hi Burak,

setReactionMeasures() takes a list of strings as Carlos mentioned, and C++ the type is std::vector<std::string>. In MATLAB you can use StdVectorString to provide string lists of this type:

Code: Select all

% Joint Torque optimization
jointCost=MocoJointReactionGoal();
problem.addGoal(jointCost);
jointCost.setName("tibiofemoral_compressive_force");
jointCost.setJointPath("/jointset/knee_l");
jointCost.setLoadsFrame("child");
jointCost.setExpressedInFramePath("/bodyset/tibia_l");
measures = StdVectorString();
measures.append("force-x");
jointCost.setReactionMeasures(measures);
Best,
-Nick

User avatar
Burak Kula
Posts: 31
Joined: Wed Dec 04, 2019 3:34 pm

Re: Joint Reaction Goal

Post by Burak Kula » Tue Nov 17, 2020 12:13 am

Hello Carlos and Nicholas,

Firstly I want to thank you for your help and quick response.

@Nicholas,
When I tried your suggestion, I had below error in attachment.
Do you have any more ideas ?
Attachments
er.PNG
er.PNG (18.32 KiB) Viewed 998 times

User avatar
Nicholas Bianco
Posts: 1057
Joined: Thu Oct 04, 2012 8:09 pm

Re: Joint Reaction Goal

Post by Nicholas Bianco » Tue Nov 17, 2020 6:28 pm

Hi Burak,

Apologies, use add(), not append(), for StdVectorString.

-Nick

User avatar
Burak Kula
Posts: 31
Joined: Wed Dec 04, 2019 3:34 pm

Re: Joint Reaction Goal

Post by Burak Kula » Thu Nov 19, 2020 3:58 am

Hello Nicholas,
Firstly, I want to thank you for your help.

I have another question. When I use "force-x" term, can Moco know this is a force in x-direction ? or is for "force-x" defined before in Moco or in any XML file?

Best Regards,
Burak.

User avatar
Nicholas Bianco
Posts: 1057
Joined: Thu Oct 04, 2012 8:09 pm

Re: Joint Reaction Goal

Post by Nicholas Bianco » Thu Nov 19, 2020 1:08 pm

Hi Burak,

When you specify "force-x", you are say to minimize the component of the reaction force in the x-direction as defined by the joint. So it depends on how your joint is oriented in the model. A quick way to check is to load your model in the OpenSim GUI, go to the joint in the Navigator, right-click and select "Toggle Parent Frame" or "Toggle Child Frame" to show the joint axes. The axes colors red/green/blue correspond to x/y/z.

-Nick

POST REPLY