CustomJoint in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Charles Yin
Posts: 11
Joined: Mon Feb 05, 2018 12:45 am

CustomJoint in Matlab

Post by Charles Yin » Thu Nov 21, 2019 11:06 am

Hello everyone,
I have found that on the website of api, there is no expression for Matlab. For CustomJoint, which relates to the operation of SpatialTransform, always outputs errors in my case.
I have attached my codes here:
spatialTrans = SpatialTransform();
spatialTrans.updTransformAxis(0).setCoordinateNames('rotation1',1);
spatialTrans.updTransformAxis(0).setFunction(LinearFunction(1,0));
spatialTrans.updTransformAxis(0).setAxis(Vec3(1,0,0));

spatialTrans.updTransformAxis(1).setCoordinateNames('rotation2',1);
spatialTrans.updTransformAxis(1).setAxis(Vec3(0, 1, 0));
spatialTrans.updTransformAxis(2).setCoordinateNames('rotation3',1);
spatialTrans.updTransformAxis(2).setAxis(Vec3(0, 0, 1));

spatialTrans.updTransformAxis(3).setCoordinateNames('translation1',1);
spatialTrans.updTransformAxis(3).setAxis(Vec3(1, 0, 0));
spatialTrans.updTransformAxis(4).setCoordinateNames('translation2',1);
spatialTrans.updTransformAxis(4).setAxis(Vec3(0, 1, 0));
spatialTrans.updTransformAxis(5).setCoordinateNames('translation3',1);
spatialTrans.updTransformAxis(5).setAxis(Vec3(0, 0, 1));


I_to_II = CustomJoint('joint', body_I, locationInParent,...
orientationInParent, body_II, locationInChild, orientationInChild, spatialTrans);


% Update the coordinates of the new joint
exoCoord =I_to_II.upd_CoordinateSet();
exoCoord.get(0).setRange([0.0, 120*pi/180]);
exoCoord.get(0).setName('rotation');

Each time when I run this snippet of codes, there is always error warning:

No method 'setCoordinateNames' with matching signature
found for class 'org.opensim.modeling.TransformAxis'.

It may tell me that the variables in 'setCoordinateNames()' are not correctly filled.

Any suggestions from the experts?
Thanks a lot for your assistance.

Tags:

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

Re: CustomJoint in Matlab

Post by Ayman Habib » Thu Nov 21, 2019 12:10 pm

Hello Charles,

The TransformAxis class indeed has no method setCoordinateNames(String, int) instead it has a setCoordinateNames(ArrayStr), so you'll have to create an ArrayStr object, append the name you want to it then send it to the method. Documentation for version 3.3 API is available here
https://simtk.org/api_docs/opensim/api_ ... mAxis.html

Best regards,
-Ayman

User avatar
Charles Yin
Posts: 11
Joined: Mon Feb 05, 2018 12:45 am

Re: CustomJoint in Matlab

Post by Charles Yin » Fri Nov 22, 2019 3:42 am

Hello Ayman,
Thanks for your support. Now I think I have delt with this problem based on your advice.
However, I also encounted with the problem underlying coordinates update. The definition of CustomJoint CoordinateSet is different from the others since the number of coordinates is not fixed (from 1-6). Thus, I think there may be errors of my codes for defining the coordinates:

angleRange = [0.0, 2*pi/3];
exoCoord =I_to_II.getCoordinateSet(); % or 'upd_CoordinateSet()';
exoCoord.get(0).setRange(angleRange);
exoCoord.get(0).setName('exo_revolute');

Both of getCoordinateSet() and upd_CoordinateSet() output errors. Would you have any suggestions?
Besides, is the coordinate name 'exo_revolute' equal to the name in setCoordinateNames()?

Thanks for your support.
Best Regards.
-Charles

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

Re: CustomJoint in Matlab

Post by Ayman Habib » Fri Nov 22, 2019 10:56 am

Hi Charles,

I'm posting a link to the 3.3 documentation of CustomJoint so you can see what methods are available:
https://simtk.org/api_docs/opensim/api_ ... Joint.html

As you can see there's no getCoordinateSet or updCoordinateSet methods available for the CustomJoint class.

It will save you time and frustration to check the documentation first to see what methods are available. Please consult the page
below for how to use our doxygen documentation
https://simtk-confluence.stanford.edu/d ... ng+Doxygen

Best regards,
-Ayman

User avatar
Charles Yin
Posts: 11
Joined: Mon Feb 05, 2018 12:45 am

Re: CustomJoint in Matlab

Post by Charles Yin » Mon Nov 25, 2019 1:07 pm

Hi Ayman,
Now I have succeeded in CustomJoint modeling with C++. Based on your suggestions, creating Osim models with API Doxygen is quite efficient.
While, I try to execute the same in Matlab, there is still a problem. For the codes in C++ as below, it worked without problem:
CoordinateSet& exoCoord = I2II->upd_CoordinateSet();
double angleRange[2] = {0.0, SimTK::Pi*2/3};
exoCoord[0].setRange(angleRange);
However, the same logic in MATLAB, where I have written:
angleRange = [0.0, 2*pi/3];
exoCoord =I_to_II.upd_CoordinateSet();
exoCoord.get(0).setRange(angleRange);
Which cannot give out reasonable results. And I cannot find the answer from API.

Do you have any adivce or is there the answer someplace in API?
Thanks a lot for your support.

As well, thanks for anyone who has some suggestions.

-Charles.

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

Re: CustomJoint in Matlab

Post by Ayman Habib » Mon Nov 25, 2019 4:20 pm

Hi Charles,

The issue in conversion from C++ to Matlab is primarily of data-types. In C++ you clearly state that you have an array of doubles that gets passed to the method Coordinate::setRange(), there's no ambiguity or data-type conversion. The Matlab side however creates a Matlab Array which is not the same as an array of doubles so can't be passed in. You could set the range using setRangeMin(double), setRangeMax(double) as primitive type 'double' should map without an issue.

Hope this helps, and please let me know how it goes.
-Ayman

User avatar
Charles Yin
Posts: 11
Joined: Mon Feb 05, 2018 12:45 am

Re: CustomJoint in Matlab

Post by Charles Yin » Tue Nov 26, 2019 10:41 am

Hi Ayman,
Thanks for your advice. I have delt with this problem.

Actually, it was the cause that I misunderstood the 'ArrayStr' as:

spatialTrans.updTransformAxis(0).setCoordinateNames(ArrayStr('exo_rotation'));

I checked it with the api, and I found the correct form should be 'ArrayStr('exo_rotation', int)'.
Thus,

exoCoord =I_to_II.upd_CoordinateSet();
numCoord=I_to_II.numCoordinates();
exoCoord.get(0).setRange([value1, value2]);

if exoCoord didn't contain coordinates, its motion range cannot be defined.

Thanks again for all your help.
Best Regards.

-Charles

POST REPLY