@@ -165,7 +165,8 @@ With the current setup the car is able to follow the black line on the first inc
![Problem with correct plateau detection](https://gitlab.au.dk/rene2014/lego/raw/master/Lesson8/Images/LowGyroProblem.jpg)
A gyroscope threshold determines whether the PlateauPilot behavior is activated. With the threshold too high the plateau is detected to late (Problem 1) and the LEGO car continues out of the track. With the threshold too low the plateau is detected too early and the LEGO car makes a right turn too soon (Problem 2). It seems to be an impossible task to determine this threshold in the current setting.
This indicates that the problem is related to the gyroscope which might not receive enough impact of the incline change when mounted close to the LEGO car in order determine a sufficient threshold. A solution to this is to place the gyroscope higher.
This indicates that the problem is related to the gyroscope which might not receive enough impact of the incline change when mounted close to the LEGO car in order determine a sufficient threshold.
In this setup the gyroscope is placed relatively low and close to the body of the LEGO car. Even though the gyroscope measures angular velocity and not translational velocity it should cause any influence by raising the gyroscope. However, a test is carried out in order to confirm this.
## Raising the gyroscope
@@ -177,7 +178,37 @@ The gyroscope is raised by placing it on a long brick as shown in the following
By raising the gyroscope and manually tuning the PID parameters and turns the LEGO car is able to drive all the way to the top of the Alishan track. On the top plateau the LEGO car performs a 180 degree turn and initiates its way back. Here a new problem arises. Whenever the LEGO car gets off the top plateau it almost immediately makes a left turn as illustrated in the following figure.
The program used to test the gyroscope earlier (Described in section "Gyro measurements on a plateau") is used again with the new setup. The result is seen in the following image where the high mounted gyroscope data is plotted together with the low mounted gyroscope data.
Although the high mounted gyroscope has a minor negative peak compared to the mean value the two settings (high and low mounted gyroscope) are almost identical and the problem must therefore be located elsewhere.
It turned out that the problem could be solved in the software. The gyroscope data threshold indicating when LEGO car enters a plateau is set relatively low and a timeout is included. The code determining if a plateau is reached is shown in the following code snippet.
The `gyroOffset` is set to `600` according to the noise floor of the gyroscope test. The plateau threshold is determined to `40` which seemed sufficient together with a timeout of 2000 milliseconds. The timeout ensures that there must be at least two seconds between each plateau. We thereby avoid having inexpedient state changes caused by two peaks in row.
By implementing these modification to the software and tuning the PID parameters and the hard coded turns, the LEGO car is able to drive all the way to the top of the track. On the top plateau the LEGO car performs a 180 degree turn and initiates its way back. Here a new problem arises. Whenever the LEGO car gets off the top plateau it almost immediately makes a left turn as illustrated in the following figure.
![Problems on the way back](https://gitlab.au.dk/rene2014/lego/raw/master/Lesson8/Images/DirectMotorControlProblem.jpg)