Total Pageviews

Saturday 30 April 2011

Line Tracking Robot



Objective:
To build a line following self-operating robot that detects and follows a line that is drawn on the floor. The path consists of a white line on a blue  surface .  Our objective is  to pick two balls from the given destination and pot them in two baskets  placed at two different destinations.
Design Specification:
1.       5V and 12V DC power supply.
2.       The robot should be able distinguish between white strip and the blue surface.
3.       It should pick two balls from the stand at the required destination.
4.       Pot the first ball in the first basket and second ball in the other basket.
Components:
·         Four LED’s and LDR’s.
·         Comparator (lm324) IC.
·         8051 Microcontroller (at89s52) IC.
·         Two motor drivers (H-Bridge l298) IC.
·         Four DC gear motors .

Block diagram:









Pin Diagram of at89s52:
Robot Assembly:
1.       8 x 8” base plate of aluminum.
2.       Two wheels controlled by two DC gear motors.
3.       A single free wheel placed at the front of the robot.
4.       Two 12V batteries fixed underneath the base plate.
5.       Vero board is mounted at an elevated level with the help of aluminum rods on the base plate.
6.       Two DC gear motors are mounted on an other aluminum rod to control two jaws to pick the balls.
7.       This ball picking assembly is mounted on an aluminum rod located at the front of the base plate.


Working of the Robot:
·         First we place the robot on the white strip.
·         The two central LED’s monitor continuously the position of the robot to check whether it is on the line or not by using LDR’s and the comparator circuit.
·         The output of the comparator circuit is given to the microcontroller port which controls the h-bridge (motor driver) IC.
·         This motor driver IC controls the two DC gear motors.


Components Description:
·       L298(motor driver):
The L298 is an integrated monolithic circuit in a 15-lead Multiwatt and PowerSO20 packages. It is a high voltage, high current dual full-bridge driver designed to accept standard TTL logic levels and drive inductive loads such as relays, solenoids, DC and stepping motors. Two enable inputs are provided to enable or disable the device independently of the input signals. The emitters of the lower transistors of each bridge are connected together and the corresponding external terminal can be used for the connection of an external sensing resistor. An additional supply input is provided so that the logic works at a lower voltage.


















·       LM324 (comparator):
The LM324 series consists of four independent, high gain, internally frequency compensated operational amplifiers which were designed specifically to operate from a single power supply over a wide range of voltages. Operation from split power supplies is also possible and the low power supply current drain is independent of the magnitude of the power supply voltage. Application areas include transducer amplifiers, DC gain blocks and all the conventional op amp circuits  hich now can be more easily implemented in single power supply systems. For example, the LM324 series can be directly operated off of the standard +5V power supply voltage which is used in digital systems and will easily provide the required interface electronics without requiring the additional ±15V power supplies.











·       DC Gear Motors:
These are very commonly used in robotics. DC motors can rotate in both directions depending upon the polarity of current through the motor. These motors have free running torque and current ideally zero. These motors have high speed which can be reduced with the help of gears and traded off for torque. Speed Control of DC motors is done through Pulse Width Modulation techniques, i.e. sending the current in intermittent bursts. PWM can be generated by 555 timer IC with adjusted duty cycle. Varying current through the motor varies the torque.

·       LED’s and LDR’s:
LED is used to strike the light at the surface and its reflection is detected through LDR’s in the form of voltage change which is compared by using a comparator IC with a reference voltage.




Source Codes:
#include<at89x52.h>

//INPUT PORT P0

//P0_0 right most sensor
//P0_1 middle right sensor
//P0_2 middle left sensor
//P0_3 left most sensor

//Output port for motors PORT1

//P1_0, P1_1 => Left motor to control left tyre
//P1_2, P1_3 => right motor to control right tyre
//P1_4, P1_5 => Upper Left motor to control left jaw
//P1_0, P1_1 => Upper right motor to control right jaw 







unsigned int b=0;


void delay()
{
                                          unsigned int i;
                                          unsigned int j;
                                          for(i=0;i<1;i++)
                                           for(j=0;j<20000;j++);
}

void delay1()
{
                                          unsigned int i;
                                          unsigned int j;
                                          for(i=0;i<3;i++)
                                           for(j=0;j<40000;j++);
}

void delay2()
{
                                          unsigned int i;
                                          unsigned int j;
                                          for(i=0;i<1;i++)
                                           for(j=0;j<33000;j++);
}

void delay3()
{
                                          unsigned int i;
                                          unsigned int j;
                                          for(i=0;i<2;i++)
                                           for(j=0;j<40000;j++);
}

void delay4()
{
                                          unsigned int i;
                                          unsigned int j;
                                          for(i=0;i<1;i++)
                                           for(j=0;j<20000;j++);
}



