---

Thursday, June 5, 2014

Building the MonkMakes Raspberry Pi Robot Kit

The latest product from MonkMakes is a robot kit that I have designed using the RaspiRobot Board v2 (RRB2). The kit is available from MonkMakes.



Overview

The kit comprises:
* a robot chassis, including two gearmotors and a 6 x AA battery holder.
* a RaspiRobot Board v2 (RRB2) that plugs onto the Raspberry Pi and controls the motors, as well as providing power to the Raspberry Pi itself. It uses a switch-mode power supply that can provide the Pi with up to 2A of current. Plenty for a WiFi dongle, display and pretty much anything else that you might want to attach to the Raspberry Pi.
* a HC-SR-04 Ultrasonic rangefinder

Construction

Building the robot is in three phases, first assemble the robot chassis, then fit the Raspberry Pi ad wire things up and finally install the software onto the Raspberry Pi.

Step 1. Check the Packing List

Note the bolts for the chassis come in three sizes. Lets call them short, medium and long. The short and long bolts take the same sized nuts. The middle bolts, used to attach the Raspberry Pi to the Chassis take smaller M2.5 nuts.

Chassis
1 x Laser cut robot platform
2 x Germotors
2 x Wheels
1 x Castor
8 x Short (8mm) bolts for attaching gearmotor assemblies and castor
4 x Brass spacers (10mm) for attaching the castor
8 x Nuts to fit short bolts and long bolts
2 x Medium (12mm) M2.5 bolts to attach the Raspberry Pi to the chassis
2 x Nuts to fit Medium bolts
4 x Long (30mm) bolts to make gearmotor assemblies
2 x Metal plates for fitting the gearmotors

Other
1 x RaspiRobot Board v2
1 x HC-SR-04 Ultrsonic Range Finder
1 x Battery holder for 6 x AA batteries
2 x Self-adhesive Velcro(TM) pads

Step 2. Peel the protective paper layer of the acrylic plastic chassis

The chassis is laser-cut plastic and has a protective layer of paper on both sides. Peel this off.




Step 3. Attach the Castor

Push a small bolt through each of the four holes on the castor and fit a nut behind it. Tighten the nut with pliers, holding the bolt in position with a screw driver. Then fit the remainder of the bolt onto the spacer and tighten up.



Finally push the spacer bolts through the four holes at the end of the chassis and secure with nuts.




Step 4. Attach the Gearmotors

Each of the two gearmotors needs a metal plate attached to it using the long bolts and nuts. One edge of the plate has threaded holes in it which will be used to bolt the motor to the chassis. Make sure that the holes are positioned as shown below so that the motors will fit the same way arround to the chassis.



Now, you can attach the gearmotors to the chassis, with the motor end of the gearmotor towards the castor, as shown below. You can also attach the wheels now.



Be careful not to tighten up the screws too much or you will crack the acrylic chassis.


Step 5.  Attach the Raspberry Pi

