RobotC Maze Solver

During my Mechatronics Design 1 Class from June to August 2024, I developed a Lego Mindstorms robot designed to autonomously solve mazes. This project involved programming the robot in RobotC and integrating an ultrasonic sensor to detect and navigate around maze barriers. The robot was capable of exploring the maze while storing the locations it visited. The primary goal was to develop an efficient maze-solving algorithm that would allow the robot to reach the end of the maze and then calculate the shortest path back to the starting point.

The robot’s logic was based on a systematic approach to navigation. It used NESW (North, East, South, West) directional values to guide its movements and a coordinate system to track its position within the maze. The robot followed a right-wall-following algorithm, driving forward until it encountered a wall. When blocked, it would turn left until it found a clear path, continuing this pattern throughout the maze. As the robot moved, it stored its visited locations in a predefined 4x6 2D array, mapping each cell to a unique integer value. Once the robot reached the target location, the system processed the stored coordinates to remove redundant locations. This was done by identifying cells the robot visited more than once, indicating either a dead end or a less optimal path. By eliminating these redundant coordinates, the robot determined the shortest path back to the start. During the return journey, the robot navigated step-by-step to each optimal location in reverse order, using the cleaned-up array of coordinates. This ensured it followed the most efficient route back to the beginning of the maze.

The success of this project was highlighted by the robot’s performance: it successfully completed the maze with the fastest solution in the class, earning an A+ for the project. This achievement demonstrated the effectiveness of the mapping system, the precision of the ultrasonic sensor, and the efficiency of the maze-solving algorithm. Note: as part of this class project, we were able to interfere with the robot up to three times during the run due to table and maze building inconsistencies.

RobotC code: https://drive.google.com/file/d/1JyzrP_PwJYRyJUFOMpZphuoxgJ4zYK6F/view?usp=sharing