A collection of line follower projects .Some of these are without microcontroller. Most of these are with atmega8 (www.atmel.com),PIC. we mostly use Codevision and Keil. a discussion of sensor array and the motors differential drive steering

Monday, February 11, 2008

fastcharged.org line follower

Introduction

The internet for me is almost always the first place I go to search for info. on any topic and I spent quite some time investigating how I should begin to enter the world of robotics.

I'd decided that I needed a step-by-step guidebook on how to build a robot, together with a general electronics book.

I prefer the creative freedom of building something from scratch, as opposed to assembling a kit, so the description of "Robot Building for Beginners" by David Cook sounded right for me. David also has his own website Robot Room.

That's the 'robot' book I settled on and after reading it and following the steps to build a robot, I can definitely recommend it to anyone new to both robotics AND electronics.

It was more difficult to identify an electronics book which I would find useful, not only as I began learning about electronics but also when I reached an intermediate level of understanding. As I didn't want to buy too many books to begin with, I finally chose "Practical Electronics for Inventors" by Paul Scherz.

This book is primarily a reference book and it appears to be one of the best general electronic's reference books available. It covers many circuits and components, including various ICs and also describes the main laws and theories which govern electronics. I've benefitted from information that it contains on a number of occassions and I expect I'll refer to it even more in the future. If you are looking for an entry text in electronics though, I suggest you buy another book.

Description

This robot is based on the line following robot detailed in David Cook's book. It uses a comparator chip as it's brains, which makes it a relatively easy first robot to build.

Due to the initial 'entry costs' , as are associated with any hobby i.e. tools, equipment and parts, this will probably end up being one of the most expensive robots I'll build for a while.

I would like to progress to building programmable microcontroller chip based robots, possibly using Atmel's AVR microcontroller series but I wanted to avoid too much complexity when creating my first robot.

There are a few differences between my robot and the one in the book:

  • Flat, hardboard body instead of a plastic sandwich box
  • Handmade hardboard wheels & plastic motor mounts instead of Lego wheels and axles
  • The circuit is built on two small pieces of breadboard instead of a single breadboard
  • To reduce friction, a third, trolley style wheel has been added to the front



Robot underside view

Robot side view
Robot side view



Circuit layout on a solderless and solderable breadboard

Solderless breadboard circuit
Solderless breadboard circuit

Here is a photo of the line following circuit on a 1660 tie-point solderless breadboard.

The Schottky barrier diodes can be seen connected to jumper leads on the left and right of the helping hands, as their leads were too large to fit into the breadboard.

I wasn't able to obtain the DC gearhead motors specified in the book but based on the stated criteria, I finally sourced alternative motors from a local manufacturer.

During my testing of the motors I came across a handy method of measuring RPM (revolutions per minute).

Here is a video (1.23MB, no sound) showing me testing the solderless breadboarded circuit.

As mentioned in the Description section, the body of my robot is quite different from the one in the book. After sketching an initial design of the robot I knew that I couldn't build the circuit on a single 72mm x 92mm breadboard. It would have been too large and the sensors wouldn't have fitted in the correct position to detect the line. Therefore I experimented and was able to fit the main part of the circuit in half of the space, as you can see here:

Half of breadboard with 2 new mounting holes
Half of breadboard with 2 new mounting holes
Using half of the fullsize breadboard
Using half of the fullsize breadboard


Using the halfsize piece of breadboard mean't that some of the components' leads were close enough in the circuit to solder together. I did cover some of these leads with insulation tubing to prevent them from touching other parts of the circuit.

Underside of the main soldered circuit
Underside of the main soldered circuit
Topside of the main soldered circuit
Topside of the main soldered circuit

The circuit's remaining components, four cadmium sulphide (CdS) photoresistor sensors and their two white LED 'headlights' , were placed on a separate strip of breadboard and I used Molex KK connectors to connect this 'sensor' circuit to the main circuit.

I made four test points (metal loops) in total. One each for the positive and negative buses and one for each of the two pairs of photoresistors.

Completed circuit
Completed circuit

Here is a photo of the completed circuit, with all of the parts attached.



TOP

Body Building

The flat body and the wheels are made from the same material, hardboard. It's a 3 1/2mm thick fibrous board with a smooth surface on one side.

