platisd/smartcar_shield

Cruise control suffers from runaway due to temporary sensor failure

michalpalka opened this issue · 8 comments

The cruise control functionality of the library can cause runaway as a result of a temporary sensor failure. As a consequence, the controlled rover moves in the direction opposite to the requested one at maximum speed.

The problem affects the cruise control functionality enabled using car.enableCruiseControl(). We observed it with this rover type.

The problem manifests when the rover is commanded to drive forward, but is still standing and the odometers temporarily report high moving speed due to signal transmission failure. The controller will then apply negative torque (meant for braking), which accelerates the rover backwards. As the rover accelerates backwards, the odometers correctly report increasing speed (the odometers report the absolute speed, not the direction), which is interpreted as the rover moving forward too fast. This results in more negative torque being applied, and a complete runaway with the rover racing backwards.

The following sketch can be used to demonstrate the problem.

#include <Smartcar.h>

Odometer encoderLeft(188), encoderRight(188);
Gyroscope gyro(22);
Car car;

const int encoderLeftPin = 2;
const int encoderRightPin = 3;
const float fSpeed = 0.3; //a ground speed (m/sec) for going forward
bool sw = false;

void setup() {
  Serial3.begin(9600);
  encoderLeft.attach(encoderLeftPin);
  encoderRight.attach(encoderRightPin);
  gyro.attach();
  delay(1500);
  gyro.begin(60);
  encoderLeft.begin();
  encoderRight.begin();
  car.begin(encoderLeft, encoderRight, gyro); //initialize the car using the encoders
  car.enableCruiseControl(); //using default PID values
  car.setAngle(0);
 // car.enableCruiseControl(12,5,17,30); //using custom values and control frequency
  car.setSpeed(fSpeed);
}

void loop() {
  car.updateMotors();
  handleInput();
}

int state = 0;

void handleInput() {
  int t = millis();
  if (t >= 1000 && state < 1) {
    car.setSpeed(fSpeed);
    state = 1;
  } else if (t >= 3000 && state < 2) {
    car.setSpeed(0);
    state = 2;
  }

}

The sketch uses the cruise control functionality, requesting to drive forward at 1 s after setup, and then stopping at 3 s. The correct behaviour with the sketch is the rover driving forward and then stopping.

We managed to trigger erroneous behaviour by using the rover with depleted batteries. With that setup, the rover will occasionally race backwards instead of moving forward. We observed incorrect behaviour once every 4 attempts or so, but this probability is greatly dependent on the state of the batteries. We also observed it by using an incomplete battery pack (6 1.5 V batteries instead of 8), giving the measured voltage 8.4 V dropping to 6.4 V under load (we could not measure voltage under load reliably due to how fast was changing). Connecting the Arduino board to USB power makes the problem go away completely.

We traced the problems to the odometers returning high speeds temporarily when the rover is standing or moving slowly. We don’t know what causes the incorrect readouts. We suspect that the voltage ripple from the motor controller is interpreted as signal edges from the odometers.

We believe that the cause of the incorrect readouts should be investigated, but the fundamental problem here is that the control turns a small disturbance (or input corruption) into a complete runaway. Using odometers that also report the direction of movement in addition to the speed would solve the problem. With the current odometers, the controller should be somehow constrained to avoid the runaway.

I will start looking into this. I think the problem that needs to be investigated is whether there are ways to safeguard against faulty odometer readings however these may occur.

As you correctly mentioned, the "simple" Odometers cannot determine direction of movement and that is why some "special" logic is in place when it comes to stopping or changing direction of movement. Specifically, when the vehicle is driving forward and we command it to start going backward, from an odometer perspective there is no difference between these two states. That's why we try to stop the car first by applying some torque in the opposite direction

To accelerate in the investigation, it would be great to provide some logs, i.e. the speed of the car (Car::getSpeed()) and the current state. Since the problem is not observed when the board is connected via USB, you should use a Bluetooth module or any other wireless means of communication.

Logs

Here are some logs from today's troubleshooting session with @Shaun-McMurray. We tried to replicate the reversing behavior with the battery pack having different voltages, and it was, as previously mentioned, very apparent that this reversing behavior happened more often when the voltage was low. The logs were sent over Bluetooth, thus no USB cable was connected to the car during the testing.

The car speed was retrieved by Car::getSpeed(), odometer speed by odometer::getSpeed() and the 'battery pack voltage' from a voltage divider connected to the battery pack and to an analog pin on the Arduino.

In addition to the reversing behavior of the car, we also observed that the car did not move at all at times. See the section at the bottom for logs retrieved when that happened.

Normal behavior (control):

