Tuesday, July 24, 2018

Let's Build Line Follower/Tracer Our First Robotic Project

The very first time I got introduced to line follower robot is when I was on my 3rd semester at college. There’re my seniors, they like to brag about themselves. Back then, every year there was a line follower competition/tournament being held in the university, but I dunno if it still exists. Never mind that, it was a long story, but today is different, science and engineering technology based civilization are growing rapidly, even elementary school or junior high student have been taught robotic course. Yes, line follower is usual for beginner, amateur, or someone that just start learning robotic. They might pick it as their first robotic project to build.

A tutorial for building line follower is abundant on the web, so I may just skip the details. Btw, this post was not mean for tutorial, this was just sharing experience.

Ok let’s get to the point, a line follower or line tracer is a robot that moves by following a line (black strip) on the ground, it usually use wheels (two or three). Basically it can be divided into three parts: sensor, actuator, and controller.

The sensor used is a type of line sensor, it use light as carrier and consist of emitter and detector. For the emitter we can choose IR (Infra Red) emitter diode or a normal LED may also works. As the detector we can use LDR (Light Dependent Resistor), photodiode, photodiode with IR filter, or phototransistor. Anyway if we accidentally scattered them, can you tell me which one is white LED, IR emitter diode, photodiode, and phototransistor just by the look? They all look quite similar and have the same tube size 5mm.
Here’s how to tell which one is which: (only if the seller didn’t make mistake)
A = photodiode, B = phototransistor, C = IR emitter diode, D = white LED.

Now, how the sensor work is simple, see the drawing below, just think of it as a voltage divider, the more the detector exposed to light the smaller its resistance will be. On white plane the emitted light from emitter will be reflected so the detector receives more light, hence the resistance is smaller and so the voltage drop. And the opposite, on black strip the emitter light from emitter will be absorbed so the detector receives less light, hence the resistance is bigger and so the voltage drop.
Deciding which pair of line sensor to choose depend on aspects like the intensity of light of the surrounding, or the position where the sensor will be installed. I choose IR emitter diode + photodiode with IR filter, as I observed it give the most satisfying margin of voltage different.
My line follower use only 3 line sensors: middle, right, and left.

OK let's move to the next one, the actuator. The actuator consists of the driver circuit (H-Bridge) and the moving parts (Geared DC Motor + Wheel). There’re various way to build H-Bridge circuit, I use the one that I think the simplest (not giving my brain too much strain), it use 4 BJT ( 2 NPN + 2 PNP ). When I did test the circuit to move the motor + wheel, I measure it need current ~400mA to be able to move the wheel (this may vary on the torque load the motor shaft must handle). For the NPN I use TIP3055 Darlington NPN, and for the PNP I use TIP2095 Darlington PNP (These power BJTs might sound overkill thought, but before I’ve tried another BJT, I've tried the combination of 2N3904 and 2N3906, but I only get ~90mA and it wasn’t enough to move the wheel. I’ve also tried 2N2222 and 2N2907, but only get ~200mA and the wheel still lazy on the ground).
At each of the BJT a schottky diode was put in reverse bias position, and also a capacitor was put across the motor. This set-up was mean to prevent damage to the motor and the transistors. The motor coil is basically behave like an inductor that store magnetic energy ( L di/dt). When the H-Bridge circuit is turned off, the motor must find a path to discharge, a high reverse voltage spike is growing across the motor coil. If no diode there, it will discharge through the BJT and destroy it. With the diode, a short circuit discharge path is provided, dissipating energy as heat within the diode, thus safe the BJT and the rest of the circuit. The diode however still need some time to turn-on, a capacitor connected across the motor help conduct the current during this time until the diode is fully conducted (This is also the reason a schottky diode with short turn-on delay is preferred). At the supply rail, three capacitors with different value were connected, their main purpose is to supress the noise, thus won’t disturb the operation of other circuit (the controller and the sensor circuit) supplied from the same source. The small ceramic 0.1uF was to suppress high frequency noise. The medium sized bipolar electrolyte capacitor 47uF was to suppress mid level frequency noise. And finally the bulk sized elco 10mF was to suppress low frequency noise, also act as bulk charge storage to quickly supply the motor with large current when turned on (the present of the bulk elco is crucial here).(note: Oh yeah btw, one H-Bridge only control one DC motor, so we need to build two)

