Add prescribed force - reference axis

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mary K
Posts: 37
Joined: Mon Feb 24, 2014 9:15 am

Add prescribed force - reference axis

Post by Mary K » Wed Mar 15, 2017 4:44 am

Hello,
I want to add an external force to a body with these settings:
The point of application should be in body frame, so that when the body moves, the force to 'follow' it.
But the direction of the force should be constant in x-direction of global frame.

Can someone help me how to do that using the API? I think I am doing it right, but I am not sure, because the visualization in the GUI is a bit tricky!

Here is my code now:

Code: Select all

 PrescribedForce *prescribedForce = new PrescribedForce(&model.updBodySet().get("tibia_r"));
	prescribedForce->setForceFunctions(new Constant(-110.0), new Constant(0.0), new Constant(0.0));
	prescribedForce->setPointFunctions(new Constant(0.0), new Constant(-0.3), new Constant(0.0));
	prescribedForce->setForceIsInGlobalFrame(true);
	prescribedForce->setPointIsInGlobalFrame(false);
	model.addForce(prescribedForce);
When I export the force with ForceReporter, and load it in the OpenSim GUI, it seems like the point of application is right, but when the tibia rotates, rotates the force as well, as if the direction of the force is set in x-direction of body frame (not global).

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

Re: Add prescribed force - reference axis

Post by Thomas Uchida » Wed Mar 15, 2017 2:48 pm

Some suggestions:
- Use model.print("test.osim") to confirm that the model has been correctly constructed.
- A PrescribedForce is defined programmatically in this example: https://github.com/opensim-org/opensim- ... mplete.cpp
- Test on a simpler model first (e.g., a block or chain of blocks) in a variety of scenarios to verify that the PrescribedForce is working as you expect.

User avatar
Mary K
Posts: 37
Joined: Mon Feb 24, 2014 9:15 am

Re: Add prescribed force - reference axis

Post by Mary K » Sun Mar 19, 2017 4:43 am

Tom, thanks for your response.
I followed your advices and I simulated a simple senario with a ground and a block with different local axis and no gravity. I think I understood how the force is applied by observing the movement of the block. But still cannot visualize the force arrow properly, in the GUI.
That's why I am not sure 100% that I know it.

To be more specific, I load the motion file, then I click "Associate motion data..." (to load the prescribed force as I exported it programmatically).
Then "Edit motion objects...", select my force and "Edit" again:

Image

"Force Expressed in: ground" is like "PrescribedForce::setForceIsInGlobalFrame(true)" from the API?
And correspondingly "Point Expressed in: "tibia_r" is like "PrescribedForce::setPointIsInGlobalFrame(false)" ?

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

Re: Add prescribed force - reference axis

Post by Thomas Uchida » Sun Mar 19, 2017 7:15 pm

"Force Expressed in: ground" is like "PrescribedForce::setForceIsInGlobalFrame(true)" from the API? And correspondingly "Point Expressed in: "tibia_r" is like "PrescribedForce::setPointIsInGlobalFrame(false)" ?
That sounds right. There is some additional information here:
- Doxygen: https://simtk.org/api_docs/opensim/api_ ... ml#details
- Confluence: http://simtk-confluence.stanford.edu:80 ... h+a+Motion

POST REPLY