Access Muscles

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Joel Quarnstrom
Posts: 11
Joined: Tue Jun 30, 2020 9:40 am

Access Muscles

Post by Joel Quarnstrom » Fri Jul 17, 2020 10:15 am

Hello,

I am using a model for a simulation. I have defined different states, and I would like to be able to read the forces, tendon lengths, etc at each state. The model uses Schutte1993Muscle_Deprecated muscles. I am able to see the names of these muscles by using: model_1.getMuscles().get(i).getName() and iterating through i. I have been unsuccessful at actually interacting with the muscles beyond reading their names.

My thought is to somehow get these Muscles as a Schutte1993Muscle_Deprecated object, and then call functions from that class to compute data and output it.

I have not figured out how to access the muscles as a Schutte1993Muscle_Deprecated object, and functions from the Muscle class like calcMuscleLengthInfo() do not show up as options when I start to type them in Visual Studio.

Do you know if my goal is possible, or is there an easier way to compute muscle data and access it?

Thank you,
Joel Quarnstrom

Tags:

User avatar
Carmichael Ong
Posts: 393
Joined: Fri Feb 24, 2012 11:50 am

Re: Access Muscles

Post by Carmichael Ong » Fri Jul 17, 2020 10:20 am

Check out the doxygen page for this class: https://simtk.org/api_docs/opensim/api_ ... cated.html

In particular, make sure to expand the section on "Public Member Functions inherited from OpenSim::Muscle" as many of the calls are from this base class.

User avatar
Joel Quarnstrom
Posts: 11
Joined: Tue Jun 30, 2020 9:40 am

Re: Access Muscles

Post by Joel Quarnstrom » Fri Jul 17, 2020 10:44 am

I tried some of those functions, but when the program reaches them as it is executing, it stops. I do not know why.

Joel

User avatar
Carmichael Ong
Posts: 393
Joined: Fri Feb 24, 2012 11:50 am

Re: Access Muscles

Post by Carmichael Ong » Fri Jul 17, 2020 10:57 am

Some additional info:

Your call of "model_1.getMuscles().get(i)" will return a generic OpenSim::Muscle. You will be able to use any of the functions up to OpenSim::Muscle in the doxygen page I linked before (i.e., between OpenSim::Component and OpenSim::Muscle).

If you also need the specific functions for Schutte1993Muscle_Deprecated, you will have to perform a safeDownCast(). One example is seen here: https://github.com/opensim-org/opensim- ... le.cpp#L65

I'm not sure why your program would stop. Is it crashing? Or does it seem to be ignoring the lines? If after you try a few things it still doesn't work, you could post a minimal code example to reproduce your issue.

User avatar
Joel Quarnstrom
Posts: 11
Joined: Tue Jun 30, 2020 9:40 am

Re: Access Muscles

Post by Joel Quarnstrom » Mon Jul 20, 2020 11:43 am

Thank you for your response,

I have attached a copy of my code for reference.

I can get the visualizer to iterate through multiple states. These states are generated from data in a csv file.

I have also attached the csv file.

I am using the model: MoBL_ARMS_module2_4_allmuscles.osim
from: https://simtk.org/projects/upexdyn

The code on line 135 of main: cout << set_1[0].computeActuation(state) << endl;

Is what causes the program to stop, without it, the states update and are displayed correctly.

Any suggestions?
Joel Quarnstrom
Attachments
design_vars.csv
(7.06 KiB) Downloaded 90 times
get_directory.cpp
(968 Bytes) Downloaded 88 times
get_csv_data.cpp
(1.11 KiB) Downloaded 80 times
Header.h
(294 Bytes) Downloaded 88 times
main.cpp
(3.3 KiB) Downloaded 90 times

User avatar
Carmichael Ong
Posts: 393
Joined: Fri Feb 24, 2012 11:50 am

Re: Access Muscles

Post by Carmichael Ong » Wed Jul 22, 2020 10:58 am

It seems like you are trying to get muscle force out at this line. Does getFiberForce() (https://simtk.org/api_docs/opensim/api_ ... baa3d7f314) cause the same issues?

It can be helpful to create a minimum code example (with a simpler model and perhaps avoiding using a data file) to help isolate the problem, as all of the other steps around it make it difficult to know what is exactly going on.

User avatar
Joel Quarnstrom
Posts: 11
Joined: Tue Jun 30, 2020 9:40 am

Re: Access Muscles

Post by Joel Quarnstrom » Fri Jul 24, 2020 8:17 am

getFiberForce did not work. I will work on creating a simpler code example.

Joel

User avatar
Joel Quarnstrom
Posts: 11
Joined: Tue Jun 30, 2020 9:40 am

Re: Access Muscles

Post by Joel Quarnstrom » Thu Jul 30, 2020 11:26 am

I am trying to learn about these functions using the SimpleOptimizationExample, because it is set up better than my code. I added a few lines and took a screen shot of them.

It seemed that the muscles in this program work properly. I was able to add line 77 to display the muscle activation. This seemed like progress, since I could not get that function to work on my code. I then tried to compute the muscle force using computeForce on line 81. I looked this function up on the API documentation, and I have a few questions about its arguments.

I was unable to find documentation on how to properly initialize a SimTK::Vector or SimTK::Vector_< SimTK::SpatialVec > for the second and third arguments of computeForce. I am also unsure about the purpose for these arguments. Are they inputs of data that needs to be defined before computeForce is called, or are they variables that the function is using to output data. If so, do you know how I can properly initialize variables to be used for this purpose? I gave my best shot in lines 79 and 80, but obviously I was doing it wrong.

Thank you,
Joel Quarnstrom
Attachments
SimpleOptimizationExample screen shot.JPG
SimpleOptimizationExample screen shot.JPG (141.21 KiB) Viewed 1369 times

User avatar
Carmichael Ong
Posts: 393
Joined: Fri Feb 24, 2012 11:50 am

Re: Access Muscles

Post by Carmichael Ong » Mon Aug 03, 2020 10:45 am

The computeForce function stores the results in those 2 vectors that you are trying to initialize. I don't recommend using that function since it seems like you want muscle or tendon force, not the body and generalized forces (as described in the documentation here https://simtk.org/api_docs/opensim/api_ ... 8ea397a3fe)

I would suggest you look at other methods in the Muscle class (https://simtk.org/api_docs/opensim/api_ ... uscle.html) or the specific class that you're using for other methods to compute force (e.g., getFiberForce(), getTendonForce()). Also, computeActuation() also gives a force (https://simtk.org/api_docs/opensim/api_ ... 34546f8c57)

User avatar
Joel Quarnstrom
Posts: 11
Joined: Tue Jun 30, 2020 9:40 am

Re: Access Muscles

Post by Joel Quarnstrom » Mon Aug 03, 2020 2:15 pm

Ok, I will try those. From a physical standpoint (not a computer science standpoint) what is the difference between the active fiber force, the passive fiber force, and the tendon force, and in general how are these values calculated?

Joel

POST REPLY