Extracting Kinematics Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mikael Koeneke
Posts: 4
Joined: Wed Jul 10, 2019 10:23 am

Extracting Kinematics Matlab

Post by Mikael Koeneke » Wed Jul 01, 2020 8:05 am

Hello everyone,
My partner and I are trying to extract kinematics data using Matlab in order to replicate the OpenSim Plotter (elbow flexion vs moment). We are aware that the plotter is not accessible from the API. We were successful in accessing the Millard2012EquilibriumMuscle class, but are having trouble updating the state variable based on elbow flexion. Is it possible to extract kinematics data similar to the plotter?
Thanks.

Tags:

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Extracting Kinematics Matlab

Post by Ayman Habib » Wed Jul 01, 2020 10:29 am

Hi Mikael,

While the plotter functionality in the application is not accessible through the API directly, the plotter internally uses the API to create the plots. Depending on what you want to calculate you can utilize the OutputReporter with the AnalyzeTool. Check the examples included in the distribution under <resources folder>\Code\Matlab\Examples, in particular wiring_inputs_and_outputs_with_TableReporter to see how to extract quantities/outputs from a state, and let us know if you continue to have questions.

Best regards,
-Ayman

User avatar
Michael Asmussen
Posts: 67
Joined: Mon Jul 11, 2016 7:46 am

Re: Extracting Kinematics Matlab

Post by Michael Asmussen » Fri Jul 03, 2020 3:37 pm

Hi Mikael,

I will also add that if you want to access, for example, the elbow flexion angle, you could use "OModel.getCoordinateSet().get('elbow_angle_r')".

That line of code assumes that you define your model in matlab as "OModel" and that there is an elbow flexion coordinate for the right arm (i.e., define the coordinate in the parentheses that you wish to extract).

All the best,

Mike

User avatar
Mikael Koeneke
Posts: 4
Joined: Wed Jul 10, 2019 10:23 am

Re: Extracting Kinematics Matlab

Post by Mikael Koeneke » Mon Jul 06, 2020 10:36 am

Hello Michael and Ayman,
We have the coordinate data extracted as the name "elbflex". We're running a loop where j = 100 equally spaced points between 0 and 2.26 radians. Each loop we're setting the coordinate using elbflex.setValue(state, j). Then inside of that it loops between all the muscles in the model, where it calculates the moment arm using .computeMomentArm(state, elbflex()). We are trying to find the moment output from all the muscles at that certain coordinate, so we were going to use the force length curves to find the force output for each muscle, then multiply that by Moment arm to get moment. An issue we are running into is that when we extract the normalized fiber lengths and velocities using .getNormalizedFiberLength(state) and .getNormalizedFiberVelocity(state), they return the same values at different coordinates (i.e. DELT1 returns a normalized fiber length of 0.9956 for each coordinate). This got us thinking that maybe we were not updating the state correctly, or that coordinate data isn't held within the state. This is our main issue. Thank you for your time.
Mikael

User avatar
Mikael Koeneke
Posts: 4
Joined: Wed Jul 10, 2019 10:23 am

Re: Extracting Kinematics Matlab

Post by Mikael Koeneke » Tue Jul 07, 2020 1:05 pm

Also Ayman,

In the wiring_inputs_and_outputs code, I'm assuming the lines:

manager = Manager(deserializedModel);
state.setTime(0);
manager.initialize(state);
state = manager.integrate(1.0);

update the state? Do we have to set a time variable in order for a state to update? Right now in our code, we want the state to update with the elbow flexion coordinates so that we can get the normalized fiber lengths. Is that possible without setting a time variable? I went into more detail about it in the previous post.
Thank you for your help.
Mikael

POST REPLY