Turning with a differential drive – Pololu 3pi Robot User Manual

Page 16

Advertising
background image

PWM speed control, showing gradual deceleration.

Speed control is achieved by rapidly switching the
motor between two states in the table. Suppose we
keep PD6 high (at 5 V, also called a logical “1”) and
have PD5 alternate quickly between low (0 V or “0”)
and high. The motor driver will switch between the
“forward” and “brake” states, causing M1 to turn
forward at a reduced speed. For example, if PD6 is
high two thirds of the time (a 67% duty cycle), then M1
will turn at approximately 67% of its full speed. Since
the motor voltage is a series of pulses of varying width,
this method of speed control is called pulse-width
modulation (PWM). An example series of PWM
pulses is shown in the graph at right: as the size of the
pulses decreases from 100% duty cycle down to 0%,
the motor speed decreases from full speed down to a
stop.

In the 3pi, speed control is accomplished using special PWM outputs of the main microcontroller that are linked to
the internal timers Timer0 and Timer2. This means that you can set the PWM duty cycle of the two motors once, and
the hardware will continue to produce the PWM signal, in the background, without any further attention.

The

set_motors()

function in the Pololu AVR Library (see

Section 6

for more information) lets you set the duty

cycle, and it uses 8-bit precision: a value of 255 corresponds to 100% duty cycle. For example, to get 67% on M1 and
33% on M2, you would call

set_motors(171,84);

To get a slowly decreasing PWM sequence like the one shown in the graph, you would need to write a loop that
gradually decreases the motor speed over time.

Turning with a differential drive

The 3pi has an independent motor and wheel on each side, which enables a method of locomotion called differential
drive.
It is also known as a “tank drive” since this is how a tank drives. It is completely unlike the steering system
of automobile, which uses a single drive motor and steerable front wheels. Turning with a differential drive is
accomplished by running the two motors at different speeds. In the previous

set_motors()

example, the left wheel

will spin faster than the right, driving the robot forward and to the right. The difference in speeds determines how
sharp the turn will be, and spinning in place can be accomplished by running one motor forward and one backward.
Spinning is an especially effective maneuver for a round robot, and you won’t have to worry about parallel parking!

Pololu 3pi Robot User's Guide

© 2001–2014 Pololu Corporation

5. How Your 3pi Works

Page 16 of 63

Advertising