\subsection{Wall Following}\label{wfalgo}
The key considerations for the Wall Following assisting behaviour are discussed below.

\textit{Assumptions}: The wheelchair can be protected only from head-on collisions (Case ii, \hyperref[oaalgo]{Section 4.1.1}) in this mode since other Obstacle Avoidance routines have been disabled. This has been done since the safety threshold for the front and corner sensors is higher than the distance being maintained for wall following. This causes the checks for obstacles in the front and corner (Cases iii and iv, \hyperref[oaalgo]{Section 4.1.1}) to push the wheelchair away from the wall. Hence it is assumed that there are no obstacles in the path of the wheelchair. Two other assumptions made related to the sensor modality are that the wall is not a glass surface or similar transparent material as the IR sensors do not detect transparent objects, and that the velocity of the wheelchair is not greater than 1m/s, the threshold distance used to detect walls. 

\textit{Threshold}: The Wall Following mode strives to maintain the wheelchair within an arm's distance of the wall, i.e., about 65cm (determined by personal perception of a comfortable distance to maintain from a wall).

\textit{Wall Detection}: If the wheelchair is brought within 1m of the wall and remains within this distance for 2 seconds (determined by checking both current and previous sensor readings), it will enter Wall Following mode. If a corridor is detected, the wheelchair will follow the closer side; or the right wall if equidistant from either wall. The approach adopted here allows the wheelchair to provide space for others to pass, particularly if the corridor is not wide. Yanco (2000), on the other hand, has chosen to centre the wheelchair in a corridor.

The main challenge in wall following is to correct for wheelchair drift. The technique to correct drift and stay within the threshold zone has been devised with the aid of trigonometry. It is known that the hypotenuse is the longest side of a right-angled triangle. The corner sensors are placed at approximately 45° to the direction of the side sensors. Hence, assuming the beams emitted by them to form the sides of a right-angled triangle if the wheelchair is parallel to the wall, it can be deduced that the corner IR sensor reading must be greater than that of the side IR sensor. In other words, if the wheelchair is parallel, the inverse cosine of the ratio of the side sensor and corner sensor should yield an angle of around 45° as shown in \hyperref[fig:WallFoll]{Figure 4.3}. Providing for some degree of error in the direction of the beams, it was expected that the inverse cosine would have some offset. Using this concept, experimental runs were conducted in manual mode to determine the range of the angles formed by the side and corner sensors. It was thus found that the inverse cosine value of the ratio of the sensor range values must be maintained between 48.5° and 51.5° to position the wheelchair approximately parallel to the wall.

\begin{figure}[t]
\centering
\includegraphics[width=0.5\textwidth]{WallFoll}
\caption[Wall Following - Drift correction]{When the wheelchair is aligned parallel to the wall, the angle made by the corner and side sensors with the wall, must theoretically be equal to 45°. Also, the corner sensor reading must be greater than the side sensor reading.}
\label{fig:WallFoll}
\end{figure}

The wheelchair is checked for drift every second. The method is explained considering the case of the right wall. Depending on the orientation of the wheelchair towards or away from the wall, it is turned left or right respectively. If side sensor reading is less than the corner sensor reading, it will go forward, provided that the angle between them is in the range 48.5° to 51.5°. The control strategy strives to maintain the wheelchair within about 40 to 65 cm from the wall depending on the velocity. The wheelchair is maintained at a greater distance from the wall for higher velocity. These values were determined empirically by trying to minimise the curvature of the path followed by the wheelchair. If the user issues a \textquoteleft{Left}' command while being within this zone, the wheelchair is brought back towards the wall gently with a right turn. If the user issues \textquoteleft{Left}' command again, it will move to the left again and if the threshold is crossed, it will exit the wall following mode. Hence the user is free to exit the mode quite easily.

