Monday, February 20, 2012

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;
}

No comments:

Post a Comment