Tuesday, February 7, 2012

Ultrasonic and flame sensors... SYNERGIZE!

So the past two days, I got the flame sensor to detect the flame and have the robot move towards it. Then I had the ultrasonic sensor stop in front of a wall.

Today I put these two commands together so that the robot would follow the flame indefinitely until it stops two inches away from it.

void orientflame()
{
  while(SensorValue[flameR] < 500)
  {
    motor[motorR] =  40;
    motor[motorL] = -40
    wait1Msec(30);
    motor[motorR] = 0;
    motor[motorL] = 0;
    wait1Msec(20);
  }
}

void stopdistance(int distance)
{
  unsigned byte SonarValue;
  SonarValue = SensorValue[sonar];
  if((SonarValue < distance)
  {
    motor[motorR] = 0;
    motor[motorL] = 0;
    wait1Msec(200);
  }
}

task main()
{
  while(1==1)
  {
    orientflame();
      motor[motorR] = 40;
      motor[motorL] = 40;
  stopdistance(3);
  }
}

No comments:

Post a Comment