int reverse()
{
                                          while(1)
                                          {
                                                     if((P0_3==1)&&(P0_0==1)&&(P0_1==1)&&(P0_2==1)) 
                                                     {
                                                     P1_0=0;
                                                     P1_1=0;
                                                     P1_2=0;
                                                     P1_3=0;
                                                     return 0;
                                                     }
                                                     else if((P0_1==1)&&(P0_2==1))
                                                     {
                                                              P1_0=1;
                                                              P1_1=0;
                                                              P1_2=1;
                                                              P1_3=0;
                                                     }
                                                     else if((P0_1==1)&&(P0_2==0))
                                                     {

                                                                        P1_0=1;
                                                                        P1_1=0;
                                                                       
                                                                        P1_2=0;
                                                                        P1_3=0;
                                         
                                                     }
                                                     else if((P0_1==0)&&(P0_2==1))
                                                     {
                                          
                                                                        P1_0=0;
                                                                        P1_1=0;

                                                                        P1_2=1;
                                                                        P1_3=0;
                                                                                                    
                                                     }

                                                     else
                                                              P1_0=1;
                                                              P1_1=0;
                                                              P1_2=1;
                                                              P1_3=0;
                                            }
                                         
}

int back()
{
                                          while(1)
                                          {
                                                     if((P0_3==1)&&(P0_2==1)&&(P0_1==1))
                                                     {
                                                     P1_0=0;
                                                     P1_1=0;
                                                     P1_2=0;
                                                     P1_3=0;
                                                     return 0;
                                                     }
                                                     else if((P0_1==1)&&(P0_2==1))
                                                     {
                                                              P1_0=1;
                                                              P1_1=0;
                                                              P1_2=1;
                                                              P1_3=0;
                                                     }
                                                     else if((P0_1==1)&&(P0_2==0))
                                                     {

                                                                        P1_0=1;
                                                                        P1_1=0;
                                                                       
                                                                        P1_2=0;
                                                                        P1_3=0;
                                         
                                                     }
                                                     else if((P0_1==0)&&(P0_2==1))
                                                     {
                                          
                                                                        P1_0=0;
                                                                        P1_1=0;

                                                                        P1_2=1;
                                                                        P1_3=0;
                                                                                                    
                                                     }

                                                     else
                                                              P1_0=1;
                                                              P1_1=0;
                                                              P1_2=1;
                                                              P1_3=0;
                                            }
                                         
}


                                         

int right()
{
                                          while(1)
                                           {                                              
                                                     if(P0_0==1)
                                                     {        
                                                              while(P0_0)
                                                              {
                                                                        P1_0=0;
                                                                        P1_1=1;
                                                                        P1_2=0;
                                                                        P1_3=0;
                                                                        }
                                                                        while(!P0_1)
                                                                        {
                                                                                  P1_0=0;
                                                                                  P1_1=1;
                                                                                  P1_2=0;
                                                                                  P1_3=0;
                                                             
                                                                 }
                                                                 P1_0=0;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=0;

                                                                        return 0;
                                                     }
                                                     else if(P0_0==0)
                                                     {
                                                              while((P0_1==0)&&(P0_2==0))
                                                              {
                                                                        P1_0=0;
                                                                        P1_1=1;
                                                                        P1_2=0;
                                                                        P1_3=0;
                                                              }
                                                                        P1_0=0;
                                                                        P1_1=1;
                                                                        P1_2=0;
                                                                        P1_3=1;
                                                                return 0;
                                                     }
                                          }
}

int left_()
{
                                          while(1)
                                           {                                              
                                                     if(P0_3==1)
                                                     {        
                                                              while(P0_3)
                                                              {
                                                                        P1_0=0;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=1;
                                                                        }
                                                                        while(!P0_2)
                                                                        {
                                                                                  P1_0=0;
                                                                                  P1_1=0;
                                                                                  P1_2=0;
                                                                                  P1_3=1;
                                                             
                                                                 }
                                                                 P1_0=0;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=0;

                                                                        return 0;
                                                     }
                                                     else if(P0_3==0)
                                                     {
                                                              while((P0_1==0)&&(P0_2==0))
                                                              {
                                                                        P1_0=0;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=1;
                                                              }
                                                                        P1_0=0;
                                                                        P1_1=1;
                                                                        P1_2=0;
                                                                        P1_3=1;
                                                                return 0;
                                                     }
                                          }
}


