3D Simulator with Hardware-in-the-Loop capability for the Micromouse Competition

Robotics competitions are a way to challenge researchers, roboticists and enthusiastic to address robot applications. One of the well-known international competition is the Micromouse where the fastest mobile robot to solve a maze is the winner. There are several topics addressed in this competition such as robot prototyping, control, electronics, path planning, optimization, among others while keeping the size of the robot as small as possible. A simulation can be used to speed-up the development and testing algorithms but faces the gap between a simulation and reality, specially in the dynamics behaviour. There are some simulation environments that allow to simulate the Micromouse competition, but in this paper, an Hardware-in-the-loop simulator tool is presented where the simulated robot is controlled by the same microcontroller used by the robot. By this way, the developed algorithms are tested and validated with the limitations and constraints presented in the real hardware, such as memory and processing capabilities. The robot dynamics, the slippage of the wheels, the friction and the 3D visualization are present in the simulator. The presented results show that the same code and hardware controlling the simulated and the real robot identically.


I. INTRODUCTION
The technological advances that are taking place in this new century accelerate the use of robots and embedded systems in everyday life and even more widely in industry.However, before these complex systems are definitively propagate in society, the development team needs to perform various tests to validate the proposed system.Knowing that at this stage of development many test runs may fail and may even be destructive, the use of a simulation at this stage of the process is important and will speed up the process.In this context, the use of hardware in the loop (HIL) becomes a powerful tool to be used before the real tests and after the tests in an isolated simulation environment, replacing the electro-mechanical systems with a dynamic 3D simulator.Consequently, earlier in the process, software and hardware errors can be found.
According to [1] HIL is a real-time simulation for embedded control systems, using real hardware and other control systems with a dynamic simulator that can replace the real system.To facilitate the understanding of HIL, and to verify where it lies between the real world and the simulation, see Figure 1.According to this Figure, when advancing in the axis of realization of tests in real conditions, the price, time and the risk increases.For example, for the real test of an airplane could result in an accident, being completely destructive, expensive and dangerous.On the other hand, using simulation alone will reduce costs, risks and time considerably, but the accuracy of the system also decreases.Therefore, HIL is at an intermediate stage, balancing costs with accuracy.The Micromouse competition consists of a small autonomous mobile robot that, when placed in an unknown labyrinth, is able to map it, look for the best possible route between the starting point and the goal and travel it in the shortest possible time.To accomplish all these tasks the robot must be able to self-locate, map the labyrinth as it traverses and plan paths based on the map obtained.The method of self-localization is based on the odometry and distance sensors present in the robot, and on the previous knowledge of the start point and the general configuration of the environment.Several navigation methodologies, in order to cover the maximum possible terrain of the labyrinth while mapping, and route planning are analyzed for the best possible combination.The robot that locates the center of the labyrinth in a shorter time wins the competition.
The main contribution of this work is to present the development of a HIL for the Micromouse competition with a 3D simulator, in order to increase the accessibility of the competition and decrease the development time.This tool is available as open source, allowing each teams to make the adaptations they deem necessary in the scenario, robot and control algorithms.
An outline of this paper is as follows.In Section II a brief state of the art about HIL and Micromouse is presented.In Section III a description of the real and simulated robot is presented.Section IV presents the architecture of the HIL tool.Experimental results are presented in Section V and Section VI concludes the paper.

II. STATE OF ART
In this chapter a brief state of the art reporting the HIL application in the robotics area will be presented.The benefits, developments and challenges in Micromouse competition will also be addressed.

A. HIL in Robotics Area
HIL systems have been widely applied because of their advantages during the process of development already mentioned in Section I.The main areas that have been developing and adopting HIL are aeronautical industries [3], [4], automotive industry [5]- [7] and power systems [8], [9].
Another field in evidence is robotics.HIL can be used in mobile robots and manipulators, which are constantly optimizing their performance.The work developed in [10], uses the HIL to test and validate the dynamic and cinematic control of a non holonomic wheeled mobile manipulators.In [11], it was proposed the development of HIL to simulate robotic manipulators with n degrees of freedom, considering the dynamism that occurs when a load is inserted in the system.In [12], it was used a mobile robot developed in simulation environment and controlled externally by an Arduino, to assist in the learning of laboratory classes of automatic control and robotics.The above examples show the usefulness of HIL in robotic systems.In order to facilitate the development of the prototypes and the validation of algorithms for mapping and path planning, is proposed in this work the elaboration of an HIL system directed to the Micromouse competition.All the source code and tools for this HIL simulation can be downloaded from [13].

