Created: July 25 2011

Box2D robot arm simulation


I was thinking about how the json files could be used as keyframes in an animation, simply by moving things around and saving the scene for each keyframe. Even though the entire world is saved in the json, you could just load it to get the joint positions and then discard it. Not very efficient for a serious animation I admit but very easy to get up and running.

Although I am thinking about doing this for a ragdoll (well, it will be more of a motor-doll really) I decided to start small with a robot arm to see what I'm up against. The arm has only 3 joints and the base is fixed to a static body which makes things a little easier to begin with.

The action is controlled simply by looping through a sequence of keyframe destinations. When all joints are within x degrees of the target, the next keyframe in the sequence becomes the new destination. At certain keyframes the hand is opened or closed and a small pause is inserted into the sequence.

To move to the next keyframe, the motor speed of each joint is set to a value proportional to the distance left to move, and clamped to a maximum value. For this simple case it manages ok, but more work would be needed if you wanted to say, have the hand following a straight line between keyframes, or move the limb segments at different rates.

I don't think I will be doing any more work on this because I have pretty much learned what I needed from it - next step I'm jumping straight to a ragdoll... er, motor-doll.

Update: Source code (You will also need the b2dJson source code)