Thursday, February 10, 2011

Last day before last day of class before the bot's competition

Whole day on wednesday as my partner Ben was working on the color sensor and its issues I worked on the programing
even though i did not have exact values i just did a layout with approximate numbers so i can replace the numbers after the testing of our bot
this is the code that i wrote


#pragma config(Sensor, in1,    RightLineSensor,     sensorLineFollower)
#pragma config(Sensor, in2,    LeftLineSensor,      sensorLineFollower)
#pragma config(Sensor, in4,    Infrared,            sensorReflection)
#pragma config(Sensor, in5,    ColorSensor,         sensorReflection)
#pragma config(Sensor, in6,    CheckSwitch,         sensorTouch)
#pragma config(Motor,  port1,           LeftMotor,     tmotorNormal, openLoop)
#pragma config(Motor,  port2,           RightMotor,    tmotorNormal, openLoop)
#pragma config(Motor,  port3,           Servo,         tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//




void goforward(int dist)
{
   motor[port2] = 50;
      motor[port1] = 50;
      wait10Msec(time);
    }




task main()
{
  while (true)
  {
  int test1 = SensorValue(LeftLineSensor);
  int test2 = SensorValue(RightLineSensor);
  int test3 = SensorValue[Infrared];
  int test4 = SensorValue[ColorSensor];
  //Code for checking the color of the floor
      // 1-




  //Maneuver Code






    //If the the bot does not hit a black line
  if((SensorValue(RightLineSensor) < 800) && _
  (SensorValue(LeftLineSensor) < 800) && _
    //or if it does not get too close to a can
  (SensorValue(Infrared) < 300) ))
{
 // go forward for 2 sec
goforward(150);
      //
      motor[port2] = 0;
      motor[port1] = 0;
      wait10Msec(100);
      int max_dist_val = 0 ;
      int dist_val1 ;
      int dist_val2 ;
      int index;
      for (int i=0;i<60:i++)
      {
        motor[port2] = 30;
        motor[port1] = -30;
        wait10Msec(100);
        dist_val1 = SensorValue (Infrared);
          if (dist_val1 > 300)
            {motor[port2] = 0;
             motor[port1] = 0;
             wait10Msec(100);
             do
             {motor[port2] = 30;
              motor[port1] = 30;
              while (




             i=60;}
          if (dist_val1 > max_dist_val)
           {
            max_dist_val = dist_val1;
            index = i;
           }
      }
      for (int i=0;i<60:i++)
      {
        motor[port2] = -30;
        motor[port1] = 30;
        wait10Msec(100);
        dist_val2 = SensorValue (Infrared);
        if (abs(dist_val2 - max_dist_val) < 30)
        {
           motor[port2] = 0;
           motor[port1] = 0;
           wait10Msec(100)
           i=60;
        }
        else
        {index = i;
        }


      }
      wait10Msec(100);
}




else if (SensorValue(RightLineSensor) > 800)
{
 motor[port2] = -44;
      motor[port1] = -44;
 wait10Msec(100);
 motor[port1] =-40;
      motor[port2] = 40;
      wait10Msec(100);
    }


    else if (SensorValue(LefttLineSensor) > 800)
{
 motor[port2] = -44;
      motor[port1] = -44;
 wait10Msec(100);
 motor[port1] = 40;
      motor[port2] = -40;
      wait10Msec(100);
    }






}
the first part of the code is mainly declaring all the variables 
the first if statement includes most of the codes 
in that part the car turns around and saves all the values received from the infrared and then moves toward the highest value which is the closest object
the last two if statements avoid passing over the black lines

No comments:

Post a Comment