A ROS2 package that enables a robot to detect and follow a human in real-time using a camera and YOLOv8 object detection.
Developed for autonomous robots running ROS2 Humble (tested on Ubuntu 22.04, Python 3.10).
This project implements a human-following robot system using YOLOv8 for real-time person detection and ROS2 for robot control and communication. The system processes camera images to detect humans, estimates their position, and publishes movement commands to make the robot follow the detected person autonomously.
It consists of two main ROS2 nodes:
human_position_publisher — runs YOLOv8 to detect humans and publishes their bounding box coordinates.
follow_human — subscribes to detected positions and controls the robot to follow the target at a safe distance.
Optional visualization using RViz2 allows monitoring camera input, detection results, and robot motion in real-time.
Make sure you have:
sudo apt install ros-humble-cv-bridge ros-humble-rclpy ros-humble-sensor-msgs
sudo apt install ros-humble-geometry-msgs ros-humble-launch ros-humble-rviz2Install ROS dependencies:
sudo apt install ros-humble-cv-bridge ros-humble-image-transport python3-colcon-common-extensionsInstall the necessary Python libraries:
cd robot_detect
pip install -r src/requirements.txt- Git clone directory
git clone https://github.com/is-buiquocdoanh/robot_detect.git- Build
cd robot_detect
colcon build
source install/setup.bash- Launch gazebo simulator and robot model (terminal 1)
cd robot_detect
source install/setup.bash
ros2 launch robot_simulation simulation.launch.pyAfter running, gazebo will be displayed with pre-set environment, along with differential robot model.
- Launch models yolov8 (terminal 2)
cd robot_detect
source install/setup.bash
ros2 launch robot_recognition launch_yolov8.launch.py- Start the YOLOv8 detector node
yolov8_ros2_pt.py - Get image from topic
/camera/image_raw - Detect people and output bounding box coordinates to topic
/inference_result - Display detection log in terminal (position and confidence)
- Launch follow human
cd robot_detect
source install/setup.bash
ros2 launch follow_human follow_human.launch.pyThis command will launch the entire “Follow Human” system, including:
- Node
human_position_publisher: detects and outputs the position of the person from the camera. - Node
follow_human: controls the robot to move according to the detected person. - (Optional) Open
RViz2to visually observe the camera and the direction of the robot's movement.
| Topic Name | Message Type | Description |
|---|---|---|
/camera/image_raw |
sensor_msgs/Image |
Input image stream from the camera |
/human_positions |
yolov8_msgs/HumanPositionArray |
Detected human positions from YOLOv8 |
/cmd_vel |
geometry_msgs/Twist |
Velocity command output for robot movement |
| Parameter | Description | Default Value |
|---|---|---|
target_area |
Target bounding box area — smaller value means the robot keeps a farther distance | 0.15 |
center_x |
Image center position (for a 640px wide image) | 320.0 |
linear_k |
Linear velocity gain — controls forward/backward movement speed | 0.3 |
angular_k |
Angular velocity gain — controls rotation speed toward the target | 0.3 |
stop_threshold |
Minimum movement threshold — smaller value reduces oscillation near the target | 0.03 |
- Name: BUI QUOC DOANH
- Email: doanh762003@gmail.com
- Github: is-buiquocdoanh
This project is released under the MIT License
