## 5 Applying Computer Vision and Fuzzy Logic  
As a first example, the utility of Andruino-R2 is presented to validate the practical application of computer vision [35] and fuzzy logic techniques in mobile robot navigation in the classroom. Specifically, Andruino-R2 must visually follow a path, marked by a green line, in addition to stopping when it detects an obstacle ahead close enough, in a qualitative sense. Fuzzy systems have been widely applied in robotics for intelligent navigation [36], visual path tracking [37], optimal obstacle avoidance in underwater vehicles [38] or design of fuzzy controllers for embedded systems [25], to name a few recent developments. In this way, students have the opportunity to acquire and apply the basics of how a rule-based knowledge decision system works. The student must identify the input and output variables, the attributes that define them and their membership functions, in addition to expressing the ruleset of expert knowledge that solve the problem. Later, the student will have to implement the code that makes it possible to obtain the output from the input using the knowledge base defined above. Specifically, the four basic stages of a fuzzy logic system will be identified to infer an output from the inputs: fuzzyfication, inference, composition and defuzzification. First the conversion of a quantitative input value to a qualitative one using the membership functions (fuzzication); second, the logical operators are applied to evaluate the degree of truth of each rule and obtain the qualitative output of each one of them (inference); third, the qualitative outputs of each rule are combined into a single system output (composition); finally, the qualitative output has to be converted to a crisp quantitative output (defuzzification), which can be used in the system. To develop this objective, students begin by acquiring and applying the basic notions of image processing and feedback control. To do this, using the smartphone camera, the robot must detect a line of a certain color on the ground, stand on it and start to follow it. Once successful, they must apply fuzzy logic to get it to stop if the frontal ultrasound sensor detects an object close enough, and stay stopped until the path is clear again. Figure 6: Andruino-R2 multi-robot simulation in Gazebo. Figure 4 shows the ROS computation graph for this task. Thus, the /follower task subscribes to both the measurement from the front ultrasonic sensor (/andruino145/hc_sr04_2) and to the image from the camera (which was previously converted into raw format, /camera/rgb/image_raw). With those inputs, it has to compute the desired linear (\(v\)) and angular (\(\omega\)) velocities (/cmd_vel) that are sent to the Andruino-R2 (/andruino145/andruino_driver_cmd_vel), and translated into actual PWM signals for each DC motor in the Andruino shield. One of the main advantages of ROS is that it greatly facilitates integration with tools for computer vision such as OpenCV. Image processing is done easily using basic commands from the OpenCV library. In this way, students begin by learning how to acquire an RGB (red, Green, Blue) picture frame and convert it to the HSV (Hue, Saturation, Value) color space where it is easier to represent a color. They then identify the color of the line to follow, set the HSV image threshold for a range of line color, and apply the resulting mask to the original image. The mask is also used to calculate the destination point on the line at a distance ahead. To calculate the actual deviation of the Andruino-R2 robot with respect to the line, it is necessary to take into account that the camera's reference system is not centered with respect to the robot's reference frame, as can be seen in Figure 7. Therefore, when the robot is centered on the line, the tracking point will not appear centered on the image.