- Our objective was to autonomously program a Vex Squarebot robot to navigate throughout a maze and blow out a candle. There were four rooms and the candle was randomly placed in one of the rooms. In order to have the candle detect the candle we used an IR detector to sense the heat from the candle and we used encoders on the wheels to make sure that the robot could have been commanded to go through the maze.
#pragma config(Sensor, in3, leftEncoder, sensorRotation)
#pragma config(Sensor, in4, fan, sensorDigitalOut)
#pragma config(Sensor, in6, frontIRSensor, sensorAnalog)
#pragma config(Sensor, in14, frontSonarSensor, sensorSONAR, int1)
#pragma config(Motor, port2, rightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port3, leftMotor, tmotorServoContinuousRotation, openLoop)
void clearEncoders();
void forward(int x);
void tleft(int x);
void tright(int x);
void backwards(int x);
void stop(int x);
void search();
void flame();
task main()
{
wait1Msec(2000);
bMotorReflected[port2] = true;
while(true)
{
//approach room 1//
clearEncoders();
stop(200);
forward(200);
stop(800);
tright(85);
stop(800);
forward(190);
stop(800);
tright(70);
stop(800);
//enter room 1 //
forward(130);
stop(800);
flame();
stop(800);
tleft(115);
stop(100);
//exit room 1 and approach room 2//
backwards(290);
stop(800);
forward(15);
stop(800);
tright(90);
stop(800);
backwards(110);
stop(800);
forward(205);
stop(800);
tright(80);
stop(800);
forward(290);
stop(800);
tright(65);
stop(800);
//enter room 2//
forward(120);
stop(800);
flame();
stop(800);
tleft(115);
stop(800);
//exit room 2 approach room 3//
backwards(150);
stop(800);
tleft(55);
stop(800);
backwards(360);
stop(800);
forward(25);
stop(800);
tright(85);
stop(800);
backwards(180);
stop(800);
//enter room 3//
forward(150);
stop(800);
tright(80);
stop(800);
forward(300);
stop(800);
flame();
stop(800);
tleft(115);
stop(800);
//exit room 3 and approach room 4//
backwards(450);
stop(800);
forward(50);
stop(800);
tleft(55);
stop(800);
forward(100);
stop(800);
tright(85);
stop(800);
forward(200);
stop(800);
tleft(75);
stop(800);
//enter room 4//
forward(150);
stop(800);
flame();
tleft(145);
stop(100);
}
}
void clearEncoders()
{
SensorValue[leftEncoder] = 0;
SensorValue[rightEncoder] = 0; //function for encoders to reset their count; therefore, to ensure that encoders are accurate at keeping consistent movements.
}
void forward(int x)
{
clearEncoders();
while(SensorValue[leftEncoder] < x && SensorValue[rightEncoder] < x) //function ensures that both encoders are working
{
motor[leftMotor] = 65;
motor[rightMotor] = 60;
}
}
void tleft(int x)
{
clearEncoders();
while(SensorValue[leftEncoder] < x && SensorValue[rightEncoder] < x)
{
motor[leftMotor] = -50;
motor[rightMotor] = 50;
}
}
void tright(int x)
{
clearEncoders();
while(SensorValue[leftEncoder] < x && SensorValue[rightEncoder] < x)
{
motor[leftMotor] = 50;
motor[rightMotor] = -40;
}
}
void backwards(int x)
{
clearEncoders();
while(SensorValue[leftEncoder] < x && SensorValue[rightEncoder] < x)
{
motor[leftMotor] = -60;
motor[rightMotor] = -60;
}
}
void stop(int x)
{
clearEncoders();
{
motor[leftMotor] = 0;
motor[rightMotor] = 0;
wait1Msec(x);
}
}
void flame() ******
{
int count=0;
while(SensorValue[frontIRSensor]==0 && count<30)//was this while function makes the IR sensor search for a flame
{
tright(5); // turns right 30 times at (5) power or in other words it is a tright(150); command if there is no IR value greater than one
stop(5);
count++;
}
if(SensorValue[frontIRSensor]>1)//loop until sonar finds an object <20 inches. // when the IR sensor detects a flame it should register a value greater than one.
{
while(SensorValue[frontIRSensor]<7) // The while function will not end until the IR sensor registers a value less than 7
{
forward(5); // keep going forward near the flame
}
stop(200);
SensorValue[fan]=true;
wait10Msec(1000);
SensorValue[fan]=false; // after the while statement above is fulfilled and the squarebot is close enough to the flame it will turn on the fan
wait10Msec(500000000);
}
}
- Here is the video of this code in action with our sqaurebot

















The heat gun for this part of the lab was extremely hot and the wire along with the tubing was only placed over the heat for a few seconds.