Motor forward (serial/usb input mode only) – Pololu Simple User Manual

Page 63

Advertising
background image

Description: If the Input Mode is Serial/USB, and you have not disabled Safe-start protection, then this command
is required before the motor can run. Specifically, this command must be issued when the controller is first powered
up, after any reset, and after any error stops the motor. This command has no serial response.

If you just want your motor to run whenever possible, you can transmit Exit Safe Start and motor speed commands
regularly. The motor speed commands are documented below. One potential problem with this approach is that if
there is an error (e.g. the battery becomes disconnected) then the motor will start running immediately when the
error has been resolved (e.g. the battery is reconnected).

If you want to prevent your motor from starting up unexpectedly after the controller has recovered from an error,
then you should only send an Exit Safe Start command after either waiting for user input or issuing a warning to
the user.

Motor Forward (Serial/USB input mode only)

Command Format:

Command Byte

Data Byte 1

Data Byte 2 Data Byte 3 Data Byte 4

Compact Protocol

0x85 (133)

speed byte 1

speed byte 2

-

-

Compact Alternate Use

0x85 (133)

0

speed %

-

-

Pololu Protocol

0xAA (170)

device number

0x05 (5)

speed byte 1 speed byte 2

Pololu Alternate Use

0xAA (170)

device number

0x05 (5)

0

speed %

Description: This command lets you set the full-resolution motor target speed in the forward direction. The motor
speed must be a number from 0 (motor stopped) to 3200 (motor forward at full speed) and is specified using two
data bytes. The first data byte contains the low five bits of the speed and the second data byte contains the high
seven bits
of the speed.

The first speed data byte can be computed by taking the full (0-3200) speed

modulo

[http://simple.wikipedia.org/wiki/

Modular_arithmetic]

32, which is the same as dividing the speed by 32, discarding the quotient, and keeping only the

remainder. We can get the same result using binary math by bitwise-ANDing the speed with 0x1F (31). In C (and
many other programming languages), these operations can be carried out with the following expressions:

speed_byte_1 = speed % 32;

or, equivalently:

speed_byte_1 = speed & 0x1F;

The second speed data byte can be computed by dividing the full (0-3200) speed by 32, discarding the remainder,
and keeping only the quotient (i.e. turn the division result into a whole number by dropping everything after the
decimal point). We can get the same result using binary math by bit-shifting the speed right five places. In C (and
many other programming languanges), these operations can be carried out with the following expressions:

speed_byte_2 = speed / 32;

or, equivalently:

speed_byte_2 = speed >> 5;

Pololu Simple Motor Controller User's Guide

© 2001–2014 Pololu Corporation

6. Using the Serial Interface

Page 63 of 101

Advertising