Page 1 of 1

Set External Torque through Matlab

Posted: Sat Feb 16, 2019 9:47 pm
by lzhen97
Hi, I tried to apply external torque at knee through Matlab scripting, and below is my code. The Matlab code was ran successfully, but when I started the forward dynamics simulation in OpenSim, nothing happened except that the model just fell. I was wondering is it because some Matlab commands are missing? Or is it because I didn't set up OpenSim correctly? Thank you so much for your help!

import org.opensim.modeling.*;
model=Model("gait2354_simbody.osim");
bodyList=model.getBodyList();
coordinateSet=model.updCoordinateSet();
model.setUseVisualizer(true);

%Create a Troque Actuator for the Knee Joint
femur_r=model.getBodySet().get('femur_r');
tibia_r=model.getBodySet().get('pelvis');
zAxis=Vec3(0,1,0);
torqueActuator = TorqueActuator;
torqueActuator.setBodyA(femur_r);
torqueActuator.setBodyB(tibia_r);
torqueActuator.setAxis(zAxis);
torqueActuator.setOptimalForce(5);

Re: Set External Torque through Matlab

Posted: Mon Feb 18, 2019 12:26 am
by tkuchida
The new Visualizer in OpenSim 4.0 displays a floor by default but it does not generate forces by default. If you don't want the model to fall, you could apply measured ground reaction forces to the model, use a contact model to compute these forces, lock the pelvis to ground, disable gravity, etc.

Re: Set External Torque through Matlab

Posted: Mon Feb 18, 2019 8:38 am
by lzhen97
Thank you so much Thomas! I locked Py (vertical position) of pelvis, applied the external torque (like the one shown in the code I attached) and restart the FD simulation. This time the model didn't fall, but it started to do some weird movement and the simulation is very slow. Do you have any idea what the problem is? Thanks a lot!