How to add a linear actuator to the ToyLandingModel

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mark Golab
Posts: 3
Joined: Wed May 29, 2019 9:34 am

How to add a linear actuator to the ToyLandingModel

Post by Mark Golab » Fri Jul 05, 2019 5:36 am

Hi,

I am trying to add a PointToPointActuator (linear) to the ToyLandingModel to determine the change in length of the actuator when the subtalar_angle_r is at +25 degrees. Ideally I would like to fix the actuator to the tibia_r_geom_2 body and the calcn_r_geom_1 body along the Y axis. This simulation has already been demonstrated in an existing thesis as shown from the image below, however, the code that was used is not provided. I know I have to use the classes, force_length_curve to determine the elastic properties of the actuator, resting_length, and pcsa_force, etc. I suppose I have two questions.
  1. Is it possible to plot the change in length of an actuator as a function of time post simulation?
  2. If the answer to question 1 is yes, is the source code of the ToyLandingModel available to modify? Would someone be able to point me in the right direction as to how to modify the code to produce the desired result.
I am relatively new to using this software and programming, so I would really appreciate some guidance with this.

Thanks
Ligament band.JPG
Ligament band.JPG (27.47 KiB) Viewed 452 times

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: How to add a linear actuator to the ToyLandingModel

Post by jimmy d » Fri Jul 05, 2019 10:57 am

I don't think you want a Point2PointActuator since that class has no Path and won't give you a length between the two points. You are probably after the PathActuator, which will add a Geometry to the model and also has a getLength() method. Below is Matlab code to add a PathActutor

Code: Select all

import org.opensim.modeling.*
model = Model('ToyLandingModel.osim');

pa = PathActuator();

% Set the location of the first point in the tibia frame. These numbers
% were determined from placing a marker on the desired location in the GUI.
tibia = model.getBodySet().get('tibia_r');
pa.addNewPathPoint('pp1',tibia,Vec3(-0.01, -0.4, 0.05));

% Set the locaton of the second point in the Calcn frame
calcn = model.getBodySet().get('calcn_r');
pa.addNewPathPoint('pp2', calcn, Vec3(0.05, 0.015, 0.04));

% Add the force to the model
model.addForce(pa);

% Initialize the sytem
s = model.initSystem();

% Get the length of the acutator
l = pa.getLength(s);

% print model
model.print('ToyLandingModel_pa.osim')
Is it possible to plot the change in length of an actuator as a function of time post simulation?
Post simulation, you could get the coordinate values over time and write a Matlab script that poses the model at each time frame and askes the PathActuator what its length is.
If the answer to question 1 is yes, is the source code of the ToyLandingModel available to modify?
The osim file is the source code. You can open the model in a text editor and edit freely.

User avatar
Mark Golab
Posts: 3
Joined: Wed May 29, 2019 9:34 am

Re: How to add a linear actuator to the ToyLandingModel

Post by Mark Golab » Tue Jul 09, 2019 7:05 am

Hi James,

Thank you for your response, this is very helpful.

Please excuse my lack of knowledge in this area, but how do I add the Matlab code to the ToyLandingModel? I know how to load the ToyLanding model into the GUI using the GUI scripting window. However, I am not too sure how to call and initialise the actuator in the ToyLandingModel in OpenSim.

Do I have to use the GUI command myModel = modeling.Model(modelFileName) to open it?
Do I have to modify the source code of the ToyLandingModel so that it calls the actuator?
I assume I have to set the variable 'model' in the code you sent?

Some help with this would be greatly appreciated.
Thanks,

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: How to add a linear actuator to the ToyLandingModel

Post by jimmy d » Tue Jul 09, 2019 9:26 am

If you haven't done any scripting before it would be good to go through some of the documentation on how to use Matlab or Python to edit and simulate models. The Scripting and Development Page is a good place to start. Do you use Matlab? If so you can set Matlab up to work with OpenSim.

User avatar
Mark Golab
Posts: 3
Joined: Wed May 29, 2019 9:34 am

Re: How to add a linear actuator to the ToyLandingModel

Post by Mark Golab » Thu Jul 11, 2019 9:39 am

I have set-up the matlab scripting environment and loaded the OpenSim libraries as shown from the code below

Code: Select all

> org.opensim.modeling.opensimCommon.GetVersion()
ans =
4.0
>> import org.opensim.modeling.*
>> methods Model
>> methods org.opensim.modeling.Model
>> methods Muscle
I've been through the scripting and development page but I still can't figure out why MATLAB won't generate a .osim when I click run on the MATLAB code you provide, I have saved it as brace.m, I just get the error code shown in the code below. Do I need to change 'model' to 'brace'?

Code: Select all

>> brace
Index exceeds Java array dimensions

Error in brace (line 1)
model = model('ToyLandingModel.osim');
Would you be able to advise what to do here? sorry for my lack of knowledge.
Thanks

User avatar
Thomas Uchida
Posts: 1777
Joined: Wed May 16, 2012 11:40 am

Re: How to add a linear actuator to the ToyLandingModel

Post by Thomas Uchida » Thu Jul 11, 2019 4:13 pm

model = model('ToyLandingModel.osim');
The second "model" should be "Model" (capitalized), as shown in James's code.

POST REPLY