Learn Robotics with Raspberry Pi by Matt Timmons-Brown

Learn Robotics with Raspberry Pi by Matt Timmons-Brown

Author:Matt Timmons-Brown
Language: eng
Format: epub, azw
Publisher: No Starch Press
Published: 2019-01-22T16:00:00+00:00


FIGURE 4-7 Two different PWM voltage traces: a duty cycle of 25 percent (top) and a duty cycle of 50 percent (bottom)

While PWM is not a perfect approximation of an analog signal, for most cases it works well, especially at this level. Digitally encoding analog signal levels will allow you to control the exact speed of your robot’s movement.

The GPIO Zero Python library authors have made it easy to vary motor speed using PWM, so you don’t need to know the exact mechanics behind it. All you need to do is provide a value between 0 and 1 in the parentheses of each motor command to represent a value between 0 percent and 100 percent, as follows:

robot.forward(0.25)

time.sleep(1)

robot.left(0.5)

time.sleep(1)

robot.backward()

time.sleep(1)

NOTE

If your robot has been zipping around too fast in the previous examples, feel free to go back and adjust the speed in the last two projects using this method!



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.