JeffB6688
JeffB6688

Reputation: 3880

box2d revolute joint motorSpeed adjustment has no effect

I have what I think is a straight forward box2d configuration consisting of a box2d arm (upper arm, forearm, and hand) on a static body where the arm is connected to the body with a revolute joint. The objective is to pull the arm back so that an object in the hand can be released when the arm moves forward (i.e. an underarm throw). I have enabled a motor to assist the arm in the underarm motion.

The problem is that I can't come up with parameter values that enable a realistic arm speed that doesn't blow past the limits I have enabled on the arm. If I set the maxMotorTorque to a small value (e.g. any number less than 3.0), the arm rotates counterclockwise and does not stop at the limits I set. If I set the motor speed to anything in the range of 5.0 to 15000.0 radians per second, the arm speed does not change when the maxMotorTorque is set to 4.0. If I reduce the maxMotorTorque to a small value, then the arm will fly around, but again it blows past the limits.

Below is the code I use to initialize the revolute joint:

// Create a Revolute Joint at the shoulder
b2RevoluteJointDef revJointDef;
revJointDef.Initialize(body, upperArmBody,
                       upperArmBody->GetWorldPoint(b2Vec2(0, 15.0/100.0)));

revJointDef.enableLimit = true;
revJointDef.lowerAngle = CC_DEGREES_TO_RADIANS(-45);
revJointDef.upperAngle = CC_DEGREES_TO_RADIANS(20); 

revJointDef.enableMotor = true;
revJointDef.motorSpeed = 15000.0;
revJointDef.maxMotorTorque = 4.0;

shoulderJoint = (b2RevoluteJoint*)world->CreateJoint(&revJointDef);

The density of the arm is 0.5 and the density of the object in the hand is 1.0. Reducing these densities will allow the arm to move faster, but again it blows past the limits.

Any ideas on what I am doing wrong? How can I get the arm to move faster without blowing past the limits?

Upvotes: 1

Views: 1232

Answers (1)

Pavel
Pavel

Reputation: 2554

When automatic fails, its time to get all in hands. There possible soultions:

  1. Try to move arm with b2MotorJoint (or b2MouseJoint, if your box2d is old) via precalculated trajectory. I think, it is the best solution for your task.
  2. Help joint limits, and stop arm moving (i.e. set velocity to zero), when it reaches them. For example see my answer there. With this, it will be possible to set greater values for maxMotorTorque.
  3. Move arm manually with applying impulses.
  4. Maybe, physical restrictors can make the work better. I mean creating of some bodies (with great fixtures), that collide only with arms (collision filtering).

Upvotes: 0

Related Questions