5.6 Motion decision

This is the highest level logic.

The logic to determine what to do next should be triggered only when it makes sense. This depends largely on where the robot is in the maze and the geometry of the robot.

For reliability, this decision can be made only when the mouse is in the center of a cell after all alignment error corrections (front wall alignment and direction alignment, both are only possible some times).

However, for efficiency, this decision can be made earlier if the best path is to lengthen the linear remaining amount. This can be confirmed by looking at the floodfill values and know that the best next step (after the current motion is completed) is to continue to go forward. This logic permits a mouse to continuously go forward even when it is mapping.

To take this to the next level, you can also implement the logic of speed run here. The speed run logic can be summarized as follows:

The speed run logic automatically degenerates to go forward one cell when the robot explores an unknown region of a maze. This means there is no need to differentiate a speed run from an exploration run!

If the floodfill values indicate that a turn is necessary, then this logic can just wait for the remaining displacement to decrement to zero, then trigger the next action then.

The overall motion decision logic should also control any alignment logic. For example, after perform the motion to move forward a cell and stop, this logic should determine whether there are enough walls to perform front wall alignment and direction alignment. If these alignments are possible, they should be performed (direction alignment first, then front wall alignment). This is because this motion decision code has the “big picture”.

Likewise, this logic also knows whether a mouse has reached the goal. If so, it should set the origin as the destination and go back there. Once the mouse moves back to the origin, the same logic should set the goal as destination again.