Skip to main content

๐ŸŸฉ Object Detection Node

The Object Detection Node is the vision brain of your robot โ€” it processes images from the onboard camera, detects objects using YOLOv8, estimates their positions, and publishes them to ROS2 so other nodes (like navigation and manipulation) can act.


๐Ÿ” What It Does & How It Worksโ€‹

Hereโ€™s a high-level summary of the main logic in object_detector.py:

  • Initializes ROS2 node and loads YOLOv8 model weights.
  • Subscribes to RGB and depth image topics.
  • For each incoming frame:
    • Runs YOLOv8 inference to detect objects.
    • For each detection, extracts bounding box, class, and confidence.
    • Uses depth data to estimate the 3D position of each detected object.
    • Publishes:
      • Target pose (geometry_msgs/PoseStamped) for navigation/manipulation.
      • Detection list (bounding boxes, classes, confidences).
      • Annotated image with detection overlays.
  • Handles configuration via parameters (e.g., depth limits, YOLO weights).
  • Includes error handling for missing images, sync issues, and model loading.

See the source code for implementation details.

  1. Subscribes to RGB and depth image topics from the Orbbec DaBai depth camera.
  2. Runs YOLOv8 inference on each frame to detect objects in real time.
  3. Estimates 3D positions of detected objects using depth data.
  4. Publishes detections:
    • /target_pose โ†’ geometry_msgs/PoseStamped (used by Mission Manager & Navigation)
    • /detections โ†’ list of bounding boxes, class names, confidence scores
    • /image_bbox โ†’ image with overlayed detection boxes and labels

โš™๏ธ Setup & Configurationโ€‹

1. Requirementsโ€‹

  • Python โ‰ฅ 3.8
  • ROS2 Foxy workspace
  • Ultralytics YOLOv8 installed
  • Depth camera drivers running

2. Installationโ€‹

Clone the object detector package into your workspace:

cd ~/limo_ws/src
git clone https://github.com/krish-rRay23/LIMO_COBOT_PROJECT/blob/main/src/object_detector/
cd ~/limo_ws
colcon build
source install/setup.bash

3. Configuration Parametersโ€‹

Inside object_detector.py:

MIN_DEPTH_METERS = 0.15     # Ignore objects closer than 15cm
MAX_DEPTH_METERS = 4.0 # Ignore objects further than 4m
APPROACH_DIST = 0.30 # Distance to stop before object
YOLO_WEIGHTS = "runs/detect/train/weights/best.pt"

You can adjust these values in the launch file or node parameters.


โ–ถ๏ธ Usage Instructionsโ€‹

Start the camera drivers:

ros2 launch orbbec_camera dabai.launch.py

Run the Object Detection Node:

ros2 run object_detector yolo_detector

Verify outputs:

  • View annotated detections in RViz or rqt_image_view
  • Monitor detection topic:
ros2 topic echo /detections
Pro Tip

For full autonomous mode, launch with full_system.launch.py โ€” it will auto-start the detector and integrate with navigation/manipulation.


๐ŸŽฏ Training Your Own YOLO Modelโ€‹

To detect new objects:

1. Collect Imagesโ€‹

  • Use the robot camera or a smartphone
  • Capture from multiple angles, lighting conditions, and distances

2. Label Dataโ€‹

  • Use LabelImg or Roboflow

3. Train YOLOv8โ€‹

yolo task=detect mode=train model=yolov8n.pt data=your_data.yaml epochs=50 imgsz=640

4. Deploy Weightsโ€‹

  • Copy best.pt to the robot
  • Update YOLO_WEIGHTS path in object_detector.py or launch file

๐Ÿ›  Troubleshooting Tipsโ€‹

ProblemPossible CauseSolution
No detectionsWrong weights or incorrect camera topicCheck YOLO_WEIGHTS path & camera topics
Poor accuracyDataset too small / poorly labeledCollect more varied training data
Depth pose is wrongDepth/RGB not syncedUse message filters for synchronized topics
Slow FPSModel too large for hardwareUse smaller YOLO model (e.g., yolov8n.pt)
Node crashes on startupMissing dependenciesReinstall ultralytics & required packages
Important

Always verify your depth alignment and TF transforms โ€” incorrect transforms will cause wrong navigation goals.


๐Ÿ“š Learn Moreโ€‹


๐ŸŽฏ Next Stepsโ€‹