Robot Avoidance Pseudocode

Written  by Elizabeth Nguyen (Project Manager)

Description: (updated on 11/19/17)

The robot avoidance code is a program that will allow robots to avoid each other under various cases after a robot detects another. There currently two parts: (1) Robot Detection (written by John Campo) and (2) Robot Avoidance. The psuedocode outlines a potential algorithm that can be implemented for the Robot Avoidance code.

Currently, this task is linked to Rules of the Maze.

Constraints

Due to the complexity of this algorithm, the psuedocode only assumes that two robots may collide with each other. Later on, it can be built upon in the case that three robots may collide with each other or even four.

Because of this constraint and based on the Rules of the Maze, it can be assumed that North- and East-facing robots will be not need to stray off their paths when “colliding” with a robot. South- and West-facing robots however will have to carry the burden to move away to allow the respective North- and East-facing robot to continue forward.

Also, regardless of direction, any robot located in an intersection will automatically carry the burden of moving away.

Pseudocode

Avoidance
   Identify direction
   Find out which room robot is in (Subroutine - WhichRoom)
   Get location from WhichRoom
   If the robot is in an intersection
      Save current location (this location can be passed to another subroutine where it can return to its original path)
      Move away (Subroutine - MoveAway)
      Return to its original path
      Continue the maze path
   Else (this is where direction will matter)
      If the robot is facing North OR East
         Check if a robot is in front of it (Subroutine - CheckAgain)
         Wait for 30 seconds (to ensure that the robot facing South moves away)
         Continue the maze path
      If the robot is facing South OR West
         CheckAgain
         Save current location (this location can be passed to another subroutine where it can return to its original path)
         Move away by backing into the nearest corner or intersection
         Return to its original path
         Continue the maze path
         
WhichRoom
   Determine location
   Return location to Avoidance subroutine

MoveAway
   Determine path to take
   Move backwards
   CheckAgain
   Return to Avoidance subroutine

CheckAgain
   Run Robot Detection Code
   If robot is detected
      Return to Avoidance subroutine
   Else
      Resume original path

Other Notes

Despite the current pseudocode possessing the parts of if-else statements, I believe it would be better to implement a finite state machine for avoidance. There also could be complications with determining how a robot can return to its original path after moving away. Interrupts may need to be utilized since there are many moments where a robot may not need to complete the avoidance subroutine.