Hello,
Is there a way to specify a body force after setting the states. What I wish to do is something like:
for (i=0:state_size-1){
osimModel.setStateVariable(osimState,stateNames,*(parameters + i));
}
applyForceToPoint (osimState, body,point, force,)
realizeToAcceleration(osimState)
However, I found out that applyForceToPoint cannot be called directly like that. Is there a workaround?
Kaiwen
apply a force at a given point
- Kaiwen Yang
- Posts: 45
- Joined: Mon Sep 03, 2018 11:25 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: apply a force at a given point
Hi Kaiwen,
You can apply a prescribed force which should be added before you initialize your model. Please look at the following example:
https://github.com/mitkof6/OpenSim_API_ ... d_force.py
You can apply a prescribed force which should be added before you initialize your model. Please look at the following example:
https://github.com/mitkof6/OpenSim_API_ ... d_force.py
- Kaiwen Yang
- Posts: 45
- Joined: Mon Sep 03, 2018 11:25 am
Re: apply a force at a given point
Thanks for the reply. However, this body force has to be calculated from the current state, something like a contact force. Can I update this prescribed force after the system is initialized?
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: apply a force at a given point
Hi,
I think you can update the values of the function. The following code is adapted from PrescribedController which does something similar but for muscles:
The above code should work with Python, but I have not tested it. If not minor changes should be made. Please use the doxygen to see how to access the different data members of the class:
https://simtk.org/api_docs/opensim/api_ ... Force.html
I think you can update the values of the function. The following code is adapted from PrescribedController which does something similar but for muscles:
Code: Select all
force = opensim.PrescribedForce.safeDownCast(model.getForceSet().get('Name of the force'))
forceFunctionSet = force.get_forceFunctions()
pointFunctionSet = force.get_pointFunctions()
toequeFunctionSet = force.get_torqueFunctions()
for j in range(forceFunctionSet.getSize()):
func = opensim.Constant.safeDownCast(functionSet.get(j)) # this depends on the type of function that you used to initially, here assumed Constant
func.setValue( float(action[j]) )
https://simtk.org/api_docs/opensim/api_ ... Force.html
- Kaiwen Yang
- Posts: 45
- Joined: Mon Sep 03, 2018 11:25 am
Re: apply a force at a given point
Thanks a lot. This is very helpful. Looks like prescribed force works similarly with prescribed controller. I will try to implement this.