MATLAB API bindings for SimTK classes

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Yujun Lai
Posts: 2
Joined: Tue Apr 23, 2019 8:13 pm

MATLAB API bindings for SimTK classes

Post by Yujun Lai » Sun Jan 10, 2021 11:23 pm

Hi OpenSim team,

Recently, I've been looking to utilise Opensim 4.1 with the MATLAB bindings. I'm in the process of converting some prior C++ code acting as a makeshift wrapper for MATLAB using mex functions for OpenSim 3.3. Given that OpenSim 4 has MATLAB bindings I was hoping to convert those old mex functions into pure MATLAB functions.

During this process, the MATLAB bindings seem to be unable to find functionality which belong to SimTK libraries, specifically for the MultibodySystem class object instance:
In C++:

Code: Select all

si = model.initSystem();
// other parts of codebase - si remains as the latest state
model.getMultibodySystem().project(si, 1e-12); //,1e-14);
model.getMultibodySystem().realize(si,SimTK::Stage::Velocity);
In MATLAB, I've created a class to embed the model and the state. When attempting to run a function using the same project() and realize() functions from SimTK::getMultibodySystem, it throws an exception.

Code: Select all

self.mdl.getMultibodySystem().project(self.state,1e-10);
self.mdl.getMultibodySystem().realize(self.state,Stage(6)); % to set it as SimTK::Stage::Velocity
The respective exceptions thrown are

Code: Select all

Undefined function 'project' for input arguments of type 'org.opensim.modeling.SWIGTYPE_p_SimTK__MultibodySystem'.
Unrecognized function or variable 'realize'.
Using methodsview, the functions available using the MATLAB bindings are:

Code: Select all

Methods for class org.opensim.modeling.SWIGTYPE_p_SimTK__MultibodySystem:

equals     getClass   hashCode   notify     notifyAll  toString   wait     
Other SimTK functionality like Vector and Stage, and parent classes like Body are all working fine without issues.

Are there limitations in the MATLAB bindings for functions for specific classes from SimTK?
The functionalities from SimTK::SimbodyMatterSubSystem are all available in MATLAB making it seem like the specific MultibodySystem class is the potential problem.

Code: Select all

Methods for class org.opensim.modeling.SimbodyMatterSubsystem:

SimbodyMatterSubsystem                    calcMotionErrors                          calcSystemMassPropertiesInGround          multiplyByM                               
calcAcceleration                          calcMotionPower                           calcSystemMomentumAboutGroundOrigin       multiplyByMInv                            
calcAccelerationIgnoringConstraints       calcP                                     calcTreeEquivalentMobilityForces          multiplyByN                               
calcBiasForAccelerationConstraints        calcPq                                    delete                                    multiplyByNDot                            
calcBiasForFrameJacobian                  calcPqTranspose                           downcast                                  multiplyByNInv                            
calcBiasForMultiplyByG                    calcProjectedMInv                         equals                                    multiplyByPq                              
calcBiasForMultiplyByPq                   calcPt                                    findConstraintForces                      multiplyByPqTranspose                     
calcBiasForStationJacobian                calcQDot                                  findMotionForces                          multiplyByStationJacobian                 
calcBiasForSystemJacobian                 calcQDotDot                               getCPtr                                   multiplyByStationJacobianTranspose        
calcBodyAccelerationFromUDot              calcResidualForce                         getClass                                  multiplyBySystemJacobian                  
calcConstraintForcesFromMultipliers       calcResidualForceIgnoringConstraints      getConstraintMultipliers                  multiplyBySystemJacobianTranspose         
calcConstraintPower                       calcStationJacobian                       getMotionMultipliers                      notify                                    
calcFrameJacobian                         calcSystemCentralInertiaInGround          getRep                                    notifyAll                                 
calcG                                     calcSystemCentralMomentum                 hashCode                                  solveForConstraintImpulses                
calcGTranspose                            calcSystemJacobian                        isInstanceOf                              toString                                  
calcKineticEnergy                         calcSystemMass                            multiplyByFrameJacobian                   updDowncast                               
calcM                                     calcSystemMassCenterAccelerationInGround  multiplyByFrameJacobianTranspose          updRep                                    
calcMInv                                  calcSystemMassCenterLocationInGround      multiplyByG                               wait                                      
calcMobilizerReactionForces               calcSystemMassCenterVelocityInGround      multiplyByGTranspose           
Thanks for your time in advance. Any insight into this and/or other users with the same issue would be welcome since I have no other information indicating that this should happen.
FYI: I'm on Ubuntu 18.04 with MATLAB R2019b. The 4.1 release source code builds completely (but ctests for some MATLAB didn't work - I'm flagging this on github itself separately).

Kind regards,
Yujun

Tags:

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

Re: MATLAB API bindings for SimTK classes

Post by Thomas Uchida » Fri Jan 15, 2021 6:59 pm

The API documentation can be found here: https://simtk.org/api_docs/opensim/api_docs/. If you search for "realize", you will find several methods in the Model class.

User avatar
Yujun Lai
Posts: 2
Joined: Tue Apr 23, 2019 8:13 pm

Re: MATLAB API bindings for SimTK classes

Post by Yujun Lai » Wed Jan 20, 2021 9:13 pm

Hi Thomas,

Looking at the model api, seems like the API between 3.3 and 4.x changed such that the realize functionality are now available in the model class.

Thanks for your time and response.

Kind Regards,
Yujun

POST REPLY