Access Muscles
- Joel Quarnstrom
- Posts: 11
- Joined: Tue Jun 30, 2020 9:40 am
Access Muscles
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
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:
- Carmichael Ong
- Posts: 381
- Joined: Fri Feb 24, 2012 11:50 am
Re: Access Muscles
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.
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.
- Joel Quarnstrom
- Posts: 11
- Joined: Tue Jun 30, 2020 9:40 am
Re: Access Muscles
I tried some of those functions, but when the program reaches them as it is executing, it stops. I do not know why.
Joel
Joel
- Carmichael Ong
- Posts: 381
- Joined: Fri Feb 24, 2012 11:50 am
Re: Access Muscles
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.
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.
- Joel Quarnstrom
- Posts: 11
- Joined: Tue Jun 30, 2020 9:40 am
Re: Access Muscles
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
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 84 times
-
- get_directory.cpp
- (968 Bytes) Downloaded 84 times
-
- get_csv_data.cpp
- (1.11 KiB) Downloaded 71 times
-
- Header.h
- (294 Bytes) Downloaded 83 times
-
- main.cpp
- (3.3 KiB) Downloaded 84 times
- Carmichael Ong
- Posts: 381
- Joined: Fri Feb 24, 2012 11:50 am
Re: Access Muscles
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.
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.
- Joel Quarnstrom
- Posts: 11
- Joined: Tue Jun 30, 2020 9:40 am
Re: Access Muscles
getFiberForce did not work. I will work on creating a simpler code example.
Joel
Joel
- Joel Quarnstrom
- Posts: 11
- Joined: Tue Jun 30, 2020 9:40 am
Re: Access Muscles
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
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 (141.21 KiB) Viewed 1188 times
- Carmichael Ong
- Posts: 381
- Joined: Fri Feb 24, 2012 11:50 am
Re: Access Muscles
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)
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)
- Joel Quarnstrom
- Posts: 11
- Joined: Tue Jun 30, 2020 9:40 am
Re: Access Muscles
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
Joel