O'Reilly logo

Make an Arduino-Controlled Robot by Michael Margolis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Controlling Speed and Direction

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 Move provides high level functions to move the robot that simplifies the code in the more complex sketches that follow in chapters to come.

Hardware Required

  • This chapter uses the AFMotor shield described in Chapter 2.

Sketches Used in This Chapter

  • 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).

myRobotMove Sketch

Figure 7-1. myRobotMove Sketch

Types ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required