Пример #1
0
int kkkk(void)
{
    velocity(255,255);
	forward();
	while(1)
    {
		servo_1(0);
		servo_2(0);
		servo_3(0);
		forward();
       red_read(); //display the pulse count when red filter is selected
	   _delay_ms(500);
	   green_read(); //display the pulse count when green filter is selected
	   _delay_ms(500);
	   blue_read(); //display the pulse count when blue filter is selected
	   _delay_ms(500); 
	   lcd_wr_command(0x01);
	   print_sensor(1,1,3);	//Prints value of White Line Sensor1
	   print_sensor(1,5,2);	//Prints Value of White Line Sensor2
	   print_sensor(1,9,1);	//Prints Value of White Line Sensor3
	   print_sensor(2,1,11);
	   servo_1(100);
	   servo_2(100);
	   servo_3(100);
	   _delay_ms(7000);
	   
    }
}
/**
  Prints White line sensor values on the screen
*/
void print_sensor_data()
{
		lcd_clear();
		print_sensor(1,1,3);	//Prints value of White Line Sensor1
		print_sensor(1,5,2);	//Prints Value of White Line Sensor2
		print_sensor(1,9,1);	//Prints Value of White Line Sensor3
}
void get_vector() {
Left_white_line = ADC_Conversion(3);
Center_white_line = ADC_Conversion(4);
Right_white_line = ADC_Conversion(5);
print_sensor(2,1,3); //Prints value of White Line Sensor Left
print_sensor(2,5,4); //Prints value of White Line Sensor Center
print_sensor(2,9,5); //Prints Value of White Line Sensor Right
}
//-------------------------------------------------------------------------------
//Main Function
//-------------------------------------------------------------------------------
int main(void)
{
	init_devices();


	while(1)
	{
		sensor_data_interpretation();
		//print_sensor(1,1,1);				//Prints IR Proximity Sensor 1
		BATT_V = ADC_Conversion(0);
		BATT_Voltage = ((ADC_Conversion(0)*100)*0.07902) + 0.7;	//Prints Battery Voltage Status
		lcd_print(1,1,BATT_Voltage,4);

		//print_sensor(1,1,0);							//Prints Battery voltage binary value

		print_sensor(1,6,5);							//Prints IR Proximity Sensor 1
		print_sensor(1,10,6);							//Prints vlaue of Analog IR Proximity Sensor 2
		print_sensor(1,14,7);							//Prints value of Analog IR Proximity Sensor 3
		print_sensor(2,2,3);							//Prints value of White Line Sensor1
		print_sensor(2,6,2);							//Prints Value of White Line Sensor2
		print_sensor(2,10,1);							//Prints Value of White Line Sensor3

		//print_sensor(2,9,11); 						//Analog Value Of Front Sharp Sensor

		sharp = ADC_Conversion(11);						//Stores the Analog value of front sharp connected to ADC channel 11 into variable "sharp"
		value = Sharp_GP2D12_estimation(sharp);				//Stores Distance calsulated in a variable "value".
		lcd_print(2,14,value,3);
	}

}
Пример #5
0
//Main Function
int main()
{
	init_devices();
	lcd_set_4bit();
	lcd_init();
	
	while(1)
	{

		while (my_signal==0x01)
		{
			PORTA = PORTA & 0x00;			
		};
		Left_white_line = ADC_Conversion(3);	//Getting data of Left WL Sensor
		Center_white_line = ADC_Conversion(2);	//Getting data of Center WL Sensor
		Right_white_line = ADC_Conversion(1);	//Getting data of Right WL Sensor

		flag=0;

		print_sensor(1,1,3);	//Prints value of White Line Sensor1
		print_sensor(1,5,2);	//Prints Value of White Line Sensor2
		print_sensor(1,9,1);	//Prints Value of White Line Sensor3
		
		
        if(Center_white_line>0x10 && Left_white_line>0x10 && Right_white_line>0x10)
        {
	        flag=1;
	        forward();
	        velocity(0,0);
	        UDR0=0x34;
        }
		if(Center_white_line<0x10)
		{
			flag=1;
			forward();
			velocity(105,100);
			UDR0=0x36;
		}

		if((Left_white_line>0x10) && (flag==0))
		{
			flag=1;
			forward();
			velocity(105,70);
			UDR0=0x36;
		}

		if((Right_white_line>0x10) && (flag==0))
		{
			flag=1;
			forward();
			velocity(75,100);
			UDR0=0x36;
		}

					
			
		
		_delay_ms(250);
		PORTA=0x00;
		_delay_ms(500);

	}
}
Пример #6
0
// MAIN FUNCTION 
int main()
{ 
	
	//init_devices2();
	 
	
	// White Line Following
	while(1) 
	{
		init_devices_motion();
		init_devices_adc();
		lcd_set_4bit();
		lcd_init();
		
		unsigned char flag = 0;
		unsigned char Left_white_line = 0;
		unsigned char Center_white_line = 0;
		unsigned char Right_white_line = 0;
		unsigned char lwl=0;
		unsigned char cwl=0;
		unsigned char rwl=0;
		
		while(1)
		{
            
			Left_white_line = ADC_Conversion(3);	//Getting data of Left WL Sensor
			Center_white_line = ADC_Conversion(2);	//Getting data of Center WL Sensor
			Right_white_line = ADC_Conversion(1);	//Getting data of Right WL Sensor

			flag=0;

			print_sensor(1,1,3);	//Prints value of White Line Sensor1
			print_sensor(1,5,2);	//Prints Value of White Line Sensor2
			print_sensor(1,9,1);	//Prints Value of White Line Sensor3
			
			

			if(Center_white_line<0x10)
			{
				flag=1;
				forward();
				velocity(100,100);
				//_delay_ms(10000);
			}

			if((Left_white_line>0x10) && (flag==0))
			{   
				
				//bot_charging_process();
				flag=1;
				forward();
				velocity(130,30);
			}

			if((Right_white_line>0x10) && (flag==0))
			{
				//bot_charging_process();
				flag=1;
				forward();
				velocity(30,130);
			}

			if(Center_white_line>0x10 && Left_white_line>0x10 && Right_white_line>0x10)
			{
				forward();
				velocity(0,0);
			}
			
			if((((Center_white_line-Right_white_line>0)&&(Center_white_line-Right_white_line<=10))||((Right_white_line-Center_white_line>0)&&(Right_white_line-Center_white_line<=10)))&&
			   (((Center_white_line-Left_white_line>0)&&(Center_white_line-Left_white_line<=10))||((Left_white_line-Center_white_line>0)&&(Left_white_line-Center_white_line<=10)))&&
			   (((Left_white_line-Right_white_line>0)&&(Left_white_line-Right_white_line<=10))||((Right_white_line-Left_white_line>0)&&(Right_white_line-Left_white_line<=10)))
		
		          ) // recognising node position that is if the reading at all three white line sensors differ maximum by 10 then that point will be node
		       {	
			     lwl=Left_white_line;
				 cwl=Center_white_line;
				 rwl=Right_white_line;
				 stop();
			     _delay_ms(500);
			      break;		   
			  }
		  }	
	  bot_charging_process();
	 //buzzer();
	 
	 
	for(int t=max_angle_of_bot;t>=0;t--)
	 {
		  soft_left_2();       //left wheel forward leaving the right wheel at rest to get
		                       //soft rotation at the axis of right wheel
		  _delay_ms(rot_time);
		  
		  stop();
		  _delay_ms(100);
	 }	
	 
	 forward();
	 _delay_ms(100);  	 
   }
}
Пример #7
0
//Main Function
int main()
{
	init_devices();
	lcd_set_4bit();
	lcd_init();

	forward();
	velocity(253,255);
	_delay_ms(50);
	
	while(1)
	{

		Left_white_line = ADC_Conversion(3);	//Getting data of Left WL Sensor
		Center_white_line = ADC_Conversion(2);	//Getting data of Center WL Sensor
		Right_white_line = ADC_Conversion(1);	//Getting data of Right WL Sensor

		flag=0;

		print_sensor(1,1,3);	//Prints value of White Line Sensor1
		print_sensor(1,5,2);	//Prints Value of White Line Sensor2
		print_sensor(1,9,1);	//Prints Value of White Line Sensor3
		
		

		if(Center_white_line>0x30)
		{
			flag=1;
			forward();
			velocity(253,255);
		}

		if((Left_white_line>0x30) && (flag==0))
		{
			flag=1;
			forward();
			velocity(200,255);
		}

		if((Right_white_line>0x30) && (flag==0))
		{
			flag=1;
			forward();
			velocity(255,200);
		}

		if(Center_white_line>0x30 && Left_white_line>0x30 && Right_white_line>0x30)
		{
			forward();
			velocity(253,255);
			_delay_ms(100);
		}

		if(Center_white_line<0x30 && Left_white_line<0x30 && Right_white_line<0x30)
		{
			stop();
			velocity(0,0);
			_delay_ms(100);
		}


	}
}
//Main Function
int main()
{
	init_devices();
	lcd_set_4bit();
	lcd_init();
	int max = 100 ; 
	
	while(1)
	{

		Left_white_line = ADC_Conversion(3);	//Getting data of Left WL Sensor
		Center_white_line = ADC_Conversion(2);	//Getting data of Center WL Sensor
		Right_white_line = ADC_Conversion(1);	//Getting data of Right WL Sensor

		flag=0;

		senser_value_L = print_sensor(1,5,3);	//Prints value of White Line Sensor1
		senser_value_C = print_sensor(1,1,2);	//Prints Value of White Line Sensor2
		senser_value_R = print_sensor(1,9,1);	//Prints Value of White Line Sensor3
		
		SetTunings();
		
		pid = PID(senser_value_L-senser_value_R);
		
		if (pid < 30)
		{
			forward();
			velocity(max+pid,max);
		}
		
		if (pid > 30)
		{
			forward();
			velocity(max,max+pid);
		}

		/*else if((Left_white_line < 0x30) && (flag==0))
		{
			pid = PID(senser_value_L);
			flag=1;
			forward();
			velocity(max,max+pid);
		}

		else if((Right_white_line<0x30) && (flag==0))
		{
			pid = PID(senser_value_R);
			flag=1;
			forward();
			velocity(max+pid,max);
		}

		if(Center_white_line>0x10 && Left_white_line>0x10 && Right_white_line>0x10)
		{
			forward();
			velocity(0,0);
		}*/
		
		lcd_print(1,13,pid,3);
	}
}
Пример #9
0
void show_color()
{
	print_sensor(1,1,3);	//Prints value of White Line Sensor1
	print_sensor(1,5,2);	//Prints Value of White Line Sensor2
	print_sensor(1,9,1);	//Prints Value of White Line Sensor3
}
Пример #10
0
//Main Function
int main(void)
{
    unsigned char flag ;

    init_devices();

    lcd_set_4bit();
    lcd_init();

    velocity(VELOCITY_MAX,VELOCITY_MAX);    // Set the speed to max velocity
    forward();                              // start to move froward

    unsigned char lch=0;
    unsigned char rch=0;
    unsigned char cch=0;
    int ler=0;
    int rer=0;
    float thd=10;
    int per=0;
    int thdh=80;
    int thdl=20;
    float kp=10;
    int kd=50;
    int rl=0,old_rl=0;

    int PWM_ratio_1 = 10;
    int PWM_ratio_2 = 25;

    unsigned char old_ler=0;
    unsigned char old_rer=0;
    unsigned char old_per=100;

    while(1)
    {

        lch=ADC_Conversion(3);
        rch=ADC_Conversion(5);
        cch=ADC_Conversion(4);

        ler=lch-cch;
        rer=rch-cch;
        per=lch-rch;

        rl=rch-lch;

        print_sensor(1,1,3);		//Prints value of White Line Sensor Left
        print_sensor(1,5,4);		//Prints value of White Line Sensor Center
        print_sensor(1,9,5);		//Prints value of White Line Sensor Right


        if(rl>0)
        {
            thd = 120 - (kp*rl+kd*(rl-old_rl));
        }
        else
        {
            thd = -120 - (kp*rl+kd*(rl-old_rl));
        }


        lcd_print (2,1,abs(rl),3);
        lcd_print (2,5,(unsigned char)abs(thd),3);


        if(rl>(-thd) && rl<(thd))
        {
            forward();
            //velocity(255,255);
        }

        else
        {
            if(rl>0)
            {
                if(rl<thd+30)
                    soft_right();
                //velocity(min(255,rl*PWM_ratio_1),0);
                else
                    right();
                //velocity(min(255,rl*PWM_ratio_2),0);
            }
            else
            {
                if(rl>-thd-30)
                    soft_left();
                //velocity(0,min(255,-rl*PWM_ratio_1));
                else
                    left();
                //velocity(0,min(255,-rl*PWM_ratio_2));
            }
        }

        old_rl=rl;
    }
}
//Main Function
int main()
{
	init_devices();
	lcd_set_4bit();
	lcd_init();
	
	while(1)
	{

		Left_white_line = ADC_Conversion(3);	//Getting data of Left WL Sensor
		Center_white_line = ADC_Conversion(2);	//Getting data of Center WL Sensor
		Right_white_line = ADC_Conversion(1);	//Getting data of Right WL Sensor
		Front_Sharp_Sensor = ADC_Conversion(11);
		Front_IR_Sensor = ADC_Conversion(6);

		flag1=0;
		flag2=0;

		print_sensor(1,1,3);	//Prints value of White Line Sensor1
		print_sensor(1,5,2);	//Prints Value of White Line Sensor2
		print_sensor(1,9,1);	//Prints Value of White Line Sensor3
		print_sensor(2,4,11);	//Prints Value of Front Sharp Sensor
		print_sensor(2,8,6);	//Prints Value of Front IR Sensor
				

		if(Front_Sharp_Sensor>0x82 || Front_IR_Sensor<0xF0)
		{
			flag2=1;
			stop();
			buzzer_on();
			
		}

		if((Center_white_line<0x28) && (flag2==0))
		{
			flag1=1;
			buzzer_off();
			forward();
			velocity(150,150);
		}

		if((Left_white_line>0x28) && (flag1==0) && (flag2==0))
		{
			flag1=1;
			buzzer_off();
			forward();
			velocity(150,50);
		}

		if((Right_white_line>0x28) && (flag1==0) && (flag2==0))
		{
			flag1=1;
			buzzer_off();
			forward();
			velocity(50,150);
		}

		if((Center_white_line>0x28) && (Left_white_line>0x28) && (Right_white_line>0x28) && (flag2==0)) 
		{
			buzzer_off();
			forward();
			velocity(0,0);
		}

	}
}
/**
* Main Function
*/
int main()
{
	init_devices();
	lcd_set_4bit();
	lcd_init();
	while(1)
	{

		Left_white_line = ADC_Conversion(3);	///< Getting data of Left WL Sensor
		Center_white_line = ADC_Conversion(2);///< Getting data of Center WL Sensor
		Right_white_line = ADC_Conversion(1);	///< Getting data of Right WL Sensor
		Front_Sharp_Sensor = ADC_Conversion(11);///< Getting data of Front Sharp sensor
		Front_IR_Sensor = ADC_Conversion(6);    ///<  Getting data of Front IR sensor


		flag1=0;
		flag2=0;


		print_sensor(1,1,3);	///< Prints value of White Line Sensor1
		print_sensor(1,5,2);	///< Prints Value of White Line Sensor2
		print_sensor(1,9,1);	///< Prints Value of White Line Sensor3
		lcd_print(1, 13, timer_flag, 4);

		if((Center_white_line<0x28))
		{
			flag1=1;
			forward();
			velocity(RegSpeed,RegSpeed);
		}


		if((Left_white_line>0x28) && (flag1==0))
		{
			flag1=1;
			forward();
			velocity(100,50);
		}


		if((Right_white_line>0x28) && (flag1==0))
		{
			flag1=1;
			forward();
			velocity(50,100);
		}


		if((Center_white_line>0x28) && (Left_white_line>0x28) && (Right_white_line>0x28))  
		{

			forward();
			velocity(RegSpeed,RegSpeed);
			if (timer_flag == 0)                 ///< vehicle at first black patch
			{	
				timer_flag=1;                    
				while(StartTheBot==0)
				{
					stop();
				}

				if (StartTheBot == 1)
				{
					forward();
					velocity(RegSpeed,RegSpeed);
					TCCR1B = 0x01;   ///< Timer 1 start witrh  no prescaler
					while(Center_white_line>0x28 && Left_white_line>0x28 && Right_white_line>0x28)//wait till the time the entire red line is crossed.
					{
						Left_white_line = ADC_Conversion(3);	///< Getting data of Left WL Sensor
						Center_white_line = ADC_Conversion(2);	///< Getting data of Center WL Sensor
						Right_white_line = ADC_Conversion(1);	///< Getting data of Right WL Sensor
					}

					timer_flag=2;
				}
			}
			else if (timer_flag == 2)           ///< vehicle at second black patch
			{
				TCCR1B = 0x00;   ///< Timer 1 stop
				timer_flag=3;
				lcd_print(2, 1, TCNT1H, 4);
				lcd_print(2, 6, TCNT1L, 4);
				lcd_print(2, 11, speed_cnt, 5);
				speed = 27/ (((unsigned int) speed_cnt * 65536 * 90.9E-9) + ((unsigned int) TCNT1H * 256 * 90.9E-9) + ((unsigned int) TCNT1L * 90.9E-9));
				f=1;
				speed_int= speed;
				speed_dec=(speed-speed_int)*100;

			}

			else if (timer_flag ==3)         ///< vehicle at third black patch
			{
				timer_flag=4;

				while (vehicle_stop==0)     ///< Capturing photo in progress
				{
					stop();
				}

				if(vehicle_stop==1)         ///< photograph taken. Vehicle can go ahead now
				{				
					forward();
				}

			}
		}


		if((Front_Sharp_Sensor>0x80)|| (Front_IR_Sensor<0xF0)) ///< Obstacle detection
		{
			flag2=1;
			stop();
		}


	}
}
//Main Function
int main(void)
{
 unsigned char flag ;
 init_devices();

 lcd_set_4bit();
 lcd_init();
 threshold();//set threshold before getting into path.Keep it in white surface.
 velocity(VELOCITY_MAX,VELOCITY_MAX);    // Set the speed to max velocity lcd_print (2,1,VELOCITY_MAX,3);
 //lcd_print (2,5,VELOCITY_MAX,3);
 forward();                              // start to move froward

 while(1)
 {
	Left_white_line = ADC_Conversion(3);	//Getting data of Left WL Sensor
	Center_white_line = ADC_Conversion(4);	//Getting data of Center WL Sensor
	Right_white_line = ADC_Conversion(5);	//Getting data of Right WL Sensor
 
	print_sensor(1,1,3);		//Prints value of White Line Sensor Left
	print_sensor(1,5,4);		//Prints value of White Line Sensor Center
	print_sensor(1,9,5);		//Prints value of White Line Sensor Right

	flag=0;
	if(Left_white_line>THRESHOLD && Center_white_line>THRESHOLD && Right_white_line>THRESHOLD )
		{
		velocity(0,0);

		_delay_ms(6000);
		velocity(50,50);
			_delay_ms(300);
		}
	if(Left_white_line>THRESHOLD && Center_white_line>THRESHOLD && Right_white_line<=THRESHOLD )
		{
		velocity(40,50);
		}
	if(Left_white_line>THRESHOLD && Center_white_line<=THRESHOLD && Right_white_line<=THRESHOLD )
		{
		velocity(30,50);
		}
	if(Left_white_line<=THRESHOLD && Center_white_line<=THRESHOLD && Right_white_line<=THRESHOLD )
		{
		velocity(30,55);

		}
	if(Left_white_line<=THRESHOLD && Center_white_line<=THRESHOLD && Right_white_line>THRESHOLD )
		{
		velocity(50,30);
		}
	if(Left_white_line<=THRESHOLD && Center_white_line>THRESHOLD && Right_white_line>THRESHOLD )
		{
		velocity(50,40);
		}
	if(Left_white_line<=THRESHOLD && Center_white_line>THRESHOLD && Right_white_line<THRESHOLD )
		{
		velocity(40,50);
		}
	
		
		
	


 }
}
//Main Function
int main()
{
 unsigned char flag ;

 init_devices();

 lcd_set_4bit();
 lcd_init();

 velocity(VELOCITY_MAX,VELOCITY_MAX);    // Set the speed to max velocity
 lcd_print (2,1,VELOCITY_MAX,3);
 lcd_print (2,5,VELOCITY_MAX,3);
 forward();                              // start to move froward

 while(1)
 {
	Left_white_line = ADC_Conversion(3);	//Getting data of Left WL Sensor
	Center_white_line = ADC_Conversion(4);	//Getting data of Center WL Sensor
	Right_white_line = ADC_Conversion(5);	//Getting data of Right WL Sensor
 
	print_sensor(1,1,3);		//Prints value of White Line Sensor Left
	print_sensor(1,5,4);		//Prints value of White Line Sensor Center
	print_sensor(1,9,5);		//Prints value of White Line Sensor Right

	flag=0;

	if(Center_white_line<THRESHOLD)               // Is middle Whiteline is within threshold limit
	{   
		USART_Transmit(0x32);                                          
		flag=1;
		velocity(VELOCITY_MAX,VELOCITY_MAX);      // Run robot at max velocity 
		lcd_print (2,1,VELOCITY_MAX,3);
		lcd_print (2,5,VELOCITY_MAX,3);
	}

	if((Left_white_line>THRESHOLD) && (flag==0))  // Is left Whiteline is not within threshold limit
	//if((Left_white_line>THRESHOLD) && (flag==0))  // Is left Whiteline is not within threshold limit
	{                        
		USART_Transmit(0x34);                     
		flag=1;                       
		velocity(VELOCITY_MAX,VELOCITY_MIN);      // Run robot left wheel at max velocity and right wheel 
		lcd_print (2,1,VELOCITY_MAX,3);           // at min velocity
		lcd_print (2,5,VELOCITY_MIN,3);         
	/*	velocity(VELOCITY_MIN,60);      // Run robot right wheel at max velocity and left wheel 
		lcd_print (2,1,VELOCITY_MIN,3);           // at min velocity
		lcd_print (2,5,VELOCITY_MAX,3);*/
	}

	if((Right_white_line>THRESHOLD) && (flag==0)) // Is right Whiteline is not within threshold limit
	//if((Right_white_line>THRESHOLD) && (flag==0)) // Is right Whiteline is not within threshold limit
	{
		USART_Transmit(0x36);
		flag=1;    
		velocity(VELOCITY_MIN,VELOCITY_MAX);      // Run robot right wheel at max velocity and left wheel 
		lcd_print (2,1,VELOCITY_MIN,3);           // at min velocity
		lcd_print (2,5,VELOCITY_MAX,3);
	/*	velocity(60,VELOCITY_MIN);      // Run robot left wheel at max velocity and right wheel 
		lcd_print (2,1,VELOCITY_MAX,3);           // at min velocity
		lcd_print (2,5,VELOCITY_MIN,3);*/
	}

	if(Center_white_line>THRESHOLD && Left_white_line>THRESHOLD && Right_white_line>THRESHOLD && (flag == 0))
	                                // if all Whiteline sensor are not within threshold limit    
	{
		USART_Transmit(0x38);
		flag=1;
		velocity(VELOCITY_LOW,VELOCITY_LOW);      // stop the robot
		lcd_print (2,1,VELOCITY_LOW,3);
		lcd_print (2,5,VELOCITY_LOW,3);
	}

 }	
}