For this customized course, we used the ROBOTC RVW Level Builder to construct a simulation of a building after an earthquake. Our course design went through several iterations as we coordinated with the coding process and which sensors to use. We decided on a route that begins with the light sensor following a line. This represents an exit route painted on the building floor. Throughout the course, there are "decoy" items such as cans and cubes to represent building debris. Near the end, the line ends at a wall, representing an unexpected barrier. The robot must choose to turn left for the path toward escape instead of continuing forward.
We begin with our BuggyBot at the starting box, as shown in the image. To its right are blue cylinders; to its left is a wall. The robot must first use its color sensor to determine the route of the exit path.The course continues in a similar manner until it reaches the barrier, at which point it must use its ultrasonic and touch sensors to react and move accordingly toward the nearest route out.
The robot checks if it is at the finish.
If it is not at the finish, it checks if there is a line to follow. If so, it follows the line.
If there is a barrier in front of it, it stops following the line and checks if there is an obstacle to its right.
If there is, it turns left and drives forward. If there is no barrier, it turns right and drives forward.
It repeats this process until it reaches the finish.
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in3, gyro, sensorGyro)
#pragma config(Sensor, in4, lightSensor, sensorLineFollower)
#pragma config(Sensor, in6, armPot, sensorPotentiometer)
#pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl8, sonarSensor, sensorSONAR_cm)
#pragma config(Sensor, dgtl11, touchSensor, sensorTouch)
#pragma config(Sensor, I2C_1, rightIME, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, leftIME, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_3, armIME, sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port2, rightMotor, tmotorVex393_MC29, openLoop, driveRight, encoderPort, I2C_1)
#pragma config(Motor, port3, leftMotor, tmotorVex393_MC29, openLoop, driveLeft, encoderPort, I2C_2)
#pragma config(Motor, port6, buggyAttachment, tmotorVex393_MC29, openLoop, encoderPort, I2C_3)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
void lineFollowing(){
while(SensorValue(rightEncoder) < 1800) {
int threshold = 1500; /* found by taking a reading on both DARK and LIGHT */
/* surfaces, adding them together, then dividing by 2. */
// sensor sees light:
if(SensorValue(lightSensor) < threshold) {
// counter-steer left:
motor[leftMotor] = 127;
motor[rightMotor] = 0;
}
// sensor sees dark:
else{
// counter-steer right:
motor[leftMotor] = 0;
motor[rightMotor] = 127;
}
if(SensorValue(sonarSensor) < 20) {
break;
}
}
}
void turnRightIfOpen(){
motor[leftMotor] = 29;
motor[rightMotor] = -29;
wait1Msec(900);
if(SensorValue(sonarSensor)< 50){
motor[leftMotor] = -29;
motor[rightMotor] = 29;
wait1Msec(1850);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main(){
wait1Msec(2000); // Robot waits for 2000 milliseconds before executing program
// Move forward at full power for 0.5 seconds
motor[rightMotor] = 127; // Motor on port2 is run at full (127) power forward
motor[leftMotor] = 127; // Motor on port3 is run at full (127) power forward
wait1Msec(500); // Robot runs previous code for 3000 milliseconds before moving on
//Clear Encoder Values
SensorValue(rightEncoder) = 0;
SensorValue(leftEncoder) = 0;
lineFollowing();
turnRightIfOpen();
motor[leftMotor] = 127;
motor[rightMotor] = 127;
wait1Msec(8000);
}
// Program ends, and the robot stops
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++