After laying out the robot's parts on the board and marking their positions, it was easy to saw the board to the right size and to drill the various holes.

For the wheels, after drawing two 48mm diameter circles and cutting them out, I was left with lot's of flat edges around their circumferences. To round off the edges, I drilled the centres of the two wheels and passed a small bolt through both and fixed it in place with a washer and nut. I then inserted the bolt with the attached wheels into the jaws of a power drill and placed the drill in my bath! - I live in an apartment and don't have a workshop. After donning a dust mask and goggles and powering on the drill, I then used a hand file to remove the wheels' flat edges! Et voila, two 'perfect' wheels :)

Underside of Robot
Underside of Robot
Topside of Robot
Topside of Robot

You can see fairly clearly the robot's body in these two photos.

You might have noticed in the above right photo that I used a 4AAA battery holder unlike in previous photos. The 4AAA and 9V battery holders are attached by a single screw which makes them easy to swap.

The motor mounts are made from a plastic watch box! I used a hacksaw and a handfile to shape them and then carefully marked and drilled the mounting holes for the motors and the body. I was very happy with the final result :)

Last but not least was the 25mm diameter 'trolley' style, castor wheel at the front of the body. It rotates smoothly and the swivel has ball bearings so turning is also smooth.




Test Run

Once the robot was built, I conducted various tests on it as prescribed in the book.

I created courses for the robot to follow out of black and white electrical insulation tape, using one colour per course. For each course I initially balanced the robot's left and right sensors and adjusted the brightness of the headlight LEDs.

One of the tests was to determine the ability of the robot to sense lines under various conditions.

For this, I measured the voltage at each of the robot's sensor test points after placing it directly over the top of a straight line in a course, with it's motors switched off. I repeated the test with the robot pointing slightly to the right and then to the left of the line.

The measurements were taken with a box covering the robot to shield it from all ambient light and then with the box removed so that I could measure the impact of the room's lighting.

Preparing to test the sensor's voltages
Preparing to test the sensor's voltages

This photo shows the robot with test leads connected but before being placed on a line and powered on.

Another test was to determine the load current i.e. the current being used as the robot follows a line. For that test I had to walk behind the robot with a multimeter :)

The final test was the battery discharge (drain) test. This was very simple.

I measured the voltage of a 9V rechargeable battery before connecting it to the robot. The one I used was a NiMH rechargeable rated at 8.4V and 170mAh. Then I powered on the robot and flicked the line-following switch to follow white lines and timed how long the robot accurately followed a simple, elongated oval course.

I had a long wait!

After 2 hours and 49 minutes the robot drifted off the course. I finally switched off the robot after I had placed it back on the course twice and it had left the course at the same point on each lap. I then removed the battery and measured it's voltage.

The starting voltage was 9.13V and the finishing voltage was 7.41V.

Here is a video (1.73MB, no sound) showing the robot following a simple course and another video (920KB, no sound) taken at ground level, that shows the benefit of using a castor wheel.

BTW, the reason there's no sound in any of the videos is due to using a USB webcam on an extended cable, as the course was in another room from my PC :) In future videos I intend to add sound and figure out a way to sync both and compress the final result into a reasonable size!

Conclusion

Well, I'm very satisfied with my first robot and have learn't a lot from the process of building it. From the early stages of reading the book, through designing the body, sourcing the components and parts, to my first ever soldered circuits and the successful 'maiden voyage' of my robot (on a figure of eight course and before it was calibrated!) ;-)

Like most people, there are things that I'd do differently if I was to build the same robot again but most are quite minor. The main change I'd make would be to build the circuit on a PCB (printed circuit board) instead of using point-to-point soldering on a breadboard.

Soldering the components to the breadboard was the most time consuming and fiddly part of building the robot, partly due to my decision to fit the main circuit on to a piece of breadboard which was half the recommended size (but it was worth it) :)

Due to my preference to 'build from scratch' though, I'd probably make my own PCB but this raises it's own problems. The biggest of which, and one I'll ask my local environmental protection dept about, is how to safely dispose of used etchant's (ferric chloride) sludge.

