Question about turning a muscle-driven model into a torque-driven model

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Chen Wenqian
Posts: 3
Joined: Wed Feb 16, 2022 3:52 am

Question about turning a muscle-driven model into a torque-driven model

Post by Chen Wenqian » 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.

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()
I tried to use "input" to drive the model from an external torque input.

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

Tags:

User avatar
Ana de Sousa
Posts: 58
Joined: Thu Apr 07, 2016 4:21 pm

Re: Question about turning a muscle-driven model into a torque-driven model

Post by Ana de Sousa » Tue Oct 31, 2023 2:49 am

Hi Chen,

I find it a bit hard to understand completly without some extra information from your code. For example, it's crucial to ensure that the initial joint angles, velocities, and external forces are correctly specified to achieve the desired behavior.

However, doesn't your model contains gravity and the oscilation is caused by that? Even if you don't have any inputs, wouldn't it oscilate anyway?

User avatar
Chen Wenqian
Posts: 3
Joined: Wed Feb 16, 2022 3:52 am

Re: Question about turning a muscle-driven model into a torque-driven model

Post by Chen Wenqian » Tue Oct 31, 2023 3:32 am

Hi Ana,

Thanks for your reply.

The model does include gravity. But if it keeps oscillating, I'm not sure that the applied coordinate actuator is in effect, so that I can't confirm whether it's an external signal that makes the hip rotate or whether the gravity that makes it rotate.

The initial angles and velocities of the model's joints are both 0. The above code changes are referenced from the OpenSim Documentation/Examples and Tutorials/Advanced Examples/Moco: Predict a Squat-to-stand.

User avatar
Ana de Sousa
Posts: 58
Joined: Thu Apr 07, 2016 4:21 pm

Re: Question about turning a muscle-driven model into a torque-driven model

Post by Ana de Sousa » Tue Oct 31, 2023 4:35 am

I'm not an expert here, but I know it is possible to plot the actuation from your external actuators. If you take a look at Moco examples, you can probably find that

User avatar
Nicos Haralabidis
Posts: 187
Joined: Tue Aug 16, 2016 1:46 am

Re: Question about turning a muscle-driven model into a torque-driven model

Post by Nicos Haralabidis » Tue Oct 31, 2023 10:53 am

Hey Chen,

In your OpenSim directory, navigate to the Code/Matlab/Moco/exampleSquatToStand - in that directory there is a file exampleSquatToStand_answers.m and it creates a torque-driven model, the function is called getTorqueDrivenModel()... there is something similar in the Python code folder too.

Hope that helps!

Best wishes,

Nicos

User avatar
Chen Wenqian
Posts: 3
Joined: Wed Feb 16, 2022 3:52 am

Re: Question about turning a muscle-driven model into a torque-driven model

Post by Chen Wenqian » Wed Nov 01, 2023 11:17 pm

Hi Nicos,

I did modify the code with reference to the example, but the effect of gravity seems to be too much, and I can't effectively control the model's motion behavior by applying torque externally, is there any way to solve this problem?

Thanks.

POST REPLY