Opensim and Matlab

The 2018 Fall Virtual Workshop will bring together a group of international scholars and OpenSim experts to help each other advance their research using modeling and simulation. This forum is a place to accelerate OpenSim based projects while also buildin
POST REPLY
User avatar
Arash Mohammadzadeh Gonabadi
Posts: 34
Joined: Sun Sep 10, 2017 10:44 am

Opensim and Matlab

Post by Arash Mohammadzadeh Gonabadi » Mon Oct 22, 2018 11:22 pm

Hello all,

I have a question about OpenSim through Matlab.
How can we display and play the final model with its motion through Matlab to see the animation? I couldn't find the command in Matlab.
Thanks.

Best,
Arash

User avatar
Ana de Sousa
Posts: 67
Joined: Thu Apr 07, 2016 4:21 pm

Re: Opensim and Matlab

Post by Ana de Sousa » Tue Oct 23, 2018 4:55 am

Hello Arash,

I do not know if Matlab opens OpenSim and starts the animation. What I do is the following:

1) I create an .sto file for visualization
2) I open the OpenSim GUI
3) I open the model and load the .sto

My code for creating the visualization file:

Nsamples = length(motionData.data(:,1)); Nstates = length(statesNames); %motionData is the return from "IntegrateOpenSimPlant" function

str = strjoin(statesNames,'\t'); %variable with the names of the states
header = ['gait_simulation \nversion=1 \nnRows=' num2str(Nsamples) ' \nnColumns=' num2str(Nstates+1) '\ninDegrees=no \nendheader \ntime ' str '\n']; % create the header of the .sto file
fid = fopen('Results/gait_simulation.sto','wt'); %open the file
fprintf(fid,header); fclose(fid); % print the header
fid = fopen('Results/gait_simulation.sto','a+');
for i = 1:Nsamples
fprintf(fid,'\t%f',motionData.data(i,:)); fprintf(fid,'\n'); % print the states
end
fclose(fid); %close the file

That is working fine for me, I hope it helps.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Opensim and Matlab

Post by Christopher Dembia » Tue Oct 23, 2018 2:40 pm

You can also use the Simbody Visualizer through Matlab. Use "model.setUseVisualizer(true)" right after constructing your model. If you are using 4.0, you can see the following example, which uses the visualizer for a forward simulation: https://github.com/opensim-org/opensim- ... isualize.m

User avatar
Arash Mohammadzadeh Gonabadi
Posts: 34
Joined: Sun Sep 10, 2017 10:44 am

Re: Opensim and Matlab

Post by Arash Mohammadzadeh Gonabadi » Sat Oct 27, 2018 5:07 pm

Hello,

Thank you so much for your help. I tested "model.setUseVisualizer(true)" previously, but unfortunately it did not work, and I was wondering what is my mistake.
Would it be possible to take a look at the following file and run it with Matlab?
Gait2392_Simbody_Matlab_Arash.rar
(445.72 KiB) Downloaded 31 times
Thank you so much.

best,
Arash

POST REPLY