Page 1 of 2

Visualization a model

Posted: Mon May 04, 2020 10:27 am
by hamed1994
hello dear all,

I have difficulty in visualization of a model through MATLAB. could you give me a step by step to-do list or maybe the code which I have to run?
And I'd better say that I have created the interface between the two software.

Thanks and the Best,
Hamed

Re: Visualization a model

Posted: Tue May 05, 2020 5:11 am
by tkuchida
There is an example on the GitHub page here: https://github.com/opensim-org/opensim-core (scroll down to the "Simple example" heading and expand the "Matlab" section).

Re: Visualization a model

Posted: Tue May 05, 2020 9:55 am
by hamed1994
thank you so much, that was helpful.
I want to visualize Arm26. what should I do at this step?

Re: Visualization a model

Posted: Thu May 07, 2020 12:14 pm
by hamed1994
tkuchida wrote:
Tue May 05, 2020 5:11 am
There is an example on the GitHub page here: https://github.com/opensim-org/opensim-core (scroll down to the "Simple example" heading and expand the "Matlab" section).
where can I find the Arm26 model code to visualize in MATLAB ? as the example for arm model you previously sent me.
could you please help me ?

thank you
Hamed

Re: Visualization a model

Posted: Thu May 07, 2020 2:52 pm
by tkuchida
where can I find the Arm26 model code to visualize in MATLAB ?
You can just adapt the code from the example on GitHub to read in a model file rather than building the model programmatically, something like this:

Code: Select all

import org.opensim.modeling.*
arm = Model('arm26.osim');
arm.setUseVisualizer(true);
state = arm.initSystem();
% etc.

Re: Visualization a model

Posted: Sat May 09, 2020 11:49 am
by hamed1994
I replaced the code you sent with the first part of the code on Github, and ran it but nothing will appear and I face this error

Code: Select all

Java exception occurred:
java.io.IOException: Object: Cannot open file arm26.osim. It may not exist or you do not have
permission to read it.
	Thrown at object.cpp:105 in Object().

	at org.opensim.modeling.opensimSimulationJNI.new_Model__SWIG_1(Native Method)

	at org.opensim.modeling.Model.<init>(Model.java:783)
what should I do here ? could you help me with this please ?

Re: Visualization a model

Posted: Sun May 10, 2020 7:40 am
by tkuchida
Cannot open file arm26.osim. It may not exist or you do not have
permission to read it.
Matlab can't find the arm26.osim file. Easiest solution is to copy it into the same directory as your script.

Re: Visualization a model

Posted: Wed May 13, 2020 10:35 am
by hamed1994
Hello, hope you having good time.

I copied arm26.osim file to the Current Folder in MATLAB and ran the following code

Code: Select all

import org.opensim.modeling.*
arm = Model('arm26.osim');
arm.setUseVisualizer(true);
state = arm.initSystem();
% etc.
the problem about java exception didn't appear and the following window opened, but nothing shows in there. what's the problem ?
Screenshot (24).png
Screenshot (24).png (113.73 KiB) Viewed 429 times

Re: Visualization a model

Posted: Thu May 14, 2020 8:53 am
by tkuchida
the problem about java exception didn't appear and the following window opened, but nothing shows in there. what's the problem ?
The last line ("etc.") means that you should fill in the rest of the code from the example (sorry if that was not clear). Here is the code in full (my best guess, at least, since I don't have Matlab set up to test it):

Code: Select all

import org.opensim.modeling.*
arm = Model('arm26.osim');
arm.setUseVisualizer(true);
state = arm.initSystem();
% Fix the shoulder at its default angle and begin with the elbow flexed.
shoulder.getCoordinate().setLocked(state, true);
elbow.getCoordinate().setValue(state, 0.5 * pi);
arm.equilibrateMuscles(state);
% Configure the visualizer
viz = arm.updVisualizer().updSimbodyVisualizer();
viz.setBackgroundColor(Vec3(0)); % white
viz.setGroundHeight(-2)
% Simulate.
manager = Manager(arm);
state.setTime(0);
manager.initialize(state);
state = manager.integrate(10.0);

Re: Visualization a model

Posted: Fri May 15, 2020 11:18 pm
by hamed1994
thank you for your help in advance,
I copied the code into the command window of matlab and ran it which you sent me, but I faced the following problem. what's wrong with it ?
Screenshot (25).png
Screenshot (25).png (160.49 KiB) Viewed 397 times