Skip to content

Autonomous Systems

AI, Algorithms, Robotics (HelloRob | Berea College)

Menu
  • Home
  • Blog Guidelines
  • Schedule
Menu

From Static to Dynamic: Translating Wall Follower Code from C++ to Python

Posted on December 14, 2023

Introduction

This time, my journey led me to Python, a shift from the familiar grounds of C++ that I navigated in our previous projects. My task? To breathe life into a Wall Follower algorithm using Python.

From Square One to Complex Mazes:

Starting with the basics, I had to get the robot to follow a simple square path, a warm-up exercise to get accustomed to commanding the Mbot in Python. That was when I realized how easy everything could be in Python. The flexibility and ease of the language are very convenient (even though that is at the expense of performance speed). To me, Python code is much more readable and user-friendly than C++, even in CSC236, the brackets all over the place are ugly and confusing.

The Challenge: Translating C++ to Python

This part was more than just coding; it was about adapting to a totally new codebase, different API implementation, and an opportunity to go through the documentation in detail which offered me a lot of insights into the Mbot.

The Wall Follower algorithm, initially coded in C++, had to be recoded in Python’s flexible script. This translation wasn’t merely about changing syntax; it involved rethinking logic, embracing Python’s dynamic typing, and exploring its rich libraries, mainly Numpy, which offers great Linear Algebra built-in features that came in handy during cross-product and vector manipulation.

The Heart of the Algorithm:

At the core of the Wall Follower lies a simple yet profound logic:

  1. Reading the World: The robot uses its LIDAR sensors to gauge its surroundings.
  2. Making the Call: Based on the sensor data, the robot decides how to adjust its path to maintain a consistent distance from the walls, or correct it otherwise.

Here is the pseudocode:

while True:
    0) Gather sensory data


    1) Analyzing for the closest obstacle: getting min_distance and min_angle

    2) Decision-making based on proximity:
    deviation = desired_distance - min_distance
    movement_strategy = compute_movement(deviation, min_angle)

    3) Executing the strategy

Day 0: Demo day:

During the demos, I learned a lot from my peers in class. Ali and Bishal’s presentation gave me insights into using NumPy directly for cross product. Nate’s presentation showed how to balance between sound wall following and a fast traversing of the maze, and Kori’s presentation was really enjoyable!!

My robot performed well on the maze, except for two times when it stopped because it was surrounded by the maze, a chair, and 4 people, and I am conjecturing that was the reason it stopped (sensory overload that Python could not handle, perhaps)

Here is the LINK to a video demo of my robot, perfectly navigating a closed map

Wrapping up:

This semester has been very insightful; I learned a lot and the collaborative non-competitive environment of the class was very convenient. I am so proud that I could get a robot to navigate mazes, follow walls, drive squares, and much more.

Thank you for bringing this class to Berea and offering us the learning opportunity!

oussema

Recent Posts

  • Dancing the Hokey Pokey
  • Python Wall-Following Project
  • From Static to Dynamic: Translating Wall Follower Code from C++ to Python
  • Final Project Reflection Blog – Hardware
  • Enhanced Obstacle Avoidance with Ultrasonic Sensors on MBOT
  • Microsoft Cuts Off Access to Bing Search Data as It Shifts Focus to Chatbots
  • The Reason Murderbot’s Tone Feels Off
  • Google DeepMind’s AI Agent Dreams Up Algorithms Beyond Human Expertise
  • Google’s Advanced Protection for Vulnerable Users Comes to Android
  • Google Is Using On-Device AI to Spot Scam Texts and Investment Fraud
©2025 Autonomous Systems | Design: Newspaperly WordPress Theme