How to Make a Line Following Robot
So you’ve just finished your Arduino Starter Kit and now you’re wondering “what next?” Let’s take what you’ve learned and put it into a line following robot.
So you’ve just finished your Arduino Starter Kit and now you’re wondering “what next?” Let’s take what you’ve learned and put it into a line following robot.
Lots of people are suggesting great ideas for new image filters on the Makelangelo. I wish I had time to do them all myself. As a compromise I’d like to make it so easy to write new filters that anyone can do it. I’m going to walk you through the simplest image filter and show you how it works.
Here is the image I converted to gcode:
Here is the result as it looks in the Makelangelo program after I converted it with the “scanline” style:
In general the process is:
Let’s take a look at a practical example, based on the converted image above. In the github project you’ll find several Filter_* classes. The simplest Filter has only one method called Convert.
[code]public void Convert(BufferedImage img) throws IOException {
// The picture might be in color. Smash it to 255 shades of grey.
Filter_BlackAndWhite bw = new Filter_BlackAndWhite(255);
img = bw.Process(img); //"process" is for filters that change the original image. "convert" should create a few file without modifying the original.
// Open the destination file
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(dest),"UTF-8");
// Set up the conversion from image space to paper space, select the current tool, etc.
ImageStart(img,out);
// "please change to tool X and press any key to continue"
tool.WriteChangeTo(out);
// Make sure the pen is up for the first move
liftPen(out);
// figure out how many lines we’re going to have on this image.
int steps = (int)Math.ceil(tool.GetDiameter()/(1.75*scale));
if(steps<1) steps=1;
// these next three might not be strictly necessary. Call me paranoid.
lastup=true;
previous_x=0;
previous_y=0;
// Color values are from 0…255 inclusive. 255 is white, 0 is black.
// Lift the pen any time the color value is > level (128 or more).
double level=255.0/2.0;
// from top to bottom of the image…
int x,y,z,i=0;
for(y=0;y<image_height;y+=steps) {
++i;
if((i%2)==0) {
// every even line move left to right
//MoveTo(file,x,y,pen up?)
MoveTo(out,(float)0,(float)y,true);
for(x=0;x<image_width;++x) {
// read the image at x,y
z=TakeImageSample(img,x,y);
MoveTo(out,(float)x,(float)y,( z > level ));
}
MoveTo(out,(float)image_width,(float)y,true);
} else {
// every odd line move right to left
MoveTo(out,(float)image_width,(float)y,true);
for(x=image_width-1;x>=0;–x) {
z=TakeImageSample(img,x,y);
MoveTo(out,(float)x,(float)y,( z > level ));
}
MoveTo(out,(float)0,(float)y,true);
}
}
// TODO Sign name here?
// pen is already lifted. Return to home.
tool.WriteMoveTo(out, 0, 0);
// close the file
out.close();
}[/code]
I’ve just implemented a new inventory management system in the warehouse that should make it easier for new hires to get up to speed and pack your orders faster. Along the way I had to relabel every item, which revealed to me that we had a build up of 3D printer parts that weren’t even listed in the store. So, without further ado, here they are.
ELEC-0053 Thermistors are 100K ohm NTC thermistors, perfect temperature sensors for your 3D printer. These come in a pack of two. One is for the nozzle and one is for the heated bed.
The microchip that drives a stepper motor in a robot has so much current flowing through it that it can get burning hot. To keep temperatures down, the ELEC-0052 heatsinks will draw the heat away from the chip. The fins increase the surface area through which the heat can be absorbed by the air. Combine with a fan for best results.
This is a pack of 5. Comes with adhesive for easy installation.
Keep air moving with the MECH-0071 12v fan. Cool plastic as it leaves the nozzle of your 3D printer for better quality results, or to make sure you stepper drivers don’t overheat. Measures 40mm * 40mm * 10mm.
I’d like to brain-dump a lot more of what I know and get more people building robots. I asked on Reddit, “What would you like to learn about most?” The number one upvoted reply was vibrunazo:
I would like to learn more about mechanics in general. Seems to be the only thing about robotics that I cannot find tutorials and online courses for. Electronics, micro-controllers and programming are well covered in YouTube, Coursera, instructables etc. But I still suck at basic mechanics like types of screws, bolts, gears, belts, understanding materials etc
Well… I can tell you what I use, but it’s a bit like dogma – the next guy will tell you something different. In the end you’ll choose what’s best for you. There’s a little story behind every decision I make, so I’ll start with the high-level view and then work down to specifics.
I have big goals that suck up every available minute. I’ve become a person who looks for the “big wins” – the most effect for the least effort. That’s one reason I love rapid prototyping with inexpensive materials. I’m learning with time to recognize that worrying too much about mechanical design is a sign that I should just “try it and see”. Rapid prototyping gives me the power to quickly make mistakes and then fix them. Choose whatever method you like to make your parts as long as it’s fast, accurate, and repeatable. 3D printing is pretty good. Laser cutting far faster and more reliable. I was using the laser cutter at the local hackspace until I did the math: 30 minutes there, laser might be offline, wait in line, cut parts, bring them home, find there’s a mistake, repeat. In travel time alone it made sense to get my own machine.
By the way: you’ve checked out your local hackspace, right? Right? Field trip! Go. It’s worth the time, they have tools and experience to help.
Wood, metal, and other raw materials are readily available here in Vancouver, Canada. I go to the Home Depot, buy the full sized sheets of 8’x4′ 3mm ply, then ask the guy with the panel saw in the back to cut it into 2’x2′ panels that I can carry under my arm. As it happens, that’s also a great size for my laser cutter.
For fasteners I’ve got a local supplier that sells me metric nuts, bolts, washers, and spacers by the hundreds. I work almost exclusively with 3mm, mainly because that’s the size of the mounting hole in the NEMA17 stepper motors I use. Once I started using them it was easiest to keep using them. Now I have M3s from 5mm all the way up to 45mm.
I recently found a local supplier for bearings. Rollerblade 608zz bearings are very common and inexpensive. Do your homework and find out what’s available around you. A small change in your design might mean you can use a cheaper, more available part. I bought a lot of thrust bearings for pan/tilt robots and the Arm3, but I’ve since found better ways to do the same job. I couldn’t find slew bearings for anything less than $170 from China and only in a few specific sizes, so in desperation I made my own for about $10. They work so well I put six in one robot.
I use a program from woodgears.ca to generate my gear profiles. For $25 CAD it does the job and it’s a lot cheaper than Gearotica. I still have to use two more programs to turn that flat design into a normal or beveled gear. Because I know exactly how big the gears are it’s really easy to laser cut a frame that will hold the axles for each gear.
Professionally made gears and belts still have to be ordered online, which takes days to deliver and might not be perfect. Heck – sometimes while I’m waiting I redesign the machine so much I don’t need the order when it shows up! I’ve only just started to be OK with belts and pulleys because of the Makelangelo, and now it would take a lot of convincing to make me use a different tooth size.
Gearboxes, on the other hand, have been a bad experience. I tried to buy a couple of worm gear gearboxes. If a website refuses to list their prices? Big red flag. I haggled with a supplier in New York and the two gearboxes cost me $250 each. They’re still sitting in my first unused, somewhere in my garage. The trouble with most gearboxes for my application is that they’ve got slop, meaning the output can move even when the input does not.
Hypocycloids don’t have any slop. I looked online for hypocycloid gearboxes for my robot arm project and nobody seems to be selling, so I’m trying to 3D print my own. There were some resources online for making gear profiles that required python and a dozen steps, so I transformed them into a web page to dynamically generate hypocycloid gear profiles and deliver a DXF file you can laser cut.
Rapid prototyping is a win. Local suppliers > internet suppliers for quick response. This is a really exciting time to be in robotics. It’s like the 70s in computers: nobody really knows what they’re doing, everybody’s trying different things. If it’s stupid and it works then it’s not stupid. There is no wrong way!
Follow imakerobots on Instagram to join in the adventure!