Software > Software

Line follower

<< < (2/2)

pranavm1502:
Hi,
I have attached my code for proportional line follower . But it is not able to turn right angle turns.
Please help.

--- Code: ---
//Main Function
int main(void)
{
 unsigned char data , i ,left_speed, right_speed;
 unsigned char data_old;
 int deviation , integration , prev_deviation , correction;
 init_devices();
 lcd_set_4bit();
 lcd_init();

 while(1)
 {
  Leftmost_white_line =  ADC_Conversion(3); //Getting data of Leftmost WL Sensor
      Left_white_line =  ADC_Conversion(2); //Getting data of left WL Sensor
  Left_center_white_line = ADC_Conversion(1); //Getting data of left center WL Sensor

  Center_white_line =  spi_master_tx_and_rx(0);
  Right_center_white_line =  spi_master_tx_and_rx(1);
  Right_white_line = spi_master_tx_and_rx(2);
  Rightmost_white_line =  spi_master_tx_and_rx(3);


  flag=0;

data_binary[0] = white_detect(Leftmost_white_line);
data_binary[1] = white_detect(Left_white_line);
data_binary[2] = white_detect(Left_center_white_line);
data_binary[3] = white_detect(Center_white_line);
data_binary[4] = white_detect(Right_center_white_line);
data_binary[5] = white_detect(Right_white_line);
data_binary[6] = white_detect(Rightmost_white_line);
/* data =0x0;
data|=data_binary[0];
data<<=1;
data|=data_binary[1];
data<<=1;
data|=data_binary[2];
data<<=1;
data|=data_binary[3];
data<<=1;
data|=data_binary[4];
data<<=1;
data|=data_binary[5];
data<<=1;
data|=data_binary[6];
data&=0b01111111;
*/
_delay_ms(10); // delay to control LCD refresh rate

lcd_home();
//lcd_string("WL4 WL5 WL6 WL7");

lcd_print(1, 1, left_speed, 3);
lcd_print(1, 6, right_speed, 3);
lcd_print(1, 10, deviation+20, 3);
//lcd_print(1, 14, data_binary [3], 3);
//lcd_print(2, 1, data_binary [4], 3);
//lcd_print(2, 6, data_binary [5], 3);
//lcd_print(2, 10, data_binary [6], 3);
//lcd_print(2, 14, data, 3);

deviation =0;
for(i=0;i<7;i++)
deviation += 5*(i+1) * data_binary[i];
deviation-=20;



correction = 2*deviation ;
left_speed = 200+ correction;
right_speed = 200 - correction;
if (correction > 55)
left_speed = 255;
if (correction <-55)
right_speed =255;
if(correction >200)
right_speed =0;
if(correction <-200)
left_speed=0;
velocity(left_speed,right_speed);
forward();

}
return 0;
}

--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version