Next to choose the pair of Geared DC Motor and Wheel, there’re 2 affordable options that I found.
Either to choose the smaller geared DC motor + white wheel + ball caster UFO (the later just to make the system more balance):
Or use bigger geared DC motor + yellow tire:


( Note: The DC motor must be geared, if not the robot will slip often when it moves! )

Both options are quite affordable (in term of budget) and have both pros and cons. The first option will make the line follower size smaller and lighter, but probably not so powerful. The second option will make the line follower size bigger and heavier, but bigger motor + tire make more powerful, I mean when the robot moves ( it's hard to explain with words, juts try to imagine how it moves more powerful :D ). At the end of the day I chose the smaller motor + wheel for the reason will be explained later, but it's not really a big deal to choose which one anyway.

Designing a robot often involve a combination of more than one discipline courses: electronics engineering, electrical engineering, computer engineering, mechanical engineering, and maybe a little civil engineering. Now, how do we connect the wheel and motor together with the body of line follower is a mechanical engineering task. Luckily I found a DC motor bracket at one shop on the net, see the black bracket shown in figure below:
With that bracket and using some 3mm screws and nuts, the wheel and motor can be connected to the body (PCB) of line follower in a good engineering way.

If I were to choose the yellow tire and geared DC motor previously, I might need to glue the plastic body of motor to the body of line follower. I’ve seen someone who designed it like that, but they use cutted acrylic material for robot body. And the yellow motor plastic body is glued to the acrylic body. At that time I couldn’t found the acrylic material easily and who provide the service that could do the cutting/shaping ( and also what kind of glue strong enough to use, alteco? aibon? fox? ). Another reason is it will be quite difficult if I want to do replacement/disassembly because the big glob of glue need to be melted using tool like heat gun, it just a matter of taste, it's not my style. That’s why I chose the first options instead.

My line follower use ATMega8A uC as the main controller, the main purpose is to turn on/off H-Bridge controlling the direction of the motor rotation. AVR uC has timer peripheral that can generate PWM ( You already know PWM right? Great! ). The uC pin is connected directly to each base lead of BJT in the H-Bridge circuit (through trimpot set to ~190-200 Ohm). During the test, I measured it draw current 18-20mA from uC pin and it’s still safe below the maximum DC current of 40mA per ATMega8A pin. The uC decide the direction where to move the line follower based on the status of the line sensor. The line sensor was connected to comparator IC LM339N, the voltage drop of the photodiode was took and then feed to the quad comparator. Then the uC can know the status of sensor by reading the output of the comparator (left, middle, right which one is ON/OFF).

The algorithm implemented on the uC firmware C code was simple since this line follower only has 3 eyes. For example if only the middle sensor was ON, then the robot know it must keep move forward. Then if the middle and left sensor was ON, then the robot know it must turn left next. And if the middle and right sensor was ON, then the robot must turn right next. If the robot somehow went off the track, I also implement some small algorithm to correct the robot position so it (hopefully) went back to the track, this is accomplished simply by storing some previous sensor states.

PCB Layout with Altium:


Final form:

The line follower was tested on simple track (at official line follower tournament, the track can be crazy like a zig-zag, maze, stripline, round, curvature, whatever):


Trivia:
  • Using acrylic material might be more sturdy than using the PCB as the body of line follower, as FR-4 PCB material only has 1.6mm thickness can crack if underwent too much stress.
  • Instead of building the H-Bridge circuit from discrete transistor, it was actually better to buy H-Bridge IC (e.g. L298N Dual Channel Full H-Bridge Driver IC), it could safe so much space on the PCB.
  • Instead of using external quad comparator IC LM339N, we could just omit it and use ADC peripheral on the uC, ATMega8A has 8 channel 10-bit ADC. It can be more accurate and faster.
  • The number of sensor used in this line follower implementation which is just 3 is actually very minimum, it limit the robot to find its way on a more complicated track. The number of sensors can be as many as 12 or even 20 in the official line follower competition.

No comments:

Post a Comment