Thank you so much for the response! I tried using InverseDynamicsSolver but got very strange values as output. the values (below) are very large, and don't seem to match up with what I think the torque should be.
here's my code:
Code: Select all
def get_torque_values(model, state, pos=None, coord_names = ["elv_angle", "shoulder_elv", "shoulder_rot", "elbow_flexion", "pro_sup", "deviation", "flexion"]):
inverse_dynamics_solver = osim.InverseDynamicsSolver(model)
coords = model.getCoordinateSet()
to_keep_index = []
for i in range(coords.getSize()):
coord = coords.get(i)
coord.setSpeedValue(state,0)
if coord.getName() in coord_names:
to_keep_index.append(i)
if pos is not None:
coord.setValue(state,pos[coords.get(i).getName()])
coord.setSpeedValue(state,0)
model.realizeVelocity(state)
udot = osim.Vector(model.getNumSpeeds(), 0.0)
torque_values = inverse_dynamics_solver.solve(state,udot)
relevant_torque_values = [torque_values[to_keep_index[i]] for i in range(len(to_keep_index))]
return relevant_torque_values
def test_torque_values(model_path, joint_names=["elv_angle", "shoulder_elv", "shoulder_rot", "elbow_flexion", "pro_sup", "deviation", "flexion"]):
model = osim.Model(model_path)
state = model.initSystem()
default = get_torque_values(model,state)
testCoord = model.getCoordinateSet().get("shoulder_elv")
testCoord.setValue(state,3.14/2)
raised = get_torque_values(model,state)
# testCoord = model.getCoordinateSet().get("elbow_flexion")
testCoord.setValue(state,3.14)
high = get_torque_values(model,state)
print('range max: ',testCoord.getRangeMax())
print(default)
print(default[1])
print(raised[1])
print(high[1])
test_torque_values(model_path)
here is what test_torque_values printed out:
[-525.8879515086584, 1759.1103165292966, -315.1703446028086, 0.07566166921931483, 58.50165393582534, -16.38013139804234, 9.067275629231764]
1759.1103165292966
2049.6546823307117
2066.793696377007
shoulder_elv ranges from zero to pi. When at shoulder_elv is at pi/2, the arm is parallel with the ground in opensim creator. To me it seems that the highest torque on this joint should be when the arm is held parallel to the ground, but the values don't reflect that. Also, I don't understand why the values are so large.