Set up Integrator and Manager for Simulation in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Robert Steidl
Posts: 16
Joined: Tue Nov 24, 2015 3:03 am

Set up Integrator and Manager for Simulation in Matlab

Post by Robert Steidl » Tue Dec 13, 2016 5:23 am

Good evening,

i try to implement an integrator in MatLab with the following Code:

Code: Select all

numInt = model.getMultibodySystem();
numInt.setAccuracy = 0.0001;
When I ran my m-file the error occurs: "Undefined function or variable setAccuracy"! Does anyone can help me with that issue? Maybe I have to declare a special integrator (for example RungeKotta) but i did not get that!

Hope you can help me,
Robert

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

Re: Set up Integrator and Manager for Simulation in Matlab

Post by jimmy d » Tue Dec 13, 2016 10:57 am

What version of OpenSim are you using?

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

Re: Set up Integrator and Manager for Simulation in Matlab

Post by Thomas Uchida » Tue Dec 13, 2016 7:40 pm

1. getMultibodySystem() returns a MultibodySystem, not an integrator. There is no setAccuracy() method on MultibodySystem (see https://simtk.org/api_docs/simbody/3.5/ ... ystem.html).

2. setAccuracy() is a method, not a field; the accuracy would be set by calling something like the following:

Code: Select all

myIntegrator.setAccuracy(1e-6);

User avatar
Robert Steidl
Posts: 16
Joined: Tue Nov 24, 2015 3:03 am

Re: Set up Integrator and Manager for Simulation in Matlab

Post by Robert Steidl » Wed Dec 14, 2016 5:31 am

Thank you for your answers,

@James: I am using OpenSim 3.3

@ Tom: Alright, I get that with the MultibodySystem now and referring to the method setAccuracy() - i have it in the right way in my code, but addes it wrong here!

As you might know - I try to complete the Tutorial: Performing a Simulation Part Two - and as you might know the call the RungeKotta Integrator with that code-line:

Code: Select all

SimTK::RungeKottaMersonIntegrator integrator(osimModel.getMultibodySystem());
integrator.setAccuracy(1.0e-4);
Manager manager(osimModel, integrator);
And I did not get that lines work in MatLab - do you have a suggestion for that?

Greetings from Vienna
Robert

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

Re: Set up Integrator and Manager for Simulation in Matlab

Post by Thomas Uchida » Wed Dec 14, 2016 1:05 pm

The name of the class is RungeKuttaMersonIntegrator (the mathematician's name was Kutta, with a "u"). Here's the doxygen documentation: https://simtk.org/api_docs/simbody/3.5/ ... rator.html).

User avatar
Robert Steidl
Posts: 16
Joined: Tue Nov 24, 2015 3:03 am

Re: Set up Integrator and Manager for Simulation in Matlab

Post by Robert Steidl » Thu Dec 15, 2016 1:52 am

Hallo,

could it be that I only have access to the OpenSim classes and no access to the SimTK classes (as the RungeKutta.. is for example) from MatLab?? I do import the libraries with

Code: Select all

import org.opensim.modeling.*
I only see the OpenSim classes and can use them - but non of the SimTK classes! What did I do wrong?

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

Re: Set up Integrator and Manager for Simulation in Matlab

Post by Thomas Uchida » Thu Dec 15, 2016 4:17 am

Thanks for clarifying. Some of the SimTK classes are not wrapped and access/modification via Matlab is limited. In this case, you can do the following:

Code: Select all

import org.opensim.modeling.*
model = Model('myModel.osim');
manager = Manager(model);  %constructs an integrator internally
manager.setIntegratorAccuracy(1e-6);

User avatar
Robert Steidl
Posts: 16
Joined: Tue Nov 24, 2015 3:03 am

Re: Set up Integrator and Manager for Simulation in Matlab

Post by Robert Steidl » Thu Dec 15, 2016 4:32 am

Great Job Tom,

now it works fine and I can generate .mot and .sto files for the states without crashing Matlab :D

The most important line was

Code: Select all

manager = Manager(model);
Because I missed to add the model to the Manager and therefore it did not work!
Another question - do I know which integrator is taken now? Where can I see or maybe change that?

Thank you again for your great help

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

Re: Set up Integrator and Manager for Simulation in Matlab

Post by Thomas Uchida » Thu Dec 15, 2016 5:21 am

The Doxygen documentation for Manager (https://simtk.org/api_docs/opensim/api_ ... nager.html) might have helped: it lists three constructors, one of which "takes a model only and builds integrator internally".
do I know which integrator is taken now?
The documentation doesn't indicate what type of integrator is built and I can't see a method that you can call from Matlab to find out, but the source code for Manager::Manager(Model& model) (https://github.com/opensim-org/opensim- ... er.cpp#L53) shows that a SimTK::RungeKuttaMersonIntegrator is constructed internally.
Where can I see or maybe change that?
There's a setIntegrator() method on Manager, but the argument is a pointer to a SimTK::Integrator so I don't think that is possible from Matlab. If your work requires that you use a particular integrator, you could move to C++. You might be able to use one of Matlab's integrators as well (see the Dynamic Walking Challenge Example here: http://simtk-confluence.stanford.edu:80 ... Id=5113821), though I wouldn't recommend adding that complexity unless RungeKuttaMersonIntegrator is intolerable for some reason.

POST REPLY