Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Robotic Blueprints

You're reading from  Raspberry Pi Robotic Blueprints

Product type Book
Published in Oct 2015
Publisher
ISBN-13 9781784396282
Pages 198 pages
Edition 1st Edition
Languages
Concepts

Table of Contents (14) Chapters

Raspberry Pi Robotic Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Adding Raspberry Pi to an RC Vehicle Adding Raspberry Pi to a Humanoid Robot Building a Tracked Vehicle That Can Plan Its Own Path Building a Robot That Can Play Laser Tag A Robot That Can Draw A Robot That Can Play Air Hockey A Robot That Can Fly Index

Chapter 4. Building a Robot That Can Play Laser Tag

In the previous chapters, you've modified an RC car to control it remotely using Raspberry Pi, you've modified a toy robot to respond to your voice commands and you've also built a tracked vehicle that uses sensors to avoid the barriers and arrive at a desired location. In this chapter, you'll leverage some of these capabilities and then add other capabilities so that you can build a pair of wheeled robots to play laser tag.

In this chapter you'll learn the following:

  • Construct a simple two-wheeled platform

  • Leverage the wireless LAN interface and a USB webcam to control your robot via a remote computer

  • Add a joystick to your host computer

  • Connect Raspberry Pi to a laser source

  • Connect Raspberry Pi to a laser receiver

  • Send and receive laser signals programmatically to enable the laser tag capabilities of your robot

Building and controlling a basic wheeled vehicle


To build this project, you'll want to start with a simple wheeled vehicle. There are many possibilities. The following is a two wheeled vehicle available at many online retail outlets like https://www.amazon.com or http://www.ebay.com:

First, you'll build the vehicle using the instructions that come with it. The vehicle uses two DC motors, so you'll control the direction and speed of your robot using a DC motor controller. Since it is so flexible and you are already familiar with it, you'll use the RaspiRobot Board V2. The following is an image of the board:

The specifics on the board can be found at http://www.monkmakes.com/?page_id=698. Connections to the board are very similar to the tracked vehicle connections that were described in Chapter 3, Building a Tracked Vehicle That Can Plan Its Own Path. You'll place the motor controller on top of the vehicle, connect the battery to the motor controller, and then connect both the motors, as shown...

Using the robot library to programmatically control your robot


First, install the libraries to support the motor control board, described in the second chapter. Since this robot uses the same control as the wheeled vehicle, you'll use the same code for the simplified library that you used as a library in the second chapter, as shown here:

The following is the simple code to exercise this program using keystrokes on Raspberry Pi:

Run this program by typing sudo python input.py. If you get an error message telling you that the program does not know about rr=RRB2(), you'll need to copy the rrb2.py file from your installation of the libraries for the motor controller board in the directory rrb2-1.1.

Now that you can control your wheeled robot from the console, let's connect it wirelessly to allow remote control.

Controlling your robot from a remote computer


The next step in constructing your laser tag playing robot is to add the remote control. You'll first need to add the ability to control Raspberry Pi via a WLAN connection. As noted in Chapter 1, Adding Raspberry Pi to an RC Vehicle, the section, Accessing the RC Car remotely, showed you how to add a WLAN interface as an access point. To prepare for the next section, you will want to configure two Raspberry Pis with WLAN, one as an access point and other that you'll connect to the access point. You'll also connect a USB web camera to Raspberry Pi on the wheeled robot for control. Finally, when you have logged in to Raspberry Pi, this will function on the remote computer. Log in to the second Raspberry Pi on the wheeled robot by typing ssh –X pi@xxx.xxx.xxx.xxx, where the xxx.xxx.xxx.xxx is the IP address of Raspberry Pi on the wheeled robot.

You can now luvcview to see the output of the webcam and you can run the input.py program to control the...

Adding a game controller to your remote system


Typing the simple ascii characters will move your robot around, but what you might want is a more intuitive and responsive control interface. The most practical way of doing this is a game controller that has joysticks and several additional buttons. This will make controlling your wheeled robot from the remote computer much easier.

To add the game controller, you'll need to first find a game controller that can be connected to your computer. If you are using Microsoft Windows as the OS on the host computer, then pretty much any USB controller that can be connected to a PC, will work. The same type of controller also works if you are using Linux for the remote computer. In fact, in this example, you'll use another Raspberry Pi as the remote computer.

Since the joystick will be connected to the remote computer, you'll need to run two programs, one on Raspberry Pi remote computer and other on Raspberry Pi on the wheeled robot. You'll use the wireless...

Connecting the laser source and target


The last step in creating the laser tag robots is to add the laser source and laser target, as well as the code that will let you fire the source and detect a hit on the target. First, you'll need to install the hardware.

Let's start with the laser source. You can just use a raw laser source, similar to the one shown in the following image:

They are inexpensive and available on eBay and other online electronics retailers. However, it is a bit easier if you get a laser source with a bit more supporting circuitry, as shown in the following:

These are also available from a number of online retailers, you can find similar modules. All you need is a way to turn on your laser with a control signal from Raspberry Pi. In this module, you'll connect the device to one of the open collector outputs on the motor controller board, the GND pin to OC1 pin, and the S pin to other OC1 pin connection, as shown in the following image:

Now, just a bit of code to add a function...

Summary


This chapter's result is a laser tag playing machine that can be guided remotely. You can even build a simple battlefield with different maze elements and let your wheeled robots loose to play a game of laser tag. In the next chapter, you'll move onto something quite different, a machine that can draw.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Robotic Blueprints
Published in: Oct 2015 Publisher: ISBN-13: 9781784396282
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}