The Arduino Code for the Performance Tests
Performance Test 1 Design 1
motorSpeed(1,42); //Sets motor 1 to 42% power
goToRelativePosition(245); //Goes for 245 marks
brake(4); //Brakes all motors
motorSpeed(2,50); //Sets motor 2 to 50% power to brake
goFor(1); //Goes for 1 second
brake(4); //Brakes all motors
goFor(12); //Stationary for 12 seconds
motorSpeed(1,40); //Runs motor 1 at 40% power
goFor(2); //Runs for 2 seconds
Performance Test 1 Design 2
motorSpeed(4,30); //Sets all motors to 30% power
goToRelativePosition(240); //Goes for 240 marks
brake(4); //Brakes all motors
reverse(4); //Reverses all motors
motorSpeed(4,20); //Sets all motors to 20% power to brake
goFor(1); //Runs for 1 second
brake(4); //Brakes all motors
goFor(12); //Stationary for 12 seconds
motorSpeed(4,20); //Runs all motors at 20% power
goFor(2); //Runs for 2 seconds
Performance Test 2 Code 1
motorSpeed(1,42); //Sets motor 1 to 42% power
goToRelativePosition(245); //Goes for 245 marks
brake(4); //Brakes all motors
motorSpeed(2,50); //Sets motor 2 to 50% power to brake
goFor(1); //Goes for 1 second
brake(4); //Brakes all motors
goFor(12); //Stationary for 12 seconds
motorSpeed(1,40); //Runs motor 1 at 40% power
goFor(2); //Runs for 2 seconds
brake(4); //Brakes all motors
goToRelativePosition(95); //Runs for 95 marks
motorSpeed(2,30); //Sets motor 2 to 30% power to brake
goFor(2); //Runs for 2 seconds
brake(4); //Brakes all motors
goFor(6); //Waits 6 seconds stationary
motorSpeed(2,50); //Sets motor 2 to 50% power to go backwards
goFor(2); //Runs for 2 seconds
Performance Test 2 Code 2
motorSpeed(1,42); //Sets motor 1 to 42% power
//While the total marks is less than 245, keep running motor 1 at 42% power
while (getTotalMarks() < 245) {
}
brake(4); //Brake all motors
boolean check = false; //Sets a variable check to false
//While the AEV is less than 265 marks and it hasn’t braked yet, this while loop will make sure the AEV brakes correctly depending on the distance the AEV has traveled.
//The motor speeds are different depending on how far away the AEV is from the gate.
while (getTotalMarks() < 265 && ~check) {
if (getTotalMarks() < 255) {
motorSpeed(2,50); //Sets motor 2 to brake at 50% power
goFor(1); //Runs for 1 second
check = true; //Sets “check” to true
} else if (getTotalMarks() < 260) {
motorSpeed(2,52); //Sets motor 2 to brake at 52% power
goFor(1); //Runs for 1 second
check = true; //Sets “check” to true
} else {
motorSpeed(2,54); //Sets motor 2 to brake at 54% power
goFor(1); //Runs for 1 second
check = true; //Sets “check” to true
}
}
motorSpeed(2,58); //Sets motor 2 to 58
brake(4); //Brakes all motors
goFor(12); //Remains stationary for 12 seconds
motorSpeed(1,38); //Sets motor 1 to 38% power
goFor(2); //Runs for 2 seconds
brake(4); //Brakes all motors
goFor(15); //Coasts and stops for 15 seconds
motorSpeed(2,50); //Sets motor 2 to 50% power to go backwards
goFor(2); //Runs for 2 seconds
Final Performance Test
motorSpeed(1,42); //Sets motor 1 to 42% power
//While the total marks is less than 245, keep running motor 1 at 42% power
while (getTotalMarks() < 245) {
}
brake(4); //Brake all motors
boolean check = false; //Sets a variable check to false
//While the AEV is less than 265 marks and it hasn’t stopped yet, this while loop will make sure the AEV brakes correctly depending on the distance the AEV has traveled.
//The motor speeds are different depending on how far away the AEV is from the gate.
while (getTotalMarks() < 265 && ~check) {
if (getTotalMarks() < 255) {
motorSpeed(2,53); //Sets motor 2 to brake at 53% power
goFor(1); //Runs for 1 second
check = true; //Sets “check” to true
} else if (getTotalMarks() < 260) {
motorSpeed(2,55); //Sets motor 2 to brake at 55% power
goFor(1); //Runs for 1 second
check = true; //Sets “check” to true
} else {
motorSpeed(2,57); //Sets motor 2 to brake at 57% power
goFor(1); //Runs for 1 second
check = true; //Sets “check” to true
}
}
brake(4); //Brakes all motors
goFor(9); //Remains stationary for 9 seconds
motorSpeed(1,40); //Sets motor 1 to 40% power
goFor(2); //Runs for 2 seconds
brake(4); //Brakes all motors
goToAbsolutePosition(640); //Coasts until it reaches 640 marks
goFor(5); //Coasts and stops for 5 seconds
motorSpeed(2,50); //Sets motor 2 to 50% power to go backwards
//This code is used for when the AEV is attached to the caboose and is going up the hill. While the total marks is less than 880, motor 2 will continue to run at 50% power.
while (getTotalMarks() < 880) {
}
brake(4); //Brakes all motors
check = false; //Sets the boolean variable check to false
//While the AEV is less than 896 marks (but greater than 880 marks since it has exited the previous while loop), this loop will brake the AEV depending on how far away it is from the gate.
while (getTotalMarks() < 896 && ~check) {
if (getTotalMarks() < 884) {
motorSpeed(1,54); //Sets motor one to 54% power
goFor(1); //Goes for 1 second
check = true; //Sets “check” to true
} else if (getTotalMarks() < 882) {
motorSpeed(1,56); //Sets motor one to 56% power
goFor(1); //Goes for 1 second
check = true; //Sets “check” to true
} else {
motorSpeed(1,58); //Sets motor one to 58% power
goFor(1); //Goes for 1 second
check = true; //Sets “check” to true
}
}
brake(4); //Brakes all motors
goFor(10); //Stops the AEV at the gate for 10 seconds
motorSpeed(2, 50); //Runs motor 2 at 50% power
goFor(6); //Runs for six seconds
brake(4); //Brakes all motors
goToAbsolutePosition(65); //Coasts until it reaches the absolute position of 65 marks
motorSpeed(1, 45); //Sets motor one to 45% power to brake
goFor(2); //Runs for 2 seconds