B. Micromouse Competition
The Micromouse competition began in the late 1970s, being the first competition promoted by the IEEE.In this competition, 8 × 8 cells mazes were used and the robots achieve speed-run times around 30 seconds.Since then, Micromouse competitions have spread all over the world [14].Nowadays, 16 x 16 cell mazes are used and the robots reach speed-run times of less than 7 seconds.
Although it started more than 35 years ago, the importance of the Micromouse problem in the field of robotics remains unparalleled, since it requires thorough analysis and proper planning to be solved [15].In addition to the acquisition of technical skills, group competitions, such as the Micromouse, develop teamwork, time management and communication skills.
In the Micromouse competition, each robot begins with some basic knowledge of the maze, obtained from the rules [16].The labyrinth has a square shape, consisting of 16 x 16 square cells of 18 cm x 18 cm, and has walls around the outer perimeter.These walls are 5 cm high, 1.2 cm wide and are painted white to reflect infrared light.The labyrinth floor is painted black to not reflect the infrared light.The initial position is one of the four corners of the maze and the goal is to reach the center.Other than that, it is necessary to explore and map the environment to perform the other tasks.In the presented paper, the focus is to present the developed HIL and simulation tool and not to address the optimized solution for the competition.

III. ROBOT ARCHITECTURE AND DRIVING ALGORITHM
In this section, the real robot developed for the competition Micromouse and which inspired the development of the simulated robot used in this work will be presented.The chapter concludes with an explanation of the standard motion wall follower algorithm.

A. Real Robot
The mobile robot shown in the Figure 2 was designed and developed for the purpose of completing a Micromouse challenge.Its structure is designed with dimensions that meet the rules of such competition [16], and with components that allow the robot to locate, move and identify the environment around it, necessary conditions to map the maze, plan the best way between the starting point and the goal and to go through this route.The robot was steered using differential geometry.Therefore, the robot has three wheels, two of them connected to DC motors, while the other is a caster wheel that has the support function.This geometry was chosen due to the several advantages presented in comparison with the other architectures, highlighting: the ability to rotate without changing the position of its central axis, a requirement to maneuver in the narrow maze environments, mechanical and control simplicity, low maintenance rates and high odometric accuracy.
The Micromouse is designed to traverse a narrow maze at high speed.In order to achieve such performance, two factors have high importance: the robot weight must not be too high and its center of mass must lie within the triangle formed by its three wheels.To obtain such characteristics, a base plate has been specially developed, as shown in Figure 2.
The Micromouse robot has an elaborate electronic structure to move through the maze independently.To this end, the Micromouse incorporated in its structure some electronic components as batteries, a Wemos D1 mini (ESP8266 based microcontroller), Wemos shields, encoders, two DC motors and laser distance sensors (VL53L0XV2), positioned at the bumper with angles of 45, 90 and 135 degrees.Information about the robot's dimensions are presented in the Table I.

B. Simulated Robot
To obtain the results of the implementation, the SimTwo simulator was used.SimTwo is an open source realistic simulation software suitable for the design and development of solutions for several types of robots [17].The dynamics realism is obtained by simulating each body and electric motor numerically using its physical characteristics: shape, mass and moments of inertia, surface friction and elasticity for the physical bodies and resistance, inductance, motor constant, rotor moment of inertia and several friction parameters for the DC motor [18].
The simulated Micromouse robot was assembled with the same dimensions as of the real one, presented at the Table I.The model is a combination of solids (cuboids and cylinders) and shells, elements without mass that do not modified the robot physical properties but are an essential part of the collisions simulation, connected by hinge joints (joints allows two objects to move between them through a single axis).Three distance sensors were installed in the same positions and angles as those present in the real robot.Connected to the side wheels are two DC motors whose simulation model can be checked in [18].The resulting robot is presented in Figure 3.

