# Integrated Design Methodology of Automated Guided Vehicles Based on Swarm Robotics
## 4 Case-Study: Application to the Design of AGVs
### Phase 2: ROS Implementation
#### 4.2.3 Creation of Algorithms  
The third step is to create the algorithms that manage the operation of the AGV system in the factory. Our methodology simplifies the creation of these algorithms because the models developed with the state machine diagrams in SysML are used to develop these operating algorithms. Figure 20 shows the process of creating algorithms to run AGVs through SysML diagrams.  
Converting these algorithms to usable software codes is the most difficult step that requires the ingenuity of IT developers. However, with the preliminary preparation work (state-machines to algorithms) the complexity of the task of the developers is considerably reduced, with a better level of conformity between the various pieces of code. Indeed, the IT developers translate the algorithms into C++ or Python codes to ROS nodes which will be called later by the run files. In most cases, IT developers can find some shared codes similar to the ones to be implemented in their application, thanks to code sharing by the ROS community. Their task is therefore to adapt the existing codes and add the missing ones while being guided by the SysML model.  
Figure 19: 3D model of a factory in Gazebo.  
Figure 18: 3D model of an AGV in Gazebo.  
As an example of code used in this case study, the simultaneous positioning and mapping (SLAM) code of the AGV system was implemented to draw a map by estimating its current location in an arbitrary space. SLAM is defined as the problem of building a map at the same time as locating the AGV in that plane. In fact, the AGV can rely on two sources of information: information specific to it and information collected in its environment. When it is in motion, the AGV can use dead reckoning and the information returned by its sensors (encoder wheels, the current consumption of motors, the position of a servomotor, etc.). However, this kind of information is not completely reliable (sliding, play, friction, etc.). The other source of information comes from sensors and systems dependent on the environment and external sources (camera and laser). Another ROS visualization environment (Rviz) can be used to see how the map is created when the robot is moving. After saving the map, it is possible to move the AGV on a chosen path. Figure 21 represents the Rviz visualization of an AGV moving on a path in the factory.  
Finally, Gazebo allows visualizing the AGV system working in 3D. Figure 22 shows the moving of the AGV system in a 3D Gazebo environment. The goal of this simulation was to verify if the AGV is able to travel a memorized path and transport pallets of goods to the unloading area so that the main design requirement is verified with simulation.  
Figure 21: Rviz visualization of an AGV moving on a path.  
Figure 20: Creation of AGVs operating algorithms using SysML diagram.  
The final step of the proposed design approach is the validation of the design requirements using ROS simulation based on the SysML description. Table 1 provides illustrative validation elements of three design requirements. The table shows the design, the requirements, the simulation actions performed in the ROS simulation environment, and the SysML information used for that purpose.  
The simulation illustrated in Figure 22 shows only one AGV system. The simulation of the swarm of AGVs to test collision avoidance, coordination, and collaborative tasks is a work in progress that will be published in another article. Indeed, the simulation of a swarm of AGVs requires managing the number of AGVs in the ROS launch configuration file, but also a specific adaptation in the codes controlling each AGV.