Book Image

Raspberry Pi Robotic Projects

By : Dr. Richard Grimmett
Book Image

Raspberry Pi Robotic Projects

By: Dr. Richard Grimmett

Overview of this book

<p>Robotics development is accelerating, and an amazing array of new hardware and software capabilities are available to anyone with an interest in the area. Robots will soon be a part of our everyday life, and it will soon be as important to know how they work as it is to know how a computer works. Raspberry Pi is a credit-card sized, fully capable PC that can be used for many of the things that your desktop PC does, such as spreadsheets, word processing, and games.</p> <p>This book starts with the essentials of turning on the basic hardware. It provides the capability to interpret your commands and have your robot initiate actions. By the time you are through, you’ll have robots that can speak, listen, and move in a number of amazing ways.</p> <p>This book is a step-by-step projects guide to unlocking some complex and interesting capabilities of Raspberry Pi. Teaching you to use Raspberry Pi from scratch, this book will discuss a wide range of capabilities that can be achieved with it. These capabilities include voice recognition, human-like speech simulation, computer vision, motor control, GPS location, and wireless control. You will then learn how to combine these capabilities to create your own robotics projects.</p> <p>By the time you have completed this book, you will be able to use Raspberry Pi to create some complex and fascinating robotics projects with a vast array of capabilities.</p>
Table of Contents (18 chapters)
Raspberry Pi Robotic Projects
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the keyboard to control your project


Now that the keyboard is connected, let's figure out how to accept commands on Raspberry Pi. Now that you can enter commands wirelessly, the next step is to create a program that can take these commands and then have your project execute them. There are a couple of options here; you'll see examples of both. The first is to simply include the command interface in your program. Let's take an example of the program you wrote to move your wheeled robot, dcmotor.py. If you want, you can copy that program using cp dcmotor.py remote.py.

In order to add user control, you need two new programming constructs, the while loop and the if statement. Let's add them to the program and then we will learn what they do. The following is a listing of the area of code you are going to change:

You will edit your program by making some changes. Add the code in the preceding screenshot just below the ser = serial.Serial('/dev/ttyUBS0', 19200, timeout = 1) statement. The...