As for my next projects, I'll probably build a 'solaroller' (micro-sized, solar powered car) in the near future. I'm also quite keen on building an Atmel AVR based robot for a number of reasons, one of which is due to the very low entry cost i.e. the chips are cheap, I can create my own simple programmer using a parallel cable and some resistors and program in Basic for free, up to 2K (that's good enough for me to start with).

If you're considering becoming a robotics hobbyist, I hope this article has helped to convince you to begin and for those already involved in this great hobby, perhaps it brings back some early memories :-)

Bye for now,

KD



another line follower



Introduction

This is my second robotics project. It is intended to be a small line following robot.

This project started when I bumped into Byron Jeff at Austin's electronics in Norcross. He introduced me to the Microchip PIC chips *free samples* and his build your own programmer (TLVP) A zillion mail order purchases and hundreds of dollars later, the project is starting to take shape!

Technical Specifications

Here is some preliminary documentation

Desired Size 3"x6"
Processor Microchip PIC 16F876A
Language C
Compiler Hitech C Lite
Programmer Homebrew TLVP + picprg + mods from Byron Jeff
Bootloader tinybld
Drive 2 small Epson stepper motors
Sensors 5 IR detection diodes

Sources

I am new to this game, and so have spent a lot of time coming up to speed and acquiring "stuff." If you're new like me, I thought you might like these links. If you are an old pro, this list probably has some humor value. Places where I have acquired parts for this project:

Pictures, Schematic, Movies, etc.


My second attempt at a drive train up close and personal (let's not mention the first attempt.)



A picture of my homebrew pic programmer. On top is the programmer hooked up to the parallel port. On the bottom is a MAX-232A that converts the signals to 0-5V to talk to the circuit board through an RJ-11 jack.



This is a blurry picture of light cast by the LEDs as seen through my camera. The light is not visible to the naked eye, so I have been using my camera to debug this part of the circuit.



This is my setup for debugging the IR detection part of the circuit. That is an op amp wired on the breadboard, and I have connected everything up with test clips to see if it is my wiring at fault. At this point, I have just discovered that everything works great until you connect the output of the sensor to the processor pin.

Introduction:

The problem is going to be to build a Lego robot with sensors, a motor controller, and a microcontroller that 1. Follows a black tape. 2. Upon reaching the end of the tape will pause for three seconds. 3. After pausing for 3 seconds will return back to the starting point.


The next step in an engineering problem is to come up with a solution. Ideas of implementation must be thought of. There are two possibilities of making a robot come back to the starting point after pausing for three seconds. The first and most obvious way is to make the robot turn around and then drive back to the starting point following the line. This way of implementing has a lot of benefits. The first is that it is the easiest to implement, and it is relatively straight forward. When the robot hits the end of the tape, the sensor will notice that it is not sensing the tape anymore, and this will cause the robot to turn around and when it sees the tape again, will continue on its path. There is one problem with this way though. It is common.


We have all seen a line following robot, and it is neat, but not impressive. I wanted to do something that has not been done. I chose to implement my robot the second possible way, and the hardest way to implement. I wanted my robot to sense the end of the line, and then pause, and after a three second pause, I wanted it to drive in reverse and follow the line going backwards using a second set of sensors, so this is the robot that I will present. The only warning, and sad part of this project is that I can’t find my code. It is on a disk somewhere, and I have no idea where that is. I will provide code for a simple line-following robot though, and will explain the differences. In essence, I will tell you how to build both robots. On a positive note though, I do have a schematic of my robot, so you can see exactly how it is done.



Simple Line following robot:


We now have an idea of what we want to do, so we need to decide what circuits we need, and how to implement them together. We need to break this project into its components, and that is exactly how I did it. Once again, the circuits that we need are 1. An LED detector circuit. 2. A motor controller. 3. A microcontroller to do all logic. 4. 5V voltage regulator.
5v Voltage Regulator:

The first part of the circuit is to use a voltage regulator. This is an integrated circuit that will take the voltage from a 9v battery, and output a constant 5v. This is important because the microcontroller is powered by a constant 5v. Here is a schematic of how to connect the wires to a voltage regulator. When you are looking at the 7805 voltage regulator, the left most pin is connected to the +9 volts, and the middle pin is connected to ground. The right most pin will be a constant 5v. This 5 volts is connected to power the LED emitter, the microcontroller, and in my schematic, the H-bridge motor controller


LED detector:The LED detector circuit is relatively straight forward. It consists of an infrared LED, and an infrared detector. The infrared detector acts like a transistor. When the infrared light hits it, the detector will complete the circuit. The way this detects a black line is, first you shine both the emitter and the detector down on the floor. If the sensor is over the white floor, the infrared light will bounce off the floor, and will be picked up by the detector. The detector output will now be a high voltage. If the sensor/emitter combo is over a black line, then no light will be reflected, and the output will be a low voltage. This voltage is connected to an analog/digital converter, which is in the microcontroller, and this controller can be programmed to make the car either turn right or left. If you start the car on the right side of the tape, the car will drive forward, but will turn to the left. As the sensor crosses over the black tape, the output will be low, and the microcontroller will tell the car to turn to the right. This happens over and over again, and the car will follow the tape



There are some requirements on the parts. You don’t want to put too much voltage across an LED. I chose a 180 ohm resistor to put in series with the LED (pictured on the left in my circuit). I did not want to put 5v across my LED, so the 180 ohm resistor cuts that voltage down, and keeps the LED from being destroyed. There are some requirements for the microcontroller A/D converter also. The input voltage has to be less than 5v. The way I did this was to connect my 9v battery to the detector and played with the resistor values until I got the output voltages to what I liked. I built the circuit, and measured my outputs with a voltage meter, with the sensor over a black tape (Vnolight), and with my sensor over the white floor (Vlight). I found Vnolight to be .2v, and found Vlight to be 3.8v, after choosing a 21Kohm resistor for the detector.





Motor Controller – H-bridge:The next part of my circuit is a motor controller. I had to use an H-bridge for my motor controller, and I will explain why later. First, I am going to explain a simple motor controller. An NPN transistor can be used to control your motor. If the output pin is set high, it can be used to turn on the base of the NPN, and is basically used as a switch to power the motors. You can see on the robot circuit diagram (This is the schematic for the simple robot that just follows a robot in one direction) that the transistors I am talking about are Q1 and Q2. They are connected to GP2 and GP4 on the microcontroller through a 230 ohm resistor. The collector is connected to the positive pole of the motor, and the other pole is connected to + 5v through a 33 ohm resistor. The emitter of the transistor is connected to ground.(This schematic is for a simple line following robot using a transistor as a motor controller. It corresponds with the code that I have supplied).








This is the circuit for a simple motor controller. You see that this microcontroller has pins left open, so it has enough pins to use this kind of controller. My robot though, is using all of the pins because of the two sensing circuits, so I had to use an H-bridge. I also need to have the ability to make the motors go backwards, and forwards, as well as turn. I also needed the capability of making both motors stop. If I was just going to drive forward, then all I need is one analog input (for the sensors), and two digital outputs (one for each motor). If I want the car to stop, I put both outputs low, and if I want to turn left, I turn the right motor on, and the left one off. I do the opposite to turn right. Now for my robot, I was using 2 analog inputs and 3 digital outputs. One output disabled my H-bridge, and the other two went to each motor controller. If the right motor output was high, the motor would drive forwards, and if it was low, it would drive in reverse. With this set up, I could either make the car spin left (by putting right motor forward, and the left motor in reverse), spin right, go forward, and go backwards.



This is an integrated circuit that has two amplifying circuits in it. Here is a schematic of an H-bridge. The way this works is that if the input pin (Phase A/B) is high, then it will cause a certain polarity of the two output pins (Out1A and Out 2A), if the phase pin goes low, it will switch this polarity. This will cause a motor to either drive forward or backwards.


Pins:


1. Ground- connected to ground for the entire chip


2. Phase A- connected to microcontroller to control Right motor


3. Enable A – this has to be grounded to enable the circuit


4. Out 1A – this is connected to one pole of the motor


5. Vea – This is connected to the emitter of the transistors, and needs to be grounded


6. Out 2A – this is connected to the other pole of the motor7-12. These are the same as the first 6, and are connected the sameThe motors that we used were geared LEGO motors.Download H-bridge pdf









Microcontroller:The Microcontroller that I used was a Microchip PIC 12C672. This is an 8 pin chip that does all of the logic for the robot. It is hard to understand, but I will do my best. For my robot, I made 2 analog inputs, I used pins 7 and 6, which was AN0, and AN1. (This all has to be set in the program that is written.) I used pins 5 (GP2), 3 (GP4), and 2 (GP5) as digital outputs. I used GP2 and GP4 to control my motors, and GP5 as an enable to make the motors stop. The PIC chip has a built in analog to digital converter. The first part of the code is setting up the A/D converter, as well as setting the pins up for either analog input, or digital output. There are multiple registers in the chip, and different registers (working ram for the chip), are in two different banks. That is what the bsf STATUS,RPO command is doing. BSF means bit set, it is setting the RPO bit in the status register to one. This selects bank one. The command movlw 0×04, sets the literal value of 04 hex, or 00000100, into the working register, and the next command movwf ADCON1, moves the contents of the working register into the functional register. ADCON1, is the register that tells what pins are set up as input or outputs.

Xtronix


A SIMPLE ALGORITHM FOR LINEFOLLOWER ROBOT

A simple line follower can be easily made without a microcontroller but when you wish to have a better control over the motion and add more features to your robot, using a microcontroller is a good idea.One such simplest form of Line Tracer is discussed here. We use two line sensing elements as shown in figure.

There are three conditions:

A) Both sensors out of line:The line is straight and both sensors are in black portion.So the bot must in ‘Forward’ direction.Hence, both wheels (Left and Right) must consecutivelymove in forward direction.

B) Right sensor on Line:The right sensor is on line and we can see that the bot needs to move in the ‘Right’ direction.Hence, Left wheel must move in forward direction and Right wheel must be stopped (or move backwards).

