https://github.com/radithsandeepa/robot-path-visualizer
Welcome to Robot Path Visualizer! This tiny project uses Python, Pygame, and NumPy to replay a precomputed trajectory (x, y, θ). It rotates a robot sprite frame-by-frame and draws a trail, making it handy for diff-drive path playback, simulation demos, and quick visual debugging of robotics experiments.
https://github.com/radithsandeepa/robot-path-visualizer
animation numpy pygame python robot-simulation robotics trajectory-visualization
Last synced: 9 months ago
JSON representation
Welcome to Robot Path Visualizer! This tiny project uses Python, Pygame, and NumPy to replay a precomputed trajectory (x, y, θ). It rotates a robot sprite frame-by-frame and draws a trail, making it handy for diff-drive path playback, simulation demos, and quick visual debugging of robotics experiments.
- Host: GitHub
- URL: https://github.com/radithsandeepa/robot-path-visualizer
- Owner: RadithSandeepa
- Created: 2025-09-05T02:30:26.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-05T03:14:29.000Z (9 months ago)
- Last Synced: 2025-09-05T04:21:20.134Z (9 months ago)
- Topics: animation, numpy, pygame, python, robot-simulation, robotics, trajectory-visualization
- Language: Python
- Homepage:
- Size: 210 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Robot Path Visualizer (Pygame)
This project demonstrates a tiny Python app that replays a precomputed robot trajectory `(x, y, θ)` using **Pygame** and **NumPy**. It rotates a robot sprite along the path and draws a trail, handy for quick demos and visual debugging of differential-drive motion.
## Summary
- Loads `simulationData.npy` → shape **(N, 3)** as columns: **x**, **y**, **theta_rad**.
- Converts `theta` (radians) to degrees for sprite rotation.
- Animates `robotImage.png` (50×50) across a `1200×800` window.
- Draws a yellow polyline trail of visited points.
## Files
- differential_robot.py → Generates simulationData.npy using a diff-drive ODE model + quick plots
- simulation_DDRobot.py → Visualizes the saved trajectory with Pygame (rotating sprite + trail)
- simulationData.npy → Generated trajectory file (created by differential_robot.py)
- robotImage.png → Robot sprite (will be scaled to 50x50)
- README.md
## What it does
### 1) `differential_robot.py` - Simulation
- Defines robot params: wheel radius `r` and wheelbase `s`.
- Sets wheel angular velocities `ΔL(t)` and `ΔR(t)`.
- Simulates the kinematics with SciPy ``` `odeint`:
\[
\dot{x} = \frac{r}{2}\cos(\theta)\,(\Delta_R + \Delta_L) \quad
\dot{y} = \frac{r}{2}\sin(\theta)\,(\Delta_R + \Delta_L) \quad
\dot{\theta} = \frac{r}{s}(\Delta_R - \Delta_L)
\]```
- Saves the result to **`simulationData.npy`** with shape `(N, 3)` = `[x, y, theta]` (theta in **radians**).
- Shows quick Matplotlib plots for sanity-check.
### 2) `simulation_DDRobot.py` - Visualization
- Opens a `1200×800` Pygame window.
- Loads `simulationData.npy`, converts `theta` to degrees (and flips sign for Pygame’s rotation).
- Draws `robotImage.png` at `(x[i], y[i])` with correct rotation and a yellow path trail.
> **Coordinate system:** Pygame’s origin is top-left, **y increases downward**.
> If you want a math-style y-up view, pre-flip `y` in your data before saving.
## Screenshots


## Requirements
```bash
python -m pip install -r requirements.txt
```
- NumPy, SciPy, Matplotlib, Pygame
## Run
1) Generate the trajectory
```bash
python differential_robot.py
```
- This creates simulationData.npy and shows plots.
2) Visualize the trajectory
```bash
python simulation_DDRobot.py
```
- Make sure robotImage.png is in the same folder.
## Data Format
### simulationData.npy: NumPy array with shape (N, 3)
- Column 0 → x (pixels)
- Column 1 → y (pixels)
- Column 2 → theta (radians)
