Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Sunday, March 16, 2025

PolyMap: Leveraging Godot for Visualization (#3)

 


Leveraging Godot for PolyMap Visualization

Introduction to PolyMap and Visualization Goals
PolyMap is my experimental platform exploring multi-agent, robotic swarm-based Simultaneous Localization and Mapping (SLAM) strategies for mapping real-world environments. Development has been incremental: starting with a simulation, robot agents, a mapping manager, and basic visualization. One key goal was to leverage existing technologies like game engines to rapidly create an operable system. Game engines also offer a natural interface to visualize the spatial data generated by the robots as they explore physical space—and it’s just really cool!


Why Godot?

Why use a game engine instead of existing tools like RViz? There’s no single answer. RViz and others are developed for the ROS environment and are reportedly easy to integrate with ROS, but I haven’t explored ROS yet. Possibly due to hardware constraints or concerns about getting locked into a specific architecture, I’ve chosen instead to learn the fundamentals of the (robot) science before adopting fully developed solutions. This is also exactly why I’m starting with a single ultrasonic sensor rather than a Lidar for spatial sensing. There is a vast amount of unbuilt software needed in this space, and I want to understand the basics before being embedded in one ecosystem. (A related question: is ROS becoming a walled garden?)

I chose Godot because it’s open source, has no license fees, and has a large community. It can render immersive 3D environments with advanced graphics and interactivity—features that would take far longer to build from scratch. This makes enhancements like zooming, panning, robot tracking, and detailed exploration straightforward. Overall, it’s a friendly platform for any maker stepping into games or 3D visualization. Plus, Thor from Pirate Software thinks "Godot is the Blender of game engines". 😉


Transitioning from Python to Godot
The original Python-based visualization tool was a solid proof-of-concept for displaying the global map and robot telemetry. As the project matured, I planned to try a game engine to overcome Python’s limitations in interactivity and feature expansion—where everything had to be built from scratch. 

Transitioning to Godot 4.4 opened new possibilities for a more fluid UI. Because PolyMap uses MQTT for distributed communication, multiple visualization clients can consume the same data. This architecture also means each component can be developed in the best language for its function: the simulation and map manager will stay in Python, while the robot agent code (currently Python) will move to C++ for real hardware deployment. 🤖

Here is a video showing the transition and new version:



Integrating MQTT Communications in Godot
A critical aspect of PolyMap is using MQTT for data exchange. Fortunately, people like Goatchurch paved the way by porting MQTT code into Godot. It was showcased at a Godot convention, and most importantly, their open-source work on GitHub allowed me to clone it. Within a short time, messages from my existing Python version appeared in Godot. Once the MQTT connections and message handling were in place, communications were solid, letting me focus on features and functionality.

In the prototype, there’s a connectivity dialog box where the user enters the server URL, port, user ID, and password. It also allows topic subscriptions and message publishing. In this setup, the visualization subscribes to global_map and telemetry topics. Currently, the entire 100×100 integer map is broadcast every second, alongside telemetry data from the robot agents.


Using Godot
One of the most exciting aspects of Godot is how easily you can configure screens and add new features. Godot is heavily object-oriented; everything is a Node with attributes and methods. It reminds me of early “thick client” GUI development (pre-Web, like Acius 4D). This is my first Godot project, so I’m still learning and deciding how much to configure in the editor versus coding in scripts. Right now, screen elements are configured in the editor, while global map rendering is done in code.

There is a learning curve to working with Godot, but I understand it is very similar to other game engines like Unity and Unreal engines. For me, it was natural to code with an AI (or two, or three) to help me quickly learn how Godot works. There are also good videos on YouTube as well such as this video. One issue I ran into was that many of the AIs did not know how Godot 4.4 had changed from earlier versions, there was a constant effort required to correct the AI when it was off hallucinating. 🙂

Building the first prototype had its challenges: positioning the camera to view the map, deciding where to place MQTT functions, and balancing performance between rendering each grid point individually or using a grid mesh. Once I got the hang of Godot, it was surprisingly simple to get the visualization working. Adding a mouse-wheel zoom took only five minutes. I’m excited to add more capabilities quickly!


Future Features
With the first iteration working, here’s what I’m planning next:

  • Persistent Map: I can choose between redrawing the global map each time, or making it more persistent and only updating changed elements as the are discovered by the robot.
  • Free Fly - Camera: I will change the primary camera and give the user the ability to 'free fly' over the map moving around the landscape discovered by the robots. 
  • Robot FPV: It should be possible to put a camera in each of the virtual robots, allowing the user to select the robot and view the 3D space from its perspective.

Looking ahead, I’m breaking out the map manager and robot agent code from the simulation, moving toward a distributed computing platform. This is a key step for migrating from simulation to real hardware. Stay tuned for more updates!

Saturday, March 1, 2025

Polymap: Mulit-Agent SLAM Simple Simulator (#2)

Multi-Agent SLAM! with Distributed Data Fusion and Frontier Searching


PolyMap is an experimental platform designed to explore Robotic Swarm–based Simultaneous Localization and Mapping (SLAM) strategies across both simulated and real-world environments. The mission is to harness distributed robotic sensor data, real-time MQTT communications, and advanced data fusion to develop robust, collaborative mapping environments that bridge virtual (systems) and the physical (machine) world.

Recent Work

Robust MQTT Communications & Security
The MQTT infrastructure now enables secure, real-time data exchange between robot agents and the Map Manager. With brokers, subscribers, and publishers designed to run on distributed platforms, the system is designed to scale smoothly to multiple robot agents. Integrating data from distributed sources has enhanced the completeness of the global maps.

PolyMap MQTT pipeline


Frontier Searching Implementation
I have integrated frontier searching techniques—drawing inspiration from Yamauci, 1997—to systematically prioritize and explore unknown regions of the map. This approach is central to refining our mapping strategy by dynamically guiding the system to areas that require further investigation.

Enhanced Visualization
The python visualization is now somewhat fully functional, offering a clear and dynamic representation of the evolving global map. Real-time updates provide immediate robot telemetry and map fusion data, ensuring that the state of the environment is always accurately reflected.

YouTube Video Demo
Here is a YouTube video showing PolyMap in action. You can see the simulated robots navigate in a virtual environment, exchange data via MQTT, and merge their local maps into a dynamic global view—all in real time. 




Current Challenges

Robot Agent Behavior
While our simulation demonstrates significant progress, the robot agents exhibit limited exploratory behavior and are challenging to fine-tune. They often get stuck in corners, a behavior likely influenced by the coarse resolution of the current scanning technology. This is a complete topic that I will expand on more in the future.

Polymap: going long on Frontiers

PolyMap: Robot Agent Exploration


Operational Mode Transitions

In the system, robots cycle through distinct operational states that define their behavior during navigation. These include:

  • Scan Mode: Actively gathering sensor data.
  • Idle Mode: Maintaining a standby state when no immediate action is required.
  • Obstruction Mode: Responding to detected obstacles.
  • Frontier Mode: Venturing into uncharted areas for further exploration.

While these states provide a structured approach to managing robot behavior, the transitions between them need further review and refinement. Enhancing these transitions is critical to achieving smoother performance and greater responsiveness during navigation.


Upcoming Developments

Enhanced Sensing
We are set to incorporate a 'radar-like scan' into both our simulation and physical platforms. This upgrade will augment the capabilities of our single ultrasonic sensor, providing richer, more detailed environmental data.

Physical Implementation – Meet MinOne
The physical build of “MinOne” is now underway. This robot will serve as the real-world counterpart to our simulation, enabling us to bridge virtual testing with tangible, hands-on experiments.

Next-Generation Visualization
In our continuous effort to improve user experience and performance, we are evaluating the Godot engine as a potential upgrade for our visualization tool, aiming to deliver a more immersive and high-performance display.

Further Enhancements
Moving forward, we will focus on fine-tuning robot behaviors and sensor parameters, as well as exploring additional sensor integrations to boost mapping fidelity. The goal remains to develop a scalable and robust platform for multi-agent SLAM exploration and discovery.


PolyMap's evolution is driven by a relentless passion for iterative improvement and DIY robotics innovation. This project is about building something tangible—each challenge overcome and every feature refined brings PolyMap closer to bridging the gap between simulation and reality and expanding the boundaries of collaborative robotic mapping.

Sunday, January 26, 2025

PolyMap: Introduction

PolyMap:
PolyMap is an experimental platform designed to explore Robotic Swarm–based Simultaneous Localization and Mapping (SLAM) strategies across both simulated and real-world environments. By combining lightweight simulation, MQTT-based communications, and emerging visualization techniques, PolyMap aims to offer an accessible yet robust toolkit in multi-robot collaboration and global mapping challenges.

Recent Progress: Building a Simple SLAM Simulator
I am pleased to share the latest milestones in developing a simple SLAM simulator under PolyMap. Over the past few weeks, I have laid the foundation for simulating robot behavior, visualizing real-time maps, and merging local maps into a unified global view. This work is an important step toward creating a versatile environment where multiple robots can collaboratively build and refine shared maps.

An early achievement in this release has been leveraging MQTT for robot-to-visualization communication. Each simulated robot transmits map updates through MQTT, which our visualization layer consolidates into a cohesive global map. I have also made headway on a basic search feature, an early step toward more sophisticated swarm coordination. Concurrently, I have improved the simulation architecture to ensure that incoming data and visualization processes run smoothly without blocking each other.

On the infrastructure side, I have established a basic development structure—not full CI/CD yet, but enough to keep things organized and maintain momentum. I have also incorporated early concurrency and event-handling mechanisms so that data flow and visual updates can occur in parallel. While there’s still much, much more to do, these accomplishments underline PolyMap’s potential to evolve into a compelling cooperative robotics exploration platform.

Next Steps and Future Directions
Looking ahead, I plan to explore using gaming engines to enhance our visualization capabilities, offering a more immersive and high-performance environment for simulating robot movements and interactions. Additionally, as the simulated framework matures, we’re setting our sights on integrating physical robots into the pipeline—bridging the gap between virtual testing and real-world application. By supporting both simulated and physical robot platforms, we hope to make PolyMap a flexible tool for multi-robot SLAM challenges. Stay tuned for more updates as the platform continues to evolve!

Here is a much more realistic screen capture of the actual 'early' simple simulation. ;)

Simple SLAM simulation

Sunday, September 29, 2024

SLAM! - Building a Simple SLAM Simulator

SLAM_play - A simple SLAM simulator

Welcome to the next step in creating my Totally Not Evil Robot Army! Today, we kick off our journey into the fascinating world of robotics with a simple SLAM (Simultaneous Localization and Mapping) project.

What’s SLAM?

In the world of robots, SLAM is what helps our mechanical minions make sense of their surroundings. Imagine a robot moving through an unknown environment—how does it know where it is and where the walls (or, you know, other targets) are? That's where SLAM comes in. The robot uses sensor data to map its environment and figure out its position on that map in real time.

My SLAM_play Project

My initial SLAM project is a basic 2D simulator called SLAM_play. This simulation features a simple robot equipped with an ultrasonic sensor that explores a grid-like environment. The robot moves around, detecting obstacles and marking unexplored areas as it builds a map of its world.

The robot updates its map in real time:

  • Grey zones represent the areas it has explored and found clear.
  • Green spots mark obstacles (which may or may not be future targets for…um...peaceful interaction).
  • Dark grey zones represent the "frontier," where the robot has reached the limits of its sensor's range and hasn’t detected anything yet.

What's Next?

This is just the beginning. As I dive deeper into SLAM, I’ll explore adding more complex sensors, like LIDAR, and even experiment with autonomous pathfinding. The ultimate goal is to build a robot army that can navigate any environment, no matter how complex…for purely benevolent purposes, of course.

For now, I'm taking small steps, but these small steps will one day become the foundation of an unstoppable (yet totally friendly) robot force.

If you’re interested in exploring the code behind this simulator, check out my public GitHub repo here:
SLAM_play Repository

Lets continue the adventure of giving the machine some SLAM —one sensor at a time!

Robot Army Motto: Mapping the future, one ultrasonic ping at a time.  (for now!)

[UPDATE]

Here is a short video of the Simple SLAM simulator:



more to come...

Sunday, December 23, 2018

Robot Arcade - LetsRobot.tv

I am creating a "Robot Arcade" on LetsRobot.tv as a holiday project!  You can visit the site LIVE here:


Robot Arcade - LetsRobot.tv
It is a work in progress, but works well to get all of the robot fantasy out of your head.  I am building this "robot" with mostly parts from recycled printers and some 3D printed parts.  It is using an L298N as the motor controller.  All driven by a Raspberry Pi that is streaming video and controls between it and the LetsRobot.tv servers. I will be using MQTT to pipe commands from the server to various computers controlling the scene.

In the first boot strap days, it was 'challenged' by the 'internet' robot operators.  my motors were not secured and were dancing around the scene.  Actually somewhat fun.  Today I put together this motor mount design and will be using it to build out the Arcade.

3D CAD designed to be a motor mount

I don't quite know what I will do with this yet, but I would like it to be some form of a remote robot - 'game of skill'.  it is fun to see some form of a battle or skill challenge performed by the remote operators.

I am open to suggestions for game ideas!  :)

