[](http://www.youtube.com/watch?v=ymecZEaL5YU)
### Exercise 6
The code produced in this exercise was based on Philippe Hurbain's implementation[1]. The body of the control loop is listed below:
```java
distance=sensor.getDistance();
leftMotor.forward();
rightMotor.forward();
if(distance<=desiredDistance)//close to wall
{
if(distance<=desiredDistance*0.7)//very close
{
rightMotor.backward();
}
else
{
rightMotor.flt(true);
}
}
else//far from wall
{
if(distance>=desiredDistance*1.1)
{
leftMotor.flt(true);
}
}
Thread.sleep(10);
```
A possible improvement on our implementation could be a proportional control system, with the error being used to control the power of both motors, allowing smoother turns than the `flt` and `backward` functions used in this exercise.