Car speed Right odometer speed Left odometer speed Battery pack voltage
0.40 0.11 0.10 9.64
0.40 0.11 0.10 9.38
0.40 0.11 0.10 9.45
0.40 0.11 0.10 9.64
0.40 0.11 0.10 9.64
0.40 0.11 0.10 9.50
0.40 0.11 0.10 8.96
0.40 0.11 0.10 9.30
0.40 0.11 0.10 9.45
0.40 0.11 0.10 9.38
0.40 0.11 0.10 9.42
0.40 0.11 0.10 9.42
0.40 0.11 0.10 9.40
0.40 0.11 0.10 9.40
0.40 0.11 0.10 8.47
0.40 0.11 0.10 8.28
0.40 0.11 0.10 6.71
0.40 0.11 0.10 9.08
0.40 0.11 0.10 8.54
0.40 0.11 0.10 8.91
0.40 0.11 0.10 9.13
0.40 0.11 0.10 8.98
0.40 0.11 0.00 9.06
0.40 0.11 0.00 6.10
0.40 0.11 0.08 8.86
0.40 0.00 0.22 7.20
0.40 0.00 0.13 8.45
0.40 0.00 0.26 6.13
0.40 0.07 0.16 7.69
0.40 0.07 0.30 8.86
0.40 0.09 0.36 8.54
0.40 0.19 0.21 8.76
0.40 0.14 0.24 6.86
0.40 0.26 0.26 8.86
0.40 0.29 0.28 8.08
0.40 0.20 0.29 6.81
0.40 0.33 0.30 6.67
0.40 0.37 0.32 6.62
0.40 0.36 0.58 8.69
0.40 0.39 0.57 7.84
0.40 0.28 0.60 8.47
0.40 0.27 0.34 7.96
0.40 0.27 0.35 8.76
0.40 0.28 0.61 8.86
0.40 0.28 0.62 6.57
0.40 0.30 0.61 7.45
0.40 0.30 0.36 6.79
0.40 0.30 0.65 8.47
0.40 0.31 0.66 6.64
0.40 0.33 0.37 7.93
0.40 0.47 0.65 8.84
0.40 0.52 0.65 8.62
0.40 0.49 0.36 8.76
0.40 0.51 0.65 6.96
0.40 0.52 0.67 8.62
0.40 0.51 0.38 7.45
0.40 0.33 0.70 7.98
0.40 0.34 0.36 6.81
0.40 0.34 0.68 6.76
0.40 0.50 0.69 8.79
0.40 0.55 0.38 8.35
0.40 0.54 0.70 8.67
0.40 0.34 0.70 7.69
0.40 0.35 0.39 8.86
0.40 0.58 0.64 8.91
0.40 0.53 0.67 6.79
0.40 0.48 0.35 7.37
0.40 0.48 0.64 6.88
0.40 0.49 0.61 8.79
0.40 0.31 0.35 7.93
0.40 0.30 0.35 8.57
0.40 0.30 0.59 8.94
0.40 0.30 0.59 8.81
0.40 0.31 0.57 8.89
0.40 0.29 0.33 6.81
0.40 0.29 0.32 8.67
0.40 0.29 0.60 7.32
0.40 0.29 0.59 8.57
0.40 0.29 0.59 6.69
0.40 0.28 0.59 7.91
0.40 0.29 0.33 8.89
0.40 0.30 0.34 8.69
0.40 0.30 0.54 8.84
0.40 0.29 0.59 7.45
0.40 0.28 0.55 8.89
0.40 0.28 0.54 8.62
0.40 0.41 0.54 8.01
0.40 0.40 0.31 7.06
0.40 0.42 0.31 6.67
0.40 0.45 0.32 8.81
0.40 0.40 0.54 8.33
0.40 0.42 0.53 8.69
0.40 0.44 0.55 8.76
0.40 0.43 0.54 8.84
0.40 0.41 0.57 8.89
0.40 0.27 0.56 6.62
0.40 0.26 0.52 8.11
0.40 0.25 0.50 7.01
0.00 0.02 0.24 8.81
0.00 0.02 0.22 9.33

Car reversing

Here are some logs from when the car started to reverse

