Introduction: 2pi Line Follower
I recently built my first robot and figured I'd share the steps and results. It is a simple line-follower built on the PlastoBot platform in Gordon McComb's Robot Builder's Bonanza and driven by an ATmega328 chip connected to an SN754410 dual H-bridge motor driver. I'm also a big fan of David Cook's Intermediate Robot Building and website, so I highly recommend anyone interested in amateur robotics check them out.
After building the wood, plastic, and metal bases in the first section of Gordon McComb's book, my next goal was to make one actually move. I considered adding a remote control receiver and turning one into a DIY RC car, but I wanted my first robot to move autonomously, so I decided to try building a classic line follower.
I had seen several amazing videos of Pololu's 3pi Robot and I wanted to see if I could build a simplified version. I've never seen a 3pi in person, but Pololu has documented everything so well, and their tech support is so helpful that I figured I could find out whatever I needed to know online. This version does not have an LCD display, LEDs, buttons, a timing crystal, or any of the other bells and whistles that the 3pi does, but the heart of it is rather similar - the microcontroller, motors, sensors, power module and software algorithms are taken right from the 3pi, hence, the 2pi.
Step 1: Build the Base
This is the base from Chapter 10 of Robot Builder's Bonanza - "Build A Motorized Plastic Platform".
I started with a 12.6" x 7.6" x 0.156" piece of white PVC foam, which was about $5 at a local art supply store. (I was looking for 1/8" thickness but 1/6" was the closest I could find.) PVC foam is incredibly light for its strength, although unlike ABS, it can't be tapped and you have to be careful the screws don't compress it too much.
I copied the 4" x 4" 2D layout from the book into Indeeo's iDraw, a terrific vector drawing program that is far less expensive than Illustrator but worked better on my Mac than the free Inkscape. I printed out the design, temporally glued it to the PVC foam with spray-on adhesive, and then cut it out on MicroMark's mini bandsaw and disc sander then drilled the holes with a Dremel mini drill press. All three of these tools are variable speed so they are great for working with plastics, woods, and soft metals, although this shape is simple enough that it could also be cut by hand.
Step 2: Build the Electronics
The brain of the robot is an ATmega328, the same 8-bit AVR chip used in the Arduino Uno. The microcontroller contiunously reads input from Pololu's array of 6 infrared sensors, determines whether it is left or right of the line, and tells an H-bridge motor driver to adjust the speed to the two motors so as to center itself on the line.
I decided to power the robot from the same 2S LiPo 500mAh battery as I used in my previous Instructable. The battery is connected to a power switch, and from the switch the power is split to two different voltage regulators. One is Pololu's 9V step-up switching regulator, which provides 9V to the motors, which is about the max they're designed to handle. (The 3pi does this to achieve a high maximum speed, but in my case it was a mistake because the motors run much faster than my sensing algorithm can keep up with, so I end up having to slow them way down to keep the robot on the line, losing much torque in the process.) The other regulator from the switch is a 5V linear low-dropout one, which provides a steady 5V for the three logic chips. So I start with 7-8V from the battery (depending on charge), step part of it up to 9V for the motors, and part of it down to 5V for everything else. (For my next version I'll just run the whole thing from a 5V battery source and skip the regulators!)
Next to the motor driver are 4 external pins, two for the left motor and two for the right motor. Above the micro controller are 9 pins connecting the IR sensor array - six for the sensors, plus positive, ground, and an enable pin that I could use to turn off the IR LEDs to save power, although so far I've just kept them on.
I designed the PCB in Eagle and then etched it using Pulsar Pro FX's toner transfer system. I attached the battery to the base with industrial strength velcro. The PCB is attached with 2-56 screws, although I didn't quite leave enough space to attach both sides (another fix for the next version). I attached the sensor array to the bottom also using 2-56 screws, but with 2 nuts on each side of the base so that I could control the height, which I need to sit 1/4" or less off the ground.
Step 3: Program and Test It
I programmed the chip off the board using Adafruit's USBtinyISP AVR Programmer, which I use for all AVR chips. (Not adding the 2x3 ISP header onto the robot's board was a big mistake - every time I want to tweak the code or test anything, I have to pry the chip out of its socket, plug it into another PCB for programming, then re-insert it into the robot. For my next version - and all future robots - I'll just add the six extra header pins.)
Once the robot turns on, it calibrates its sensors by spinning right and left in place, then it just continuously loops through Pololu's PID algorithm.
Part of the art of designing the smoothest and fastest line follower is getting the PID constants just right, which I definitely have not done. This robot is slow and jerky, a first prototype of my first robot attempt. I have a long list of improvements I'd like to make for the next version.
In the meantime, I've embedded a few test videos. The first one is using a simple linear algorithm that just goes left or right based on where the line is at that moment. The second one uses the PID algorithm, which has the interesting benefit that it gets smarter or smoother the longer it runs. By the second lap, it's handling the curves more smoothly, although sometimes the robot veers off the line bizarrely before it gets a chance to refine its constants. The third video is a simple speed and brake test, accelerating to full speed and then stopping as soon as it crosses a line.
I look forward to any comments, questions, or suggestions and hopefully this version, early as it is, will be of interest to other electronics enthusiasts.
1 Person Made This Project!
- DIY GUY Chris made it!