Friday, June 1, 2018

Hello World!

"Hello World" is the ubiquitous start to all things technical! It is the classic program that beginners write to understand what the most 'basic' program is. For the maker working with physical computing, "Blinky light" is stated as the "Hello World" equivalent. Now that we have makers by the droves jumping into Robotics and Mechatronics, what would be the bench mark for "Hello World"? Perhaps, it should be the ever popular "RC Car with Camera Rover".

Here is my "Hello World!" in Robotics.  "Polybot" - the Rover:



It is comprised of fairly standard components for this type of build:
  • Chassis of an old RC car. Removed all of the existing controller components. Kept the physical chassis, wheels, struts, drive motor, steering motor, and awesome bumper.
  • Raspberry PI for the brains.  Command, control, communications, video, etc.
  • Off-the-Shelf USB webcam
  • Double H-Bridge for motor control
  • Portable power: 4XAA battery pack for the motors, USB Power bank for the RPI
  • 3D printed frame to attach the RPI, Camera, and stow away the power bank
For hardware, this is a pretty basic set up. It does not get much simpler. One of the challenges for a beginner is how power is managed. In this case, by having a separate power source for the motors, separate from the RPI, solves the issue of having to use a Buck Converter to reduce the voltage for the RPI.

Of course, its the control of the Rover that makes it a Robot vs. a RC car. I used Python as the base language to set up the code to drive my Rover.  Python's control of the GPIO of the PI is simple enough to control the car. The drive software takes a simple command of forward/reverse, left/right/straight combinations. 