C) Left sensor on Line:The left sensor is on line and we can see that the bot needs to move in the ‘Left’ direction.Hence, Right wheel must move in forward direction and Left wheel must be stopped (or move backwards).

Analysis Results:

1) Right Sensor On Line => Right Wheel Stopped => Right Motor Stopped => Move Right or StopelseRight Sensor Not On Line => Right Wheel Running => Right Motor Running => Move Left or Forward

2) Left Sensor On Line => Left Wheel Stopped => Left Motor Stopped => Move Left or StopelseLeft Sensor Not On Line => Left Wheel Running => Left Motor Running => Move Right or Forward

LINE FOLLOWER WITH PID CONTROL ( ATMEGA8 )


About Line Follower
The line follower is one of the self operating robot that follows a line that drawn on the floor. The basic operations of the line following are as follows:
Capture line position with optical sensors mounted at front end of the robot. Most are using several number of photo-reflectors, and some leading contestants are using an image sensor for image processing. The line sensing procss requires high resolution and high robustness.
Steear robot to track the line with any steearing mechanism. This is just a servo operation, any phase compensation will be required to stabilize tracking motion by applying digital PID filter or any other servo argolithm.
Control speed according to the lane condition. Running speed is limited during passing a curve due to friction of the tire and the floor.
There are two line styles, white line on the black floor and black line on the white floor. Most contest are adopting the first one in line width of between 15 and 25 millimeters.
Hardware
Mechanics
Right image shows bottom view and side view of the built line following robot. All mechanical and electrical parts are mounted on a proto board, and it also constitutes the chasis.
The line following robot is upheld in three points of two driving wheels and a free wheel. The driving wheels are made with a 7 mm dia ball bearing and a rubber tire. The free wheel is a 5 mm dia ball bearing attached loosely. To drive driving wheels, two tiny vibration motors that used for cellular phone, pager or any mobile equipment are used. Its shaft is pressed onto the tire with a spring plate, the output torque is transferred to the wheels.
The steearing mechanism is realized in differential drive that steear the robot by difference in rotation speed between the left wheel and the right wheel. It does not require any additional actuator, only controling the wheel speed will do.
Electronics
Controller- ATmega8 (Atmel)
Line sensor Six photo-reflectors
Power supply Two CR2032 lithium cells(One is for controller, the other is for motors)
Motor Two micromotors for left wheel and right wheel
Dimensions 45(L), 33(W), 12.5(H) [mm]
Weight 15 grams (Body:8g, Cells:7g)
Performance 53 centimeter per second at oval course







