RBE2002FinalProject/DualDCMotor.cpp
// drive straight while following the wall on the left side
drive straight while following the wall on the left side
drive straight while following the wall on the left side
void DualDCMotor::driveAlongWall() {
  lastTime = millis();
  setMotorSpeed(1, PWM);
  setMotorSpeed(0, PWM);
  while (analogRead(MaxBotixPin) > 10 && analogRead(lineSensorPin) > 500 && leftULS.Range() < 8) {
    if (millis() - lastTime >= 200) {
      sideError = leftULS.Range() - setDis;
      if (sideError > 0) {
        setMotorSpeed(0, PWM - sideError * 20);
      }
      else if (sideError < 0) {
        setMotorSpeed(1, PWM - sideError * 20);
      }
      lastTime = millis();
    }
  }
  stopMotors();
}
void DualDCMotor :: driveAlongWall ( ) { lastTime = millis ( ) ; setMotorSpeed ( 1 , PWM ) ; setMotorSpeed ( 0 , PWM ) ; while ( analogRead ( MaxBotixPin ) > 10 && analogRead ( lineSensorPin ) > 500 && leftULS . Range ( ) < 8 ) { if ( millis ( ) - lastTime >= 200 ) { sideError = leftULS . Range ( ) - setDis ; if ( sideError > 0 ) { setMotorSpeed ( 0 , PWM - sideError * 20 ) ; } else if ( sideError < 0 ) { setMotorSpeed ( 1 , PWM - sideError * 20 ) ; } lastTime = millis ( ) ; } } stopMotors ( ) ; }
drive straight while following the wall on the left side
drive straight while following the wall on the left side
// start driving the robot forward // when the wall in front is far enough, the line sensor is not detecting an edge, and leftULS is detecting a wall