Question about turning a muscle-driven model into a torque-driven model
Posted: Tue Oct 31, 2023 1:17 am
Hello everyone! I'm having a trouble converting a muscle-driven model to a torque-driven model. The model I used is squatToStand_3dof9musc.osim. I tried to create a torque-driven model by removing the muscles and adding some coordinate actuators on the joints but it failed.
To test if the signal can be fed from an external source, I set all the initial joint angles of the model to 0 and locked the knee and ankle joints. As you can see in the gif, the model will keep doing oscillating motion without any input, which does not match my expectation of sagging and remaining motionless. If the model cannot remain motionless without input, then it is unlikely to be able to manipulate using external moments.
Could anyone help me with this please, appreciate it! Part of the code is as follows.
I tried to use "input" to drive the model from an external torque input.
To test if the signal can be fed from an external source, I set all the initial joint angles of the model to 0 and locked the knee and ankle joints. As you can see in the gif, the model will keep doing oscillating motion without any input, which does not match my expectation of sagging and remaining motionless. If the model cannot remain motionless without input, then it is unlikely to be able to manipulate using external moments.
Could anyone help me with this please, appreciate it! Part of the code is as follows.
Code: Select all
import opensim as osim
...
coordNames = ['hip_flexion_r', 'knee_angle_r', 'ankle_angle_r']
optForces = [0, 0, 0]
...
model = osim.Model(model_path)
model.updForceSet().clearAndDestroy()
model.initSystem()
brain = osim.PrescribedController()
muscleSet = model.getMuscles()
forceSet = model.getForceSet()
bodySet = model.getBodySet()
jointSet = model.getJointSet()
markerSet = model.getMarkerSet()
contactGeometrySet = model.getContactGeometrySet()
func = osim.Constant(0.0)
for i in range(3):
coordSet = model.updCoordinateSet()
actu = osim.CoordinateActuator()
actu.setName(coordNames[i])
actu.setCoordinate(coordSet.get(coordNames[i]))
actu.setOptimalForce(optForces[i])
actu.setMinControl(-1)
actu.setMaxControl(1)
model.addComponent(actu)
brain.addActuator(actu)
brain.prescribeControlForActuator(i, func)
noutput = 3
model.addController(self.brain)
model.initSystem()
Code: Select all
def actuate(input):
brain = osim.PrescribedController.safeDownCast(model.getControllerSet().get(0))
functionSet = brain.get_ControlFunctions()
for j in range(functionSet.getSize()):
func = osim.Constant.safeDownCast(functionSet.get(j))
func.setValue(float(input[j]))