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
Unlock Coordinates in Scaled model in Matlab
- Maud Hendriksen
- Posts: 20
- Joined: Thu May 14, 2020 12:00 am
- Thomas Uchida
- Posts: 1792
- Joined: Wed May 16, 2012 11:40 am
Re: Unlock Coordinates in Scaled model in Matlab
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"):
A code snippet would be helpful if you're having trouble debugging.
Code: Select all
shoulder.getCoordinate().setLocked(state, true);
- Maud Hendriksen
- Posts: 20
- Joined: Thu May 14, 2020 12:00 am
Re: Unlock Coordinates in Scaled model in Matlab
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.
Could you please help me with my problem? It is probably not that hard, but I really don't know how to fix it.
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);
- Thomas Uchida
- Posts: 1792
- Joined: Wed May 16, 2012 11:40 am
Re: Unlock Coordinates in Scaled model in Matlab
You have not included the line where you're defining the "pelvis_tilt" variable. Something like this should work:pelvis_tilt.getCoordinate().setLocked(state, true);
Code: Select all
coord = myModel.getCoordinateSet().get('pelvis_tilt')
coord.setLocked(myState, True)
- Maud Hendriksen
- Posts: 20
- Joined: Thu May 14, 2020 12:00 am
Re: Unlock Coordinates in Scaled model in Matlab
Thank you! Do I also need to update the model? Right now the .osim model file has not changed.
- Thomas Uchida
- Posts: 1792
- Joined: Wed May 16, 2012 11:40 am
Re: Unlock Coordinates in Scaled model in Matlab
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").Do I also need to update the model? Right now the .osim model file has not changed.
- Maud Hendriksen
- Posts: 20
- Joined: Thu May 14, 2020 12:00 am
Re: Unlock Coordinates in Scaled model in Matlab
Thank you! now its working
- Evan Dooley
- Posts: 33
- Joined: Sun Nov 24, 2019 11:17 am
Re: Unlock Coordinates in Scaled model in Matlab
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.
**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
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);
Best,
Evan