Well, the best I've been able to manage is (in Java):
Code:
float MOTOR_SPEED = 32.0f;
this.ball0_shape = new CircleShape();
this.ball0_shape.m_radius = 0.125f;
this.ball0_shape.m_p.x = -0.25f;
this.ball0_shape.m_p.y = 0.0f;
this.ball1_shape = new CircleShape();
this.ball1_shape.m_radius = 0.125f;
this.ball1_shape.m_p.x = 0.25f;
this.ball1_shape.m_p.y = 0.0f;
this.torso_shape = new PolygonShape();
this.torso_shape.setAsBox(0.5f, 0.5f);
/*
* Fixtures.
*/
this.ball0_fixture_def = new FixtureDef();
this.ball0_fixture_def.density = 8.0f;
this.ball0_fixture_def.shape = this.ball0_shape;
this.ball0_fixture_def.friction = 1.0f;
this.ball0_fixture_def.restitution = 0.0f;
this.ball0_fixture_def.isSensor = false;
this.ball0_fixture_def.userData = this;
this.ball1_fixture_def = new FixtureDef();
this.ball1_fixture_def.density = 8.0f;
this.ball1_fixture_def.shape = this.ball1_shape;
this.ball1_fixture_def.friction = 1.0f;
this.ball1_fixture_def.restitution = 0.0f;
this.ball1_fixture_def.isSensor = false;
this.ball1_fixture_def.userData = this;
this.torso_fixture_def = new FixtureDef();
this.torso_fixture_def.density = 1.0f;
this.torso_fixture_def.shape = this.torso_shape;
this.torso_fixture_def.friction = 0.4f;
this.torso_fixture_def.restitution = 0.0f;
this.torso_fixture_def.isSensor = false;
this.torso_fixture_def.userData = this;
/*
* Body.
*/
this.torso_body_def = new BodyDef();
this.torso_body_def.position.x = position.getX();
this.torso_body_def.position.y = position.getY() + 2.0f;
this.torso_body_def.type = BodyType.DYNAMIC;
this.torso_body_def.fixedRotation = true;
this.torso_body_def.userData = this;
this.wheel_body_def = new BodyDef();
this.wheel_body_def.position.x = position.getX();
this.wheel_body_def.position.y = position.getY();
this.wheel_body_def.type = BodyType.DYNAMIC;
this.wheel_body_def.fixedRotation = false;
this.wheel_body_def.userData = this;
this.pin_body_def = new BodyDef();
this.pin_body_def.position.x = position.getX();
this.pin_body_def.position.y = position.getY();
this.pin_body_def.type = BodyType.DYNAMIC;
this.pin_body_def.fixedRotation = false;
this.pin_body_def.userData = this;
this.wheel_body = controller.createBody(this.wheel_body_def);
this.pin_body = controller.createBody(this.pin_body_def);
this.torso_body = controller.createBody(this.torso_body_def);
this.torso_fixture =
this.torso_body.createFixture(this.torso_fixture_def);
this.ball0_fixture =
this.wheel_body.createFixture(this.ball0_fixture_def);
this.ball1_fixture =
this.wheel_body.createFixture(this.ball1_fixture_def);
this.revolve_joint_def = new RevoluteJointDef();
this.revolve_joint_def.initialize(
this.pin_body,
this.wheel_body,
new Vec2(position.getX(), position.getY()));
this.revolve_joint_def.enableLimit = false;
this.revolve_joint_def.enableMotor = true;
this.revolve_joint_def.maxMotorTorque = MOTOR_SPEED;
this.revolve_joint_def.collideConnected = false;
this.revolve_joint_def.localAnchorA.set(0.0f, 0.0f);
this.revolve_joint_def.localAnchorB.set(0.0f, 0.0f);
this.revolve_joint =
(RevoluteJoint) this.wheel_body.getWorld().createJoint(
this.revolve_joint_def);
this.line_joint_def = new LineJointDef();
this.line_joint_def.initialize(
this.pin_body,
this.torso_body,
this.pin_body.getWorldCenter(),
new Vec2(0.0f, 1.0f));
this.line_joint_def.enableLimit = true;
this.line_joint_def.collideConnected = false;
this.line_joint_def.lowerTranslation = 3.0f;
this.line_joint_def.upperTranslation = 3.0f;
this.line_joint =
(LineJoint) this.wheel_body.getWorld().createJoint(this.line_joint_def);
Which results in something that looks like:

Unfortunately, this is a little "rigid"... The joint doesn't come to a resting state when the motor is switched off - it stays locked to whatever rotation it was at last:

And eventually, after about ten seconds of walking left and right, the torso slips down the line joint until it blocks the rotation of the "legs" (I've no idea why this happens):

This has been the most successful attempt out of any of them, I was really just interested in knowing if there was an obviously-better way to do this...
Edit: The green tendrils sticking out of the circular shapes are just the current body angle for debugging.