... | ... | @@ -66,7 +66,18 @@ controlSignal(controlledValue); |
|
|
lastError = error;
|
|
|
Delay.msDelay(dt);
|
|
|
````
|
|
|
where the function `controlSignal()` controls the power of the two motors in the following way
|
|
|
|
|
|
were the function `calculateError()` calculates the error as the difference between the measured light and the given set point. The set point for this application is determined by the light sensor value when it is placed exactly between a white and a black surface. In this case the set point is 48. The function `calculateError()` is seen below
|
|
|
|
|
|
```java
|
|
|
protected int calculateError() {
|
|
|
LCD.drawString("Light value: " + lightsensor.readValue() + " ",0,6);
|
|
|
return setpoint - lightsensor.readValue();
|
|
|
}
|
|
|
````
|
|
|
|
|
|
The function `controlSignal()` controls the power of the two motors in the following way
|
|
|
|
|
|
```java
|
|
|
protected void controlSignal(float controlledValue) {
|
|
|
leftMotor.controlMotor((int)(Tp + controlledValue),1);
|
... | ... | @@ -74,7 +85,7 @@ protected void controlSignal(float controlledValue) { |
|
|
}
|
|
|
````
|
|
|
|
|
|
In order to avoid a bang-bang control mechanism the two motors are applied a standard power `Tp`. The set point for this application is determined by the light sensor value when it is placed exactly between a white and a black surface. In this case the set point is 48.
|
|
|
In order to avoid a bang-bang control mechanism the two motors are applied a standard power `Tp`.
|
|
|
|
|
|
The control algorithm is wrapped in an LeJOS NXT application that is able to communicate with a PC running a LeJOS GUI application letting us choose values for `kp`,`ki`,`kd` and `Tp` remotely. Due to the complexity of the physical world many factors affect the controlling of the Lego car and it is therefore beneficial to modify control parameters on the fly.
|
|
|
|
... | ... | |