Vizard 7 » Reference » Physics » Motors
7.3

## Motors

There are three basic motors in vizard and each of these act upon the joint objects. Each axis may have a motor applied to it and the force created by the motor remains until another motor is applied or the motor is removed through the disableMotor function.

#### setMotorAngle

This motor attempts to set the axis angle of the joint and is limited by the force applied and the max speed of which to reach the angle. Using our hingeJoint example we will expand it by using a motor to keep the angle constant.

ball.collideSphere()

ANCHOR_POS = (0,1.8,5)

joint.setMotorAngle(0,90,.26,1)

Here one can see that the ball is trying to reach the straight up position (90 degrees) with a maxTorque of .26 and a speed scale of 1. The ball oscillates shortly because the force is not strong enough to counteract the momentum of the ball once it reaches 90 degrees. To dampen the oscillation try a smaller value for the speed scale such as .5. Note that the speed does not directly correspond to a degree per second or angle per second and is just used to scale the speed at which the desired angle is reached.

#### setMotorVelocity

This motor attempts to set the velocity of a motor and is limited by the force applied. Using the previous example we will replace the angle motor with a velocity motor.

ball.collideSphere()

ANCHOR_POS = (0,1.8,5)

joint.setMotorVelocity(0,-6,2)

For this function the value of velocity passed in correlates to degrees per second and as one can see in this example the ball completes a full rotation in 60 seconds thus making it rotate 6 degrees per second. In the event a smaller force is applied the motor may not be able to maintain the velocity and thus is used as a maximum velocity.

#### setMotorThrottle

This motor scales the amount of torque applied based on the value of the throttle which is in the range -1 to 1. This motor is limited by the total torque, as well as a maximum velocity. Replacing the motor in the previous example with a throttle motor gives us the following:

ball.collideSphere()

ANCHOR_POS = (0,1.8,5)

def onKeyDown(key):
key = float(key)
if key==0:
key=10
if 0<key<=10:
print( key/5-1)
joint.setMotorThrottle(0,key/5-1,.33,0xFFFFF)
viz.callback(viz.KEYDOWN_EVENT,onKeyDown)

In this example pressing any of the number keys will change the throttle applied to the joint with 1 being -.8 throttle, 5 being no throttle and 0 being full throttle.

Notice that the max speed is set to a very large value. By doing this essentially no speed limit is placed on the object and thus it is only limited by other forces.

Another thing to note is that when the velocity of the object is zero full torque will be applied and the torque curve is linear so that when the max velocity is reached zero torque will be applied. While this motor works well to simulate a car it is not accurate as car motors do not have a linear torque curve.