void CCar::PressForward() { if(bkp) { Unclutch(); NeutralDrive(); } else { DriveForward(); } fwp=true; }
void GoToObject(int power, int sonarNum) { //The distance we want the robot to be away from an object const int targetDistance = 30; //The margin of error for the target distance const int accuracyMargin = 3; //If the sensor is farther away from an object than the target distance, the robot moves forward if(ReadSonar(sonarNum) > targetDistance + accuracyMargin) { DriveForward(power); } //If the sensor is closer to an object than the target distance, the robot moves backward else if(ReadSonar(sonarNum) < targetDistance - accuracyMargin) { DriveBackward(power); } //If the robot is within the margin of error from the target distance, the motors stop and the function tells itself to stop else { StopAllDriveMotors(); } }
void DriveBackward(int power) { DriveForward(-1 * power); }