This code is more "advanced" than the one used in the video. Basically every time the sonar servo completes a sweep, the angle for the direction with the maximum distance is determined, and the robot tries to turn in that direction. The direction with the minimum distance is also determined, and the rover tries to turn away from that direction.
-Z-
How do you do to synchronize the servo of your sensor ? After few seconds, the angle of mine is not respected... It starts to go more on the right a little bit and it difficult to calibrate it. After three minutes, it is not anymore in the good direction.
What do you mean? The servo driving the sonar is just a normal servo controlled through PWM, I've never needed to calibrate it. I check the angle of the sonar just by knowing the angle I'm telling the servo to point. The angle is probably not 100% accurate, but the robot only needs a rough idea which direction is clear of stuff.
-Z-