Dependencies: mbed Servo mbed-rtos Motor
Diff: main.cpp
- Revision:
- 11:45ee4a96bca0
- Parent:
- 10:1402608022be
- Child:
- 12:439c0b3f0673
--- a/main.cpp Mon Apr 27 23:28:49 2020 +0000 +++ b/main.cpp Tue Apr 28 21:24:08 2020 +0000 @@ -77,7 +77,7 @@ float rightMotorSpeed = 0.0; int encoderCountDifference = 0; - int countDifferenceTolerance = 2; //How many counts difference between encoders is allowed + const int countDifferenceTolerance = 3; //How many counts difference between encoders is allowed while(1){ if(leftJoystickState != 0 && rightJoystickState != 0 && leftJoystickState == rightJoystickState) //only need to match speeds if they're moving in same direction @@ -124,11 +124,11 @@ //add or subtract motor speed, depending on if its positive or negative if(leftMotorSpeed < 0){ rightMotorSpeed = rightMotorSpeed + 0.01; - rightMotor.speed(leftMotorSpeed); + rightMotor.speed(rightMotorSpeed); } else if(leftMotorSpeed > 0){ rightMotorSpeed = rightMotorSpeed - 0.01; - rightMotor.speed(leftMotorSpeed); + rightMotor.speed(rightMotorSpeed); } leftEncoderCount = 0; //reset encoder counts rightEncoderCount = 0;