An Atmel ATmega8 is used for the controller and it is powered by a lithium coin cell. The other lithium coin cell is for only motors. Separating the power supply into two cells is to avoid accidental reset of the microcontroller due to voltage dip by motor start current. Six photo-reflectors are mounted at front end of the chasis. They sense reflection rate of the floor under them. Motors are driven in PWM to control rotation speed lineary.
Software




To detect a line to be followed, most contestants are using two or more number of poto-reflectors. Its output current that proportional to reflection rate of the floor is converted to voltage with a resister and tested it if the line is detected or not. However the threshold voltage cannot be fixed to any level because optical current by ambent light is added to the output current like the image shown right.
Most photo-detecting modules for industrial use are using modurated light to avoid interference by the ambient light. The detected signal is filtered with a band pass filter and disused signals are filtered out. Therefore only the modurated signal from the light emitter can be detected. Of course the detector must not be saturated by ambient light, this is effective when the detector is working in linear region.
In this project, pulsed light is used to cancel ambient light. This is suitable for arraied sensors that scanned in sequence to avoid interference from next sensor. The microcontroller starts to scan the sensor status, sample an output voltage, turn on LED and sample again the output voltage. The difference between the two samples is the optical current by LED, output voltage by the ambient light is canceled. The other sensors are also scanned the same avobe in sequence.





