Page 1 of 1
Opensim and Matlab
Posted: Mon Oct 22, 2018 11:22 pm
by arashopensim
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
Re: Opensim and Matlab
Posted: Tue Oct 23, 2018 4:55 am
by anacsousa
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.
Re: Opensim and Matlab
Posted: Tue Oct 23, 2018 2:40 pm
by chrisdembia
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
Re: Opensim and Matlab
Posted: Sat Oct 27, 2018 5:07 pm
by arashopensim
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?
Thank you so much.
best,
Arash