This chapter covers the principles of robot motor control that apply to both two wheeled
and four wheeled platforms. The motor controller hardware is explained, as is the code used
to make this functionality accessible to the sketches. The second half of this chapter
(Software Architecture for Robot Mobility) describes software modules that frees the sketch
logic from a dependency on any specific motor hardware. All sketches use the library named
RobotMotor that provides a consistent interface to the hardware
specific motor system. An optional software module named
high level functions to move the robot that simplifies the code in the more complex sketches
that follow in chapters to come.
This chapter uses the AFMotor shield described in Chapter 2.
The motor control code used in Chapter 6 is explained and two new sketches are introduced:
MyRobotCalibrateRotation.ino—A sketch for running the robot
through a range of speeds to calibrate the robot.
MyRobotMove.ino—This sketch shows how to use higher level
movement functions. Constants for defining the current robot movement are added to the
robotDefines tab. A new tab named Move is added that contains the high level movement
functions. The IrSensor tab and RobotMotor library are unchanged (Figure 7-1).
Figure 7-1. myRobotMove Sketch