How to Build an AMR Using Python, ROS, and OpenCV

Building an Autonomous Mobile Robot (AMR) has transitioned from a high-budget industrial endeavor to a structured engineering project accessible to developers, thanks to the maturation of the Robot Operating System (ROS). By combining Python for high-level logic, ROS for middleware communication, and OpenCV for computer vision, you can create a robot capable of navigating complex environments without human intervention.

Success in this project requires a deep understanding of how these three pillars interact: ROS handles the “plumbing” between hardware and software, Python provides the scripting flexibility, and OpenCV acts as the robot’s eyes.

Your reading tools

  • Simplify
    Any section in plain language
  • Summarize
    The key points at a glance
  • FAQ
    Quick answers to common questions
  • New
    i
    Spotted a mistake? We fix it in minutes!

Written with AI from the sources listed at the end.

Table of Contents

  1. 1. Hardware Fundamentals: The Mobile Base
  2. 2. Setting Up the Software Stack: ROS 2 and Python
  3. 3. Computer Vision Integration with OpenCV
  4. 4. Navigation and SLAM (The AMR Core)
  5. 5. The Control Loop
  6. Summary of Key Takeaways
  7. Sources

1. Hardware Fundamentals: The Mobile Base

An AMR differs from a basic remote-controlled car because it must perceive its surroundings and make its own decisions. Before writing code, you need a robust physical platform.

  • Kinematics: Most DIY and mid-range AMRs use differential drive (two wheels and a caster). This is the simplest to program in ROS using the diff_drive_controller plugin.
  • Sensors: For true autonomy, you need a LiDAR (Standard for SLAM) or a Depth Camera (like the Intel RealSense).
  • The Brain: A Raspberry Pi 4 or 5 (8GB) or an NVIDIA Jetson Orin Nano is recommended; the Jetson is preferred if you plan to run heavy OpenCV-based object detection. Avoid the original Jetson Nano: it is limited to JetPack 4, whose support ended in November 2024 [6].

If you are new to the hardware side, you might want to start with our foundational guide on how to build an autonomous mobile robot to understand the structural requirements before diving into the Python stack.

Table: Core Hardware Selection for Your AMR
ComponentRecommended HardwareRole in System
The BrainNVIDIA Jetson Orin Nano or Raspberry Pi 4/5High-level logic and Vision
SensorsLiDAR or Intel RealSenseSLAM and Obstacle Avoidance
Drive BaseDifferential Drive (2 Wheels)Standard mobility and control

2. Setting Up the Software Stack: ROS 2 and Python

ROS 1 reached its end of life with Noetic on May 31, 2025 [5]; ROS 2 (Jazzy, or Humble until May 2027) is the standard, due to improved security and real-time capabilities [2].

The Workspace Setup

Python is the primary language for writing high-level ROS nodes. You must initialize a workspace and create a package:

mkdir -p ~/amr_ws/src cd ~/amr_ws/src ros2 pkg create --build-type ament_python my_amr_package --dependencies rclpy sensor_msgs cv_bridge

rclpy is the Python library for ROS 2. sensor_msgs allows your robot to read laser scans and camera feeds, and cv_bridge is the critical link that converts ROS image messages into a format OpenCV can process.

3. Computer Vision Integration with OpenCV

OpenCV allows your AMR to perform tasks like lane following, obstacle identification, or visual docking.

Visual Processing Node

Rather than just “seeing” pixels, your Python node uses OpenCV to filter data. A common use case is color-based tracking (e.g., following a green line).

  1. Capture: Subscribe to the /image_raw topic.

  2. Convert: Use cv_bridge to turn the feed into an OpenCV BGR image.

  3. Process: Apply a Gaussian blur and an HSV mask to isolate specific features.

  4. Publish: Translate the feature’s position into move commands sent to the /cmd_vel topic.

For those interested in more creative applications of these vision tools, the same underlying principles of image processing can be found in our guide on how to create anime with AI.

Visual Node Data FlowDiagram showing the flow from /image_raw through CV_Bridge to OpenCV processing./image_raw (ROS)cv_bridge TransformOpenCV Processing/cmd_vel

