Roban2 Docs
Roban2 (ROS1) Legacy VersionsFeature ExamplesGeneral Examples

Face Tracking Example

Example Description

This example is a ROS node that implements vision-based active head tracking for a humanoid robot. It uses the YOLOv8 model to perform face detection on the live camera image stream, and communicates with the robot's low-level controller through ROS topics, driving the head joints to keep the detected face locked in the center of the frame.

  • The example code is located at: ~/kuavo-ros-opensource/src/manipulation_nodes/planarmwebsocketservice/scripts/face_track_demo/
  • Main files:
    • Face tracking main program: main.py
    • YOLOv8 face recognition model: yolov8n-face.pt

File Structure

face_track_demo/
├── main.py         # 人脸追踪主程序
└── requirements.txt
└── yolov8n-face.pt # YOLOV8面部识别模型

Running Steps

  1. Terminal 1: Start the lower-level controller program

    cd ~/kuavo-ros-opensource
    source devel/setup.sh # 进入每个终端都要执行
    roslaunch humanoid_controllers load_kuavo_real.launch
  2. Terminal 2: Start the robot vision feedback node

    roslaunch realsense2_camera rs_camera.launch 
  3. Terminal 3: Run the face tracking node

    python ~/src/manipulation_nodes/planarmwebsocketservice/scripts/face_track_demo/main.py

    After startup, place your face within the camera's field of view, and the robot's head will begin tracking.

ROS Interfaces

Published Topics

  • /robot_head_motion_data
    • Message type: kuavo_msgs/robotHeadMotionData
    • Description: Publishes the target motion commands for the head (Yaw and Pitch angles), used to directly drive the head motors.
  • /camera/detected_face
    • Message type: sensor_msgs/Image
    • Description: Publishes the image with the detected face bounding box.

Subscribed Topics

  • /camera/color/image_raw
    • Message type: sensor_msgs/Image
    • Description: Subscribes to the raw color image stream from the camera on top of the robot's head, which serves as the input for face detection.
  • /sensors_data_raw
    • Message type: kuavo_msgs/sensorsData
    • Description: Raw sensor data published by the physical robot or the simulator. This node parses the current angles of the head Yaw and Pitch joints from it, as the current-state input for PID control.

PID Control Parameters

The core control logic of this example does not depend on external data files; it is determined by the internal PID controller parameters, which can be tuned according to actual performance.

# Yaw 轴 (左右转动) PID 参数
self.yaw_pid = PID(kp=0.015, ki=0.00, kd=0.001, output_limits=(-90, 90))

# Pitch 轴 (上下转动) PID 参数
self.pitch_pid = PID(kp=0.015, ki=0.00, kd=0.001, output_limits=(-20, 30))

Notes

  1. Manually publishing the /robot_head_motion_data kuavo_msgs/robotHeadMotionData topic can return the robot's head to the neutral position.

    rostopic pub /robot_head_motion_data kuavo_msgs/robotHeadMotionData "joint_data: [0,0]"

    In the two-element array published, the first number is the yaw angle and the second is the pitch angle. When standing in front of the robot, turning left is negative and turning right is positive.

  2. Make sure the input image resolution is 640×480; an incorrect resolution will prevent the face tracking program from running properly.