Stage realization not working- Calculating reaction force on parent body in a pin joint
Posted: Mon Jan 27, 2020 1:16 am
Hello,
I am trying to run a simple pendulum and calculate reaction forces on ground. I have made a ball of given radius and an arm length of 2.5 and oscillating it directly with respect to ground, under the influence of gravity only. I have run the simulation in a loop, and set the integration time. Following is the complete code:
import org.opensim.modeling.*
model = Model();
model.setUseVisualizer(true);
bob = Body('bob',10,Vec3(0),Inertia(1));
geo2 = Sphere(1);
bob.attachGeometry(geo2);
model.addBody(bob);
j2 = PinJoint('j2',model.getGround(),Vec3(0,5,0),Vec3(0),bob,Vec3(0,2.5,0),Vec3(0));
model.addJoint(j2);
model.getJointSet().get(0).getCoordinate().setDefaultValue(pi/2);
state = model.initSystem();
for i = 0:500
manager = Manager(model);
state.setTime(0);
manager.initialize(state);
state = manager.integrate(0.02);
model.realizeDynamics(state);
j2.calcReactionOnParentExpressedInGround(state);
end
Dynamic stage is realized but an error is coming. When I run the code simply without using the for loop, output is ok. So, when I run it in the loop, it should give output data in every loop. But that is not happening. I have attached the error file below.
In my main project, I have to get the force between exoskeleton and human forearm in every loop. So, I am attempting to do this as an example.
Thanks in advance.
I am trying to run a simple pendulum and calculate reaction forces on ground. I have made a ball of given radius and an arm length of 2.5 and oscillating it directly with respect to ground, under the influence of gravity only. I have run the simulation in a loop, and set the integration time. Following is the complete code:
import org.opensim.modeling.*
model = Model();
model.setUseVisualizer(true);
bob = Body('bob',10,Vec3(0),Inertia(1));
geo2 = Sphere(1);
bob.attachGeometry(geo2);
model.addBody(bob);
j2 = PinJoint('j2',model.getGround(),Vec3(0,5,0),Vec3(0),bob,Vec3(0,2.5,0),Vec3(0));
model.addJoint(j2);
model.getJointSet().get(0).getCoordinate().setDefaultValue(pi/2);
state = model.initSystem();
for i = 0:500
manager = Manager(model);
state.setTime(0);
manager.initialize(state);
state = manager.integrate(0.02);
model.realizeDynamics(state);
j2.calcReactionOnParentExpressedInGround(state);
end
Dynamic stage is realized but an error is coming. When I run the code simply without using the for loop, output is ok. So, when I run it in the loop, it should give output data in every loop. But that is not happening. I have attached the error file below.
In my main project, I have to get the force between exoskeleton and human forearm in every loop. So, I am attempting to do this as an example.
Thanks in advance.