API tips and tricks

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Marc Carmichael
Posts: 45
Joined: Thu Jul 16, 2009 2:50 am

API tips and tricks

Post by Marc Carmichael » Mon Aug 09, 2010 1:01 am

Hello everyone,

I have been using OpenSim's API for a little while now, and it is great for performing analyses not based on motion capture data. However understanding the operation of the low level functions is sometimes challenging. I have a few questions on making life easier with the API, and thought I would combine it into a single thread. Here are a few questions:


1) Is there a function which returns the coordinate indices of the generalized coordinates only? At the moment I implement a loop which goes through every coordinate, and record its index if its 'isConstrained()' is false.


2) Is there a function for calculating the torque at the joints required to statically oppose gravity? (i.e no external forces, velocity or accelerations)? In robotics this is usually referred to as the gravity or 'g' vector, and is a function of the generalized coordinates.


3) Similar to the previous question, is there a function that calculates the joint torque required to statically oppose external forces on the model? (not taking into account gravity or dynamics)


4) Is there a simple way of performing static optimization on a single model pose via API, not using a mot file? I have asked this in another thread (https://simtk.org/forum/message.php?msg_id=3697) but I thought I may as well ask again here.


5) Is there a way of quickly extracting the Jacobian from the model in a current pose? I noticed there are some "formJacobian" functions in the SimbodyEngine class, can these be used for this?


6) Is there a sneaky way of performing an analysis which is typically done using a mot or sto file, but using a single (or a small number) of states I define in my code? If so then this might be able to solve some of these questions. For example, I could perform an ID analysis on two identical states, and because there is zero displacement between the two then that essentially would solve question (2) if there are no external forces, or solve question (3) if I set gravity to zero. If this is possible then how can it be done without using a mot or sto file? (maybe a solution is to load the states into a Storage class and have the analysis read it from there? Can this be done?)



I have many questions but I think that's enough for now :) I think using OpenSim through the API is a very powerful tool. If anyone could help me with these questions it would greatly help me and I am sure help a lot of others. Also if anyone else has any other questions they would like to ask the OpenSim community regarding API tips then I would encourage them to add to this thread :)

Thanks in advance

Marc

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

RE: API tips and tricks

Post by Ayman Habib » Mon Aug 09, 2010 2:20 pm

Hi Marc,
Let me prefix the answers below by stating that we're refactoring the API for our tools for the specific reason of making things similar to what you need possible, in the meantime here're the answers as of version 2.1 (beta):
1. Constrained generalized coordinates are generalized coordinates indeed. A call to a model.getCoordinateSet() or (updCoordinateSet() if non-const version is required) does the trick. If you need to filter out constrained, locked or any other option you'll need to do it by asking the specific coordinate.
2 & 3. Not as it is now, there are some low level Simbody functions to support this functionality but none at the OpenSim API level.
4. This will be much cleaner after the refactoring. As it is, StaticOptimization can only be invoked from the Analyze Tool which requires a motion, you can use the same frame 10 times to make a motion and feed that to the AnalyzeTool (I know it sounds contrived and we're fixing it). The reason I said 10 is because some splining is done to compute derivatives and this needs 10 data points at least.
5. Unfortunately these functions do not have an implementation, it's a documentation mistake. We'll remove them until they do have an implementation.
6. My answer to 4 above should do the trick for now but please let me know if it doesn't or if you have any other questions.

All the best,
-Ayman


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

RE: API tips and tricks

Post by Marc Carmichael » Mon Aug 09, 2010 8:34 pm

Thanks Ayman. I am really looking forward to these additions in the next release. I know it's hard to estimate when this release will be ready, but do you have any feeling on the time frame we might expect it? (a week or two? a month? 6 months?) :)

Cheers

Marc


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

RE: API tips and tricks

Post by Ayman Habib » Fri Aug 13, 2010 9:39 am

Marc,

I expect we'd have some development builds (that we can share) within a month, but we haven't decided yet on the date of a public release.

Cheers,
-Ayman

POST REPLY