Signal processing of line detection
Right image shows the actual line posisiton vs detected line position in center value of 640. The microcontroller scans six sensors and calcurates the line position by output ratio of two sensors near the line. Thus the line position can be detected lineary with only six sensors. All the sensor outputs are captured as analog value that proportioning to reflection ratio, and the sensitivity have variety between each one of them. In this system, to remove the variations from the outputs, calibration parameters for each sensor can be held into non-volatile memory. This can be done with online mode. The microcontroler enters the online mode when an ISP cable is attached, and it can be controlled with a terminal program in serial format of N81 38.4kbps. S1 command monitors sensor values, and S2 command calibrates variation of sensor gain on the reference surface (white paper). The ATmega8 must be set to 8MHz internal osc.







Tracking control
The line position is compeared to the center value to be tracked, the position error is processed with Proportional/Integral/Diffence filters to generate steering command. The line folloing robot tracks the line in PID control that the most popular argolithm for servo control.
The proportional term is the commom process in the servo system. It is only a gain amplifire without time dependent process. The differencial term is applied in order to improve the responce to disturbance, and it also compensate phase lag at the controled object. The D term will be required in most case to stabilize tracking motion. The I term is not used in this project from following resons. The I term that boosts DC gain is applied in order to remove left offset error, however, it often decrease servo stability due to its phase lag. The line following operation can ignore such tracking offset so that the I term is not required.
When any line sensing error has occured for a time due to getting out of line or end of line, the motors are stopped and the microcontroller enters sleep state of zero power consumption.


Notes
Development diary [Ja]
Circuit diagram
Firmware May 23, 2004

Following motion with only P controlThis is a video file of line following motion with only P control. The servo system oscllated.

Following motion with P and D controlsAdding D control could improve the servo stability. The robot follows the line correctly. Therefore the servo parameter must be optimized for mechanical characterristics to improve the tracking stability.

Line follower Robot











I was started 2 years ago. searched in google get a no of pages on this topic. But i cann't get sufficient data anywhere. I was unknown about the Microcontrollers.I hav just little knowledge about electronics and programming.
A line follower can be made without microcontroller also. SENSORS:The LFROBO uses 2 or more sensors tw see the line .The sensors are optical sensors i.e. LDR or photo diode/transistor(Better to use TSOP Demodulator)LOGIC:The data collected by the sensors can be processed through a programmed micro controller or logic circuits.






I designed my Robot, which use two motors control rear wheels and the single front wheel is free. It has 4-infrared sensors on the bottom for detect black tracking tape, when the sensors detected black color, output of comparator, LM324 is low logic and the other the output is high.
Microcontrollor AT89C2051 and H-Bridge driver L293D were used to control direction and speed of motor.
Fig 1. Circuit diagram of my Robot.
Fig 2. Circuit diagram of Infrared sensors and comparators.
Fig 4. Position of sensors, left hand side is side view and right hand side is top view.
Software
Software for write to AT89C2051 is robot1.hex ,which was written by C-language ,the source code is robot1.ccompiled by using MC51 in TINY model with my start up code robot.asm .
MPEG files
Sample of competition between 2051 and 68HC11.
movie1.mpg (1,303kB)
movie2.mpg (373kB)