C. Driving Algorithm
The robot's control is obtained by the configuration of the speed to be applied in each motor.The set of such velocities defines the robot's final speed and the direction in which it moves.Two variables were used to control these characteristics.Such variables configure the angular velocity ω in [rad/s] and linear velocity V [m/s] to be performed by the robot.The constant b represents the distance between the traction wheels of the robot at its point of contact with the ground.The speed applied to each motor is defined according to the Equations ( 1) and ( 2).
To ease the robot's control and avoid collisions during its movements, a centralization algorithm has been implemented.This algorithm uses the distance of the walls obtained by the laser distance sensors and the previous knowledge of the size of the cells to keep the robot centered around the currently unused axis.This centralization is realized when there is a wall near to the robot, as can be seen in Figure 4, and the correction is performed by setting the angular speed of the motors.To perform this correction a triangulation is applied.Using the known angle of the sensor (45 degrees), the size of the cell (16.8 × 16.8 cm) and the distance measured by the sensor, the current distance between the wall and the robot is calculated.This distance is then compared to the distance required for the robot to be in the center of the cell and the angular velocity is adjusted.The complete calculation of this is presented in the Equation ( 3), where x is the distance between the robot's sensor and the wall (41.5 mm).K is a constant that represents the proportional gain to cancel out the error of centralization of the robot in relation to the walls.The angular velocity (ω) is set according to the distance measured by the most significant sensor, i.e., if the sensor on the left side sensor has the largest distance component, the robot tends to turn left, else it turns right.

D. Wall Follower Algorithm
The most common algorithm for a maze solver robot is the wall follower algorithm, also called left hand/right hand rule.In this method, the robot will decide its direction by following the left or right wall.Whenever the robot arrives at a junction, it will detect the opening walls and select its direction, giving priority to the selected wall, in our case, the right wall.This selection occurs according to the following steps: 1) Sense the right wall.
2) If the right wall is not present, turn 90 degrees right and return to step 1. 3) Sense the front wall.4) If the front wall is not present, move straight and return to step 1. 5) Sense the left wall.6) If the left wall is not present, turn 90 degrees left, else rotate 180 degrees.7) Return to step 1. Taking the walls as a guide, this strategy is able to make the robot reach the goal of the maze without actually solving it.However, this algorithm is not an efficient method to solve a maze since the wall follower algorithm is not capable to solve mazes with a closed loop region [19].Also remind that the main focus of this paper is to propose a HIL simulation tool,as described in the next section.

IV. HARDWARE IN THE LOOP TOOL
This chapter will present the architecture of hardware in the loop for the Micromouse competition.This tool provides a feature to test the hardware responsible for controlling all actions of the real robot, but controlling the virtual robot in SimTwo simulation environment.

A. System Architecture HIL
Figure 5 shows the implemented architecture system.Communication between the controller (Wemos) and the SimTwo runs in real time through USB port (Serial Communication) between devices.In other words, the simulator will provide the sensor data (right, left and front distance sensor and motors encoders) to the embedded controller in the hardware, which will process the data and control the actions of the virtual robot (right and left motors).The use of a real microcontroller stresses the typical hardware limitations such as memory and processing time.Once the serial port is used both for programming (Arduino IDE used for Wemos platform compilation) and for communicate with SimTwo, these steps below must be followed to execute the HIL: then execute pressing (F 9).After this step the HIL tool will be in operation.

B. Maze Generator
Based on the necessity of validate and test the developed Micromouse algorithms in the most varied scenarios, a maze generator was implemented.It is an existing executable (Maze-Generator.exe)inside the SimTwo environment folder, which converts more than 450 different classic labyrinths encoded in a txt file (credits to [20]) to XML file "obstacle.xml"that will represent the maze in SimTwo simulator.Those labyrinths reproduce the competition environment with greater fidelity, having the same characteristics of a real competitive maze.The sequence to execute the MazeGenerator.exeapplication is described in Figure 6.All the developed tools for the Micromouse HIL can be downloaded from [13].

