PRISMATIC JOINT

21
Jun
2012

A prismatic joint allows for relative translation of two bodies along a specified axis. A prismatic joint prevents relative rotation. Therefore, a prismatic joint has a single degree of freedom. The prismatic joint definition is similar to the revolute joint description; just substitute translation for angle and force for torque.

Distance Joint

Make sure the following codes are at the beginning.

var    b2Vec2 = Box2D.Common.Math.b2Vec2
,      b2BodyDef = Box2D.Dynamics.b2BodyDef
,      b2Body = Box2D.Dynamics.b2Body
,      b2FixtureDef = Box2D.Dynamics.b2FixtureDef
,      b2World = Box2D.Dynamics.b2World
,      b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape
,      b2CircleShape = Box2D.Collision.Shapes.b2CircleShape
,      b2MouseJointDef =  Box2D.Dynamics.Joints.b2MouseJointDef
,	   b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef
,      b2DebugDraw = Box2D.Dynamics.b2DebugDraw
,      b2Fixture = Box2D.Dynamics.b2Fixture
,      b2AABB = Box2D.Collision.b2AABB;

Line 9 should be present.

Prismatic Joint Definition

var prismaticJointDef = new b2PrismaticJointDef();
var worldaxis = new b2Vec2(0,1); //Must be a Unit Vector
prismaticJointDef.Initialize(box1, box2, box2.GetWorldCenter(), worldaxis);
//prismaticJointDef.referenceAngle = Math.PI/4;
prismaticJointDef.lowerTranslation = -5; // in the direction of vector
prismaticJointDef.upperTranslation = 5; // opposite the direction of vector
prismaticJointDef.enableLimit = true;
prismaticJointDef.maxMotorForce = 111.0;
prismaticJointDef.motorSpeed = -100.0; // -ve in the direction of vector; +ve away from the vector
prismaticJointDef.enableMotor = true;
var prismatic_joint = world.CreateJoint(prismaticJointDef);
World Axis should be a unit vector. A unit vector means its magnitude is ONE. For example, if we want to create a World Axis at an angle of 45 degrees with positive X Axis in counter clockwise direction.

Prismatic

We must do this:
var vec = 1/Math.sqrt(2);
var worldaxis = new b2Vec2(vec,vec);

The Prismatic Joint will be created between box1 and box2 with anchor point at the center of box2 with allowed direction in Y Axis. The anchor point may or may not lie on the bodies.

Reference angle will turn the world axis by the given angle in anti clockwise direction. The angle should be supplied in Radians.

These two lines:
prismaticJointDef.lowerTranslation = -5; // in the direction of vector
prismaticJointDef.upperTranslation = 5; // opposite the direction of vector
will limit the relative movement of the bodies. The "lowerTranslation" will limit the movement of the body in the direction of Vector and "upperTranslation" will limit the movement in the Opposite Direction of the vector. For this to work "enableLimit" should be set to true.

Notice the -ve sign in the LowerTranslation line. This -ve sign should be there.

These three lines:
prismaticJointDef.maxMotorForce = 111.0;
prismaticJointDef.motorSpeed = -100.0; // -ve in the direction of vector; +ve away from the vector
prismaticJointDef.enableMotor = true;
will move the body depending on the set motor speed. Set Maximum motor force and Motor Speed. If motor speed is +ve Body will move on its own in the direction away from the specified direction vector. The opposite will happen when it is set to -ve. For this to work "enableMotor" should be set to true.

Here are the relevant member functions:
prismatic_joint.GetJointTranslation();
prismatic_joint.GetJointSpeed();
prismatic_joint.GetMotorForce();
prismatic_joint.SetMotorSpeed(speed);
prismatic_joint.SetMotorForce(force);

By administrator at 04:24:00 PM 0 Comment(s)

Comments

There are no comments yet. Be the first one to add a comment!

Add a Comment

Please enter the email address.Invalid format. (Won't be Displayed)
Notify me of followup comments
Enter the displayed Code: captcha