Use the two thinner "medium" bolts and nuts to attach the Raspberry Pi to the chassis. Put the bolts through the two holes on the Raspberry Pi board (note that the original revision 1 boards do not have mounting holes and the Pi will have to be attached in some other way.

With the bolts in place position the Raspberry Pi on the top side of the chassis at the opposite end of the board from the castor. Place one bolt through the wide center slot at the edge of the board and the other bolt near the middle of the board will find another hole in the chassis.

Fix the Raspberry Pi in place with the nuts. Do not tighten them too much.





Step 6. Attach the Battery Box

The battery box is attached to the chassis using self-adhesive velcro pads.

First, stick the 'hook' part of the velcro to the bottom of the battery box in roughly the positions shown below:


Next, peel the other half of the pads off their backing paper and place them onto the parts already attached to the battery box with the adhesive side up.


Finally, you can press the battery box into place with the wires towards the Raspberry Pi.



Do not put the batteries into the battery holder yet.


Step 7. Attach the RaspiRobot Board v2 (RRB2) and wire up

We are now ready to wire up the remaining components. Attach the RRB2 to the raspberry Pi. Make sure that all the holes on the socket line up with the pins. Your Raspberry Pi should be powered off while you do this.

Thread the wires from the motors through the big hole in the middle so that they can reach up to the screw terminals on the RRB2. The connections are as follows:


  • The leads from the left motor should go to the two screw terminals on the left of the RRB2.
  • Those for the right motor to the center two screw terminals.
  • The battery box negative lead (black) goes to the screw terminal marked GND
  • The battery box positive lead (red) goes to the screw terminal marked Vin on the right of the row of screw terminals.




At this point, you can also attach the HC-SR-04 ultrasonic rangefinder to the socket labelled "sonar" on the RRB2 facing over the battery box.




Step 8. Fit the batteries and then disconnect

Before we install the test software, we can do a quick test with batteries to make sure our basic setup is ok.

First, make sure that your Raspberry Pi is not powered by its USB lead. We are going to let the RRB2 supply it with power using the batteries. So, fit the batteries (regular or rechargeable) and you should see the LEDs on the Raspberry Pi start to flicker as it boots up. The two LEDs on the RRB2 should also light up.

If this test is successful, then you can now pull one end of the batteries out of the battery holder to act as a switch, because while we are setting up the software, we may as well save the power from our batteries and use the USB power lead to the Pi.

Note. It is important not to power the Pi from its USB connector and using batteries at the same time. One or the other, but not both, or you could damage your Raspberry Pi.


Step 9. Install the Software

To control the RRB2, you need to download and install a Python library onto your Raspberry Pi. The Python library also includes an example program that will make the rover wander around until it detects something near and then reverse away from it, turning a random amount before setting off again.

You can find full instructions for using this library at raspirobot.com.

Before you start, pull the wheels off the gearmotors to stop the robot accidentally driving off your table.

You could attach keyboard, mouse and monitor to your Raspberry Pi, but they are not very portable, so it is better to use SSH. See the tutorial for doing this here. You may also wish to do this over WiFi (see instructions here).

Powering the Raspberry Pi from its USB connector and with a network connection, use SSH to, run the following commands:

$ wget https://github.com/simonmonk/raspirobotboard2/raw/master/python/dist/rrb2-1.1.tar.gz
$ tar -xzf rrb2-1.1.tar.gz
$ cd rrb2-1.1
$ sudo python setup.py install
Having installed the library, we can do some basic tests on the RRB2 using its built-in LEDs. We can experiment with the RaspiRobot Board v2, even without any motors.
Open a Python console (Python2 not 3) by typing the following into a Terminal window:
 $ sudo python
Then, within the python console, type the following, one line at a time:
from rrb2 import *
rr = RRB2()
rr.set_led1(1)
rr.set_led1(0)
rr.set_led2(1)
rr.set_led2(0)
This should turn the LEDs on the RRB2 on and off.


Step 10. Run the Rover Example.

Disconnect the USB power connector from the Raspberry Pi and push the battery you were using as a switch fully into the battery holder. The raspberry Pi should boot up, powered from the batteries via the RRB2.

Leave the network (or WiFi) connected so that you can SSH onto the Raspberry Pi.

To run the obstacle avoiding test program, enter the following commands into the SSH terminal:

$ cd rrb2-1.1/examples
sudo python rover_avoiding.py

Although the program is running, the robot will not start to move until SW2 on the RRB is closed. So using a screwdriver, momentarily short together the connections for SW2 as shown below.



Books.
You may be interested in the books I have written about the Raspberry Pi.

1 comment:

Mike Jupp said...

Hi,

I am reading the 'Programming Arduino' book and have worked my way through to chapter 10. I have everything working but I am a bit mystified about a couple of lines of code. What does the line:
pinState[i] = valueOfParam(i + '0');
do? In particular the + '0' bit!
and its companion line:
return (line1[i+2] - '0');
Thanks

Mike