# Wall Following

Automated movement of robots requires some sort of localisation, using which the robot is able to identify the path it is supposed to take and even obstacles in the path. There are various methods of localisation for example GPS(Global Positioning System), Point-cloud localisation, Line following, Wall following etc. Wall following refers to the motion in which a robot traverses along a wall. It is very useful in cases where there is a wall along the required path.

For Robocon ‘16 we were aimed at making a robot able to move parallel to wall at any given distance. We were focused on creating various algorithms and based on test results optimising for the best result and increasing the speed of the robot as much as possible. We used modified PID as our controller for wall following.

This whole project took almost two weeks to be completed.

The figure accurately describes what Wall following really is, the path of the robot parallel to the wall is shown in red.

The robot for wall following in had two distance sensors on the side of the wall to be followed. In the root of all our algorithms we were calculating a value proportional to the angle imposed by robot at the wall. The values was simply the difference of the readings from the two sensors, further by averaging out the values from the sensors the distance from wall can be calculated.

Therefore we have the following variables and constants :-

1. Individual values : d1, d2
2. Distance from wall : dist = (d1 + d2)/2
3. Angle with the wall : angle = (d1 - d2)
4. The Distance to be maintained (setpoint): dist_to_wall

Using the above mentioned values and their previous values (those from the previous iteration) and the some other quantities such as transient or variable setpoints for the angle and distance various algorithms can be created so as to give an optimised performance. The root idea being, if too close move away, if at the optimum distance move straight otherwise move closer.

Apart from the most basic one there were various algorithms which were designed throughout the project duration, the major ones are :-

1. Three Region
2. Stop-Turn
3. Variable Setpoint
4. Dual PID

### Three region

The most intuitive algorithm for wall following, it worked as follows :- We divided the whole plane as

1. Close: Distance to wall minus the error,
2. Safe: Error region,
3. Away: region beyond Distance to wall plus the error.

Where error was a controllable constant. If the bot was in region close then it moved away and vice-versa and moved forward if in the Error region.

### Stop-Turn

This algorithm was designed on the first (basic) algorithm with the underlying idea remaining same except during execution there was no translational velocity while rotating and no rotational velocity when translating and hence the name. This algorithm executes as:

1. Check for the region in which the robot is present.
2. Based on the response( e.g too close) the robot stops momentarily while turning to a certain limiting angle.(in this example turns away from the wall)
3. Translates in the forward direction
4. Repeats the above steps.

This algorithm ended up giving a very reliable but a rather shaky performance. Only due to the mechanical requirements of higher smoothness (i.e less vibration) this didn’t end up as our final method.

### Variable setpoint

This algorithm was an attempt to imporve of the stop-turn, as this one has smoother convergence. In this one the setpoint for every iteration is the weighted mean of the distance from the wall (dist) and the original set point (dist_to_wall), where the weight was a constant. Now the robot converges to the new variable setpoint instead of the distance to the wall.

Thus we have two new quantities :

1. Weight (weight)
2. Variable setpoint (var_setpoint) = weight * (dist) + (1- weight) * (dist_to_wall)

The shortcoming in this case is a bit slower convergence.

### Dual PID

This algorithm basically dropped the idea of three regions, here it’s only use it to create commands for movement. Until now we had only one PID controller on dist and there was a crude control over angle. In this one we introduced another proportional controller for angle control. This angle control was controlling the turning and turning rate of the robot by feeding the motors additional input.

Now due to the addition part, there are certain cases where the two inputs (distance control and angle) might be conflicting, resulting in a loss of control effort. For the resolution of this problem we considered all such cases individually and generated appropriate output. While we did not straight up used two PIDs independently because their tuning is very difficult, as the observable effects are intertwined.

This method deals with mostly all the problems faced by us during implementation. The shortcoming here is that each conflict case has to be resolved or the controller fails.

Many factors in general stop a robot from moving in straight path. They range from Mechanical faults and different response of motors to similar input to the fact that friction is non uniform in a real world scenario. Due to this, during the implementation of the algorithms as designed above was not straightforward instead few tweaks were made. The most notable ones are :

• The PID controller was modified to correct for different response by the motors. For this instead of having the control effort fed to them, we had an adjusted effort for each motor.
• We had to use complementary filter to put a check on random erroneous values from the sensors.
• 90° turns were also implemented.
• Reverse wall following was also implemented for which certain modifications to the system were made. Most importantly the addition of another distance sensor.
• Many a combinations of the above algorithms were also tested and can be very efficiently implemented for different cases of use. In most cases the best algorithms shall be a hybrid one rather than a pure one.

The source code is available at: harshsinh/Wall-Following

Sensors :

1. Polulu Sharp distance sensors https://www.pololu.com/product/136

Do not use serial based sensors which have very low sampling rate. For eg. http://www.rhydolabz.com/distance-sensors-c-137_144/ultrasonic-distance-sensor-pwm-op-p-307.html