make_a_raspberry_pi-controlled_robot.pdf

(160002 KB) Pobierz
Make:
A Raspberry Pi-
Controlled Robot
Building a Rover with Python, Linux,
Motors, and Sensors
Wolfram Donat
Robotics/Programming
Make a Raspberry
Pi-Controlled Robot
Space agencies shouldn’t be the only ones who get to play with robotic rovers piled high
with sensors. In tackling just one project—a four-wheeled robotic rover inspired by NASA’s
designs—this book teaches you the basics of the Raspberry Pi, demystifies programming
on Linux, outlines motor basics, and explains the different kinds of sensors needed to make
a cool robot do cool things. Best of all, when you’ve completed the book, you’ll have built a
robot rover ready to do your bidding.
The Raspberry Pi is one of the world’s most popular tiny computers. Inexpensive and small,
it’s perfect for projects that interact with the world, which is exactly what your robot rover is
going to do!
You don’t need to be an electronics expert to follow along with the fully illustrated step-by-
step instructions in this book. You don’t even need to know how to solder! In addition to the
basic instructions, the book is also rich with resources you can use to enhance your robot’s
capabilities.
In
Make a Raspberry Pi-Controlled Robot,
you’ll learn how to:
»
»
»
»
»
Build a robot chassis and control motors and motor drivers from a Raspberry Pi.
Monitor the real world with temperature, barometric pressure, and distance sensors.
Know where your bot is going using GPS, an accelerometer, and a magnetometer.
Control your robot—and see what it sees—remotely over a WiFi connection.
Connect to sensors with I2C, General Purpose I/O, and an Analog-to-Digital Converter.
You’ll learn how to build a rover from start to finish—a satisfying project that teaches you
all the basics you’ll need to move on to more advanced construction with confidence and a
firm understanding of basic robotics. What are you waiting for?
Experience the World Through the Eyes of the Pi
US $19.99 CAN $20.99
ISBN: 978-1-4571-8603-5
Make a Raspberry
Pi–Controlled Robot
Wolfram Donat
Make a Raspberry Pi–Controlled Robot
by Wolfram Donat
Copyright © 2015 Wolfram Donat. All rights reserved.
Printed in the United States of America.
Published by Maker Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
Maker Media books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http:/
/safaribooksonline.com).
For more information, contact O’Reilly
Media’s corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor:
Patrick Di Justo
Production Editor:
Melanie Yarbrough
Copyeditor:
Sharon Wilkey
Proofreader:
Kim Cofer
November 2014: First Edition
Indexer:
Angela Howard
Cover Designer:
Riley Wilkinson
Interior Designer:
Nellie McKesson
Illustrator:
Rebecca Demarest
Revision History for the First Edition:
2014-11-10:
First release
See
http:/
/oreilly.com/catalog/errata.csp?isbn=9781457186035
for release details.
Make:, Maker Shed, and Maker Faire are registered trademarks of Maker Media, Inc. The Maker Media logo
is a trademark of Maker Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and Maker Media, Inc. was aware of a trademark
claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the user of the information con-
tained herein.
ISBN: 978-1-457-18603-5
[LSI]
Table of Contents
Preface
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
1.
Introduction
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.
Intro to the Raspberry Pi
. . . . . . . . . . . . . . . . . . . . . . . . 7
Model A and Model B
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Model B+
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
GPIO
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
USB
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Power
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Shape
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Where to Get Help
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.
Intro to Linux
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Structure
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Commands
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Navigation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.
Setting Up the Wireless
. . . . . . . . . . . . . . . . . . . . . . . . 27
Historical Problems
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
The Ralink Chipset
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Making It Work: The GUI Way
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Making It Work: The Command-Line Way
. . . . . . . . . . . . . . . . . . . . . . . . . . 32
Setting a Static IP Address
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Running the Pi Headless
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Setting Up an Ad Hoc Network
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
iii
Zgłoś jeśli naruszono regulamin