# Staircase Detection, Characterization and Approach Pipeline for Search and Rescue Robots
## 2 Materials and Methods
### Fuzzy Controller for Alignment  
To implement the staircase approach and alignment algorithm, a fuzzy controller was used. To do this, 45 rules (shown in Table A1 in Appendix A) were implemented using 3 inputs: the position within the image of the detected staircase, the distance to the staircase and the orientation of the riser with respect to the robot. The logic behind this controller is to use the staircase's position within the image frame and the distance to the staircase to approach the obstacle slowly until it can determine the staircase's orientation. The fuzzy controller executes the initial approach in such way that the staircase bounding box is always centered in the image. The robot moves slowly towards the staircase until it can segment at least two risers and determine the orientation of the staircase with respect to the robot. Once this is achieved, the fuzzy controller enters into a second phase where the robot will try to move parallel to the risers and at the same time keep moving towards them, but without losing the obstacle from the image frame. Once the robot has gotten closer to the staircase, it inters the third phase of alignment where it will now use the orientation of the staircase to align itself with the staircase, in such way that the robot will end up centered in front of it. The fuzzy variables and fuzzy sets are the following:  
* Fuzzy variables and fuzzy sets:
* Input variables:
* Center of the bounding box with the detected staircase (_bb_center_xcentroid_pos_). * Fuzzy sets: _left_, _left_center_, _center_, _right_center_ and _right_. * Distance to the centroid of the staircase (_centroid_dist_). * Fuzzy sets: _closer_, _close_, _far_. * Staircase orientation (_riser_angle_). * Fuzzy sets: _left_, _center_ and _right_. * Output variables:
* Linear velocity (linear_vel). * Fuzzy sets: _fast_, _slow_ and _stopstop_ and _go_. * Angular velocity (angular_vel). * Fuzzy sets: _left_, _center_ and _right_. The membership functions of the variables are shown in Figures 3 and 4. Figure 3a shows the membership functions used for the _centroid_pos_ input. The universe of discourse is the width of the RGB image and each fuzzy set represents a zone within this image. On the other hand, in Figure 3b shows the fuzzy sets corresponding to the three distances considered in this controller. For this variable, the universe of discourse was kept between 0 and 4 m and three fuzzy sets were used. When the staircase is _far_ from the robot, it is impossible to obtain the staircase orientation due to camera limitations, but once the robot gets _close_ or _closer_, the staircase orientation can be obtained. Finally, Figure 3c shows the fuzzy sets that represent the orientations considered. Considering the way the orientation is measured, the universe of discourse for the _riser_angle_ variable is between 0 and 180 degrees, where values below 90 degrees represent a staircase rotated to the left, values above 90 degrees represent a staircase rotated to the right and values equal to 90 degrees represent a staircase completely parallel to the camera's frontal plane (XY plane in Figure 2). Finally, for the outputs, we used single value constants or singletons. For the linear velocity, the universe of discourse is kept between 0 and 0.5, but we only use values at 0 (zero velocity) and 0.1 (see Figure 4). For the angular velocity, the universe of discourse is keep between \(-0.5\) and 0.5, where negative numbers represent a rotation to the right and a positive value a rotation to the left. For both output variables, large velocities are not required and they can be unfavorable due to the rate at which the staircase parameters are published. Figure 3: Membership functions for the input variables: (**a**) center of bounding box within the image, (**b**) distance to the centroid of the staircase, (**c**) riser orientation with respect to the camera frame.