Unlock Coordinates in Scaled model in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Maud Hendriksen
Posts: 20
Joined: Thu May 14, 2020 12:00 am

Unlock Coordinates in Scaled model in Matlab

Post by Maud Hendriksen » Tue Jul 21, 2020 12:46 am

Hi all,

I have a question regarding my scaled model. I have scaled my model through matlab. The original model had locked coordinates in the knee, hip and ankle for scaling. Now my scaled model has locked coordinates as well in these joints, however, for inverse kinematics I have to get them unlocked. Is there a way to do this through matlab? I have 50 participants, so this would be much easier than doing it manually in OpenSim. I have tried to use the coordinate class and setlocked in the API, but it did not seem to work. Is there anyone that has had the same problem? Any help would be greatly appreciated.
Kind regards,
Maud

Tags:

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

Re: Unlock Coordinates in Scaled model in Matlab

Post by Thomas Uchida » Wed Jul 22, 2020 4:43 am

The Coordinate::setLocked() method should work (https://simtk.org/api_docs/opensim/api_ ... 4de7213eb3). See the example in the README.md file on GitHub (https://github.com/opensim-org/opensim-core; scroll down to the bottom of the "Simple example" section and expand "Matlab"):

Code: Select all

shoulder.getCoordinate().setLocked(state, true);
A code snippet would be helpful if you're having trouble debugging.

User avatar
Maud Hendriksen
Posts: 20
Joined: Thu May 14, 2020 12:00 am

Re: Unlock Coordinates in Scaled model in Matlab

Post by Maud Hendriksen » Wed Jul 29, 2020 12:31 am

Thank you for your reply. I have looked at the example in the README.md file. The thing that I don't understand is how to change it for a couple of joints. I would like to unlock coordinates in my scaled Gait2354 model in which I locked some coordinates before scaling and now would like to unlock. I want to unlock:
pelvis_tilt
knee_angle_r and left
ankle_angle_r and left and
hip_flexion_r and left.
If I achieve this all coordinates will be unlocked. In the .osim file the coordinate which I would like to change is called pelvis-tilt, but I realized that it is not as simple as filling in pelvis_tilt instead of shoulder. The thing I am struggling with is how to run this getCoordinate().setLocked(state, true); for the specific coordinates.

Code: Select all

modelIK_file = dir(strcat(folder_scaledmodel, patient,'_scaled_finished_model.osim'));

modelIK = Model(fullfile(modelIK_file.folder, modelIK_file.name));
state = modelIK.initSystem();
pelvis_tilt.getCoordinate().setLocked(state, true);
Could you please help me with my problem? It is probably not that hard, but I really don't know how to fix it.

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

Re: Unlock Coordinates in Scaled model in Matlab

Post by Thomas Uchida » Wed Jul 29, 2020 8:18 am

pelvis_tilt.getCoordinate().setLocked(state, true);
You have not included the line where you're defining the "pelvis_tilt" variable. Something like this should work:

Code: Select all

coord = myModel.getCoordinateSet().get('pelvis_tilt')
coord.setLocked(myState, True)

User avatar
Maud Hendriksen
Posts: 20
Joined: Thu May 14, 2020 12:00 am

Re: Unlock Coordinates in Scaled model in Matlab

Post by Maud Hendriksen » Fri Jul 31, 2020 5:15 am

Thank you! Do I also need to update the model? Right now the .osim model file has not changed.

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

Re: Unlock Coordinates in Scaled model in Matlab

Post by Thomas Uchida » Sun Aug 02, 2020 6:46 am

Do I also need to update the model? Right now the .osim model file has not changed.
If you want the .osim file to change, you need to save the new model to file. I suggest looking at the Matlab examples in your Resources directory (e.g., "C:\OpenSim 4.1\Resources\Code\Matlab").

User avatar
Maud Hendriksen
Posts: 20
Joined: Thu May 14, 2020 12:00 am

Re: Unlock Coordinates in Scaled model in Matlab

Post by Maud Hendriksen » Mon Aug 03, 2020 1:53 am

Thank you! now its working

User avatar
Evan Dooley
Posts: 33
Joined: Sun Nov 24, 2019 11:17 am

Re: Unlock Coordinates in Scaled model in Matlab

Post by Evan Dooley » Mon Oct 11, 2021 2:42 pm

I was attempting something similar and was using this thread for tips. Ultimately, this is the combination I ended up with that actually changed the coordinates in the model (.osim) file. Hope it speeds things up for the next person trying to figure this out, because as Maud pointed out: it is very handy if you have lots of participants/trials.

Code: Select all

model.updCoordinateSet().get('mtp_angle_r').setDefaultLocked(false);
model.updCoordinateSet().get('subtalar_angle_r').setDefaultLocked(false);
model.updCoordinateSet().get('mtp_angle_l').setDefaultLocked(false);
model.updCoordinateSet().get('subtalar_angle_l').setDefaultLocked(false);
**Note = 'mtp_angle_r' (etc) are the strings of the names of the coordinates I was trying to default to unlocked, change this part if you are trying to unlock/lock other coordinates in the default position

Best,
Evan

POST REPLY