Page 1 of 1

calcAngularMomentum() functionality

Posted: Thu Sep 05, 2024 6:40 am
by anushkarathi
Hello! I am fairly new to using OpenSim and am having some trouble with MATLAB scripting. I want to use the calcAngularMomentum() function on the walking data that I have processed. I have a scaled model and have been able to run IK on this model by uploading the file with marker data that I had. I am not sure how this function works however. This is the script I am running in MATLAB, however, I do not think that this takes into account the walking data since I am opening the placed static trial. How do I affiliate the walking data to this?

import org.opensim.modeling.*;
model_path = 'C:\modelPath\\FullBodyModelCGM\CGM24_FullBody\CGM24FullBody_placed.osim';

model = Model(model_path);
state = model.initSystem();
ground_frame = model.getGround();

angular_momentum = model.calcAngularMomentum(state);

Re: calcAngularMomentum() functionality

Posted: Thu Sep 05, 2024 10:00 pm
by nicos1993
Hello Anushka,

For each frame of your walking data you need to set each of your model's coordinates positions [1] and speeds [2] using your IK data.
As an example:

Code: Select all

model.getCoordinateSet.get('coordinate_X').setValue(state,position_data(frame_i, coordinate_X_index);
model.getCoordinateSet.get('coordinate_X').setSpeedValue(state,speed_data(frame_i, coordinate_X_index);
angular_momentum(frame_i, 1:3) = model.calcAngularMomentum(state);
Hope that helps.

Nicos

[1] https://simtk.org/api_docs/opensim/api_ ... f2e88d7c42
[2] https://simtk.org/api_docs/opensim/api_ ... dd7a8febd3

Re: calcAngularMomentum() functionality

Posted: Sat Sep 07, 2024 11:25 pm
by kernalnet
Hi, it might be out of the scope of this post; you can also get angular momentum through OutputReporter.
An example in GUI can be found here: https://opensimconfluence.atlassian.net ... Simulation