Calling static optimization from main program

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Michael Hardegger
Posts: 1
Joined: Thu Feb 25, 2010 2:44 am

Calling static optimization from main program

Post by Michael Hardegger » Tue Mar 23, 2010 8:48 am

I'd like to call static optimization within a main program as I need muscle forces to calculate some other data (only at one moment in time). The inputs would be measured coordinate positions, velocities and accelerations.

Therefore I wanted to find out how I can call an analysis within a main program. For MuscleAnalysis, it worked when I just instantiated the class and then called A.begin(State); A.step(State,1); A.end(State);

When I call StaticOptimization like that, I get an error. Also, I wondered how I can set the measured coordinate accelerations, since the state only contains coordinate position and velocity (and the muscle information, which I want to find).

Probably I do something completely wrong ... I'd appreciate any kind of help!!! Unfortunately there isn't a lot of information in the guide about static optimization.

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

RE: Calling static optimization from main program

Post by Ayman Habib » Tue Mar 23, 2010 4:03 pm

Hi Michael,

For analyses/tools that do not modify the model your approach for the MuscleAnalysis should work (e.g. PointKinematics, Kinematics, Actuation) since the analyses work on the actual model being analyzed. In situations where the analysis modifies the model (e.g by optionally adding forces ala ID, SO) this doesn't work.

We're refactoring this part of the API to make it possible to do these operations more smoothly in the future, so stay tuned.

Accelerations can't be set since they are computed based on the model and forces applied to it (that's how we guarantee that f=ma).

Hope this explains,
-Ayman

User avatar
Marc Carmichael
Posts: 45
Joined: Thu Jul 16, 2009 2:50 am

RE: Calling static optimization from main program

Post by Marc Carmichael » Mon May 17, 2010 12:37 am

Hi everyone.

From the sounds of it I am hoping to do something similar to Michael. I wish to use the OpenSim API to load a model, set the state (joint angles, external forces, etc) and then perform static optimization to calculate the forces in the individual muscles.

But I too am having trouble implementing this via the API. The following is the code I use after I have loaded the model and set the model's state:


osimModel.equilibrateMuscles(si);
osimModel.computeEquilibriumForAuxiliaryStates(si);

// Perform static optimization for current state
StaticOptimization* staticoptimizer = new StaticOptimization(&osimModel);

osimModel.updAnalysisSet().append(staticoptimizer);

staticoptimizer->begin(si);


The program crashes, unless I comment out the staticoptimizer->begin(si) line. Is there something I am supposed to initialize before I run this? Sorry I am pretty new to this, any help is greatly appreciated.

Marc

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

RE: Calling static optimization from main program

Post by Ayman Habib » Mon May 17, 2010 2:09 pm

Marc,

Considering that we're doing some rework on the Analysis/Tools API I'd suggest that you do not use this level of the API for now to run StaticOptimization. An alternative, if you can run Static Optimization on your model in the GUI, is saving the settings file from the GUI (for example StaticOptimizationSetup.xml). Then you can instantiate an "AnalyzeTool" using the setup file and run the analyses, the code would look like this:

AnalyzeTool tool("StaticOptimizationSetup.xml");
tool.run();

you may need to reconstruct the results back from a file after the run is finished. It's a little awkward but should be workable. Please let me know if you have questions or need help regarding this approach.

Best,
-Ayman

User avatar
Marc Carmichael
Posts: 45
Joined: Thu Jul 16, 2009 2:50 am

RE: Calling static optimization from main program

Post by Marc Carmichael » Sun Aug 08, 2010 11:03 pm

Hello,

I thought I would give this thread a fresh bump since I have been trying to solve this problem for some time and have made little progress.

What I am trying to do is perform static optimization of a model via the API. I can't use the GUI because I am using the linux version of OpenSim, and I do not have a mot file of a motion to perform the analysis on, since I am only interested in a single static pose which I define from the model's generalized coordinates.

I am confused how OpenSim goes about performing the static optimization. Because I dont have the GUI source code I can't track back the steps to perform it on a motion. I would have thought to perform this on a single static pose would be simple but it appears the API functions aren't designed to be used in this way?

So I guess what I am asking is more help or explanation on the steps the OpenSim GUI takes when performing its static optimization. For example does it work the the following way?...

1) Create and set up an AnalyzeTool
2) Create an AnalysisSet
3) Create and initialize a StaticOptimization analysis
4) Create a storage class for storing resluts
5) Load the static state into the StaticOptimization analysis
6 ) ...

I am thinking these are the kind of steps the OpenSim GUI takes, but if someone could actually tell me how it works (and maybe in a bit more detail) it would help me a lot.

If this cannot be done easily, I am considering making my own static optimization using the SimTK Optimizer. I would call it something like "StaticPoseOptimization" and it would compute the optimal muscle activation for a single state (not a motion) assuming static conditions. It would be a great help if someone could tell me how the current StaticOptimization goes about performing this (for example what OpenSim/SimTK functions does it use, and in what procedure?).

Any help is greatly appreciated. OpenSim is a fantastic program, just a little difficult to integrate with the low level functions without all the source code :)

Cheers

Marc

POST REPLY