C. Methodology to Validate the Real Control Script
Before migrating the code to the robot and testing it in real environment, a sequence of three procedures are suggested to validate the control script.This proposal consists in performing tests on several mazes available in the simulator, subjecting the developed control code by the team to different conditions that can occur in a competition.This procedures is described in Figure 7.It consists in initially developing the code to the robot to perform exploration of the maze to find the best path between the initial position and the target position (procedure 1).The next step is to test the script in the HIL tool (procedure 2).If the test succeeds, replace the current maze (procedure 3) with a new maze and re-test your script.When encountering errors or new proposals to optimize the code, return to procedure 1.After a considerable number of tests occur between procedures 2 and 3, the script will be validated for testing in real environments within the real robot.

Fail
Test Maze

V. RESULTS
For the validation of HIL developed in this paper, this section will be separated into two steps.The first step will discuss the trajectory to explore the maze using the wall follower algorithm.The second step will present information obtained from the sensors provided by the simulator and speed information to be applied in the simulated robot provided by the real hardware control.

A. Map Exploration with Wall Follower Algorithm
The wall follower algorithm provided in this paper comes as standard to be compiled on the actual controller (e.g.Wemos D1 mini).The choice of this simple algorithm has the objective to foment the interest of new teams in the competition, being able to be a starting point for the development of more complex exploration algorithms particular of each team.Figure 8 presents the simulation environment with the maze hokurico-030-2012 (available in this tool), explored by the above mentioned algorithm.As predicted, the algorithm does not perform the complete exploration of the maze, initiating a cycle of movements every 140 seconds.

B. Sensors and Speeds Motors Data
In the HIL tool the simulator sends the data acquired from the linked distance sensors in the simulated robot to the real controller (Wemos D1 mini).These sensors provide the distance in meters from the right, left and front walls.Figure 9 presents these data during the first 20 seconds of the scanning trajectory (red trail) presented in the Figure 8.These data are processed by the real controller and have the same magnitude of the sensors assembled in the real robot, due to the accurate model.The controller will process the simulator data in real time and returns the speeds of left and right wells to simulated robot.Figure 10 shows the speed values of the wheels during the first 20 seconds of the scanning trajectory presented in the Figure 8.The data of Figures 9 and 10 correspond to the same path and were acquired at the same time.Taking into consideration the high torque of the DC motor and the relatively small mass of the robot, the reference speed of the controller and the speed of the simulated robot are practically the same.
By correlating the data of the graphs, the following events can be observed: When executing the rotation, the right sensor detects the halfway in the interval between 4 to 5 seconds.• At intervals of 5 to 8 seconds a speed transition occurs, as the robot finishes the rotation around its axis and returns to straight way.Moments after the transition is observed a ripple at the speeds applied to the motor, because the robot is centralizing; • The other events have behavior similar to those described above.

VI. CONCLUSION AND FUTURE WORK
While the Micromouse competition started more than 35 years ago, it still is an important challenge to the researchers.It address robotics topics such as prototyping, control, localization, path planning, among the others.This paper described a Hardware-in-the-loop tool to this competition, where the microcontroller present in the robot can be used to control the simulation environment based on SimTwo.Using the same microcontroller and the same programming language, it is possible to test and fix the developed solutions faster and easier, even before the real robot is developed.The presented results showed the proposed tool (provided by the authors) can help the development of the Micromouse solution.As future work, the accuracy of the assumed models should be improved and other sensors can be modelled and included both in the Simulation and in the Hardware-in-the-loop communication protocol.

1 )
Compile the code in the controller (Arduino IDE) and then close all dependencies of the Serial port (Monitor Serial); 2) On the SimTwo, in the Conf ig− > I/O tab, configure the Serial port with a Baud Rate of 115200 [bps] and select the COM port corresponding to the Arduino IDE, and then open the communication.To finish this step, open the communication by selecting the "open" checkbox; 3) On the Editor tab, compile the code (Ctrl + F 9) and