Answers.Body: <p>If a significant distance from the wall, you'll need to turn 90 degrees in place clockwise, drive up to the wall and turn 90 degrees in place counterclockwise.
  I'd suggest mounting a touch sensor in front of the vehicle handle the part of driving up to the wall, if that is not possible, estimate from the scanned distance how far the vehicle should drive.</p>
  
  <p>If close to the wall but not close enough to have the wall-following algorithm work correctly, I'd suggest "wiggling":
  Repeat the following steps until close enough to the wall:</p>
  
  <ul>
  <li>rotate left wheel forward by a small angle while blocking the right
  wheel. </li>
  <li>rotate right wheel forward by a small angle while blocking the
  left wheel. </li>
  <li>rotate left wheel backward by a small angle while
  blocking the right wheel. </li>
  <li>rotate right wheel backward by a small
  angle while blocking the left wheel.</li>
  </ul>
  
  <p>In each step use the same angle (determine an optimal angle by trial and error)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-23T15:44:41.133Z
Answers.Text: Also could set the target distance to +2 cm for a short time, then +1 cm, and then the actual target distance.  I was hoping that I had missed a trick in using the ultrasonic sensor.
Answers.UserDisplayName: dfrevert
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-23T14:32:12.027Z
Answers.LastActivityDate: 2018-02-23T14:32:12.027Z
Answers.UserDisplayName: Michael Verschaeve
Body: <p>This wall following algorithm uses the ultrasonic sensor.  It has a horrible worst case behavior.  Place the robot about 3 cm too far from the wall.  Instead of moving closer to the wall, the robot turns toward the wall and spins.</p>
  
  <p>Place the robot too close to the wall and it works very well.</p>
  
  <p>The sensor points out from the right side of the robot, in front of the powered wheels.</p>
  
  <p><a href="https://i.sstatic.net/zaaxu.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zaaxu.jpg" alt="Robot viewed from the back. The sensor is on an beam. Making the beam longer did not fix the problem."></a></p>
  
  <p><a href="https://i.sstatic.net/PiV9C.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PiV9C.png" alt="Wall Following algorithm using the ultrasonic sensor"></a></p>
  
  <p>How should the algorithm be changed to handle the "too far away" case?</p>
  
Tags: <ev3><programming><ev3-g><sensor-ultrasonic>
Title: What is a better algorithm for wall following with an ultrasonic sensor?
UserDisplayName: dfrevert
ThreadText: # What is a better algorithm for wall following with an ultrasonic sensor?
  
  (Asked by: username_0 on 2018-02-19)
  
  This wall following algorithm uses the ultrasonic sensor. It has a horrible worst case behavior. Place the robot about 3 cm too far from the wall. Instead of moving closer to the wall, the robot turns toward the wall and spins.
  
  Place the robot too close to the wall and it works very well.
  
  The sensor points out from the right side of the robot, in front of the powered wheels.
  
  [![Robot viewed from the back. The sensor is on an beam. Making the beam longer did not fix the problem.](https://i.sstatic.net/zaaxu.jpg)](https://i.sstatic.net/zaaxu.jpg)
  
  [![Wall Following algorithm using the ultrasonic sensor](https://i.sstatic.net/PiV9C.png)](https://i.sstatic.net/PiV9C.png)
  
  How should the algorithm be changed to handle the "too far away" case?
  
  **Tags:** ev3, programming, ev3-g, sensor-ultrasonic
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-02-23. Score: 1
  
  If a significant distance from the wall, you'll need to turn 90 degrees in place clockwise, drive up to the wall and turn 90 degrees in place counterclockwise.
  I'd suggest mounting a touch sensor in front of the vehicle handle the part of driving up to the wall, if that is not possible, estimate from the scanned distance how far the vehicle should drive.
  
  If close to the wall but not close enough to have the wall-following algorithm work correctly, I'd suggest "wiggling":
  Repeat the following steps until close enough to the wall:
  
  * rotate left wheel forward by a small angle while blocking the right
    wheel.
  * rotate right wheel forward by a small angle while blocking the
    left wheel.
  * rotate left wheel backward by a small angle while
    blocking the right wheel.
  * rotate right wheel backward by a small
    angle while blocking the left wheel.
  
  In each step use the same angle (determine an optimal angle by trial and error)
  
  > **Comments:**
  > **username_0**: Also could set the target distance to +2 cm for a short time, then +1 cm, and then the actual target distance.  I was hoping that I had missed a trick in using the ultrasonic sensor.  
  
  ---
  
  