Car speed Right odometer speed Left odometer speed Battery pack voltage
0.35 0.11 0.38 9.59
0.35 0.11 0.38 9.59
0.35 0.11 0.38 9.52
0.35 0.11 0.38 9.59
0.35 0.11 0.38 9.57
0.35 0.11 0.38 9.57
0.35 0.11 0.38 9.52
0.35 0.11 0.38 9.57
0.35 0.11 0.38 9.57
0.35 0.11 0.38 9.55
0.35 0.11 0.38 9.57
0.35 0.11 0.38 9.55
0.35 0.11 0.38 9.57
0.35 0.11 0.38 9.57
0.35 0.11 0.38 9.47
0.35 0.11 0.38 8.33
0.35 0.11 0.38 9.30
0.35 0.11 0.38 9.50
0.35 0.11 0.38 9.47
0.35 0.11 0.38 9.47
0.35 0.11 0.38 9.47
0.35 0.11 0.38 9.47
0.35 0.11 0.38 9.47
0.35 0.11 0.38 8.98
0.35 0.11 0.38 9.45
0.35 0.11 0.38 8.01
0.35 0.11 0.38 9.38
0.35 0.11 0.38 9.13
0.35 0.11 0.38 9.30
0.35 0.11 0.38 9.40
0.35 0.11 0.38 9.35
0.35 0.11 0.38 9.38
0.35 0.11 0.38 7.52
0.35 0.11 0.38 9.38
0.35 0.11 0.38 9.35
0.35 0.11 0.38 9.13
0.35 0.11 0.38 6.69
0.35 0.11 0.38 8.76
0.35 0.11 0.38 9.25
0.35 0.11 0.38 9.13
0.35 0.11 0.38 9.20
0.35 0.11 0.38 9.01
0.35 0.11 0.38 9.23
0.35 0.11 0.38 9.25
0.35 0.11 0.38 8.45
0.35 0.11 0.38 7.69
0.35 0.11 0.38 6.49
0.35 0.11 0.38 9.13
0.35 0.11 0.38 8.69
0.35 0.11 0.38 8.96
0.35 3.34 0.38 9.16
0.35 3.34 0.38 9.08
0.35 3.34 0.38 9.13
0.35 3.34 0.38 9.25
0.35 3.34 0.38 9.42
0.35 3.34 0.38 9.45
0.35 3.34 0.38 9.38
0.35 3.34 0.38 9.13
0.35 3.34 0.38 9.33
0.35 3.34 0.38 9.25
0.35 3.34 0.38 9.16
0.35 3.34 0.38 9.20
0.35 3.34 0.38 6.93
0.35 3.34 0.38 9.01
0.35 0.01 0.38 8.47
0.35 0.01 0.38 8.74
0.35 0.01 0.00 7.15
0.35 0.06 0.16 8.03
0.35 0.06 0.16 9.20
0.35 0.10 0.09 9.08
0.35 0.10 0.16 9.20
0.35 0.07 0.16 9.30
0.35 0.07 0.09 9.28
0.35 0.10 0.09 9.30
0.35 0.10 0.14 8.98
0.35 0.10 0.14 9.38
0.35 0.10 0.07 7.84
0.35 0.05 0.07 9.40
0.35 0.05 0.07 9.33
0.35 0.05 0.07 9.40
0.35 0.05 0.07 9.45
0.35 0.05 0.07 9.47
0.35 0.05 0.07 9.47
0.35 0.05 0.07 9.38
0.35 0.05 0.07 9.47
0.35 0.05 0.07 9.50
0.35 0.05 0.07 9.45
0.35 0.05 0.07 9.23
0.35 0.05 0.07 9.40
0.35 0.05 0.07 9.45
0.35 0.05 0.07 9.38
0.35 0.05 0.07 9.42
0.35 0.05 0.07 9.35
0.35 0.05 0.07 9.35
0.35 0.05 0.07 9.38
0.35 0.05 0.07 8.79
0.35 0.05 0.07 8.28
0.35 0.05 0.07 6.71
0.00 0.05 0.07 9.18
0.00 0.05 0.07 9.42
0.00 0.05 0.07 9.45
0.00 0.05 0.07 9.50
0.00 0.05 0.07 9.50
0.00 0.05 0.07 9.50
0.00 0.05 0.07 9.52
0.00 0.05 0.07 9.52
0.00 0.05 0.07 9.52
Car speed Right odometer speed Left odometer speed Battery pack voltage
0.40 0.00 0.00 6.96
0.40 0.00 0.00 6.96
0.40 0.00 0.00 6.91
0.40 0.00 0.00 6.81
0.40 0.00 0.00 6.86
0.40 0.00 0.00 6.86
0.40 0.00 0.00 6.79
0.40 0.00 0.00 6.81
0.40 0.00 0.00 5.47
0.40 0.00 0.00 6.74
0.40 0.00 0.00 6.76
0.40 0.00 0.00 6.01
0.40 0.00 0.00 5.08
0.40 0.00 0.00 7.01
0.40 0.00 0.00 6.42
0.40 0.00 0.00 5.91
0.40 0.00 0.00 6.05
0.40 0.00 0.00 5.47
0.40 0.00 0.00 6.32
0.40 0.00 0.00 6.32
0.40 0.00 0.00 6.42
0.40 0.00 0.00 5.27
0.40 0.00 0.00 5.08
0.40 0.00 0.00 6.03
0.40 0.00 0.00 7.01
0.40 0.00 0.00 6.23
0.40 0.00 0.00 5.47
0.40 0.00 0.00 6.01
0.40 0.00 0.00 5.88
0.40 4.03 0.00 5.88
0.40 3.29 0.00 5.27
0.40 2.87 0.00 5.27
0.40 2.87 0.00 6.18
0.40 3.51 2.06 5.86
0.40 3.13 2.88 6.57
0.40 3.13 2.88 6.52
0.40 0.11 0.08 6.45
0.40 0.14 0.08 6.54
0.40 0.14 0.08 5.47
0.40 3.17 5.81 6.27
0.40 3.62 5.81 5.47
0.40 3.62 5.81 6.18
0.40 3.62 5.81 5.47
0.40 3.62 5.81 6.62
0.40 3.62 5.81 5.98
0.40 3.62 5.81 6.52
0.40 3.62 2.12 6.13
0.40 3.62 2.94 5.47
0.40 3.62 0.11 5.98
0.40 3.51 3.23 6.15
0.40 4.42 6.07 6.20
0.40 0.15 4.30 5.88
0.40 4.66 0.43 6.23
0.40 0.41 0.21 6.81
0.40 0.43 0.24 6.10
0.40 0.44 0.25 6.10
0.40 0.45 0.28 5.86
0.40 0.47 0.28 6.03
0.40 0.46 0.27 5.98
0.40 0.46 0.27 6.01
0.40 0.45 0.28 5.66
0.40 0.50 0.27 5.86
0.40 0.48 0.29 6.23
0.40 0.51 0.54 6.01
0.40 0.49 0.55 6.15
0.40 0.49 0.54 5.93
0.40 0.46 0.59 6.23
0.40 0.46 0.61 6.03
0.40 0.51 0.63 5.86
0.40 0.50 0.55 5.96
0.40 0.52 0.56 5.66
0.40 0.52 0.56 6.05
0.40 0.52 0.55 5.96
0.40 0.49 0.56 6.03
0.40 0.47 0.56 6.08
0.40 0.50 0.57 6.05
0.40 0.50 0.29 6.23
0.40 0.53 0.29 5.66
0.40 0.52 0.31 6.01
0.40 0.32 0.65 5.81
0.40 0.30 0.55 6.03
0.40 0.32 0.61 5.76
0.40 0.30 0.61 5.91
0.40 0.52 0.58 6.57
0.40 0.50 0.58 6.08
0.40 0.52 0.30 6.10
0.40 0.52 0.30 5.76
0.40 0.51 0.64 6.23
0.40 0.55 0.63 6.03
0.40 0.54 0.58 6.01
0.40 0.32 0.58 5.66
0.40 0.31 0.56 5.86
0.40 0.31 0.30 6.01
0.40 0.52 0.31 6.03
0.40 0.51 0.60 6.03
0.40 0.53 0.61 6.03
0.40 0.55 0.59 6.10
0.40 0.53 0.61 6.23
0.40 0.32 0.62 5.86
0.40 0.32 0.32 5.91
0.40 0.32 0.59 5.76
0.40 0.51 0.64 6.08
0.40 0.53 0.65 5.91
0.40 0.52 0.65 6.03
0.40 0.53 0.32 6.23
0.40 0.58 0.31 6.05
0.40 0.32 0.60 6.08
0.40 0.32 0.63 5.76
0.40 0.33 0.62 6.18
0.40 0.56 0.32 5.76
0.40 0.55 0.31 6.01
0.40 0.52 0.66 5.86
0.40 0.34 0.59 5.98
0.40 0.32 0.66 6.10
0.40 0.33 0.33 6.10
0.40 0.58 0.35 6.03
0.40 0.56 0.63 5.86
0.40 0.60 0.67 6.05
0.40 0.32 0.64 6.23
0.40 0.33 0.33 5.98
0.40 0.55 0.69 5.86
0.40 0.58 0.67 5.88
0.40 0.57 0.66 6.05
0.40 0.59 0.33 6.03
0.40 0.34 0.64 6.03
0.40 0.61 0.68 6.23
0.40 0.58 0.68 6.03
0.40 0.57 0.34 6.01
0.40 0.36 0.66 5.91
0.40 0.35 0.68 6.03
0.40 0.59 0.34 5.86
0.40 0.58 0.68 6.01
0.40 0.60 0.68 5.96
0.40 0.34 0.71 6.05
0.40 0.62 0.35 6.03
0.40 0.56 0.74 6.03
0.40 0.59 0.74 6.03
0.40 0.34 0.34 5.96
0.40 0.34 0.72 6.10
0.40 0.61 0.71 6.08
0.40 0.64 0.35 6.05
0.40 0.35 0.75 5.98
0.40 0.62 0.70 6.01
0.40 0.61 0.36 6.05
0.40 0.59 0.73 6.01
0.40 0.37 0.77 6.03
0.40 0.64 0.37 5.98
0.40 0.64 0.73 6.05
0.40 0.36 0.76 6.01
0.40 0.37 0.35 6.05
0.40 0.62 0.77 6.08
0.40 0.61 0.36 6.01
0.40 0.36 0.75 6.01
0.40 0.62 0.74 6.08
0.40 0.63 0.36 5.98
0.40 0.63 0.73 6.03
0.40 0.36 0.76 6.01
0.40 0.61 0.36 6.03
0.40 0.66 0.71 6.01
0.40 0.37 0.75 6.13
0.40 0.61 0.36 6.01
0.40 0.62 0.72 6.10
0.40 0.64 0.72 5.98
0.40 0.36 0.72 6.08
0.40 0.60 0.73 6.08
0.40 0.61 0.35 6.01
0.40 0.35 0.73 6.13
0.40 0.36 0.75 6.10
0.40 0.60 0.36 5.96
0.40 0.62 0.69 6.05
0.40 0.36 0.75 6.13
0.40 0.63 0.36 6.03
0.40 0.63 0.71 5.96
0.40 0.63 0.71 6.10
0.40 0.36 0.36 5.98
0.40 0.59 0.73 5.98
0.40 0.62 0.72 6.13
0.40 0.35 0.36 6.05
0.40 0.63 0.72 6.03
0.40 0.62 0.75 6.05
0.40 0.62 0.35 5.98
0.40 0.34 0.73 6.20
0.40 0.61 0.37 6.13
0.40 0.60 0.71 6.01
0.40 0.35 0.70 6.03
0.40 0.34 0.35 6.05
0.40 0.62 0.73 6.05
0.40 0.65 0.73 6.05
0.40 0.36 0.37 6.03
0.40 0.65 0.77 6.03
0.40 0.59 0.71 6.08
0.40 0.60 0.37 6.03
0.40 0.36 0.73 6.05
0.40 0.64 0.72 6.10
0.40 0.61 0.36 6.01
0.40 0.36 0.78 6.08
0.40 0.62 0.36 5.96
0.40 0.63 0.75 6.08
0.40 0.61 0.71 6.03
0.40 0.36 0.37 6.05
0.40 0.62 0.73 5.98
0.40 0.61 0.72 6.01
0.40 0.36 0.36 6.01
0.40 0.35 0.73 6.03
0.40 0.64 0.76 6.13
0.00 0.26 0.25 6.23
Car speed Right odometer speed Left odometer speed Battery pack voltage
0.40 0.14 0.12 7.03
0.40 0.14 0.12 5.27
0.40 0.14 0.12 6.98
0.40 0.14 0.12 6.86
0.40 0.14 0.12 6.91
0.40 0.14 0.12 6.93
0.40 0.14 0.22 6.88
0.40 0.14 0.49 6.88
0.40 0.14 2.45 6.05
0.40 0.14 2.46 6.91
0.40 0.14 2.46 6.91
0.40 0.14 2.46 6.91
0.40 0.14 2.46 6.76
0.40 0.14 2.46 6.86
0.40 0.14 2.46 6.69
0.40 0.14 2.46 6.42
0.40 0.14 2.46 6.59
0.40 0.14 2.46 5.47
0.40 0.14 2.46 6.45
0.40 0.14 2.46 6.49
0.40 0.14 2.46 6.32
0.40 0.14 2.46 5.08
0.40 0.14 2.50 6.15
0.40 0.14 5.56 6.08
0.40 0.14 4.83 6.42
0.40 0.14 4.79 6.23
0.40 0.14 2.47 6.08
0.40 0.14 7.10 6.05
0.40 3.80 3.36 5.96
0.40 0.19 0.12 6.27
0.40 0.12 0.38 6.25
0.40 0.29 0.47 6.13
0.40 0.15 3.35 6.62
0.40 0.29 0.45 6.20
0.40 4.02 0.44 6.20
0.40 0.33 0.14 6.01
0.40 0.36 0.54 6.18
0.40 0.40 0.23 6.08
0.40 0.23 0.25 6.05
0.40 0.24 0.26 5.86
0.40 0.39 0.26 6.01
0.40 0.42 0.64 6.15
0.40 0.46 0.57 6.15
0.40 0.50 0.62 6.10
0.40 0.48 0.58 6.05
0.40 0.48 0.58 6.10
0.40 0.48 0.61 6.23
0.40 0.50 0.59 5.98
0.40 0.52 0.31 5.76
0.40 0.49 0.30 5.86
0.40 0.48 0.32 6.10
0.40 0.47 0.59 6.01
0.40 0.51 0.63 6.08
0.40 0.51 0.59 6.13
0.40 0.52 0.58 6.10
0.40 0.29 0.29 6.10
0.40 0.30 0.31 5.86
0.40 0.30 0.68 6.23
0.40 0.31 0.70 5.91
0.40 0.31 0.70 6.18
0.40 0.52 0.68 5.98
0.40 0.54 0.32 6.05
0.40 0.58 0.65 6.05
0.40 0.55 0.63 6.05
0.40 0.32 0.67 6.05
0.40 0.32 0.33 6.01
0.40 0.31 0.33 6.08
0.40 0.54 0.67 6.08
0.40 0.53 0.68 6.10
0.40 0.55 0.32 6.03
0.40 0.59 0.33 6.08
0.40 0.33 0.69 6.05
0.40 0.33 0.68 6.05
0.40 0.59 0.33 6.13
0.40 0.57 0.32 6.05
0.40 0.58 0.75 6.03
0.40 0.56 0.69 6.05
0.40 0.34 0.34 6.05
0.40 0.34 0.69 6.10
0.40 0.61 0.69 6.01
0.40 0.60 0.71 6.08
0.40 0.57 0.34 6.10
0.40 0.33 0.71 6.03
0.40 0.32 0.68 6.08
0.40 0.56 0.34 6.01
0.40 0.55 0.70 6.10
0.40 0.57 0.68 6.10
0.40 0.61 0.71 6.01
0.40 0.34 0.33 6.10
0.40 0.59 0.70 6.05
0.40 0.59 0.70 6.03
0.40 0.58 0.32 6.05
0.40 0.54 0.33 6.27
0.40 0.48 0.73 6.30
0.40 0.37 0.73 6.30
0.40 0.18 0.60 6.42
0.40 0.41 0.21 6.42
0.40 0.37 0.58 6.35
0.40 0.18 0.59 6.35
0.40 0.38 0.53 6.37
0.40 0.32 0.17 6.40
0.40 0.32 0.50 6.35
0.40 7.06 0.13 6.45
0.40 7.06 0.49 6.32
0.40 0.28 0.49 6.40
0.40 0.28 0.52 6.45
0.40 0.29 0.47 6.35
0.40 0.29 0.17 5.66
0.40 6.76 4.53 6.23
0.40 4.94 3.02 5.96
0.40 0.10 0.37 6.37
0.40 0.22 0.44 6.42
0.40 0.22 0.14 6.18
0.40 4.88 6.51 6.42
0.40 5.39 0.15 5.98
0.40 5.39 3.99 6.40
0.40 0.08 0.12 6.05
0.40 0.18 0.40 6.40
0.40 0.18 0.13 6.23
0.40 3.93 5.48 5.08
0.40 3.93 3.25 5.98
0.40 5.27 3.07 5.37
0.40 5.27 0.11 6.45
0.40 0.07 0.35 6.40
0.40 0.20 0.12 6.23
0.40 0.20 5.27 6.23
0.40 0.20 4.63 6.45
0.40 5.95 5.84 6.40
0.40 0.12 0.12 6.42
0.40 0.12 0.37 6.40
0.40 0.12 0.13 6.35
0.40 3.27 3.08 5.32
0.40 2.56 2.13 5.47
0.40 3.36 2.97 5.08
0.40 3.36 2.97 6.40
0.40 3.36 0.33 6.45
0.40 2.58 4.06 6.40
0.40 2.58 3.00 5.86
0.40 3.49 5.43 6.52
0.40 3.49 5.95 6.40
0.40 0.07 5.95 6.42
0.40 0.18 0.41 6.35
0.40 0.18 0.41 6.40
0.40 3.79 3.00 6.32
0.40 3.79 3.10 5.37
0.40 5.21 3.21 6.37
0.40 5.21 3.21 6.45
0.40 5.21 0.37 6.47
0.40 0.06 0.13 6.23
0.40 3.16 3.03 5.47
0.40 3.16 0.13 6.08
0.40 3.16 3.81 5.27
0.40 3.16 3.81 6.45
0.40 6.72 0.38 6.49
0.40 6.72 0.38 6.45
0.40 7.10 0.40 6.37
0.40 7.10 0.40 6.32
0.40 7.10 0.44 6.45
0.40 6.91 0.13 6.45
0.40 7.06 0.46 6.52
0.40 7.06 0.13 6.40
0.40 7.06 0.43 6.47
0.40 0.21 0.44 6.49
0.40 0.21 0.44 6.23
0.40 4.55 7.06 6.81
0.40 6.04 7.06 5.76
0.40 6.04 3.00 6.54
0.40 0.09 3.00 6.42
0.40 0.19 0.40 6.47
0.40 0.19 0.13 6.23
0.40 3.42 6.83 5.13
0.40 3.42 3.42 6.03
0.40 3.26 3.07 5.47
0.40 3.26 3.07 6.42
0.40 3.26 0.35 6.42
0.40 0.06 0.35 6.45
0.40 4.66 4.79 6.23
0.40 4.66 0.14 6.40
0.40 4.88 6.35
Car speed Right odometer speed Left odometer speed Battery pack voltage
0.40 0.15 0.09 6.93
0.40 0.15 0.09 6.96
0.40 0.15 0.09 6.93
0.40 0.15 0.09 6.81
0.40 0.15 0.09 6.86
0.40 0.15 0.09 6.84
0.40 0.15 0.09 6.81
0.40 0.15 0.09 6.84
0.40 0.15 0.09 5.47
0.40 0.15 0.09 6.76
0.40 0.15 0.09 6.79
0.40 0.15 0.09 6.40
0.40 0.15 0.09 7.20
0.40 0.15 0.09 6.03
0.40 0.15 0.09 6.59
0.40 0.15 0.09 6.35
0.40 0.15 0.09 6.47
0.40 0.15 0.09 5.86
0.40 0.15 0.09 6.52
0.40 0.15 0.09 6.57
0.40 0.15 0.09 6.23
0.40 0.15 0.09 5.47
0.40 0.15 0.09 5.08
0.40 0.15 0.09 6.10
0.40 0.15 0.09 6.23
0.40 0.15 0.09 6.03
0.40 0.15 0.09 6.30
0.40 0.15 0.09 6.10
0.40 0.15 0.09 6.20
0.40 0.15 0.09 5.18
0.40 0.15 0.09 5.47
0.40 0.15 0.09 5.08
0.40 0.15 0.09 6.13
0.40 0.15 0.09 5.62
0.40 0.15 0.09 6.62
0.40 0.15 0.09 6.03
0.40 0.15 0.09 6.13
0.40 0.15 0.09 5.98
0.40 0.15 0.09 5.27
0.40 0.15 0.09 5.66
0.40 0.15 0.09 5.18
0.40 0.15 0.09 6.62
0.40 0.15 0.09 5.66
0.40 0.15 7.06 6.37
0.40 0.15 3.73 6.08
0.40 0.15 6.10 7.01
0.40 0.15 6.79 6.23
0.40 4.40 2.96 5.57
0.40 2.16 2.96 6.10
0.40 3.62 4.51 6.23
0.40 3.62 4.51 6.23
0.40 3.62 5.39 6.59
0.40 3.62 5.39 5.83
0.40 3.62 6.58 6.03
0.40 3.62 6.94 7.79
0.40 3.62 2.47 6.18
0.40 3.62 2.42 6.13
0.40 3.62 2.48 5.98
0.40 3.62 2.48 6.01
0.40 3.62 5.12 5.81
0.40 3.62 5.43 5.47
0.40 3.62 3.46 5.27
0.40 0.01 0.20 6.32
0.40 0.18 0.20 6.37
0.40 0.12 0.43 6.32
0.40 4.02 0.17 5.96
0.40 3.89 0.37 6.23
0.40 0.26 3.74 6.03
0.40 0.16 4.70 6.08
0.40 0.29 0.49 5.76
0.40 6.16 0.52 5.96
0.40 0.20 0.59 6.23
0.40 0.21 0.62 6.20
0.40 0.42 0.61 6.23
0.40 0.43 0.63 6.23
0.40 0.44 0.58 6.20
0.40 0.46 0.55 6.23
0.40 0.44 0.56 6.01
0.40 0.24 0.57 6.03
0.40 0.26 0.28 5.76
0.40 0.27 0.28 6.10
0.40 0.27 0.29 5.96
0.40 0.24 0.29 6.10
0.40 0.43 0.69 6.23
0.40 0.43 0.52 6.30
0.40 0.37 5.19 6.30
0.40 0.19 0.22 6.37
0.40 0.39 0.55 6.35
0.40 0.37 0.63 6.05
0.40 0.17 0.15 6.25
0.40 5.41 6.25 5.86
0.40 0.15 6.83 6.15
0.40 0.31 0.52 6.37
0.40 0.15 0.58 6.42
0.40 0.32 0.57 6.42
0.40 4.06 4.19 6.13
0.40 0.15 3.41 6.42
0.40 4.68 0.44 6.47
0.40 4.68 0.45 6.35
0.40 0.28 0.45 6.35
0.40 0.28 0.45 6.35
0.40 0.27 3.16 6.37
0.40 0.27 3.74 6.25
0.40 0.23 4.72 6.37
0.40 0.23 4.72 6.54
0.40 0.12 0.45 6.71
0.40 0.28 4.73 7.01
0.40 5.30 4.73 5.66
0.40 3.86 3.74 6.23
0.40 2.98 0.16 5.86
0.40 0.25 5.68 6.45
0.40 0.25 0.11 6.25
0.40 0.30 0.15 6.30
0.40 0.30 3.68 6.52
0.40 6.25 4.63 6.37
0.40 6.25 4.63 6.40
0.40 0.11 0.44 6.40
0.40 0.24 0.15 6.40
0.40 0.12 0.50 6.23
0.40 4.96 3.23 5.47
0.40 4.96 3.44 5.93
0.40 3.63 2.93 5.52
0.40 3.63 2.93 6.42
0.40 5.46 3.17 6.45
0.40 5.46 3.17 6.47
0.40 0.25 0.44 6.40
0.40 0.25 0.44 6.45
0.40 0.10 0.43 6.42
0.40 5.08 5.06 5.37
0.40 5.08 5.30 6.13
0.40 5.08 5.43 5.86
0.40 0.06 0.33 6.47
0.40 0.15 0.12 6.42
0.40 0.15 0.39 6.23
0.40 0.15 3.49 6.23
0.40 3.26 2.88 6.37
0.40 3.26 2.88 7.20
0.40 3.18 6.79 6.27
0.40 3.18 6.79 6.45
0.40 0.07 0.39 6.25
0.40 0.07 0.39 6.40
0.40 4.48 0.40 6.47
0.40 4.48 0.40 6.49
0.40 0.07 0.43 6.37
0.40 0.18 0.13 6.25
0.40 0.18 0.41 6.47
0.40 7.02 6.91 6.23

