Saturday, May 21, 2011

An Algorithm for path tracking robot with junction detecting and signal detecting


Algorithm

We use several important concepts for the robot’s motion.
·        Forward – two motos rotate in the forward direction
·        Right-  left motor rotates while right motor rests
·        Left- right motor rotates while left motor rests
·        Sharp right- left motor rotates forward while right motor rotates backward. Two motors rotate with the same speed in opposite directions. This movement is used when the robot needs to take a sharp right turn.
·        Sharp left- right motor rotates forward while left motor rotates backward. Two motors rotate with the same speed in opposite directions. This movement is used when the robot needs to take a sharp left turn.
·        Reverse- both motors rotate in the backward direction.


B3

B4

B6

B5

B7

B0

B2

B1
 




                             
                                          A top view of the sensor panel
This robot is continuosly repeats the source code until we power it off.so we use  instructions inside a infinite loop.

Path tracking

Basic path tracking is done using B3 and B4.



 If ( B3==0 and B4==0) , go forward  
 If(B3==0 and B4==1), turn left  
 If(B3==1 and B4==0), turn right  
 If (B3==1 and B4==1) {//  this situation occurs when the robot is out of the track, discontinuity,                    in a sharp bend,  
      If(B0==0 or B1==0 or B2==0) turn left while ( B3==1 and B4==1) // sharp left bends  
 and continue  
 If (B5==0 or B6==0 or B7==0) turn right while ( B3==1 and B4==1) // sharp right bend  
 and continue  
 If ( B0==1 and B1==1 and B2==1 and B3==1 and B4==1 and B5==1 and B6==1 and B7==1) go forward , a counter starts , after exeeding a specific limit, turn right and continue within this loop.// to find the path when roaming , in discontinuities the count doesn’t exeed the limit.  
 } // path tracking is done.  

Signal detecting

Signal posts are 4 x 4 cm2  black squares. To detect a signal we use six detectors and three variables , sig_right, sig_left and turn_val with all initial values 0.
Sig_left =1 if a signal is to the left, otherwise 0 ,
Sig_right=1 if a signal is to the right, otherwise 0,
Turn_val has 3 values, 0,1 and 2.
Turn_val becomes 0 after turning at a junction.
Turn_val becomes 1 when a signal is to left
Turn_val becomes 2 when a signal is to right



 If (B0==0 and B1==0 and B2==0 and B3==0 and B4==0 and B7==1 and( (sig_left==0 and sig_right ==0 ) or turn_val==2) ) // identifies a signal post to the left,  
      {  
      Sig_left=1,  
 sig_right=0 ,  
  turn_val=1,  
 continue to the main loop  
        }  
 If (B5==0 and B6==0 and B7==0 and B3==0 and B4==0 and B0==1 and( (sig_left==0 and sig_right ==0 ) or turn_val==1) ) // identifies a signal post to the right  
      {  
 Sig_left=0,  
 sig_right=1 ,  
 turn_val=2,  
      continue to the main loop  
 }  




Junction detecting

This algorithm is developed to detect 4-way junctions and turn according to the signals.We have already ddiscussed how the robot identifies a signal and here we explain how it turns at a junction according to the signals.
We employee six sensors out of the eight sensors to detect a junction.



 If ((B0==0 or B1==0 or B2==0) and (B5==0 or B6==0 or B7==0 ) and (sig_left==1 or sig_right==1))  
      {   
           If ( sig_left==1 and sig_right==0) {  
 Turn left, // to take the middle two sensors to the white background  
 Sharp left , // this takes a sharp left turn  
 Turn left while (B3==1 and B4==1)  
 Sig_left=0;  
 Sig_right=0;  
 Turn_val=0;  
 Continue to main loop;  
             }  
 If ( sig_left==1 and sig_right==0) {  
 Turn right,//to take the middle two sensors to the white background  
 Sharp right , // this takes a sharp right turn  
 Turn right while (B3==1 and B4==1)  
 Sig_left=0;  
 Sig_right=0;  
 Turn_val=0;  
 Continue to main loop;  
                   }  
 }  
 Else // if some signal comes except all combinations discussed above,        
      Go forward and continue to main loop;   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

1 comment:

  1. If u have any problems with this algorithm please send me a email to milindasf@gmail.com

    ReplyDelete