//Main Function
int main()
{
    init_devices();
    lcd_set_4bit();
    lcd_init();
    while(1);
}
Esempio n. 2
0
int main()
{
	init_devices();
	lcd_set_4bit();
	lcd_init();
	color_sensor_scaling();/*
	threshold= calcThresh();
	setIndicatorAndColor();
	ct = 0; adj = 2;
	lcd("Begin");
	while (sorted<total)
	{
		canDrop();
		if (visitedCount == 3)
			predict();
		if (sorted == total)
			break;
		pickup();
		traverseToSort(ct, ct % 2 + 4);
		sortCheck();
	}
	for (i = 0; i<4; i++);
		//..printf("%d %d\n", term[i][0], term[i][1]);
	//..printf("Sort 0=%dSort 1=%d\nArm 0=%dArm 1=%d\n", sort[0], sort[1], arm[0], arm[1]);
	//..printf("Cost=%d\nSORTED!!!!!\n", cost + 7);
	//getch();
	*/
	
	forwardJaa();
	return 1;
}
Esempio n. 3
0
//-------------------------------------------------------****MAIN FUNCTION ****------------------------------------------------
int main()
{
	
	init_devices();
	lcd_set_4bit();
	lcd_init();
    lcd_cursor(1,1);
	lcd_string("START");
	_delay_ms(rand());
//--*** GRIPPER INITAL POSITION ***---
	S2 = 0x73;
	cli();
	timer0_init();
	TIMSK |= (1 << OCIE0) | (1 << TOIE0); // timer 0 compare match and overflow interrupt enable 
	sei();
	pickup();
	
	while(1)
	{
	if( bot_id_set == 1)
	{	
	
		init_devices2();
		init_grid();
		dispersion();
		localize();
		region_division();
		break;
	}
	
 }
 }
