Joints for a pseudo-walker

Hello.

I've been trying for a couple of days, using various combinations of joints, to achieve the following:

Image

The box at the top is supposed to have fixed rotation and the two circles orbit around central anchor point in order to achieve a reasonable "walking" motion (assuming sufficient friction on the circles). Could somebody please give me an example of how I can achieve this?
A revolute joint should work fine... perhaps you could mention what problems you are having.
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:

Image

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:

Image

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):

Image

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.
I think you just need to set the max motor torque to a much lower value when not walking, to allow the feet to 'relax' into a natural position.

The torso slipping down could be due to the pin body having no fixture and iirc it takes the default mass of 1 which makes it much lighter than the torso body it supports. When a joint makes position corrections for the bodies it connects, heavier bodies prevail over lighter bodies. It's better to keep the mass of intermediate bodies like you have to a similar or higher mass than the bodies they connect.

Another side effect of the pin body having no fixture is that the rotational inertia takes a default value of zero, ie. it becomes a fixed rotation body. Normally the line joint should allow rotation between the bodies it connects, but if both the bodies are fixed rotation then you basically have a prismatic joint. After you give the pin body some mass by giving it a fixture you will find that it cannot walk because the pin body is free to rotate. You could intentionally set the pin body to be fixed rotation to avoid that, but.... I thought the point of the line joint was to avoid the need for a two-joint combo in the first place. I don't use the java port but in the C++ version the wheel joint (the line joint renamed afaik) does a good job of this kind of movement on it's own. http://www.youtube.com/watch?v=g5QXrx6_WZI
Quote:
I think you just need to set the max motor torque to a much lower value when not walking, to allow the feet to 'relax' into a natural position.


Ah, yes, thanks. I was actually setting the motor speed as opposed to just disabling the motor.

Quote:
The torso slipping down could be due to the pin body having no fixture and iirc it takes the default mass of 1 which makes it much lighter than the torso body it supports. When a joint makes position corrections for the bodies it connects, heavier bodies prevail over lighter bodies. It's better to keep the mass of intermediate bodies like you have to a similar or higher mass than the bodies they connect.


Adding a fixture to the pin body unfortunately makes the whole setup go insane:

http://youtu.be/g01zGRMg1aw

As opposed to without:

http://youtu.be/OY3fBNHvZv0

I tried setting the torso fixture to a density of 1.0, (without the pin fixture) but it makes no difference.

Quote:
I don't use the java port but in the C++ version the wheel joint (the line joint renamed afaik) does a good job of this kind of movement on it's own. http://www.youtube.com/watch?v=g5QXrx6_WZI


That's exactly the kind of movement I was looking for! The Java port doesn't seem to have the wheel joint yet, but it does have the line joint.
I've attempted to simplify the setup based on the few examples I could find of the wheel/line joint in the wild:

Code:
    float  MOTOR_SPEED = 1024.0f;

    this.ball_left_shape = new CircleShape();
    this.ball_left_shape.m_radius = 0.125f;
    this.ball_left_shape.m_p.x = -0.5f;
    this.ball_left_shape.m_p.y = 0.0f;

    this.ball_right_shape = new CircleShape();
    this.ball_right_shape.m_radius = 0.125f;
    this.ball_right_shape.m_p.x = 0.5f;
    this.ball_right_shape.m_p.y = 0.0f;

    this.ball_up_shape = new CircleShape();
    this.ball_up_shape.m_radius = 0.125f;
    this.ball_up_shape.m_p.x = 0.0f;
    this.ball_up_shape.m_p.y = 0.5f;

    this.ball_down_shape = new CircleShape();
    this.ball_down_shape.m_radius = 0.125f;
    this.ball_down_shape.m_p.x = 0.0f;
    this.ball_down_shape.m_p.y = -0.5f;

    this.torso_shape = new PolygonShape();
    this.torso_shape.setAsBox(0.5f, 0.5f);

    /*
     * Fixtures.
     */

    this.ball_left_fixture_def = new FixtureDef();
    this.ball_left_fixture_def.density = 1.0f;
    this.ball_left_fixture_def.shape = this.ball_left_shape;
    this.ball_left_fixture_def.friction = 0.5f;
    this.ball_left_fixture_def.restitution = 0.0f;
    this.ball_left_fixture_def.userData = this;

    this.ball_right_fixture_def = new FixtureDef();
    this.ball_right_fixture_def.density = 1.0f;
    this.ball_right_fixture_def.shape = this.ball_right_shape;
    this.ball_right_fixture_def.friction = 0.5f;
    this.ball_right_fixture_def.restitution = 0.0f;
    this.ball_right_fixture_def.userData = this;

    this.ball_up_fixture_def = new FixtureDef();
    this.ball_up_fixture_def.density = 1.0f;
    this.ball_up_fixture_def.shape = this.ball_up_shape;
    this.ball_up_fixture_def.friction = 0.5f;
    this.ball_up_fixture_def.restitution = 0.0f;
    this.ball_up_fixture_def.userData = this;

    this.ball_down_fixture_def = new FixtureDef();
    this.ball_down_fixture_def.density = 1.0f;
    this.ball_down_fixture_def.shape = this.ball_down_shape;
    this.ball_down_fixture_def.friction = 0.5f;
    this.ball_down_fixture_def.restitution = 0.0f;
    this.ball_down_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.5f;
    this.torso_fixture_def.restitution = 0.0f;
    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.torso_body = controller.createBody(this.torso_body_def);
    this.torso_fixture =
      this.torso_body.createFixture(this.torso_fixture_def);

    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.wheel_body = controller.createBody(this.wheel_body_def);
    this.ball_left_fixture =
      this.wheel_body.createFixture(this.ball_left_fixture_def);
    this.ball_right_fixture =
      this.wheel_body.createFixture(this.ball_right_fixture_def);
    this.ball_up_fixture =
      this.wheel_body.createFixture(this.ball_up_fixture_def);
    this.ball_down_fixture =
      this.wheel_body.createFixture(this.ball_down_fixture_def);

    this.line_joint_def = new LineJointDef();
    this.line_joint_def.initialize(
      this.torso_body,
      this.wheel_body,
      this.wheel_body.getWorldCenter(),
      new Vec2(0.0f, 1.0f));
    this.line_joint_def.enableLimit = true;
    this.line_joint_def.enableMotor = true;
    this.line_joint_def.maxMotorForce = BipedWheeled.MOTOR_SPEED;
    this.line_joint_def.collideConnected = false;

    this.line_joint =
      (LineJoint) this.wheel_body.getWorld().createJoint(this.line_joint_def);


This results in the following:

Image

...which is unable to move, regardless of the motor speed set. The structure doesn't seem "stuck" as some rotation does occur if I initially set the angular velocity of the wheel body, but it's unable to move under its own power even with huge values for MOTOR_SPEED (like the 1024.0 shown).
(reply to your previous post)
...the density of the torso was already 1 wasn't it? How about if you set the density of the pin fixture to something large like 100 to ensure that it is heavier than the two other bodies it is connecting.
irresistible force wrote:
(reply to your previous post)
...the density of the torso was already 1 wasn't it? How about if you set the density of the pin fixture to something large like 100 to ensure that it is heavier than the two other bodies it is connecting.


Makes no positive difference unfortunately, just goes insane in a different way:

http://youtu.be/SWAY92ugEsQ

I'm not convinced the original approach is worth it. As far as I can tell (from code that you yourself have written, no less), that what I'm after is doable with a single line/wheel joint and two bodies.

Original thread: https://box2d.org/forum/viewtopic.php?t=8334