Change Name of a Coordinate

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Change Name of a Coordinate

Post by Ruth Meißner » Wed Dec 11, 2019 3:33 pm

Hi,

I am trying to change the name of a coordinate in my model via Matlab. I want some of the coordinate names shown in the GUI in the coordinates window to be more "understandable".
Here is my code:

Code: Select all

    pelvis_ground = preparedModel.getJointSet().get('ground_pelvis');
    for i = 0 : pelvis_ground.numCoordinates()-1
        coord =  pelvis_ground.upd_coordinates(i);
        if strcmp(coord.getName(), "pelvis_list")
           coord.setName("pelvis_list_newName");
        end
    end
    pelvis_ground.finalizeFromProperties();
 
But I get an error when I try to call after my changes preparedModel.FinalizeFromProperties() prior to finalizeConnections() and initSystem().
Java exception occurred:
java.lang.RuntimeException: SimTK Exception thrown at joint.cpp:142:
Internal bug detected: Joint::constructCoordinate() must be passed enumerations in the same order as the enumerations have been defined
(Assertion 'static_cast<unsigned>(cix) == idx' failed).
Please file an Issue at https://github.com/simbody/simbody/issues.
Include the above information and anything else needed to reproduce the problem.

at org.opensim.modeling.opensimCommonJNI.Component_finalizeFromProperties(Native Method)

at org.opensim.modeling.Component.finalizeFromProperties(Component.java:66)


I also tried to access the coordinate directly via the coordinate set (example with another coordinate):

Code: Select all

    
  coordinates = preparedModel.updCoordinateSet(); // or .getCoordinateSet()
 for a= 0: coordinates.getSize()-1
        coordinate = coordinates.get(a);
        name = coordinate.getName();
       if strcmp( name, "flexion_r")
           coordinate.setName("hand_flexion_r")
       end
   
Here my code runs through, but if I check the osim-file or the coordinates window in the GUI with the model opened, the name has not been changed.

Additionally, I tried to change a name of a coordinate directly in the osim file. To do so, I searched the osim file and changed the name of the coordinate in every case it was mentioned. But if I open this osim file in the GUI after saving the changes, the coordinate is still shown with its old name.

Probably I am doing something wrong, maybe you have an hint?

Thank you :)
Ruth Meissner

Tags:

User avatar
Thomas Uchida
Posts: 1794
Joined: Wed May 16, 2012 11:40 am

Re: Change Name of a Coordinate

Post by Thomas Uchida » Wed Dec 11, 2019 9:13 pm

You should be using single quotes, not double quotes. Information about quotes in Matlab can be found on the mathworks website (e.g., https://www.mathworks.com/matlabcentral ... uble-quote). There are several Matlab examples you can use for reference (e.g., a Coordinate name is set here: https://github.com/opensim-org/opensim- ... per.m#L125). The following pages in the documentation may also be helpful (in case you haven't seen them already):
- "Common Scripting Commands": https://simtk-confluence.stanford.edu/d ... g+Commands
- "Scripting with Matlab": https://simtk-confluence.stanford.edu/d ... ith+Matlab

User avatar
Ruth Meißner
Posts: 16
Joined: Sat Mar 23, 2019 11:28 am

Re: Change Name of a Coordinate

Post by Ruth Meißner » Thu Dec 12, 2019 2:29 am

Hi Thomas,
thanks. I already tried changing the double quotes to single quotes and it remains the same.
With the first code snippet I get the error message and the second snippet runs through without changing the names. (I am using the API Doxygen all the time, it is really helpful!)
Regarding the github-link you gave me, where coordinates are set: If I compare my code and the example code, I have the impression, that I am doing exactly the same, only that I have the additional "if" since I am looping through all coordinates:

Code: Select all

	%% MY CODE
    pelvis_ground = preparedModel.getJointSet().get('ground_pelvis');
    for i = 0 : pelvis_ground.numCoordinates()-1
        coord =  pelvis_ground.upd_coordinates(i);
        if strcmp(coord.getName(), 'pelvis_list')
           coord.setName('pelvis_list_newName');  % --> when not commented the preparedModel.finalizeFromProperties throws the error from my first post
           end

    end
    
    %% EXAMPLE CODE
    sliderToGround = SliderJoint('slider', ...
        hopper.getGround(), Vec3(0), sliderOrientation, ...
        pelvis,             Vec3(0), sliderOrientation);
     hopper.addJoint(sliderToGround); % I DON'T NEED THOSE FIRST TWO LINES BECAUSE MY JOINT ALREADY EXISTS
     sliderCoord = sliderToGround.upd_coordinates(0);
     sliderCoord.setName('yCoord');
     




Another thing that I realized in the meantime that I can only change the default value of a coordinate using the approach of the first snippet (accesing the coordinate via its joint):

Code: Select all

 pelvis_ground = preparedModel.getJointSet().get('ground_pelvis');
    for i = 0 : pelvis_ground.numCoordinates()-1
        coord =  pelvis_ground.upd_coordinates(i);
        if strcmp(coord.getName(), 'pelvis_ty')
           coord.setDefaultValue(0.0) %--> Coordinate will be changed
        end
    end
If I change it using the second approach via coordinateset, it won't work

Code: Select all

    coordinates = preparedModel.getCoordinateSet();
    for a= 0: coordinates.getSize()-1
        coordinate = coordinates.get(a);
        name = string(coordinate.getName());
       if strcmp( name, 'flexion_r')
           coordinate.setName('hand_flexion_r')
       end
       coordinate.setDefaultValue(0.0);   % --> The change won't be saved in the model
    end
 
What surprises me here, is the fact that I am using successfully that second approach on another model to set my default values.
[I am using an existent model, change it to a "general setting" (which is why I want to change coordinate names) and make then several copies with different scaling factors applied. On those copies I can change the default values with the getCoordinteSet() approach, but on the "generalsetting-model" those changes are not applied."

Thanks again,
Ruth

POST REPLY