//Main Function
int main(void)
{
 double error_p = 0.0;
 double error_i = 0.0;
 double error_d = 0.0;
 double angle;
 kalman_state k = kalman_init(1, 16, 1, 137);
 init_devices();
 lcd_set_4bit();
 lcd_init();
 double preverror = 0.0;
	 while(1)
	 {            
		sensor2 = ADC_Conversion(2);
        kalman_update(&k,(double)sensor2);
		angle = k.x;  
     	lcd_print(1,5,(int)angle,3);	 
		error_p = (angle - 137);
		error_i += error_p*dt;
		error_d = (error_p - preverror)/dt;
		lcd_print(1,1,abs((int)error_p),3);
		Disturbance = ((error_p*kp) + (error_i*ki) + (error_d*kd));
		if(angle > 137) back();
		else { 	forward();}
		if (Disturbance > MAX) Disturbance = MAX;
		if (Disturbance < MIN) Disturbance = MIN;
		lcd_print(2,6,abs((int)Disturbance),5);
		velocity(35+abs((int)Disturbance),35+abs((int)Disturbance));
		preverror = error_p;
	}
}
int main(void)
{
	init_devices();
	lcd_set_4bit();
	lcd_init();
	lcd_cursor(1,5);
	lcd_string("HI");
	lcd_print(2,1,read,3);
	while(1)
	{ 
		//white line sensing
	    sensor_data_interpretation();

		flag=0;
		

		if(Center_white_line<0x28)
		{
			flag=1;
			forward();
			velocity(150,150);
		}

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

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

		if(Center_white_line>0x28 && Left_white_line>0x28 && Right_white_line>0x28)
		{
			forward();
			velocity(0,0);
		}
		if(count>=6)
		 break;
	}
	stop();
	read = 0;
	lcd_init();
	//Printing the stored value on lcd after the count value is reached 6.
	lcd_print(1,1 , store[0][0], 3);
	lcd_print(1,5 , store[0][1], 3);
	lcd_print(1,9 , store[0][2], 3);
	lcd_print(1,13 , store[0][3], 3);
	lcd_print(2,1 , store[0][4], 3);
	lcd_print(2,5 , store[0][5], 3);
	while(1);
	 
	
}
//Main Function
int main(void)
{
	init_devices();
	lcd_init();
	lcd_set_4bit();
	while(1){
		detect();
	}
}
Esempio n. 7
0
int main()
{
	int i=0;
	init_devices();
	lcd_set_4bit();
	lcd_init();
	color_sensor_scaling();
	/*
	//variable 'i' scales at 13,14 for sharp sensor for velocitty 240 240
	//u turn 1600ms at 200,200 velocity
	velocity(200,200);
	left();
	_delay_ms(1600);
	stop();
	while(1);
	
	threshold=6000;
	
	right();
	while(ADC_Conversion(11)<65)
	{
		i++;
		lcd_print(1,11,i,3);
	}
	stop();
	lcd_print(2,11,scan(),1);
	stop();
	while(1);
	*/
	setIndicatorAndColor();
	threshold=6000;
	ct = 0; adj = 2;
	//lcd("Begin");
	while (sorted<total)
	{
		canDrop();
		//buzzer_on();
		//_delay_ms(500);
		//buzzer_off();
		if (visitedCount == 3)
			predict();
		if (sorted == total)
			break;
		pickup();
		traverseToSort(ct, ct % 2 + 4);
		sortCheck();
	}
	for (i = 0; i<4; i++);
		//..printf("%d %d\n", term[i][0], term[i][1]);
	//..printf("Sort 0=%dSort 1=%d\nArm 0=%dArm 1=%d\n", sort[0], sort[1], arm[0], arm[1]);
	//..printf("Cost=%d\nSORTED!!!!!\n", cost + 7);
	//getch();
	return 0;
}
Esempio n. 8
0
void init_devices1 (void)
{
	cli(); //Clears the global interrupts
	
	lcd_port_config();  // configure the LCD port
	lcd_set_4bit();
	lcd_init();
	port_init();
	timer5_init();
	sei(); //Enables the global interrupts
}
Esempio n. 9
0
void init_devices (void)
{
 cli(); //Clears the global interrupts
 port_init();
 adc_init(); 
 lcd_init();
 lcd_set_4bit();
 
// timer1_init();
 sei(); //Enables the global interrupts
}
Esempio n. 10
0
//Function to Initialize LCD
void lcd_init()
{
	lcd_set_4bit();
	
	_delay_ms(1);

	lcd_wr_command(0x28); //4-bit mode and 5x8 dot character font
	lcd_wr_command(0x01); //Clear LCD display
	lcd_wr_command(0x06); //Auto increment cursor position
	lcd_wr_command(0x0E); //Turn on LCD and cursor
	lcd_wr_command(0x80); //Set cursor position
}
Esempio n. 11
0
File: test1.c Progetto: Devj92/test1
//-------------------------------------------------------------------------------
// Main Programme start here.
//-------------------------------------------------------------------------------
int main(void)
{   
 uint16_t x_byte = 0,y_byte = 0,z_byte = 0;
  uint8_t x_byte1 = 0,x_byte2 = 0,y_byte1 = 0,y_byte2 = 0,z_byte1 = 0,z_byte2 = 0;

 init_devices();
 lcd_set_4bit();                // set the LCD in 4 bit mode
 lcd_init();                    // initialize the LCD with its commands
 display_clear();               // clear the LCD
 write_byte(0x0,0x2D);
 write_byte(0x8,0x2D);

 
while(1)
{
	   
	   
	  x_byte1 = read_byte(X1);
	   //lcd_print(1,1,x_byte1,3);
	   
	   x_byte2 = read_byte(X2);
	   //lcd_print(2,1,x_byte2,3);
	   
	   y_byte1 = read_byte(Y1);
	   //lcd_print(1,6,y_byte1,3);
	   
	   y_byte2 = read_byte(Y2);
	   //lcd_print(2,6,y_byte2,3);
	   
	   z_byte1 = read_byte(Z1);
	   //lcd_print(1,10,z_byte1,3);
	   
	   z_byte2 = read_byte(Z2);
	   //lcd_print(2,10,z_byte2,3);
	   //_delay_ms(100);
	   
	   x_byte = x_byte2;
	   x_byte = x_byte<<8;
	   x_byte |= x_byte1;
	   pr_int(1,1,x_byte,3);
	   
	   y_byte = y_byte2;
	   y_byte = y_byte<<8;
	   y_byte |= y_byte1;
	   pr_int(2,4,y_byte,3);
	   
	   z_byte = z_byte2;
	   z_byte = z_byte<<8;
	   z_byte |= z_byte1;
	   pr_int(1,9,z_byte,3);
	 	   
}
}
Esempio n. 12
0
void init_devices (void)
{
 cli(); //Clears the global interrupt
 port_init();  //Initializes all the ports
 uart0_init();
 lcd_set_4bit();
 lcd_init(); 
 servo_init();
 left_position_encoder_interrupt_init();
 right_position_encoder_interrupt_init();
 sei();   // Enables the global interrupt 
}
//Main Function
int main(void)
{
	
	init_devices();
	lcd_set_4bit();
	lcd_init();
	while(1)
	{
		lcd_cursor(1,3);
		lcd_string("FIRE BIRD 5");
		lcd_cursor(2,1);
		lcd_string("NEX ROBOTICS IND");
	}
}
//!Main Function This just initializes the ports and goes into a infinate wait
int main(void)
{
    PositionPanServo_1=0;
    PositionPanServo_2=0;
    PositionPanServo_3=0;
    init_devices();
	lcd_set_4bit();
	lcd_init();
//	servo_1(0);
//	_delay_ms(30);
//	servo_2(0);
   while(1){
   	//servo_3(0);
   }
}
Esempio n. 15
0
//Main Function
int main(void)
{   
	int t = 0;
	uint i=65535;
	init_devices();
	lcd_set_4bit();
	lcd_init();
	start_timer4();
	_delay_ms(70);
	t=micro_sec();
	
	lcd_print(1,3,i,5);
	
	
}
//The main loop!
int main()
{
	//Initialize all devices
	init_devices();
	lcd_set_4bit();
	lcd_init();
	leftVel=100;
	rightVel=100;
	functionFlag=0;

	while(1)
	{	
		//Extract out commands from received data
		process_rcvd_data();

		//Perform certain actions according to the state of the Firebird
		if (white_line_flag) {
			whiteline_follow_continue();
		}

		if (acc_flag) {
			acc_continue();
		}
		
		if (acc_modified_flag) {			
			acc_modified();
		}	
		
		//If there exists a command on the command buffer, call the invoker on it
		if(command_rcvd >= 1){
			unsigned char a;
			int error = get_char_from_input(&a);
			if (error == -1) {
				//lcd_string("ERROR");
				buzzer_prompt(1000);
				_delay_ms(1000);
				buzzer_prompt(1000);
				command_rcvd--;
				continue;
			}
			//lcd_num(a);
			my_invoker(a);
			command_rcvd--;
			//serial_sendString("ok");
		}

	}	
}
//Main Function
int main(void)
{

	unsigned char x;
	int flag=1;
	
	init_devices();			//Initialize all the devices
	lcd_set_4bit();			//Set the LCD in 4 bit mode
	
	while(1)
	{
		
		x = PINL & (1<< 6);			//Read the PL6 pin to read the PIR Sensor output
		lcd_init();					//Initialize the LCD
		if(x)						//Check if the PL6 pin is HIGH
		{
			PORTJ = 0xFF;			//Turn ON Bargraph LED
			
			
			
			if(flag ==1)			// A flag has been added to stop the screen from re-initializing every time in the while loop
			{
				lcd_init();
				lcd_cursor(1,1);
				
			}
			lcd_string("Human Detected");		//Display "Human Detected" on the LCD
			flag=0;
		}
		else
		{
			
			PORTJ = 0x00;			//Turn OFF Bargraph LED
			
			if(flag==0)
			{
				lcd_init();
				lcd_cursor(1,1);
			}
			lcd_string("Empty Space");			//Display "Empty Space" on the LCD
			flag=1;
		}
		
	}
}
int main(void)
{
    init_devices();
    lcd_set_4bit();
    lcd_init();
	color_sensor_scaling();
	
	while(1)
    {
       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); 
	   no_filter();//display the pulse count when no filter is selected
	   _delay_ms(500);
    }
}
/*
 * Main function, will call different phases, locate/clean
 */
