... | ... | @@ -82,4 +82,54 @@ We built the robot as seen in fig 3 with the light sensor mounted in the front. |
|
|
As an addition to the sensors mounted in the front of the car, we decided to make the whole front of the car flexible (see Fig. 6) We knew from lab lesson 1 that the light sensor reading vary according to the distance from the sensor to the surface. By doing this we made sure that the sensors mounted to the front would always keep the same distance to the surface which can be a challenge when the robot drives over the plateaus (see fig. 6).
|
|
|
|
|
|
![sensorDistancesThis](http://gitlab.au.dk/uploads/group-22/lego/d7f438caf8/sensorDistancesThis.jpg)
|
|
|
##### Fig 5: Indicates a robot approaching the hill on the racetrack. It shows why the flexible front mount is preferred to a static mount as it makes sure that the distance to the ground is the same regardless of the angle. |
|
|
\ No newline at end of file |
|
|
##### Fig 6: Indicates a robot approaching the hill on the racetrack. It shows why the flexible front mount is preferred to a static mount as it makes sure that the distance to the ground is the same regardless of the angle.
|
|
|
|
|
|
![Racecar arm](http://gitlab.au.dk/uploads/group-22/lego/45dcb431bc/Racecar_arm.jpg)
|
|
|
##### Fig. 7: Shows the flexible front mount on the robot. By implementing this feature we made sure that the sensor keeps the same distance to the ground throughout the course.
|
|
|
|
|
|
#### Driving using light sensor and PID control
|
|
|
The attached light sensor was used to follow the black line along the racetrack. We used the sensor readings to implement a PID-controller in order to follow the line smoothly. In lab lesson 4 we created a PID-controller for a line follower robot which we decided to reuse in this case (code snipped fig. 7).
|
|
|
|
|
|
```
|
|
|
while (! Button.ESCAPE.isDown())
|
|
|
{
|
|
|
|
|
|
LCD.refresh();
|
|
|
|
|
|
LightValue = sensor.light();
|
|
|
float error = LightValue - OFFSET;
|
|
|
|
|
|
LCD.drawString("Light Val: ", 0, 2);
|
|
|
LCD.drawInt(getLightVal(),0,9,3);
|
|
|
LCD.refresh();
|
|
|
|
|
|
integral = integral + error;
|
|
|
|
|
|
derivative = error - lastError;
|
|
|
|
|
|
float Turn = KP*error + KI*integral + KD*derivative;
|
|
|
|
|
|
float powerLeft = 0;
|
|
|
float powerRight = 0;
|
|
|
|
|
|
powerLeft = TP + Turn;
|
|
|
powerRight = TP - Turn;
|
|
|
|
|
|
// Only drive if power is positive
|
|
|
if (powerLeft > 0 && powerRight > 0){
|
|
|
|
|
|
car.forward((int)powerLeft, (int)powerRight);
|
|
|
}
|
|
|
|
|
|
if((lastError >= 0 && error <= 0) || (lastError <= 0 && error >= 0)){
|
|
|
integral = 0;
|
|
|
}
|
|
|
|
|
|
lastError = error;
|
|
|
|
|
|
Thread.sleep(60);
|
|
|
|
|
|
}
|
|
|
```
|
|
|
|
|
|
##### Fig. 7: inner loop of the line follower PID-control class. |
|
|
\ No newline at end of file |