Make a Raspberry PiControlled Robot
Wolfram Donat
Preface
So you want to build a robot.
Like many others before you, you saw the introduction of the Raspberry Piminicomputer as a milestone in not just portable computing technology, but mobile robotic technology. After all, here was a device the size of a credit card, with a processor equivalent to a Pentium III. Here was a device about the same size as an Arduino board, but capable of HD 1080p graphics. Here was a 700MHz CPU, with a set of 26 GPIO pins that could connect it to the outside world. Here, in a nutshell, was a robotic brain.
Unfortunately, it probably didnt take you very long to figure out that calling a computer a robotic brain and making it a robotic brain are two very, very different things. Sure, you can plug the Pi into your desktop monitor, add a keyboard and a mouse, and start to program. But unless you have a specific goal in mind and a clear path to get there, its easy to get lost in the mechanics of writing the program, and adding sensors and motors and switches and cameras and the countless other things that make up a robot. So even though the Raspberry Pi made robotics cheaper and smaller, it didnt necessarily immediately make it easier (see ).
Figure P-1. Not as easy as it looks
Were fortunate that this didnt stop people from pressing forward; a Google search for raspberry pi robot brings up over two million results, not counting the YouTube videos and all of the specialized subsearches, like raspberry pi robot arm and raspberry pi robot servo and raspberry pi robot butler. Robotics is just like any other discipline: there will always be backyard tinkerers, hobbyists, and off-duty professionals, as well as hardware and software hackers who take off-the-shelf parts and stretch them toand pasttheir limits.
Yes, the swarm of synchronized flying drones at MIT is awesome, but that project has several million dollars in funding behind it. Meanwhile, your next-door neighbor has succeeded in creating a wheeled robot that can play fetch with his dog, chase the kids, and play Minecraft , all for a budget of under $500something I find quite a bit more impressive.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold
Shows commands or other text that should be typed literally by the user. Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
This element signifies a tip, suggestion, or general note.
This element indicates a warning or caution.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from Make: books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Make a Raspberry PiControlled Robot by Wolfram Donat (Maker Media). Copyright 2015 Wolfram Donat, 978-1-4571-8603-5.
.
Safari Books Online
Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the worlds leading authors in technology and business.
Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.
Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like Maker Media, OReilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
Make: |
1005 Gravenstein Highway North |
Sebastopol, CA 95472 |
800-998-9938 (in the United States or Canada) |
707-829-0515 (international or local) |
707-829-0104 (fax) |
Make: unites, inspires, informs, and entertains a growing community of resourceful people who undertake amazing projects in their backyards, basements, and garages. Make: celebrates your right to tweak, hack, and bend any technology to your will. The Make: audience continues to be a growing culture and community that believes in bettering ourselves, our environment, our educational systemour entire world. This is much more than an audience, its a worldwide movement that Make: is leadingwe call it the Maker Movement.
For more information about Make:, visit us online:
Make: magazine: http://makezine.com/magazine/ |
Maker Faire: http://makerfaire.com |
Makezine.com: http://makezine.com |
Maker Shed: http://makershed.com/ |
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/make_a_raspberry_pi_controlled_robot.
To comment or ask technical questions about this book, send email to:
Acknowledgments
Its truewriting a book is a solitary endeavor, but it definitely cant be done alone. There are several people Id like to thank, without whom neither the Rover nor this book about it would exist.
First and foremost, thank you to Becky and Reed, for supporting me and putting up with my parts, tools, and half-built, weirdo projects scattered around the house.
Dexter and Jrgenyou can both stop talking now.
And finally, a big thanks to all of the crew at Make: and OReillyBrian, Melanie, Frank, Sharon, Gretchen, Dale, and especially Patrick. You guys are awesome, and all of your support was much appreciated!
Chapter 1. Introduction
The task of building a robot is unlike any other in computer science. Its a strange amalgamation of computer, electrical, and mechanical engineering. Being able to program is great (and necessary), but if you cant get your program to interact with physical items like sensors and motors, then your robot will forever be a virtual one. If your motors cant move your rover without pulling more current than your circuits can source, the rover will be immobile until you find a solutioneither different motors, a different circuit, or a lighter rover. And using a reed switch to determine when your rover runs into a wall is a great idea, until you discover that the switch you bought online cant stand up to the force of a 20-pound rover hitting a wall at 10 miles per hour. You need to learn to roll with the punches, fix what breaks, andwhen possibleprevent it from breaking in the first place.