Example #1
0
/*
This function first rotates the bot by 5 degree till 360 
Stores the voltage at each angle in array
Find maximum value of voltage from the array
Aligns the bot at that value of voltage.
*/
void bot_rotation360()
{    
     init_devices_motion();
	 init_devices_adc();
	 int bot_ang=0;
	 float panel_voltage[72];
	 float max_panel_volt=0;
	 float bat_voltage = 0.0;
	 int j;
	
	
	 for(j=0;j<72;j++)
	 {
		 
		 soft_right();
		                           // halting right wheel and moving only the left wheel for specified time to get the desired angle of rotation(according to calculation)
		 _delay_ms(rot_time);      // rot_time is calculated according to power from the battery
		 
		  stop();
		  _delay_ms(delay_time);
		
		 panel_voltage[j]=value_in_volt(ADC_Conversion(10)); // channel 10 contains voltage reading 
		 lcd_print(2,1,panel_voltage[j],3);
		 bat_voltage=batt_volt(ADC_Conversion(0));
		 lcd_print(1,13,bat_voltage,4);      // Printing battery voltage.
		
	 }
	  _delay_ms(1000);      // Stopping the bot momentarily.
	  
	  // for getting the angle of bot corresponding to maximum voltage and maximum voltage also.
	  for( j=0;j<72;j++)
	  {      
		  if(panel_voltage[j]>max_panel_volt)
		  {
			  max_panel_volt=panel_voltage[j];
			  bot_ang=j;
		  }
	  }
     lcd_print(2,1,panel_voltage[bot_ang],3);      // Printing maximum voltage.
	 
	                                // Realigning the bot at the maximum angle of intensity in circular plane
	   j=1;         
	  while(j!=bot_ang)            // Since the bot_ang variable contains the angle for which the intensity was maximum
	  {
		  
		  soft_right();       //left wheel forward leaving the right wheel at rest to get
		                     //soft rotation at the axis of right wheel
		  _delay_ms(rot_time2);
		  float servo_volt=value_in_volt(ADC_Conversion(10));
		  lcd_print(2,5,servo_volt,3);
		  j++;
		  stop();
		  _delay_ms(delay_time);
		  
	  }
	   lcd_print(2,5,panel_voltage[bot_ang],3);
	 	
	  max_angle_of_bot=bot_ang;
	 
}
Example #2
0
void soft_right_degrees(unsigned int Degrees)
{
 // 176 pulses for 360 degrees rotation 2.045 degrees per count
 soft_right();  //Turn soft right
 Degrees=Degrees*2;
 angle_rotate(Degrees);
}
void right_degrees(unsigned int Degrees)
{
// 28 pulses for 360 degrees rotation 12.92 degrees per count
 //right(); //Turn right
 //angle_rotate(Degrees);
 soft_right();  //Turn soft right
 Degrees=Degrees*2;
 angle_rotate(Degrees);
}
//Main Function
int main()
{
	init_devices();
	velocity (100, 100); //Set robot velocity here. Smaller the value lesser will be the velocity
						 //Try different valuse between 0 to 255
	while(1)
	{
	
		forward(); //both wheels forward
		_delay_ms(1000);

		stop();						
		_delay_ms(500);
	
		back(); //both wheels backward						
		_delay_ms(1000);

		stop();						
		_delay_ms(500);
		
		left(); //Left wheel backward, Right wheel forward
		_delay_ms(1000);
		
		stop();						
		_delay_ms(500);
		
		right(); //Left wheel forward, Right wheel backward
		_delay_ms(1000);

		stop();						
		_delay_ms(500);

		soft_left(); //Left wheel stationary, Right wheel forward
		_delay_ms(1000);
		
		stop();						
		_delay_ms(500);

		soft_right(); //Left wheel forward, Right wheel is stationary
		_delay_ms(1000);

		stop();						
		_delay_ms(500);

		soft_left_2(); //Left wheel backward, right wheel stationary
		_delay_ms(1000);

		stop();						
		_delay_ms(500);

		soft_right_2(); //Left wheel stationary, Right wheel backward
		_delay_ms(1000);

		stop();						
		_delay_ms(1000);
	}
}
//Main Function
int main()
{
	init_devices();
		
	while(1)
	{
	
		forward(); //both wheels forward
		_delay_ms(1000);

		stop();						
		_delay_ms(500);
	
		back(); //bpth wheels backward						
		_delay_ms(1000);

		stop();						
		_delay_ms(500);
		
		left(); //Left wheel backward, Right wheel forward
		_delay_ms(1000);
		
		stop();						
		_delay_ms(500);
		
		right(); //Left wheel forward, Right wheel backward
		_delay_ms(1000);

		stop();						
		_delay_ms(500);

		soft_left(); //Left wheel stationary, Right wheel forward
		_delay_ms(1000);
		
		stop();						
		_delay_ms(500);

		soft_right(); //Left wheel forward, Right wheel is stationary
		_delay_ms(1000);

		stop();						
		_delay_ms(500);

		soft_left_2(); //Left wheel backward, right wheel stationary
		_delay_ms(1000);

		stop();						
		_delay_ms(500);

		soft_right_2(); //Left wheel stationary, Right wheel backward
		_delay_ms(1000);

		stop();						
		_delay_ms(1000); 
	}
}
Example #6
0
void my_velocity(float val,float scale, int offset, float drive)
{
	unsigned char velocity = scale*drive + offset;

	if(val>0)
		{
				if(val<scale+offset)
					soft_right(velocity,0);
				else
					right(velocity,-velocity);
		}
	else
		{
			if(val>-(scale+offset))
				soft_left(0,velocity);
			else
				left(-velocity,velocity);
		}
}
Example #7
0
void move()
{
  int i;

  /*variable to use in figuring out the "best" option*/
  int max_q_score = 0;

  /*what do we do next? store it here*/
  /*we init to -1 as an error*/
  int next_movement = -1;

  /*Where we started.*/
  /*We don't use ROTATION_2 all the way through in case it changes.*/
  int initial_angle = norm_rotation(ROTATION_2);

  /*Where we ended up.*/
  int new_angle;

  /*Show the current angle*/
  cputc_native_user(CHAR_A, CHAR_N, CHAR_G, CHAR_L);  // ANGL
  msleep(200);
  lcd_int(initial_angle);
  msleep(500);
  
  /*
   * Most of the time, we do the "correct" thing
   * by finding the best q_score of our possible options.
   * On the off chance that norm_random() is low (or EPSILON is high ;)
   * we then "explore" by choosing a random movement.
   */

  if(norm_random() > EPSILON_CURRENT)
    {
      /*We are doing what the table tells us to.*/
      cputc_native_user(CHAR_r, CHAR_e, CHAR_a, CHAR_l);  // real
      msleep(500);

      for(i=0; i<MOVEMENTS; i++)
  {
    if(q_score[initial_angle][i] > max_q_score)
      {
        max_q_score = q_score[initial_angle][i];
        next_movement = i;
      }
  }
    }
  else
    {
      double temp;
      /*We are just picking something at random.*/
      cputc_native_user(CHAR_r, CHAR_a, CHAR_n, CHAR_d);  // rand
      msleep(500);

      /*pick one. Any one.*/
      
      temp = norm_random();
      next_movement = temp*MOVEMENTS;   

      /*show what we do next*/
      lcd_int(next_movement);
      sleep(1);
    }
  
  /*what happens if next_movement never gets changed?*/
  /*we'd hate to do HARD_LEFT over and over again*/
  /*so we choose randomly*/

  if(-1==next_movement)
    {
      double temp;
      temp = norm_random();
      next_movement = temp*MOVEMENTS;
    }

  /*having chosen a movement, lets do it*/
  switch(next_movement)
    {
    case HARD_LEFT:
      cputc_native_user(CHAR_H, CHAR_L, 0, 0);  // HL
      hard_left();
      break;
    case SOFT_LEFT:
      cputc_native_user(CHAR_S, CHAR_L, 0, 0);  // SL
      soft_left();
      break;
    case FORWARD:
      cputc_native_user(CHAR_F, CHAR_W, CHAR_W, CHAR_D); // FWD
      go_forward();
      break;
    case SOFT_RIGHT:
      cputc_native_user(CHAR_S, CHAR_R, 0, 0);  // SR
      soft_right();
      break;
    case HARD_RIGHT:
      cputc_native_user(CHAR_H, CHAR_R, 0, 0);  // HR
      hard_right();
      break;
    case REVERSE:
      cputc_native_user(CHAR_R, CHAR_E, CHAR_V, 0);  // REV
      go_back();
      break;
    default:
      /*this is an error and should never be reached*/
      cputc_native_user(CHAR_E, CHAR_R, CHAR_R, 0);  // ERR
      stop_motors();
      sleep(1);
      break;
    }

  /*Once we've started, we'd better stop*/
  stop_motors();

  /*Allows us to read direction*/
  msleep(500);

  /*This is here just to make the next function cleaner*/
  new_angle = norm_rotation(ROTATION_2);

  /*Where are we now?*/
  cputc_native_user(CHAR_N, CHAR_E, CHAR_W, CHAR_W);  // NEW
  msleep(200);
  lcd_int(new_angle);
  msleep(500);
  
  /*
   * Since we know that "next_movement" took us from "initial_angle"
   * to new_angle (ROTATION_2), we store that increased probability.
   */
  
  steering_results[initial_angle][next_movement][new_angle] += ALPHA;
  
  /*here we re-norm so that the sum of the probabilities is still 1*/
  for(i=0; i<ANGLES; i++)
    {
      steering_results[initial_angle][next_movement][i] /= (1+ALPHA);
    }  
  
  /*The last thing we do is reduce Epsilon*/
  if(EPSILON_CURRENT > EPSILON_MIN)
    {
      EPSILON_CURRENT-=EPSILON_DECAY;
    }

}
Example #8
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;
    }
}
int main(void)
{
	
	cli();
    set_lcd();
    set_motors();
    set_ADC();
    sei();
	
	int getValue1(void);                      //This function returns the value of the sensor mounted on the arm 
	void findagte(void);     
	void entergate(void);
	int follow_wall(void);
	int getValue2(void) ;                              
	
	int row;
	int state;
	
	
	
   centre = ADC_Conversion(2);
   sensorLeft = ADC_Conversion(3);
   sensorRight = ADC_Conversion(1);
	 
   value_front = ADC_Conversion(11); 
   value_4sens= ADC_Conversion(12);
   value_2sens= ADC_Conversion(10);
   value_1sens=ADC_Conversion(9);
/*
    lcd_print(2, 1, sensorLeft, 3);
    lcd_print(2, 5, centre, 3);
    lcd_print(2, 9, sensorRight, 3);
*/

    if(sensorLeft <50 && sensorRight <50 && centre < 50)                 //when the bot enters the arena first
	{
		
		velocity(forwardLeftSpeed, forwardRightSpeed);
        forward_mm(350);
		stop();
        _delay_ms(100);
		
		
	}
	
	   
        //getValue2();
		 value_front = ADC_Conversion(11);
		 if(value_front>150)
		 {
			 
			 centre = ADC_Conversion(2);
			  while(centre<150)
			  {
				  
				   velocity(forwardLeftSpeed, forwardRightSpeed);
			       forward();
				   value_front = ADC_Conversion(11);
				   if(value_front<150)
				   {
					   findgate();
				   }
				 
			        centre = ADC_Conversion(2);
			  }
			
			 entergate(); 
		 }
		 
		 
		 else if(value_front < 50)
		 {
			 
			 left_degrees(90);
			 stop();
			 _delay_ms(500);
			 
			  //turn the gripper
			  servo_2(90);
			 
			 while(1)
			 {
				 
				 row=follow_wall();
				 
				 if(state)
				 {
					 soft_right();
					 
					 centre = ADC_Conversion(2);
					 while(centre<150)
					 {
						 
						velocity(forwardLeftSpeed, forwardRightSpeed);
			            forward();
				   if(value_front<150)
				   {
					   findgate();
				   }
				   
				   centre = ADC_Conversion(2);
					 }
					 entergate();
					 						 
				 }			       
				 
			 }
			 
			 	
	}		
		
			return(row); 
		 }