The Problem
Students and researchers need ready‑to‑run Python implementations of core robotics algorithms (localization, mapping, SLAM, path planning, control). Existing textbooks often omit runnable code or provide fragmented snippets, forcing users to re‑implement the logic and waste time on debugging.
What This Does
The repository supplies self‑contained Python scripts that demonstrate a full spectrum of classic algorithms. The PathPlanning/ folder (92 files) hosts A*, D*, RRT*, Hybrid A*, and Frenet‑optimal planners; SLAM/ and Localization/ implement EKF, FastSLAM, particle filters, and ICP. 3‑D drone trajectory following lives in AerialNavigation/drone_3d_trajectory_following/ and arm‑navigation examples under ArmNavigation/.
Key entry points are:
PathPlanning/DStar/dstar.py– definesrun()(line 159) that builds a grid map, invokes the D* planner, and visualises the result.AerialNavigation/drone_3d_trajectory_following/drone_3d_trajectory_following.py–main()(line 192) creates aQuadrotorinstance, runs a simulation loop, and calls the genericplot()helper (77 callers).
All algorithms share utility modules utils/angle.py (26 importers) and utils/plot.py (8 importers), which centralise geometry calculations and Matplotlib visualisation.
How It Is Wired
Execution starts in a concrete script, e.g. PathPlanning/DStar/dstar.py → run(). run() constructs a map, calls DStar class methods (cost, set_state) and then invokes plot() from utils/plot.py. The call graph shows plot is the most frequently called internal function (77 distinct callers), giving it the widest blast radius; any change here ripples through most planners and visualisations.
main in the drone example follows a similar pattern:
- Instantiate
Quadrotor(AerialNavigation/.../Quadrotor.py). - Loop over time steps, calling
calculate_position,calculate_velocity, andcalculate_acceleration. - Each step ends with
plotto render the trajectory.
The internal call graph records 1 607 intra‑repo call edges; notable hot spots are flatten (16 callers) and Node (24 callers) used by the Time‑Based Path Planning submodule. No circular import cycles were detected, but utils/angle.py is a hub (26 importers), so stability there is critical. Deep nesting (max indentation depth 6) appears in PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py, utils/plot.py, and MissionPlanning/StateMachine/state_machine.py, making those files harder to modify safely.
External interaction is limited to five functions that launch shell commands; the code otherwise stays in‑process and writes only image files for visualisation (e.g., PathPlanning/SpiralSpanningTreeCPP/map/*.png).
How To Use It
# Clone the exact upstream repository
git clone https://github.com/moses-y/PythonRobotics.git
cd PythonRobotics
# Install the declared Python deps (no lockfile, so versions may vary)
pip install -r requirements/requirements.txt
To run a planner:
python PathPlanning/DStar/dstar.py # executes run() → visualises D* path
To simulate the drone demo:
python AerialNavigation/drone_3d_trajectory_following/drone_3d_trajectory_following.py
The docs/Makefile can build the Sphinx documentation (make -C docs html) if you need the textbook‑style narrative.
Real‑World Use
A robotics research team can import a planner directly, e.g.:
from PathPlanning.RRTStar.rrt_star import RRTStar
planner = RRTStar(start, goal, obstacle_map)
path = planner.plan()
The returned path can feed a ROS node’s trajectory controller without further modification, because the data structures are plain Python lists of (x, y) tuples.
Code Health & Issues
Measured findings (static analysis)
- HIGH – Hub module:
utils/angle.py(26 importers). Keep API stable; extract volatile logic. - HIGH – Deep nesting: observed in
PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py,utils/plot.py,MissionPlanning/StateMachine/state_machine.py. Refactor to early returns. - HIGH – Duplicated code: similar 6‑line blocks across multiple
ArmNavigation/files. Consolidate into shared helpers.
Code‑health audit (GitHub Actions)
- HIGH – Pin third‑party actions to commit SHA (
.github/workflows/*). - HIGH – CI does not run the test suite; add a
pyteststep. - MEDIUM – Declare least‑privilege
permissionsforGITHUB_TOKEN(.github/workflows/Linux_CI.yml). - MEDIUM – Add a dependency‑vulnerability scan (e.g.,
dependency-review-action). - MEDIUM – Set
persist-credentials: falseon checkout to avoid credential leakage. - LOW – Set
timeout-minuteson workflow jobs to prevent hangs.
No Dockerfile, no lockfile, and the repository relies on a single requirements.txt, which limits reproducibility.
The Bottom Line
The repo delivers a breadth of well‑organised, runnable robotics algorithms useful for education and rapid prototyping. Its primary limitation is operational hygiene: CI does not execute tests, and dependency management lacks lockfiles and pinned actions, which raises reproducibility and security concerns. Teams comfortable managing their own CI pipeline will find the code valuable; others should first address the health issues before adopting it in production.