Building a Real-Time Object Detection Pipeline with ROS 2 and YOLOv11

Build a production-ready robotic perception pipeline using ROS 2 and YOLOv11. Learn threaded inference, ByteTrack integration, and ONNX optimization.

MiHiR SEN
MiHiR SEN
·2 min read
Building a real-time robotic perception pipeline requires decoupling data ingestion from model inference to prevent system lag. Using ROS 2 with YOLOv11, developers can implement a threaded architecture that drops stale frames and maintains tracker accuracy. Exporting the model to ONNX format is critical for achieving the necessary performance on edge hardware. Perception is fundamentally a systems engineering challenge.

The Challenge of Robotic Perception

Building a robotics system that can see and respond to the world is challenging. The hard part is not training a detection model. The difficulty lies in making that model run reliably inside a real robotic software stack in real time, without failing when hardware constraints or timing issues arise.

Architecting the Pipeline

A robust perception pipeline requires clear separation of concerns. The system must capture raw image frames, run inference, track objects across frames, and validate detections before passing them to navigation logic.

  1. Camera Publisher: Captures frames from a simulator like CARLA and publishes them as ROS 2 messages.
  2. Perception Node: Runs YOLOv11 inference in a dedicated thread to avoid blocking the ROS 2 executor.
  3. Tracker: Integrates ByteTrack to associate detections across frames, giving each object a stable identity.
  4. Validator: Adds a confidence gating layer to prevent low-quality detections from corrupting downstream logic.

Decoupling Ingestion and Processing

ROS 2 processes subscriber callbacks on a single executor thread by default. If YOLO inference happens inside the callback, it blocks the thread, causing the system to process stale frames. The solution is to decouple ingestion from processing. The callback places the incoming frame into a bounded queue and returns immediately. A separate thread pulls from this queue and runs inference. If the queue is full, new frames are dropped, ensuring the tracker always sees the most current state of the world.

Optimizing for Edge Deployment

Running PyTorch models directly on edge hardware is often too slow. Exporting the YOLOv11 model to the Open Neural Network Exchange format is a critical step. ONNX Runtime, potentially accelerated by TensorRT, applies kernel fusion and layer optimization. This compilation specifically for the target GPU can be the difference between a usable 30 FPS pipeline and an unusable one.

Robotics perception is fundamentally a systems problem, not just a model problem. A well-trained model is necessary, but what matters in production is whether the pipeline handles timing correctly and degrades gracefully under load.