Set External Torque through Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Zhenwei Liu
Posts: 6
Joined: Sat Sep 15, 2018 7:03 pm

Set External Torque through Matlab

Post by Zhenwei Liu » Sat Feb 16, 2019 9:47 pm

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

Tags:

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Set External Torque through Matlab

Post by Thomas Uchida » Mon Feb 18, 2019 12:26 am

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.

User avatar
Zhenwei Liu
Posts: 6
Joined: Sat Sep 15, 2018 7:03 pm

Re: Set External Torque through Matlab

Post by Zhenwei Liu » Mon Feb 18, 2019 8:38 am

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!

POST REPLY