Vizard 7 » Reference » Physics » Motors
7.6

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.

#Add a ball
ball = viz.add('ball.wrl',pos=(1,1.8,5))
ball.collideSphere()

ANCHOR_POS = (0,1.8,5)
viz.add('white_ball.wrl',pos=ANCHOR_POS) # Anchor Model

joint = viz.phys.addHingeJoint(ball,None,pos=ANCHOR_POS,axis0=[0,0,1])
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.

#Add a ball
ball = viz.add('ball.wrl',pos=(1,1.8,5))
ball.collideSphere()

ANCHOR_POS = (0,1.8,5)
viz.add('white_ball.wrl',pos=ANCHOR_POS) # Anchor Model

joint = viz.phys.addHingeJoint(ball,None,pos=ANCHOR_POS,axis0=[0,0,1])
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:

#Add a ball
ball = viz.add('ball.wrl',pos=(1,1.8,5))
ball.collideSphere()

ANCHOR_POS = (0,1.8,5)
viz.add('white_ball.wrl',pos=ANCHOR_POS) # Anchor Model

joint = viz.phys.addHingeJoint(ball,None,pos=ANCHOR_POS,axis0=[0,0,1])

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.

See also

In this section:

Physics basics

Physics Shapes - In depth discussion of the collide methods.

Forces - More detail on applyForce and applyTorque.

Joints - In depth overview of the joint types.

Motors - In depth explanation of how each motor works with each joint.

Physics Command Table

Other sections:

Tutorial: Physics

Event Reference

Example scripts:

Basic physics

Tracking an object

Collision plane

Callbacks & complex shapes

Forces & materials