int first_stop()
{
                                         
                                           while(1)
                                           {
                                                     if((P0_3==1)&&(P0_0==1)&&(P0_1==1)&&(P0_2==1))
                                                     {
                                                     P1_0=0;
                                                     P1_1=0;
                                                     P1_2=0;
                                                     P1_3=0;
                                                     return 0;
                                                     }
                                                     else if((P0_1==1)&&(P0_2==1))
                                                     {
                                                              P1_0=0;
                                                              P1_1=1;
                                                              P1_2=0;
                                                              P1_3=1;
                                                     }
                                                     else if((P0_2==0)&&(P0_1==1))
                                                     {

                                                                        P1_0=0;
                                                                        P1_1=1;
                                                                       
                                                                        P1_2=0;
                                                                        P1_3=0;
                                         
                                                     }
                                                     else if((P0_2==1)&&(P0_1==0))
                                                     {
                                          
                                                                        P1_0=0;
                                                                        P1_1=0;

                                                                        P1_2=0;
                                                                        P1_3=1;
                                                                                                    
                                                     }

                                                     else
                                                     {        
                                                             
                                                              P1_0=0;
                                                              P1_1=1;
                                                              P1_2=0;
                                                              P1_3=1;
                                                     }
                                           }
}


int straight_1()
{
                                         
                                           while(1)
                                           {
                                                     if((P0_3==1)&&(P0_2==1)&&(P0_1==1))
                                                     {
                                                                        P1_0=0;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=0;
                                                                       
                                                                        return 0;
                                                             
                                                     }
                                                     else if((P0_1==1)&&(P0_2==1))
                                                     {
                                                              P1_0=0;
                                                              P1_1=1;
                                                              P1_2=0;
                                                              P1_3=1;
                                                     }
                                                     else if((P0_1==1)&&(P0_2==0))
                                                     {
                                                             
                                                     // P1_0 left motor
                                                                        P1_0=0;
                                                                        P1_1=1;
                                                                       
                                                                        P1_2=0;
                                                                        P1_3=0;
                                                             
                                                     }
                                                     else if((P0_1==0)&&(P0_2==1))
                                                     {
                                                    
                                                                        P1_0=0;
                                                                        P1_1=0;

                                                                        P1_2=0;
                                                                        P1_3=1;
                                                             
                                                     }

                                                     else
                                                     {        
                                                              P1_0=0;
                                                              P1_1=0;
                                                              P1_2=0;
                                                              P1_3=1;
                                                     }        
                                            }
}


int straight_2()
{
                                         
                                           while(1)
                                           {
                                                     if((P0_3==1)&&(P0_2==1)&&(P0_1==1))
                                                     {
                                                                        P1_0=0;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=0;
                                                                       
                                                                        return 0;
                                                             
                                                     }
                                                     else if((P0_1==1)&&(P0_2==1))
                                                     {
                                                              P1_0=0;
                                                              P1_1=1;
                                                              P1_2=0;
                                                              P1_3=1;
                                                     }
                                                     else if((P0_1==1)&&(P0_2==0))
                                                     {
                                                             
                                                     // P1_0 left motor
                                                                        P1_0=0;
                                                                        P1_1=1;
                                                                       
                                                                        P1_2=0;
                                                                        P1_3=0;
                                                             
                                                     }
                                                     else if((P0_1==0)&&(P0_2==1))
                                                     {
                                                    
                                                                        P1_0=0;
                                                                        P1_1=0;

                                                                        P1_2=0;
                                                                        P1_3=1;
                                                             
                                                     }

                                                     else
                                                     {        
                                                              P1_0=0;
                                                              P1_1=1;
                                                              P1_2=0;
                                                              P1_3=0;
                                                     }        
                                            }
}


int push()
{
                                          while(1)
                                          {
                                           while((P0_3)&&(P0_2)&&(P0_1)&&(P0_0))
                                           {
                                                     P1_0=0;
                                                     P1_1=1;
                                                     P1_2=0;
                                                     P1_3=1;

                                           }
                                           if((!P0_3)&&(!P0_2)&&(!P0_1)&&(!P0_0))
                                           {
                                                     P1_0=0;
                                                     P1_1=0;
                                                     P1_2=0;
                                                     P1_3=0;
                                                     return 0;
                                           }

                                          }
}
int push2()
{
                                          while(1)
                                          {
                                           while(P0_3)
                                           {
                                                     P1_0=0;
                                                     P1_1=1;
                                                     P1_2=0;
                                                     P1_3=1;

                                           }
                                           if((!P0_3))
                                           {
                                                     P1_0=0;
                                                     P1_1=0;
                                                     P1_2=0;
                                                     P1_3=0;
                                                    
                                                     return 0;
                                           }

                                          }
}
int push3()
{
                                          while(1)
                                          {
                                           while(P0_3)
                                           {
                                                     P1_0=1;
                                                     P1_1=0;
                                                     P1_2=1;
                                                     P1_3=0;

                                           }
                                           if(!P0_3)
                                           {
                                                     P1_0=0;
                                                     P1_1=0;
                                                     P1_2=0;
                                                     P1_3=0;
                                                     return 0;
                                           }

                                          }
}



