Read Chip Huyen's answer to Who do you think is the best professor in the world and why? on Quora

Thursday, 26 September 2013

Line Follower Robot Prototype

Introduction
A line Follower robot is a simple mobile robot that follows a line drawn on a floor. For example a black colored floor with a white line drawn as shown in the next figure. The idea behind the line follower robot is usinglight sensor. When light is incident on white line, the light is reflected and the light sensor detects the reflected light and this signal is used by microcontroller to know that the robot is following the line. When light is incident on black floor, all light is absorbed and nothing is reflected and the light sensor detects nothing and this means that the robot is away from the white line. However, in the last case, the robot may be on the right or left of the white line. So three light sensors are used and the three signals indicates the position of the robot from the line. It is always required to center the three light sensors at the white line as therobot moves.




The Proposed Prototype
A line follower robot is to be designed using ATmega16 microcontroller. Three InfraRed reflectance sensors is arranged in one line. They are composed of an IR LED and an IR phototransistor as shown in the next figure. The analog signal received of each of the phototransistors is proportional to its coverage of the line, and lies between 0 and 2V. The signals of the sensors are weighted by 1,2 and 3 for left, middle and right sensors respectively. The average of the weighted readings gives a value for deviation of the robot from the line. This average has the range between 1 and 3 when the line is at far left or far right of therobot respectively. This average is used to control the speed of the rear left and right wheels of the robot.



Timer-0 and timer-2 in phase correct PWM mode are used for the left and right wheels. It is such that if the average of the weighted readingsis 2, the robot is on the line and the OCR0, and OCR2 values are half the top, and correspondingly by an average value of 1 the right speed is highest and the left is 0, and by an average value of 3 the right speed is 0 and the left is highest. In between the speed (i.e. the values of OCR0 and OCR2) change linearly. It is assumed that the microcontroller frequency is to be 1 MHz, and the A/D clock to be lowest and the timer clocks to be highest.
Code Sample
  • Download Here

  • Free address labels

  • Traffic Control
  • A/D initialization:
// ADC Clock frequency: 7.813 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: None
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x87;
  • Timer-0 initialization:
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Phase correct PWM top=FFh
// OC0 output: Non-Inverted PWM
TCCR0=0x61;
TCNT0=0x00;
OCR0=0x00;
  • Timer-2 initialization:
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Phase correct PWM top=FFh
// OC2 output: Non-Inverted PWM
ASSR=0x00;
TCCR2=0x61;
TCNT2=0x00;
OCR2=0x00;
  • The main code:
// asume that left sensor connected to PA0
// asume that Middle sensor connected to PA1
// asume that right sensor connected to PA2
// any analg value it's digital value is multiplied by 255/2

//    DIGITAL AVERAGE    ANALOG AVERAGE                OCR value
//       255/2                                    1                              0
//       255                                       2                           255/2
//       3*255/2                                3                             255
while (1)
      {
      // Place your code here
      L=read_adc(0);
      M=read_adc(1);
      R=read_adc(2);
      Dav=(L*1+M*2+R*3)/3;
      // TIMER2 CONTROLS THE LEFT MOTOR
      OCR2 = Dav-255/2;
      // TIMER0 CONTROLS THE RIGHT MOTOR
      OCR0 = 255-(Dav-255/2);
      };
  • Simulation using Proteus

You can download the project code and simulation from the following link:
Reference:

No comments:

Post a Comment