// Bringing the panel at 0 angle. void servo_panel_0(void) { init_devices_servo(); _delay_ms(500); servo_1_free(); }
// aligning the panel on servo at 45 degree void servo_panel_45(void) { init_devices_servo(); for (int i = 0; i <45; i++) //FIRST ALINGING THE PANEL AT 45 DEGREE FROM GROUND TO HAVE THE LOCAL MAXIMUM INTENSITY IN ONE PLANE { servo_1(i); _delay_ms(100); } _delay_ms(1000); servo_1_free(); }
/* Rotating the panel in the plane of servo hinge by one degree each till 165 Here we have rotated the servo only upto 165 not 180 due to large size of panel, that is when rotated by more than 165 it start touching the upper plate of bot. Here first the servo is rotated upto 165 each by one degree and the value corresponding to voltage is noted in the array then maximum value is calculated from the array and the corresponding angle. Then the panel is aligned to that angle. Delay time for each rotation is 400 milli-seconds. */ void servo_rotation_165() { init_devices_servo(); unsigned int i = 0; float max_panel_volt=0.0; int counter=0; float panel_voltage_s[165]; for (i = 0; i <165; i++) { servo_1(i); _delay_ms(delay_time); panel_voltage_s[i]=value_in_volt(ADC_Conversion(10)); // ADC_Conversion gives analog value of voltage through channel 10 lcd_print(1,13,batt_volt(ADC_Conversion(0)),4); // Printing the battery voltage. lcd_print(2,9,panel_voltage_s[i],3); // Printing voltage of panel at specific angles. // _delay_ms(50); } // finding the maximum intensity of value and corresponding angle for(int j=0;j<165;j++) { if(panel_voltage_s[j]> max_panel_volt) { max_panel_volt= panel_voltage_s[j]; counter=j; // identifier counter contains the angle for which the intensity is maximum } } lcd_print(2,9,panel_voltage_s[counter],3); // Printing maximum voltage. // setting the panel at that angle of maximum intensity servo_panel_0(); for (int j = 0; j<counter;j++) // Setting the panel at maximum voltage. { servo_1(j); _delay_ms(delay_time); float panel_volt=value_in_volt(ADC_Conversion(10)); lcd_print(2,13,panel_volt,3); } lcd_print(2,13,panel_voltage_s[counter],3); // Checking the value to be exact by printing again. _delay_ms(1000); servo_1_free(); }
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); }