box2danglejbox2drevolute-joints

How do I set a RevoluteJoint angle and velocity exactly?


I've built a simple simulator using JBox2D, which involves a character built from a collection of bodies and four Revolute Joints. I've run into a problem: I need to restore the 'pose' of this character exactly, given a list of joint angles, joint velocities, and the torso position/rotation/velocity/angular velocity.

There are convenient getters and setters for the state of a body, but I can't find a good way to force the joint angles to where they need to be (moving bodies in the process). A couple solutions on this site recommends setting up a basic feedback system to try to get a joint motor to drive the joint to the desired angle, but this seems like it would be imprecise and possibly compute intensive. I'd ideally like to find a way to just set these values directly.

As a last resort, I could use forward kinematics to calculate all the translations and rotations myself, but maybe there is an easier way.

Any help appreciated. Thanks.


Solution

  • Joints don't inherently have any angle or velocity of their own. It's the relative angle and velocity of the two bodies they connect that determines what you get when you call GetJointAngle and GetJointSpeed (see the source).

    So it follows that there is so direct means to set these things in the joint. You need to set the angle and velocity, angular velocity etc of the bodies that are involved with that joint.