apply a force at a given point

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Kaiwen Yang
Posts: 45
Joined: Mon Sep 03, 2018 11:25 am

apply a force at a given point

Post by Kaiwen Yang » Wed Oct 14, 2020 9:01 pm

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

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: apply a force at a given point

Post by Dimitar Stanev » Thu Oct 15, 2020 2:32 am

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

User avatar
Kaiwen Yang
Posts: 45
Joined: Mon Sep 03, 2018 11:25 am

Re: apply a force at a given point

Post by Kaiwen Yang » Thu Oct 15, 2020 5:57 am

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?

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: apply a force at a given point

Post by Dimitar Stanev » Thu Oct 15, 2020 6:35 am

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:

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]) )
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

User avatar
Kaiwen Yang
Posts: 45
Joined: Mon Sep 03, 2018 11:25 am

Re: apply a force at a given point

Post by Kaiwen Yang » Thu Oct 15, 2020 6:57 am

Thanks a lot. This is very helpful. Looks like prescribed force works similarly with prescribed controller. I will try to implement this.

POST REPLY