I have recently been troubled by a very strange phenomenon. When I tried to perform an inverse dynamics calculation on a very simple model (shown below), I found that whether or not I added a muscle actually affected the magnitude of the generalized force output from the inverse dynamics. The model only contains a block with a mass of 1kg, a muscle attached to the block and ground, and a PinJoint connecting the block to the ground. The generalized coordinates of the model are set to be 0 at any moment, i.e., always in a static state. According to the Inverse Dynamics equations, the net joint torque acting about the coordinate axe should be zero. However, the output from OpenSim is not 0. This is really confusing. Could you tell me what is the reason for this deviation?
Any help would be greatly appreciated.
Best regards,
Jiahao Zhou
The codes are as follows:
Code: Select all
%% Import OpenSim libraries
import org.opensim.modeling.*
%% Instantiate an empty model
model = Model();
% Get a reference to the model's ground body
ground = model.getGround();
%% Define Body and Joint in the Model
% Instantiate a Body with mass, inertia, and a display geometry
block1 = Body();
block1.setName('Block1');
block1.setMass(1);
block1.setMassCenter(Vec3(0));
block1.setInertia(Inertia(1,1,1,0,0,0));
% Add display geometry for the block
block1.attachGeometry(Brick(Vec3(0.05)));
% Instantiate Pin Joint that connects the block1 and ground.
joint1 = PinJoint('joint1', ground,Vec3(0),Vec3(0,pi/2,0),block1, Vec3(0), Vec3(0));
coord = joint1.updCoordinate();
coord.setName('r1');
coord.setRange([-pi,pi]);
% Add the block body and joint to the model
model.addBody(block1);
model.addJoint(joint1);
%% Define Muscle in the Model
% Define parameters for a Muscle
maxIsometricForce = 10;
optimalFiberLength = 0.25;
tendonSlackLength = 0.1;
pennationAngle = 0.0;
% Instantiate a Muscle
muscle1 = Thelen2003Muscle();
muscle1.setName('muscle1')
muscle1.setMaxIsometricForce(maxIsometricForce)
muscle1.setOptimalFiberLength(optimalFiberLength)
muscle1.setTendonSlackLength(tendonSlackLength);
muscle1.setPennationAngleAtOptimalFiberLength(pennationAngle)
% Add Path points to muscle 1
muscle1.addNewPathPoint('muscle1-point1', ground, Vec3(0.0,0.35,0.05))
muscle1.addNewPathPoint('muscle1-point2', block1, Vec3(-0.05,0.0,0))
% Add the muscle (as force) to the model
model.addForce(muscle1)
%% Finalize connections so that sockets connectees are correctly saved
model.finalizeConnections();
%% Inverse Dynamics
id=InverseDynamicsTool();
id.setModel(model);
id.setCoordinatesFileName('motion.sto'); % the value of coord is 0 in the file 'motion.sto'
id.setStartTime(0.01);
id.setEndTime(0.1);
id.run();