Focus Areas for Final Testing
Our final design was focused on being balanced and efficient. With everything centered on top of the AEV, it kept it very balanced as well as cheaper than the stock AEV. The final code was adapted from the first two performance tests and focused on consistency. It contains an auto-correction system that allowed the AEV to adjust for inconsistencies while stopping at the gate. Coasting was used wherever possible and the power level was kept low to ensure minimal power usage and cost.
Final Design
Final Code
// Performance Test Final Run
int sensorPos;
// track traveling ——————————————————————————–
reverse(4); // Reverse motors to start going forward
motorSpeed(4,39); // all motors 39% power
goToAbsolutePosition(157); // travel for about 6 feet
brake(4); goFor(5); // brake all motors for 5 seconds to coast and reach gate
// gate waiting ———————————————————————————–
sensorPos = 297;
if (getVehiclePostion() < sensorPos) { // If AEV hasnt reached sensor, give a little burst of power
motorSpeed(4,30); goFor(0.5);
}
double timeLapsed = 0.0;
bool motorsForward = true;
int power = 0;
double timeStep = 0.1;
while (timeLapsed <= 7.5){ // for 7 seconds, while waiting at gate
if (getVehiclePostion() > sensorPos + 3) { // if AEV passes the sensor, reverse
if (motorsForward == true) { // check motor direction
reverse(4);
motorsForward = false;
}
power = 20;
}
else if (getVehiclePostion() < sensorPos – 3) { // if AEV reverses too far, go forward
if (motorsForward == false) { // check motor direction
reverse(4);
motorsForward = true;
}
power = 20;
}
else { // dont move
power = 0;
}
motorSpeed(4, power); goFor(timeStep);
timeLapsed += timeStep;
}
brake(4); goFor(1);
if (motorsForward == false) { // check motor direction
reverse(4);
motorsForward = true;
}
// track traveling ———————————————————————————-
motorSpeed(4,35); // all motors 35% power
goToAbsolutePosition(425); // travel to about the 18 foot mark
brake(4); goToAbsolutePosition(604); // coast until reach the caboose
reverse(4); //power brake
motorSpeed(4,30); goFor(0.75); // reverse to avoid slamming the caboose
brake(4); goFor(6); // wait for passengers to board caboose
motorSpeed(4,47); // head back to the gate
goToAbsolutePosition(485); // travel about 4 feet
brake(4); goFor(2.12); // travel about 2 seconds to coast to gate
// gate waiting time ————————————————————————-
reverse(4); // power brake
motorSpeed(4,50); goFor(1.25); // reverse to stop at gate
brake(4); goFor(7.25); // wait for gate to open
reverse(4); // continue forward
// track traveling —————————————————————————
motorSpeed(4,40); goFor(3.5); // continue through gate
brake(4); goFor(4); // coast until end of the track
reverse(4); // power brake
motorSpeed(4,40); goFor(0.75); // reverse to stop at end of track
brake(4);
// DONE!