Hi,
I am working on a Matlab script that calculates state derivatives of the model, given the state and control inputs.
This is a part of my optimization simulation. When I used the script on some simple models (TugofWar, arm26, leg6dof9musc), the results on OpenSim 4.0 and OpenSim 3.3 are the same. However, when I ran on the full body model (subject01, copied from OpenSim 4.0 folder), the results on OpenSim 4.0 and OpenSim 3.3 are significantly different (order of 10, 100 times). The differences are in the derivatives of velocities and muscle lengths. I have tried a couple things with the subject01 model:
1, removed all muscles (Millard model), the problem was not solved.
2, tried to remove the knee joint in the model (removed all bodies after knee, removed all muscles), the problem was solved. I suspect the problem is at the custom knee joint in the subject01.osim model because OpenSim 4.0 updated the custom joint. However, the leg6dof9musc model also has a custom knee joint.
3, opened subject01.osim model and saved the model in 4.0 version. Then ran the scripts with the models corresponding to the OpenSim versions, the problem was not solved.
At this point, I am not sure what causes the problem, and how to fix it.
Any advice and feedback would be appreciated!
Thanks in advance.
Vinh
Different results when using different OpenSim versions
- Vinh Nguyen
- Posts: 21
- Joined: Fri Sep 26, 2014 8:53 pm
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Different results when using different OpenSim versions
Please see the "Upgrade Notes for OpenSim 4.0" page in the Confluence documentation (https://simtk-confluence.stanford.edu/d ... penSim+4.0), under the "Upgrading your model files" heading, bullet 4: "If you are using models with CustomJoints that have coupled motion...".
- Vinh Nguyen
- Posts: 21
- Joined: Fri Sep 26, 2014 8:53 pm
Re: Different results when using different OpenSim versions
Thanks Dr. Uchida for your reply.
I was able to open the model subject01.osim in OpenSim 4.0. I did not get any warning about motion types.
I tried to change the motion type of "knee_angle_r" and "knee_angle_l" in the model from "rotational" to "coupled". Then when I opened in OpenSim 4.0, I got the warning says:
"Coordiate 'knee_angle_r' was labeled as 'Coupled' but was found to be 'Rotational' based on the joint definition.
Coordiate 'knee_angle_l' was labeled as 'Coupled' but was found to be 'Rotational' based on the joint definition..."
I am confused here about what should I change to make the model correct.
I was able to open the model subject01.osim in OpenSim 4.0. I did not get any warning about motion types.
I tried to change the motion type of "knee_angle_r" and "knee_angle_l" in the model from "rotational" to "coupled". Then when I opened in OpenSim 4.0, I got the warning says:
"Coordiate 'knee_angle_r' was labeled as 'Coupled' but was found to be 'Rotational' based on the joint definition.
Coordiate 'knee_angle_l' was labeled as 'Coupled' but was found to be 'Rotational' based on the joint definition..."
I am confused here about what should I change to make the model correct.
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Different results when using different OpenSim versions
It is difficult to say for sure without knowing what methods your script is calling. However, another thing you might want to check is whether your rotational coordinates are being reported in the same units as before (degrees vs. radians). The change in how some CustomJoints are interpreted may lead to different units being reported.I am working on a Matlab script that calculates state derivatives of the model, given the state and control inputs. This is a part of my optimization simulation. When I used the script on some simple models (TugofWar, arm26, leg6dof9musc), the results on OpenSim 4.0 and OpenSim 3.3 are the same. However, when I ran on the full body model (subject01, copied from OpenSim 4.0 folder), the results on OpenSim 4.0 and OpenSim 3.3 are significantly different (order of 10, 100 times).
- Vinh Nguyen
- Posts: 21
- Joined: Fri Sep 26, 2014 8:53 pm
Re: Different results when using different OpenSim versions
Hi Dr. Uchida,
The differences are only in the derivatives of velocities and the derivatives of muscle lengths. The derivatives of positions and and the derivatives of muscle activations are the same for both OpenSim versions. And here is an sample of the derivatives of the velocities:
OpenSim 3.3: -4305.01442914287 124.831702169798 -253.786282436156 7123.32353700211 -5884.10975305196
OpenSim 4.0: -3931.64464945090 78.4693438216204 -286.531075197484 5939.48126368199 6393.03786948105
Therefore, it does not seem to be the problem of units (degree, radian).
I put here the code that I used for calculating the state derivatives in case you could take a look.
The differences are only in the derivatives of velocities and the derivatives of muscle lengths. The derivatives of positions and and the derivatives of muscle activations are the same for both OpenSim versions. And here is an sample of the derivatives of the velocities:
OpenSim 3.3: -4305.01442914287 124.831702169798 -253.786282436156 7123.32353700211 -5884.10975305196
OpenSim 4.0: -3931.64464945090 78.4693438216204 -286.531075197484 5939.48126368199 6393.03786948105
Therefore, it does not seem to be the problem of units (degree, radian).
I put here the code that I used for calculating the state derivatives in case you could take a look.
Code: Select all
%% Calculate the derivatives of positions, velocities, muscle lengths, muscle activations
% Update model state with current values
osimState.setTime(0);
numVar = osimState.getNY();
for i = 0:numVar-1
osimState.updY().set(i, states_input(i+1)); % states_input is an vector of state values
end
% Update the state derivative calculations
osimModel.computeStateVariableDerivatives(osimState);
% Create a model control vector
modelControls = Vector(Ncontrols, 0.0);
% Pass control values into a control vector
for i = 0:Ncontrols-1
modelControls.set(i, controls_input(i+1));
end
% Input control vector
osimModel.setControls(osimState,modelControls);
% Update the state derivative calculations
osimModel.computeStateVariableDerivatives(osimState);
% Set output variable to Matlab vector
x_dot = zeros(numVar,1);
for i = 0:numVar-1
x_dot(i+1,1) = osimState.getYDot().get(i);
end
x_dot = x_dot'