Introduction

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):
Solid solid0 = sim.CreateSolid(); 
Solid solid1 = sim.CreateSolid();
Joint joint = sim.CreateJoint(); 

Note: sim is an initialized Simulator

Attractor Motor

Now we’ll make an Attractor Motor and initialize it:
AttractorMotorData data = new AttractorMotorData();
data.Solid0 = solid0;
data.Solid1 = solid1;
data.Strength = 10.0f;
data.Exponent = 2.0f;
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:
GearedMotorData data = new GearedMotorData();
data.Joint = joint;
data.JointAxisNum = 0;
data.MaxTorque = 10.0f;
data.MaxVelocity = 2000.0f;
data.Throttle = 0.5f;
GearedMotor engine = sim.CreateGearedMotor();
engine.Init(data); 


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:
ServoMotorData data = new ServoMotorData();
data.Joint = joint;
data.Mode = ServoMotorMode.DesiredAngleMode;
data.JointAxisNum = 0;
data.DesiredAngle = 35.0f;
data.MaxTorque = 4.0f;
data.RestoreSpeed = 2.0f;
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:
SpringMotorData data = new SpringMotorData();
data.Solid = solid0;
data.Mode = SpringMotorMode.LinearAndAngular;
data.DesiredPos = new Vector3(4.0f, 0.0f, -8.5f);
data.DesiredForward = new Vector3(0.0f, 0.0f, -1.0f);
data.DesiredUp = new Vector3(0.0f, 1.0f, 0.0f);
data.DesiredRight = new Vector3(1.0f, 0.0f, 0.0f);
data.LinearKd = 2.0f;
data.LinearKs = 20.0f;
data.AngularKd = 0.2f;
data.AngularKs = 0.6f;
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 next Motor is a Thruster:
ThrusterMotorData data = new ThrusterMotorData();
data.Solid = solid0;
data.Force.Type = ForceType.LocalForce;
data.Force.Position = new Vector3(0.0, 250.0, 0.0);
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.

Velocity Motor

The basic idea is to try to reach a certain velocity as soon as possible, ideally in one step. This is often useful for character control.
VelocityMotorData data = new VelocityMotorData();
data.Solid = solid0;
data.MaxForce = 100;
data.Velocity = new Vector3(0.0f, 0.0f, 50.0f);
data.LetGravityAffectSolid = true;
VelocityMotor velMotor = sim.CreateVelocityMotor();
velMotor.Init(data); 


Now, velMotor will work to achieve given velocity as soon as possible, while letting gravity pull the solid down. Note, you can change target velocity later with VelocityMotor.Velocity

Destroying Motors

When you are done with a Motor, tell the Simulator to destroy it:
sim.DestroyMotor(motor); 

Last edited Oct 12, 2006 at 7:04 PM by KleMiX, version 2

Comments

No comments yet.