int main(void)
{
	unsigned char sharp;
	unsigned int value=0;
	init_devices();
	lcd_set_4bit();
	lcd_init();
	lcd_wr_command(0x0C);// Display ON Cursor OFF
	while(1) {
		if (phase == 1) {
			locate();	
		}
		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,1,value,3);
	}
	servo_1_free();
	return 0;
}
Esempio n. 20
0
//Main Function
int main(void)
{   
	//all initializations
    init_devices_motion();
	init_devices();
	init_devices_lf();
	lcd_set_4bit();
	lcd_init();

	//setting gripper arm 
	initial_angle = 120;
	servo1_init();
	servo_2(initial_angle);
	servo_3(180);
	//UDR0 = 0x31;
	//line_follower();
	//pluck_fruit();

	while(1);
}
//-------------------------------------------------------------------------------
//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 cli();              //disable all interrupts
 port_init();
 uart2_init();
 adc_init();
 timer1_init();
 timer5_init();
 lcd_set_4bit();
 lcd_init();
 spi_init();
 
 // below for lines are important for Encoder init
 left_position_encoder_interrupt_init();
 right_position_encoder_interrupt_init();
 EICRB  = 0x0A;     //pin change int edge 4:7
 EIMSK  = 0x30;

 sei();             //re-enable interrupts
 //all peripherals are now initialized
}
Esempio n. 22
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);

	}
}
Esempio n. 23
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);  	 
   }
}
//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);
		}

	}
}
Esempio n. 25
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;
    }
}
void main()
{
	unsigned int value,value1;
	int a=0,b=0;
	cli();
	INIT_PORTS();										//Initialize ports
	uart0_init();										//Initialize UART0 for xbee communication
	timer5_init();
	sei();

	INIT_PORTS_ROTATE();								//Initialize ports 
	right_position_encoder_interrupt_init();			//Initialize control registers for wheel
	left_position_encoder_interrupt_init();				//           encoders.
			
	init_devices();
	lcd_set_4bit();										//LCD initialization functions.
	lcd_init();

	unsigned char angle = 0;
 	init_devices_servo();								//Initialize servo motors.

	data='0';
	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(1,1,value,3);

//	sharp1 = ADC_Conversion(10);						//Stores the Analog value of front sharp connected to ADC channel 11 into variable "sharp"
//	value1 = Sharp_GP2D12_estimation(sharp1);			//Stores Distance calsulated in a variable "value".
//	lcd_print(1,5,value1,3);


// set servo for camera to ground zero
			servo_1(0);								// code to bring the camera to ground state
			_delay_ms(1000);
// set servo for incline to ground zero	
			servo_2(90);							// align camera	
			_delay_ms(500);

	
// the bot rotating slowly trying to find the bot 
	int terminate = 0;
			while(data=='0' && terminate < 150)
			{
				velocity(150,150); 							//If no ball is detected the rotate and scan
				angle_rotate_left(3);							// for ball in the arena.
				_delay_ms(500);
				stop();
				_delay_ms(500);
				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".
				terminate++;
			//	lcd_print(1,1,value,3);
			}	

			if(terminate == 60)
			{
					buzzer_on();
					return;
			}

/*If a ball(red colour) is detected then matlab code sends a '5' signal through
 zigbee.If a '5' is received then the robot stops rotating and moves towards the 
 ball*/			

			value2 = 100;
			if(atoi(data) > 5) 
			{
				lcd_print(1,5,value2,2);
			}

			velocity(160,184);

// change value
			while(value>140)
			{
				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(1,1,value,3);
				forward();
			}
			stop();
			_delay_ms(2000);
		
/* the servo_1 is for the camera and the servo_2 is for the inclined plane */

// rotate 90 at left
			left90_at_place();
			_delay_ms(1000);
// rotate the camera 90 degrees to the right
			servo_1(90);
			_delay_ms(1000);
//rotate in circle
			rotate_in_circle();
			int perceived_height;
			perceived_height = atoi(data);
			lcd_print(1,5,perceived_height,5);
// rotate 90 degrees to the right to face the ball again
			right90_at_place();
			stop();
			_delay_ms(2000);
// rotate camera also to ground state to face the ball again
			servo_1(0);								// code to bring the camera to ground state
			_delay_ms(1000);
		
// set servo for incline

			int angle_of_inclination = get_angle(perceived_height);
			lcd_print(1,2,angle_of_inclination,5);
  			servo_2(angle_of_inclination);
			_delay_ms(1000);

				
	while(1);
}
//Main Function
int main()
{
	init_devices();
	init_encoders();
	lcd_set_4bit();
	lcd_init();
	int value=0;
	forward();
	velocity(130,130);
	lcd_print(2,1,130,3);
	lcd_print(2,5,130,3);
	lcd_print(2,9,pathindex,2);
	lcd_print(2,13,dirn,3);


	while(1)
	{	
		read_sensor();
		follow();
		
		if(isPlus())
		{	
			read_sensor();
			value = path[pathindex++];
			
			// Code inserted for calculation of actual location wrt initial starting point , 
			// It will consider direction also.

			if (value == F)
			{
				// Move the bot forward, for location only , No movement on ground.
				move_bot(FR);
			}
			else if (value == L)
			{
				// Move the bot left , for location only , No movement on ground.
				move_bot(LT);
			}
			else if (value == R)
			{
				// Move the bot right, for location only , No movement on ground.
				move_bot(RT);
			}
			else if (value == M)
			{
				// To stop the Bot and then break out
				stop();
				break;
			}
					
			orient(value);

/*			lcd_print(2,9,pathindex,2);
			lcd_print(2,13,dirn,3);
			lcd_print(1,13,turnL,1);
			lcd_print(1,15,turnR,1);
*/
			
		}
		
		if(turnL == 1)
		{/*
		lcd_print(1,13,turnL,1);
		forward_mm(20);
		stop();
		velocity(180,180);
		left_degrees(95);
		//_delay_ms(120);
		read_sensor();
		//	 while(Left_white_line <0x40)
		// {
		//	read_sensor();
		//	left();
		// }
		 stop();
	 	 forward();
		velocity(180,180);
		 turnL = 0;
		 */

		 back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		left_degrees(50);
		rotate_left_slowly();
	 	forward();
		velocity(130,130);
		turnL = 0;
		}
		
		if(turnR == 1)
		{
		/*
		lcd_print(1,15,turnR,1);
		forward_mm(20);
		stop();
		velocity(180,180);
		right_degrees(95);
		//_delay_ms(200);
		read_sensor();
		// while(Right_white_line <0x30)
		// {
		// read_sensor();
		// right();
		// }
		stop();
		forward();
		//follow();
		velocity(180,180);
		 turnR = 0;
		*/

		back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		right_degrees(50);
		rotate_right_slowly();
	 	forward();
		velocity(130,130);
		turnR = 0;
		}
	
	}


	// Three Beeps for Interval
	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	//code to head-back to starting position , i.e. Origin
	return_path_counter = reach_origin();
	
	forward();
	velocity(130,130);
	int counter = 0;
	int intermediate_value = 0;

	while(counter < return_path_counter)
	{	
		read_sensor();
		follow();
		
		if(isPlus())
		{	
			read_sensor();
			value = path_to_origin[counter];
			counter++;
			
			// Code inserted for calculation of actual location wrt initial starting point , 
			// It will consider direction also.

			if (intermediate_value == FR)
			{
				// Move the bot forward, for location only , No movement on ground.
				value = F;
			}
			else if (value == LT)
			{
				// Move the bot left , for location only , No movement on ground.
				value = L;
			}
			else if (value == RT)
			{
				// Move the bot right, for location only , No movement on ground.
				value = R;
			}
			else if (value == ST)
			{
				value = M;
				// specially inserted as break will not allow the bot to stop using "orient(value)".
				orient(value);
				break;
			}
					
			orient(value);
		
		}
		
		if(turnL == 1)
		{
		 back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		left_degrees(50);
		rotate_left_slowly();
	 	forward();
		velocity(130,130);
		turnL = 0;
		}
		
		if(turnR == 1)
		{
		back_mm(50);
		//stop();
		//velocity(130,130);
		stop();
		right_degrees(50);
		rotate_right_slowly();
	 	forward();
		velocity(130,130);
		turnR = 0;
		}
	
	}


	// Three beeps for Finish
	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

	buzzer_on();
	_delay_ms(100);
	buzzer_off();
	_delay_ms(100);

}
Esempio n. 28
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);
	}
}
void intialisation()
{
	cli();   //Clears the global interrupts 
	
	//usart init
	UBRR0L = 0x5F; //set baud rate lo
	UBRR0H = 0x00; //set baud rate hi
	UCSR0B = (1 << TXEN0);
	UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
	//buzzer initialization
	DDRC = DDRC | 0x08;					//Setting PORTC 3 as output
	PORTC = PORTC & 0xF7;				//Setting PORTC 3 logic low to turnoff buzzer
	//motion 
	DDRA = DDRA | 0x0F;					//PA3..PA0 for DC motor direction control
	PORTA = PORTA & 0xF0;
	DDRL = DDRL | 0x18;   				//Setting PL3 and PL4 pins as output for PWM generation
	PORTL = PORTL | 0x18; 				//PL3 and PL4 pins are for velocity control using PWM.
	
	//bar LED
	DDRJ = 0xFF;						//LED Bar graph
	PORTJ = 0x00; 						//LED Bar graph OFF
	
	//position encoder
	DDRE  = DDRE & 0xCF;  				//INT4 & INT5 for left & right position encoder
	PORTE = PORTE | 0x30; 				//Enable internal pull-up for PE4 & PE5
		//left position encoder
		 EICRB = EICRB | 0x05; 			// INT4 & INT5 - both edge (+ & -) triggered
		 EIMSK = EIMSK | 0x10; 			// INT4 Interrupts Enabled
		 /*
		 EICRA = EICRA | 0x01;               // INT0 is set to trigger with both edges(+ & -)
		 EIMSK = EIMSK | 0x01;               // Enable Interrupt INT0 for color sensor*/
	
	//lcd
	DDRC = DDRC | 0xFF; 				//all the LCD pin's direction set as output
	PORTC = PORTC & 0x80; 				//all the LCD pins are set to logic 0 except PORTC 7
	
	//adc
	DDRF = 0x00;						//set PORTF direction as input
	PORTF = 0x00;						//set PORTF pins floating
	DDRK = 0x00;						//set PORTK direction as input
	PORTK = 0x00;						//set PORTK pins floating
	ADCSRA = 0x00;
	ADCSRB = 0x00;		//MUX5 = 0
	ADMUX = 0x00;		//Vref=5V external --- ADLAR=1 --- MUX4:0 = 0000
	ACSR = 0x80;
	ADCSRA = 0x87;		//ADEN=1 --- ADIE=1 --- ADPS2:0 = 1 1 0
	
	//TIMER4 initialize - prescale:256
	// WGM: 0) Normal, TOP=0xFFFF
	// desired value: 1Hz
	// actual value:  1.000Hz (0.0%)
		TCCR4B = (1 << WGM42);
		OCR4A = COUNT_OCR4A;
		TIMSK4 = (1 << OCIE4A);
	
	// Timer 5 initialized in PWM mode for velocity control
	// Prescale:256
	// PWM 8bit fast, TOP=0x00FF
	// Timer Frequency:225.000Hz
	TCCR5B = 0x00;						//Stop
	TCNT5H = 0xFF;						//Counter higher 8-bit value to which OCR5xH value is compared with
	TCNT5L = 0x01;						//Counter lower 8-bit value to which OCR5xH value is compared with
	OCR5AH = 0x00;						//Output compare register high value for Left Motor
	OCR5AL = 0xFF;						//Output compare register low value for Left Motor
	OCR5BH = 0x00;						//Output compare register high value for Right Motor
	OCR5BL = 0xFF;						//Output compare register low value for Right Motor
	OCR5CH = 0x00;						//Output compare register high value for Motor C1
	OCR5CL = 0xFF;						//Output compare register low value for Motor C1
	TCCR5A = 0xA9;						/*{COM5A1=1, COM5A0=0; COM5B1=1, COM5B0=0; COM5C1=1 COM5C0=0}
 					  					   For Overriding normal port functionality to OCRnA outputs.
				  	  					   {WGM51=0, WGM50=1} Along With WGM52 in TCCR5B for Selecting FAST PWM 8-bit Mode*/
	TCCR5B = 0x0B;						//WGM12=1; CS12=0, CS11=1, CS10=1 (Prescaler=64)	
	
	sei();     //Enables the global interrupts
	lcd_set_4bit();
	lcd_init();	
}