# Implementation of the motion planning algorithms

The standard motion planning algorithm that is explained in Section 'State of the Art' is implemented without major changes. When the robot starts in the upper left corner, it moves to the upper right corner while it is continuously cleaning. It then turns in the upper right corner and thus also checks the last bit of the row with its dirt detect sensors. The robot then assesses the cleanliness of the entire row. If the row is perceived as clean, the robot moves to the next row and repeats the process. If not, it moves to the upper left corner while continuously cleaning, turns again and checks again and so fort. It should be noted that when the robot perceives a row as clean, it is not necessarily entirely clean. This is because patches that have a difference of previous dirtiness value and current dirtiness value that is smaller than the set minimum difference are not considered anymore by the robot. The only real difference that the implementation has when compared to the explanation is that the robot is not actually continuously checking with its dirt detect sensors, but checks once every time all the patches in the row have been in contact with a dirt detect sensor of the robot. This is done for practical purposes in NetLogo and results in exactly the same behavior as described in the earlier explanation.

To implement algorithm 1, which is also denoted as zigzag, some small modifications had to be made. When the robot starts at the upper left corner and starts cleaning and moving to the right, it continuously checks the patches below the dirt detect sensor. When the dirt detect sensor detects at least one dirty patch, the robot is ”teleported” back five patches (this is called the backwards movement) and moves again over these dirty patches with its cleaning section. This is done to model the reciprocating motion. It should be noted that the time and the consumed energy for the backwards movement are still respectively added to the time and energy consumption variables. The major problem of the backwards movement is that it is not possible to execute this movement when the robot is (partly) located in the first five columns of patches of the row. This is of course also the case when the robot is heading in the other direction, thus the backwards motion is not applicable in the first and last five columns of patches of the row. When a persistent spot of dirt is located in one of these columns, the robot uses the standard cleaning method with the exception that it is not continuously cleaning but only cleans when its cleaning section comes into contact with a considered dirty patch. To prevent stripes, the robot cleans the row one more time when it has used the reciprocating motion in its last movement over the row and has determined that the row is clean. The cleanliness of the entire row is again determined after reaching an end of the row and turning and checking the cleanliness of the considered patches.

For the implementation of algorithm 2, which is also denoted by turndirt, some small modifications had to be made again. The first and last row are cleaned with the standard method. The reason for this is that when the robot has to turn in these rows, it has to first move away form the window edge, then turn and then move back. For the top row this would mean that the robot comes into contact with the part of the window that is still dirty which would potentially mean that dirt from this part is again introduced to the top row. For the bottom row it would mean that the robot moves from the dirty bottom row into the clean row above that and that the turning motion would potentially leave stripes there. Because of these reasons, these rows are thus cleaned with the standard method.

For the other rows, the motion pattern is as follows: The robot starts at one window edge and moves to the other while continuously cleaning like the standard algorithm. When it has reached the other edge it turns and checks the cleanliness of the row. When the row is considered clean the robot moves to the next one. When the row is not yet considered clean, the robot determines the outermost dirty patches in the row and repeats the previously mentioned movement between these patches with the exception that the robot only cleans when its cleaning section comes into contact with a dirty patch. When the robot reaches one of the outermost dirty patches, it turns and checks the cleanliness of the patches again. When the row is still not considered clean, the robot again determines the outermost dirty patches and repeats the motion. This goes one until the entire row is clean with one exception. If the two outermost dirty patches are placed closer together than the dimensions of the robot, or just one dirty patch remains, the robot moves somewhat further than an outermost dirty patch to make sure that the cleaning section can reach the dirty patches after turning. This ensures that the robot does not end up in an endless loop of turning without being able to clean the patches for which it turns. When the row is considered clean and turned in the middle of the row, the robot moves to one of the outer edges of the window and moves over entire row one more time to remove any stripes. Thereafter, it moves to the next row.

One special case still needs to be considered. This is the case that there is one persistent dirty patch that is still considered and is located in the first or last five patch columns of the row. In this case the robot is not able to move a little further since the dirty spot is located so close to the window edge. In this case, the robot cleans the entire row like the standard algorithm with the exception that the robot only cleans when its cleaning section comes into contact with a dirty patch.