Hi. I am looking to use the opensim API to calculate the mass matrix of the musculoskeletal rigid body system. When I say the mass matrix, I mean the square matrix which when multiplied by a vector of generalized coordinate accelerations computes the joint inertial torques
ie. M*qdd = tau, where
M = nxn square mass matrix (n = number of generalized coordinates)
qdd = nx1 vector of generalized coordinate accelerations
tau = nx1 vector of inertial torques
My question is does opensim provide an easy means of finding M? I am interested in functions such as:
OpenSim::SimbodyEngine::formMassMatrix(double * rI);
OpenSim::SimbodyEngine::getSystemInertia(SimTK::State & s,double & rM,SimTK::Vec3 & rCOM,double rI[3][3]);
Any help is greatly appreciated
Marc
calculate system mass matrix via api
- Ayman Habib
- Posts: 2242
- Joined: Fri Apr 01, 2005 12:24 pm
RE: calculate system mass matrix via api
Hi Marc,
I'd suggest you use the code snippet
SimTK::Matrix massMatrix;
const int nu = model.getNumCoordinates();
massMatrix.resize(nu,nu);
SimTK::Vector v(nu);
...
v = 1;
model.getMatterSubsystem().calcMV(s, v, massMatrix(i));
to build the massMatrix one column at a time, where s is the state.
It's generally more efficient to compute the product of the mass matrix with a vector than to compute the full matrix then use a generic matrix multiplication method to multiply the Mass matrix with a specific vector, but you'll have to decide for yourself if that would work for your use case.
Good luck and please let me know if you have questions,
-Ayman
I'd suggest you use the code snippet
SimTK::Matrix massMatrix;
const int nu = model.getNumCoordinates();
massMatrix.resize(nu,nu);
SimTK::Vector v(nu);
...
v = 1;
model.getMatterSubsystem().calcMV(s, v, massMatrix(i));
to build the massMatrix one column at a time, where s is the state.
It's generally more efficient to compute the product of the mass matrix with a vector than to compute the full matrix then use a generic matrix multiplication method to multiply the Mass matrix with a specific vector, but you'll have to decide for yourself if that would work for your use case.
Good luck and please let me know if you have questions,
-Ayman
- Marc Carmichael
- Posts: 45
- Joined: Thu Jul 16, 2009 2:50 am
RE: calculate system mass matrix via api
I just noticed that the SimTK doxygen documentation on the OpenSim page appears out of date.
If I search for the latest SimTK documentation I can find a few new functions. The one of interest to me is SimTK::SimbodyMatterSubsystem::calcM() which appears to explicitly calculate the nXn mass matrix. Just what I was looking for
https://simtk.org/api_docs/simtkcore/ap ... 28477f1f08
Would someone please be able to update the OpenSim doxygen page to point to the latest SimTK doxygen? I am assuming the latest OpenSim has this version of SimTK as I have compiled it and the calcM() function appears to work.
Cheers
Marc
If I search for the latest SimTK documentation I can find a few new functions. The one of interest to me is SimTK::SimbodyMatterSubsystem::calcM() which appears to explicitly calculate the nXn mass matrix. Just what I was looking for
https://simtk.org/api_docs/simtkcore/ap ... 28477f1f08
Would someone please be able to update the OpenSim doxygen page to point to the latest SimTK doxygen? I am assuming the latest OpenSim has this version of SimTK as I have compiled it and the calcM() function appears to work.
Cheers
Marc
- Ayman Habib
- Posts: 2242
- Joined: Fri Apr 01, 2005 12:24 pm
RE: calculate system mass matrix via api
Hi Marc,
You're right. Thanks for finding the stale documentation issue, we'll update it in the next release, but please file a bug report to make sure it doesn't fall through the cracks (Please indicate which url did you use to get this stale documentation as there're a few of them around, some on the Documentation page as well as the links in the distribution sdk/doc folder).
Best,
-Ayman
You're right. Thanks for finding the stale documentation issue, we'll update it in the next release, but please file a bug report to make sure it doesn't fall through the cracks (Please indicate which url did you use to get this stale documentation as there're a few of them around, some on the Documentation page as well as the links in the distribution sdk/doc folder).
Best,
-Ayman