To add my own twist to the Polybot Rover, I decided to use MQTT as a protocol to communicate with the Rover and provide it with commands. This would allow me to create different clients that can provide the command signals to the rover.  By nature that would mean that the rover could be controlled by humans - or a massive Totally Not Evil Robot Army Controller, mewha ha ha. But, I digress.



To use MQTT, I created a 'Base Station' that hosted a Mosquito Broker. The Rover's command software is a MQTT Listener written in Python. And I wrote a Flask Web App, that uses Socket IO and MQTT Client to input the commands and publish them to the broker. 

The Flask, Socket IO, and MQTT are all Python libraries and easy to program. The interface used a simple 6 quadrant set of buttons for Left Forward, Forward, Right Forward, Left Reverse, Reverse, and Right Reverse. It also contained an input field to designate the 'distance/time' to be traveling. The MQTT messages were a very simple LF3 - Left Forward Three, command protocol.

One advantage of using Flask for the Web App is that it is immediately viable for use on a mobile device. The device just needs to be on the same Wifi Network as the Rover, and then connect to the Web App.



Web cam streaming, was provided by using FFMPEG to capture video from the camera and pipe it to stdout. This allows for the ability to create a lifestream on YouTube. This streaming ability has a significant lag, but it really cool to see your Rover on YouTube.  Cool, but not quite FPV! :)

The best part of doing a "Hello World" is that is gets you actually started 'doing it'!  Once you get comfortable with the very most basic, then you can start making your really cool ideas become reality.

There are lots of ways to take the Polybot Rover forward.
  • Add better portable power, with more energy for the motors
  • integrated streaming on the Web App
  • Status messages, Sensor feedback
  • Commands, servos, and actuators on the Rover.  Grippers!!
  • Autonomous control, AI
  • make 10k more rovers, and create a Totally Not Evil Robot Army (ma haha)!!
its only limited by imagination! :)