int left()
{
                                          while(1)
                                          {
                                                     if(!P0_1)
                                           {

                                                     while(!P0_1)
                                                     {
                                                                        P1_0=1;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=1;
                                         
                                                     }
                                                     if((P0_1)&&(P0_2))
                                                     {
                                                                        P1_0=0;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=0;
                                                                        delay4();
                                                                        return 0;
                                                     }
                                            }
                                            else
                                            {
                                                                        P1_0=1;
                                                                        P1_1=0;
                                                                        P1_2=0;
                                                                        P1_3=1;

                                                    
                                            }
                                          }
}
void infinite()
{
                                          while(1);
}

int pick()
{
                                          unsigned int i,j;
                                          while(1)
                                          {
                                           P1_4=0;
                                           P1_5=1;
                                           P1_6=0;
                                           P1_7=1;  
                                           for(i=0;i<27;i++)
                                                     for(j=0;j<6993;j++);
                                           P1_4=0;
                                           P1_5=0;
                                           P1_6=0;
                                           P1_7=0;
                                           return 0;
                                          }
                                         
}

int relase_1()
{
                                          unsigned int i,j;
                                          while(1)
                                          {
                                           P1_4=1;
                                           P1_5=0;
                                           P1_6=0;
                                           P1_7=0;  
                                           for(i=0;i<27;i++)
                                                     for(j=0;j<6993;j++);
                                           P1_4=0;
                                           P1_5=0;
                                           P1_6=0;
                                           P1_7=0;
                                           return 0;
                                          }
                                         
}

int release_2()
{
                                          unsigned int i,j;
                                          while(1)
                                          {
                                           P1_4=0;
                                           P1_5=0;
                                           P1_6=1;
                                           P1_7=0;  
                                           for(i=0;i<27;i++)
                                                     for(j=0;j<6993;j++);
                                           P1_4=0;
                                           P1_5=0;
                                           P1_6=0;
                                           P1_7=0;
                                           return 0;
                                          }
                                         
}

void timer0(void) interrupt 1
{                                        
                                          b++;       //time to pass first two crosing
                                          if (b==48)
                                          {
                                          
                                           first_stop();
                                           pick();            //picking the two balls              
                                           delay1();
                                                     P1_0=1;
                                                     P1_1=0;
                                                     P1_2=1;
                                                     P1_3=0;
                                          


                                           delay();
                                          
                                           reverse();
                                          
                                         
                                                     P1_0=1;
                                                     P1_1=0;
                                                     P1_2=1;
                                                     P1_3=0;

                                           delay2();
                                          
                                           reverse();
                                           delay4();
                                          
                                           right();  //turn right after reversing
                                           delay4();
                                          
                                           first_stop();
                                           delay4();
                                          
                                           push();
                                           delay4();
                                          
                                           left();
                                           delay4();

                                         
                                          
                                           straight_1();
                                           delay4();
                                          
                                           push2();
                                           delay4();
                                          
                                           straight_1();
                                           delay4();
                                          
                                           push2();
                                           delay4();

                                           straight_1();
                                           delay4();

                                           push2();
                                           delay4();

                                           release_1();       //relase ball in the right jaw
                                           delay4();
                                                             
                                           back();
                                           delay4();

                                           push3();
                                           delay4();

                                           back();
                                           delay4();

                                          

                                           left_();
                                           delay4();


                                           straight_2();
                                           delay4();

                                           push2();
                                           delay4();

                                           straight_2();
                                           delay4();

                                          right();
                                           delay4();

                                           release_2();       //release ball from the second jaw

                                          


                                          
                                          

                                          
//====================================================================================================                 
                                           infinite();                 
                                         
                                          }         
}


void main()
{                                        
                                          
                                          P0=0xFF;
                                          IE = 0x82;
                                          delay3(); 
                                          TMOD = 0x01;
                                          TH0 = 0x00;
                                          TL0=0x00;
                                          TR0=1;

                                         
                                          while (1)
                                          {
                                         
                                           if((P0_2==1)&&(P0_1==1))
                                           {
                                                     P1_0=0;
                                                     P1_1=1;
                                                    
                                                     P1_2=0;
                                                     P1_3=1;  
                                           }
                                           else if((P0_2==1)&&(P0_1==0))
                                           {
                                                     P1_0=0;
                                                     P1_1=0;
                                                     P1_2=0;
                                                     P1_3=1;
                                           }
                                           else if((P0_2==0)&&(P0_1==1))
                                           {
                                                     P1_0=0;
                                                     P1_1=1;
                                                     P1_2=0;
                                                     P1_3=0;
                                           }
                                           else if((P0_2==0)&&(P0_1==0))
                                           {
                                                     P1_0=0;
                                                     P1_1=1;
                                                     P1_2=0;
                                                     P1_3=0;
                                                    
                                                                       
                                           }
                                          }
 }


No comments:

Post a Comment