MATLAB accessibility of SimBody methods in OpenSim 4.0

The Question and Answer and Support Forum for the 2017 Fall Virtual Workshop.
Locked
User avatar
Hide Kimpara
Posts: 135
Joined: Mon Sep 19, 2016 5:12 am

MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Hide Kimpara » Mon Oct 23, 2017 3:55 pm

Hello,

We used several methods of SimBody APIs to control our OpenSim model.

The functions we used in C++ programming were like followings:
  • _model->getMultibodySystem().realize
    _model->getMatterSubsystem().calcResidualForceIgnoringConstraints
    _model->getMatterSubsystem().multiplyBySystemJacobianTranspose
    _model->getMatterSubsystem().calcM
    _model->getForceSet

    MobilizedBody& findFrameTransforminGround
    MobilizedBody& findFrameVelocityInGround
    _model->getMatterSubsystem().calcStationJacobian
    _model->getMatterSubsystem().calcFrameJacobian
    _model->getMatterSubsystem().multiplyByMInv
    _model->getMatterSubsystem().calcBiasForStationJacobian
    _model->getMatterSubsystem().calcBiasForFrameJacobian
In case of OpenSim 4.0, can we use them directly from MATLAB? Or do we need to still think about keeping C++ programming between MATLAB and SimBody APIs?
Unfortunately, we have not succeeded in MEX programing until today.

Thank you
Hide

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

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Thomas Uchida » Mon Oct 23, 2017 4:08 pm

You can call methodsview(Model) in MATLAB to see which methods have been "wrapped" (are accessible through MATLAB) for the Model class. In case you need it, the doxygen documentation for the latest build of 4.0 can be found here: http://myosin.sourceforge.net/1978/.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Christopher Dembia » Mon Oct 23, 2017 5:05 pm

Many of these methods should be available. See here for an example: https://github.com/opensim-org/opensim- ... tSimbody.m

User avatar
Hide Kimpara
Posts: 135
Joined: Mon Sep 19, 2016 5:12 am

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Hide Kimpara » Mon Oct 23, 2017 5:06 pm

Hi Tom,

Thank you for your quick response.
I changed path files of MATLAB. Then there is no error on "import org.opensim.modeling.*". However, if I try to read some models using Model('aaa.osim'), error happens with pop-up message saying "Required library failed to load. Check that the dynamic library osimJavaJNI is in your PATH java.lang.UnsatisfiedLinkError: C:\opensim-core\bin\osimJavaJNI.dll: The specified procedure could not be found".

Then another error message comes on Command Window:

Code: Select all

Java exception occurred:
java.lang.UnsatisfiedLinkError:
org.opensim.modeling.opensimSimulationJNI.new_Model__SWIG_1(Ljava/lang/String;)J

	at org.opensim.modeling.opensimSimulationJNI.new_Model__SWIG_1(Native Method)

	at org.opensim.modeling.Model.<init>(Model.java:783)
Do you have any solutions?

Thank you,
Hide

User avatar
Kenechukwu Mbanisi
Posts: 51
Joined: Fri Feb 10, 2017 2:50 pm

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Kenechukwu Mbanisi » Mon Oct 23, 2017 5:20 pm

Hello Chris,
chrisdembia wrote:Many of these methods should be available. See here for an example: https://github.com/opensim-org/opensim- ... tSimbody.m
I'm absolutely delighted to see that we have access to Simbody methods now from MATLAB, great addition!

Is there some documentation for MATLAB API? It would be very helpful to have a way to 'look-up' corresponding methods and functions from Simbody.

Thanks again,

Kenechukwu

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

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Thomas Uchida » Mon Oct 23, 2017 10:38 pm

Hide: Do you have any solutions?
I would need a lot more information to diagnose the issue. I suggest discussing the issue in your meeting tomorrow so you can work out the details in real time. Assuming the Windows PATH environment variable is correct and MATLAB has been properly configured, perhaps you built OpenSim 4.0 from source but didn't check the box in CMake to build bindings?
Kenechukwu: Is there some documentation for MATLAB API?
Although not all methods are available from MATLAB, you can still use the doxygen documentation as a reference. Here's the documentation for the most recent build of 4.0: http://myosin.sourceforge.net/1978/.

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

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Ayman Habib » Mon Oct 23, 2017 11:48 pm

Hi,

The message "The specified procedure could not be found" suggests that the library in question was located indeed but it is missing some symbols that the Java bindings are refereing to. This likely is due to the JNI library being loaded not consistent with the java class files. Make sure you have only one installation of OpenSim on your machine, or if more than one make sure the one you want to use is at the front of the Path and is used by Matlab.

Hope this helps,
-Ayman

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Christopher Dembia » Tue Oct 24, 2017 12:30 am

It sounds like you've built from source. If you run the OpenSim tests (in Visual Studio, this is the RUN_TESTS or RUN_TESTS_PARALLEL project; from the command-line, you can use ctest; see the README for more information), you should see some MATLAB tests are run. Do those pass? If so, that tells you that you *can* get the environment working properly, but that there are just some configuration issues (PATH, etc.).

User avatar
Hide Kimpara
Posts: 135
Joined: Mon Sep 19, 2016 5:12 am

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Hide Kimpara » Tue Oct 24, 2017 5:33 am

Dear Tom, Ayman, and Christopher,

Now I solved! :D

Code: Select all

org.opensim.modeling.opensimCommon.GetVersion()
 
ans =
 
4.0
I believe the main reason would be PATH for MATLAB. I installed R2016a and R2016b. Since I mostly used R2016a, I deleted PATH for R2016b. But I found OpenSim 4.0 recognized R2016b as the MATLAB during the intall.
So, I add PATH for R2016b, then it works!

Thank you so much for the kind supports!
Now we concentrate on accessibility from MATLAB to methods of force and position feedback controls.


Thank you,
Hide

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: MATLAB accessibility of SimBody methods in OpenSim 4.0

Post by Christopher Dembia » Tue Oct 24, 2017 10:03 am

:)

Locked