Tutorial 3: Joints

Joints connect two Solids, constraining their relative motion.  There are several types of Joints, each constraining motion in different ways.  The available Joints are: Hinge Joints (one rotational degree of freedom), Universal Joints (two rotational degrees of freedom), Ball Joints (three rotational degrees of freedom), Wheel Joints (two rotational degrees of freedom; typically one axis coincides with a wheel’s axis, and the other is used for steering), Slider Joints (one translational degree of freedom), and Fixed Joints (zero rotational degrees of freedom).

Joints are created much like Solids:

 opal::Simulator* sim = opal::createSimulator(); opal::Joint* joint = sim->createJoint();

Before using the Joint, it must be initialized with a JointData object.  Before it can be initialized, you must create two Solids and position them:

 opal::Solid* solid0 = sim->createSolid(); opal::BoxShapeData boxData; solid0->addShape(boxData);   opal::Solid* solid1 = sim->createSolid(); opal::Matrix44r solid1Transform; solid1Transform.translate(0.0, 1.5, 0.0); solid1->setTransform(solid1Transform); opal::CapsuleShapeData capsuleData; solid1->addShape(capsuleData);   opal::JointData jointData; jointData.setType(opal::HINGE_JOINT); jointData.solid0 = solid0; jointData.solid1 = solid1; jointData.anchor = opal::Point3r(0.0, 0.75, 0.0); jointData.axis[0].direction = opal::Vec3r(1.0, 0.0, 0.0); joint->init(jointData);

Note that a Joint can connect two Solids, or it can pin a single Solid to the static environment by simply setting the Joint’s other Solid to NULL.  Joints can have limits for each of their degrees of freedom.  Let’s create another Joint with some limits:

 opal::JointData jointData; jointData.setType(opal::HINGE_JOINT); jointData.solid0 = solid0; jointData.solid1 = solid1; jointData.anchor = opal::Point3r(0.0, 0.75, 0.0); jointData.axis[0].direction = opal::Vec3r(1.0, 0.0, 0.0); jointData.axis[0].limitsEnabled = true; jointData.axis[0].limits.low = -45.0; jointData.axis[0].limits.high = 25.0; joint->init(jointData);

By default, Joints are unbreakable: they can withstand unlimited amounts of stress.  Joints can also be setup as breakable Joints.  The following code sets up an existing Joint in “threshold” break mode (when the combined force and torque on the Joint exceeds some threshold, it breaks):

 joint->setBreakParams(opal::THRESHOLD_MODE, 3.0);

Another Joint break mode in OPAL is “accumulated” mode: stress is accumulated until it exceeds a threshold, at which point the Joint breaks.  When a Joint breaks, it is immediately disabled, and the Joint’s JointBreakEventHandler is notified (if one has been set).

When you are done with a Joint, tell the Simulator to destroy it:

 sim->destroySolid(joint);

If anything depends on this Joint, like a Motor, it will automatically be disabled.

OPAL is Copyright © 2004-2005 Alan Fischer, Andres Reinot, and Tyler Streeter