Monday, February 20, 2012

Autonomous Maze Traversal

To find the flame, we had to program the Squarebot to move towards each room so that it can call it detect flame function. We used a combination of simple drive calls in conjunction with the ultrasonic sensor.


void searchRoom1()
{
  goForward(340);
  goRightSlowly(63);
  goForward(268);
  goRightSlowly(63);
  goForward(170);
  roomNum=1;
}

void searchRoom2()
{
  goLeftSlowly(67);
  goLeftSlowly(67);
  uSonicMove(7);
  goLeftSlowly(63);
  goForward(450);
  goLeftSlowly(67);
  uSonicMove(7);
  roomNum=2;
}

void searchRoom3()
{
  goRightSlowly(67);
  goRightSlowly(67);
  uSonicMove(7);
  goRightSlowly(63);
  goForward(170);
  goLeftSlowly(63);
  goForward(180);
  goLeftSlowly(63);
  uSonicMove(7);
  roomNum=3;
}

void searchRoom4()
{
  goRightSlowly(67);
  goRightSlowly(67);
  uSonicMove(7);
  goLeftSlowly(63);
  uSonicMove(7);
  goRightSlowly(63);
  uSonicMove(14);
  goRightSlowly(63);
  roomNum=4;
}

We successfully navigated on both our attempts. Our problem was that the squirt gun did not fire due to technical difficulties of the water pump. Overall, we had a blast and are looking forward to the next firefighting competition.

  

Firefighting Robot Challenge: Flame Detection and Extinguishing

To detect a flame, we use a flame sensor with 22,000 ohms resistor in conjunction with the Squarebot to read flame values. Our strategy was to sense  for flame values as soon as we stepped into any of the obstacle's rooms. We detect the flame and approach the flame and extinguish the flame with our squirt gun firing mechanism.
We set our main function to call the aim detection function twice to maximize the accuracy of the squirt gun.

bool aim4flame()
{
  if(SensorValue[flame]>=60)
  {
      //Initializers
      SensorValue[rEncoder]=0;
      SensorValue[lEncoder]=0;
      int highestFlame=SensorValue[flame];
      bool highestFlameOnRight=false;
      bool highestFlameOnLeft=false;
      int encoderVal=0;

      //Procedure
      if(SensorValue[flame]>=995)
      {
         return true;
      }
      
      else if(SensorValue[flame]<995)
      {
      while(SensorValue[rEncoder]<=90) //turning right until 90
      {
        if(sensorValue[flame]>995)
        {
          return true;
        }
        goRight(1);
        if(SensorValue[flame]>highestFlame) //set a new highestFlame if a greater flame value is detected
        {
          encoderVal=SensorValue[rEncoder];
          highestFlame=SensorValue[flame];
          highestFlameOnRight=true;
        }
      }
      goLeft(43);
      SensorValue[rEncoder]=0;
      while(SensorValue[rEncoder]<=90)
      {
        if(sensorValue[flame]>995)
        {
          return true;
        }
        goLeft(1);
        if(SensorValue[flame]>highestFlame)
        {
          encoderVal=SensorValue[rEncoder];
          highestFlame=SensorValue[flame];
          highestFlameOnLeft=true;
        }
      }
      goRight(53);
      if(highestFlameOnRight==true && highestFlameOnLeft==false)
      {
        int newEncoderVal=(((encoderVal/2)/2)/2);
        goRight(newEncoderVal);
        uSonicMove(12);
        if(SensorValue[flame]>995)
        {
          return true;
        }
        else
        {
          aim4flame();
        }
      }
      else if(highestFlameOnLeft==true)
      {
        int newEncoderVal2=((encoderVal/3));
        goLeft(newEncoderVal2);
        uSonicMove(12);
        return true;
        if(SensorValue[flame]>995)
        {
        return true;
        }
        else
        {
          aim4flame();
        }
      }
    }
  }
  return true;
}

Sunday, February 19, 2012

Traversing Through a Maze with the Squarebot

My partner and I set the Squarebot to traverse through a maze autonomously. We began on the bot by taking away the radio receiver and then writing a program to traverse though the maze. This program is written in RobotC:


#pragma config(Sensor, in7,    rEncoder,         sensorRotation)
#pragma config(Sensor, in8,    lEncoder,         sensorRotation)
#pragma config(Motor,  port2,           rMotor,        tmotorNormal, openLoop)
#pragma config(Motor,  port3,           lMotor,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
int left = 98;
int right = 70;
int wt = 250;
void goForward(int length)
{
  //wait1Msec(2000);
  bMotorReflected[port2]=1;
  SensorValue[lEncoder] = 0;
  while(SensorValue[lEncoder]<length)
  {
    motor[port3]=127;
    motor[port2]=95;
  }
}

void goleft(int length)
{
  //wait1Msec(2000);
  bMotorReflected[port2]=1;
  SensorValue[lEncoder] = 0;
  while(SensorValue[lEncoder]<length)
  {
    motor[port3]=-127;
    motor[port2]=80;
  }
}

void goright(int length)
{
  //wait1Msec(2000);
  bMotorReflected[port2]=1;
  SensorValue[lEncoder] = 0;
  while(SensorValue[lEncoder]<length)
  {
    motor[port3]=127;
    motor[port2]=-80;
  }
}

void w(int wt)
{
  while(SensorValue[lEncoder]<wt)
  {
    motor[port3]=0;
    motor[port2]=0;
    wait1Msec(wt);
  }

}

task main()
{
  goForward(570);
  goleft(left);
  goForward(280);
  goleft(left);
  goForward(550);
  goRight(right);
  goForward(280);
  goRight(right);
  goForward(740);
  goRight(right);
  goRight(3000);
}