Car not moving

Here are some logs from when the car did not move at all

Car speed Right odometer speed Left odometer speed Battery pack voltage
0.40 0.00 0.01 7.50
0.40 0.00 0.01 7.47
0.40 0.00 0.01 7.40
0.40 0.00 0.01 7.30
0.40 0.00 0.01 7.32
0.40 0.00 0.01 7.25
0.40 0.00 0.01 7.13
0.40 0.00 0.01 7.18
0.40 0.00 0.01 5.30
0.40 0.00 0.01 7.01
0.40 0.00 0.01 7.01
0.40 0.00 0.01 6.27
0.40 0.00 0.01 6.23
0.40 0.00 0.01 6.23
0.40 0.00 0.01 6.52
0.40 0.00 0.01 6.03
0.40 0.00 0.01 6.15
0.40 0.00 0.01 5.18
0.40 0.00 0.01 6.30
0.40 0.00 0.01 6.30
0.40 0.00 0.01 6.52
0.40 0.00 0.01 5.08
0.40 0.00 0.01 4.98
0.40 0.00 0.01 5.98
0.40 0.00 0.01 6.23
0.40 0.00 0.01 6.23
0.40 0.00 0.01 5.27
0.40 0.00 0.01 5.98
0.40 0.00 0.01 5.93
0.40 0.00 0.01 6.27
0.40 0.00 0.01 5.08
0.40 0.00 0.01 4.98
0.40 0.00 0.01 6.23
0.40 4.48 0.01 6.32
0.40 4.19 0.01 7.01
0.40 2.42 0.01 6.18
0.40 2.45 0.01 5.93
0.40 2.45 0.01 6.18
0.40 3.94 0.01 5.08
0.40 4.15 0.01 6.03
0.40 3.97 0.01 5.47
0.40 6.54 0.01 6.64
0.40 6.54 0.01 6.45
0.40 6.54 0.01 6.69
0.40 2.46 0.01 6.30
0.40 2.47 0.01 6.03
0.40 2.42 0.01 6.10
0.40 2.42 0.01 6.45
0.40 2.47 0.01 6.45
0.40 2.45 0.01 6.52
0.40 6.51 0.01 6.62
0.40 3.96 0.01 5.08
0.40 4.05 0.01 4.79
0.40 2.45 0.01 6.23
0.40 2.48 0.01 6.32
0.40 2.48 0.01 6.62
0.40 2.45 0.01 5.18
0.40 2.42 0.01 6.18
0.40 2.50 0.01 5.52
0.40 2.50 0.01 6.32
0.40 2.50 0.01 5.44
0.40 2.50 0.01 6.23
0.40 2.50 0.01 6.47
0.40 2.50 0.01 6.30
0.40 2.50 0.01 6.32
0.40 2.50 0.01 5.64
0.40 2.50 0.01 6.32
0.40 2.50 0.01 6.32
0.40 2.50 0.01 6.35
0.40 2.50 0.01 6.64
0.40 2.50 0.01 6.30
0.40 2.50 0.01 6.23
0.40 2.50 0.01 6.27
0.40 2.50 0.01 6.32
0.40 2.50 0.01 6.30
0.40 2.50 0.01 6.32
0.40 2.50 0.01 6.45
0.40 2.50 0.01 6.03
0.40 2.50 0.01 5.25
0.40 2.50 0.01 6.54
0.40 2.50 0.01 6.45
0.40 2.50 0.01 6.37
0.40 2.50 0.01 6.37
0.40 2.50 0.01 6.69
0.40 2.50 0.01 6.74
0.40 2.50 0.01 6.42
0.40 2.50 0.01 6.32
0.40 2.50 0.01 6.40
0.40 2.50 0.01 6.52
0.40 2.50 0.01 6.25
0.40 2.50 0.01 6.35
0.40 2.50 0.01 6.59
0.40 2.50 0.01 6.30
0.40 2.50 0.01 6.37
0.40 2.50 0.01 6.40
0.40 2.50 0.01 6.35
0.40 2.50 0.01 6.32
0.40 2.50 0.01 5.79
0.00 2.50 0.01 6.62
0.00 0.00 0.01 6.62
0.00 0.00 0.01 6.71
0.00 0.00 0.01 6.79
0.00 0.00 0.01 6.79
0.00 0.00 0.01 6.84
0.00 0.00 0.01 6.84
0.00 0.00 0.01 6.86
0.00 0.00 0.01 6.86
Car speed Right odometer speed Left odometer speed Battery pack voltage
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.74
0.40 0.40 0.41 9.74
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.72
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.64
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.64
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.62
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.64
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.64
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.64
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.45
0.40 0.40 0.41 9.64
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.69
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.64
0.40 0.40 0.41 9.67
0.40 0.40 0.41 9.30
0.00 0.40 0.41 9.69
0.00 0.40 0.41 9.67
0.00 0.40 0.41 9.69
0.00 0.40 0.41 9.69
0.00 0.40 0.41 9.69
0.00 0.40 0.41 9.69
0.00 0.40 0.41 9.69
0.00 0.40 0.41 9.69
0.00 0.40 0.41 9.69

