DEV Community

Jeff Liu
Jeff Liu

Posted on

1 1

a simple solution to escape maze

GitHub_Link

Left Wall Following Algorithm

The Left Wall Following Algorithm is a simple yet effective approach for maze navigation. While it does not guarantee the shortest path, it ensures a successful exit in almost 100% of test cases.

Image description


Sensor-Based Approach

The robot makes decisions based on two key sensor readings:

Sensor-Based Approach

  • Front scan (-15° to 15°): Detects obstacles directly in front.
  • Left side scan (45° to 135°): Measures the closest distance to the left wall.

Algorithm Logic

Obstacle Detection

  • If an obstacle is in front:
    • If the left-turn state is True, turn left.
    • Otherwise, turn right.

Path Navigation

  • If no obstacle ahead:
    • If in the dead zone, turn right.
    • If between the dead line and keep line, move toward the keep line.
    • If between the keep line and boundary line, maintain position.
    • If outside the boundary line, move straight until a left wall is detected.

Algorithm Logic

Image description


Code Structure

class LeftWallFollower:
    def __init__(self):
        # Initialization logic here

    def clst_dtc_and_dir(self, start_degree, end_degree):
        # Detects the closest wall and its direction

    def scan_cb(self, msg):
        # Processes sensor scan data

    def follow_left_wall(self):
        # Implements velocity control and Bang-Bang Control logic
Enter fullscreen mode Exit fullscreen mode

Test Results

The algorithm was tested 10 times in different maze positions, yielding a 100% success rate:

  • Perfect route: 60% of cases.
  • Imperfect route: 40% of cases (still successfully escaped).

Fault Tolerance

Two fault cases were observed:

  1. Dead-end handling: If the robot turns left into a dead-end, it resets its state when encountering a new wall.
  2. Exit room misinterpretation: The robot may bypass a small room at the exit due to sensor inaccuracy.

Conclusion

The Left Wall Follower algorithm is an effective solution for autonomous robotic navigation. Future enhancements could include:

  • PID-based control for smoother motion.
  • SLAM integration for dynamic mapping.
  • Machine learning enhancements for improved adaptability.

The article ends here, below is the advertisement of the website.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post