Tutorial 4: Motors

 

 

A Motor applies forces/torques to Solids or Joints to achieve some desired effect.  There are several types of Motors, including Attractor Motors, Geared Motors, Servo Motors, Spring Motors, and Thruster Motors.  This tutorial will show how to setup each type.  It will also give examples of how each type could be used.

 

Let’s first create all the objects we’ll need (and assume they will be initialized elsewhere):

 

 

opal::Simulator* sim = opal::createSimulator();

opal::Solid* solid0 = sim->createSolid();

opal::Solid* solid1 = sim->createSolid();

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

 

 

 

 

 

 

 

 

Attractor Motor

Now we’ll make an Attractor Motor and initialize it:

 

 

opal::AttractorMotorData data;

data.solid0 = solid0;

data.solid1 = solid1;

data.strength = 10.0;

data.exponent = 2.0;

opal::AttractorMotor* attractor = sim->createAttractorMotor();

attractor->init(data);

 

 

 

 

 

 

 

 

 

 

 

This Attractor Motor will constantly apply forces to the two Solids to make them gravitate toward one another.  This makes it easy to simulate planetary gravitation or magnetic attraction.

 

Geared Motor

Next, let’s make a Geared Motor:

 

 

opal::GearedMotorData data;

data.joint = joint;

data.jointAxisNum = 0;

data.maxTorque = 10.0;

data.maxVelocity = 2000.0;

opal:: GearedMotor* engine = sim->createGearedMotor();

engine->init(data);

engine->setThrottle(0.5);

 

 

 

 

 

 

 

 

 

 

 

 

The Geared Motor’s throttle should now be updated as desired.  The Motor will have more torque available when its angular velocity is low.  As it approaches its max velocity, it will apply less and less torque.  This Motor is great for simulating automobile engines.

 

Servo Motor

The next Motor is a Servo Motor:

 

 

opal::ServoMotorData data;

data.joint = joint;

data.mode = opal::DESIRED_ANGLE_MODE;

data.jointAxisNum = 0;

data.desiredAngle = 35.0;

data.maxTorque = 4.0;

data.restoreSpeed = 2.0;

opal::ServoMotor* servo = sim->createServoMotor();

servo->init(data);

 

 

 

 

 

 

 

 

 

 

 

 

 

The Servo will continually use up to its max torque to try to achieve its desired angle.  Servos are extremely stable controllers, similar to PD or PID controllers.  They make automatic adjustments to keep from overshoot their target angle.  Servos are really good for robot simulations: the robot can simply set its desired Joint angles, and the Servo automatically provides enough torque to reach that angle without overshooting.

 

Spring Motor

A Spring Motor is a simple linear and/or torsional spring with damping that brings a Solid to a desired position and/or orientation:

 

 

opal::SpringMotorData data;

data.solid = solid0;

data.mode = opal::LINEAR_AND_ANGULAR_MODE;

data.desiredPos = opal::Point3r(4.0, 0.0, -8.5);

data.desiredForward = opal::Vec3r(0.0, 0.0, -1.0);

data.desiredUp = opal:: Vec3r (0.0, 1.0, 0.0);

data.desiredRight = opal:: Vec3r (1.0, 0.0, 0.0);

data.linearKd = 2.0;

data.linearKs = 20.0;

data.angularKd = 0.2;

data.angularKs = 0.6;

opal::SpringMotor* spring = sim->createSpringMotor();

spring->init(data);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Springs are good for all kinds of things.  In an application with 3D graphics you can connect a Spring to your camera and have it smoothly move from one desired position/orientation to the next.  They are also great for picking up objects: simply attach the selected object to a Spring with its desired position directly in front of the camera.

 

Thruster Motor

The final Motor is a Thruster:

 

 

opal::ThrusterMotorData data;

data.solid = solid0;

data.force.type = opal::LOCAL_FORCE;

data.force.vec = opal::Vec3r(0.0, 250.0, 0.0);

opal::ThrusterMotor* thruster = sim->createThrusterMotor();

thruster->init(data);

 

 

 

 

 

 

 

 

 

 

Thrusters provide a constant amount of force or torque to a Solid.  This is different from the Geared Motor which runs out of torque when it reaches its max velocity.  Thrusters are naturally good as rocket engines.

 

Destroying Motors

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

 

 

sim->destroyMotor(motor);

 

 

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