cvf06035 created page: Lesson7 authored by Camilla Marie Vinther Frederiksen's avatar Camilla Marie Vinther Frederiksen
......@@ -113,14 +113,36 @@ With this flaw in our algorithm corrected we where able to see the actual effect
The issue with the robot trying to avoid light rather than follow it, was quickly solved by simply inverting the directions of the light sensor motor in all uses, resulting in a control loop as seen in code snippet 1.
´´´ Java
if (int i = 0) {
```java
// Follow light as long as the light level is above the threshold
while ( frontLight > lightThreshold )
{
// Get the light to the left
MotorPort.A.controlMotor(powerLight, 2);
Delay.msDelay(msLight);
leftLight = light.getLightValue();
// Get the light to the right
MotorPort.A.controlMotor(powerLight, 1);
Delay.msDelay(2*msLight);
rightLight = light.getLightValue();
// Turn back to start position
MotorPort.A.controlMotor(powerLight, 2);
Delay.msDelay(msLight);
MotorPort.A.controlMotor(0, 3);
// Follow light for a while
delta = leftLight-rightLight;
car.forward(power-delta, power+delta);
Delay.msDelay(ms);
frontLight = light.getLightValue();
}
´´´
TODO: insert program code - tjek syntax for codning - tror det er korrekt.
```
*Code snippet 1: Control loop of Follow behavior with seperate motor for light sensor control*
After beliving that the follow behavior now worked with the additional motor controlling the light sensor, we decided to test it in the dark to obtain a bigger light difference. In here (the bathroom of Suze), the robot's response was easy to observe as seen in video 8. Note, though, that the big difference in measured light values caused it to increase the motor speed of one motor a lot and by that turning much faster than in the room with a normal ambient light setting.
After believing that the follow behavior now worked with the additional motor controlling the light sensor, we decided to test it in the dark to obtain a bigger light difference. In here (the bathroom of Suze), the robot's response was easy to observe as seen in video 8. Note, though, that the big difference in measured light values caused it to increase the motor speed of one motor a lot and by that turning much faster than in the room with a normal ambient light setting.
[![Follower in dark room](http://img.youtube.com/vi/bbRn_WVlDwk/0.jpg)](https://www.youtube.com/watch?v=bbRn_WVlDwk)
*Video 8: Testing the Follower behavior in a darker ambient lighting environment.*
......
......