Page 1 of 1
Set up Integrator and Manager for Simulation in Matlab
Posted: Tue Dec 13, 2016 5:23 am
by steidlr
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
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Tue Dec 13, 2016 10:57 am
by jimmy
What version of OpenSim are you using?
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Tue Dec 13, 2016 7:40 pm
by tkuchida
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:
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Wed Dec 14, 2016 5:31 am
by steidlr
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
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Wed Dec 14, 2016 1:05 pm
by tkuchida
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).
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Thu Dec 15, 2016 1:52 am
by steidlr
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
I only see the OpenSim classes and can use them - but non of the SimTK classes! What did I do wrong?
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Thu Dec 15, 2016 4:17 am
by tkuchida
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);
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Thu Dec 15, 2016 4:32 am
by steidlr
Great Job Tom,
now it works fine and I can generate .mot and .sto files for the states without crashing Matlab
The most important line was
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
Re: Set up Integrator and Manager for Simulation in Matlab
Posted: Thu Dec 15, 2016 5:21 am
by tkuchida
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.