The “Autonomous” in AMR comes from its ability to map a room and find its way through it. In the ROS ecosystem, this is handled by the Nav2 framework.

  • SLAM (Simultaneous Localization and Mapping): Use the slam_toolbox package. As the robot moves, it uses LiDAR data to build a map, saved as an image with a .yaml description [3].
  • Path Planning: Nav2 uses “Behavior Trees” to decide how to reach a goal. When a person walks in front of the robot, it replans around them, and if it gets stuck the tree falls back on “recovery behaviors” such as spinning in place or backing up.
  • Localization: The AMCL (Adaptive Monte Carlo Localization) node compares real-time laser scans against the saved map to tell the robot exactly where it is.

5. The Control Loop

In your Python scripts, you will likely implement a PID (Proportional-Integral-Derivative) controller. This ensures that the robot accelerates smoothly rather than jerking toward a target. Poorly tuned motor control also degrades the wheel odometry that SLAM and localization rely on, so tune it before blaming the navigation software.

ROS 2 Releases and When Their Support Ends

Which ROS 2 release should a new robot use, and until when is it supported? Below are 7 distributions, read in the official ROS 2 documentation on between 3 November 2026 and 2 December 2026.

ROS 2 distributions (checked between 3 November 2026 and 2 December 2026)
DistributionReleasedSupport endsLong-term supportUbuntu it targets
Lyrical LuthMay 22, 2026May 2031YesUbuntu 26.04 (Resolute)
Kilted KaijuMay 23, 2025November 30, 2026NoUbuntu 24.04 (Noble)
Jazzy JaliscoMay 23, 2024May 2029YesUbuntu 24.04 (Noble)
Iron IrwiniMay 23, 2023December 4, 2024NoUbuntu 22.04 (Jammy)
Humble HawksbillMay 23, 2022May 2027YesUbuntu 22.04 (Jammy)
Galactic GeocheloneMay 23, 2021November 2022NoUbuntu 20.04 (Focal)
Foxy FitzroyJune 5, 2020June 20, 2023YesUbuntu 20.04 (Focal)

How to read it

  • Long-term support (LTS) releases come out in even years and are supported for five years, like the Ubuntu LTS they target; the releases of odd years are supported for about a year and a half.
  • Kilted Kaiju’s own page gives November 30, 2026 for its end of support, where the distributions table rounds it to December 2026.

Checked on 2 December 2026: compiled with AI from the official sites listed in the sources, each figure confirmed by two separate searches of the official site or on the page itself; every month the figures are checked again, automatically. Rules and prices change; the official site always has the last word.

Sources of this table: 7 official pages, checked between 3 November 2026 and 2 December 2026
  1. ROS 2 documentation (Lyrical): Distributions, checked 2 December 2026
  2. ROS 2 documentation: Kilted Kaiju, checked 3 November 2026
  3. ROS 2 documentation: Distributions, checked 2 December 2026
  4. REP 2000: ROS 2 releases and target platforms, checked 2 December 2026
  5. ROS 2 documentation: Distributions, checked 2 December 2026
  6. ROS 2 documentation: Galactic Geochelone, checked 2 December 2026
  7. ROS 2 documentation: Distributions, checked 2 December 2026

Summary of Key Takeaways

Building an AMR is a modular process where hardware, middleware, and logic must be perfectly synchronized. By using ROS 2 as the foundation, you gain access to professional-grade navigation stacks that handle the heavy mathematical lifting of autonomy.

Action Plan

  1. Select Hardware: Use a differential drive base with an NVIDIA Jetson for optimal OpenCV performance.
  2. Install ROS 2: Choose a Long Term Support (LTS) version such as Jazzy (supported until May 2029); Humble ends in May 2027.
  3. Develop Vision Nodes: Write Python scripts using OpenCV to detect obstacles or follow markers.
  4. Implement SLAM: Use slam_toolbox to generate a map of your environment.
  5. Configure Nav2: Use the Nav2 stack to manage goal-setting and obstacle avoidance.
  6. Refine: Tune your Python-based PID controllers to ensure smooth movement.

While simpler platforms like LEGO Mindstorms EV3 are excellent for learning logic, a true Python/ROS AMR prepares you for real-world robotics development in warehouse automation and service industries.

Table: Summary of ROS-Based AMR Architecture
Stack LayerPrimary ToolKey Function
MiddlewareROS 2 (Humble/Jazzy)Node communication and messaging
VisionOpenCV & cv_bridgeObject detection and feature extraction
Nav CoreNav2 & SLAM ToolboxPath planning and mapping
ControlPython (rclpy)Scripting and PID motor control

Sources