Is it when we see the peak in the odometer speed that the car starts driving the wrong way or has it already started reversing when these unusually high speeds are logged?

In other words can we say for a fact that these high speed readings are causing the weird behavior?

The reversing is triggered when a peak in the odometer speed occurs. So yes, it seems that this is the direct cause of the reversing behavior.

Thanks a lot for your feedback. It's hard for me to reproduce this so these logs should settle this odometer malfunction as the cause of the defect.

Figuring out why the odometers behave this why would be rather hard as they are cheap pieces of hardware that shouldn't be taken very seriously. So I think whatever fix should be there and not in the Car logic. We should somehow ensure that the readings are as trustworthy as possible.

Can you try to increase this value to 1000 or more so to see if the problem gets mitigated?

The problem can be easily reproduced on any car (regardless of how good or bad the odometers are) by using the following simple code and process:

/* Drive using cruise control for a specified amount of time and then stop */
#include <Smartcar.h>

Odometer encoderLeft, encoderRight;
Car car;
const unsigned long TIME_TO_STOP = 10000; // In milliseconds
float carSpeed = 0.3;

void setup() {
  encoderLeft.attach(2);
  encoderRight.attach(3);
  encoderLeft.begin();
  encoderRight.begin();
  car.begin(encoderLeft, encoderRight);
  car.enableCruiseControl();
  car.setSpeed(carSpeed);
}

void loop() {
  car.updateMotors();
  if (millis() > TIME_TO_STOP) {
    car.stop();
  }
}

Under normal circumstances, the above sketch makes the car move for 10 seconds (or whatever you set the TIME_TO_STOP variable to) and then stops. Faulty readings can be simulated by pushing the car forward while making sure that the wheels are touching the ground and thus spinning faster than they usually do. This could also be an actual scenario by the way, if the car is on a downhill and moves faster than it should.
In that case, the car moves towards the wrong direction. I am trying to figure out what is the best way of fixing this without affecting too much the more common use cases. 👍

@michalpalka @Shaun-McMurray @guslauer @Archico @FFrostYY feel free to try out the fix found at #9 and/or review the code. It should be resolving the problem.

If no objections I will merge it in a couple of days.