Coasting Code:
// Runs the motors until position 40 before coasting to a stop
motorSpeed(4,40);
goToRelativePosition(40);
brake(4);
Power Braking Code:
// This code runs the motor until it reaches 6.5ft (78in) then power brakes the AEV
motorSpeed(4, 40);
goToAbsolutePosition(156); // 6.5ft (78in)
reverse(4);
motorSpeed(4, 40);
brakeAEV(); // I defined this function (see below)
brake(4);
// This function waits until the AEV is travelling in a different direction, at which point we know
// it has turned around. This has the effect of stopping, as the AEV will be travelling very slowly
// the moment it turns around.
void brakeAEV() {
int currentDir = dir; // dir is a global variable which holds the direction
int delayFor = 70;
while (currentDir==dir){
delay(delayFor);
}
}