Welcome to MicroROS V2 Robot Car repository
6. Mediapipe Gesture Tracking
Mediapipe Gesture Tracking (No-PTZ)
1. Experiment Objective
MediaPipe gesture recognition is used to track the palm while recognizing the gesture category (5 fingers open / 4 fingers / 3 fingers / 2 fingers / 1 finger / fist), and the car rotates to keep the hand at the center of the frame. It supports Tracking mode (rotation only), Follow mode, and Control mode.
2. Experiment Principle
1. Keyword Explanation
| Keyword | Description |
|---|---|
| Gesture Recognition | Computes the extension state of each finger based on MediaPipe hand keypoints, classifying them into 6 categories: 0–5 fingers open and fist |
| Fingertip Counting | Determines whether a finger is open by checking the distance relationship between the fingertip keypoints (numbered 4, 8, 12, 16, 20) and the corresponding finger roots |
| MediaPipe Hands | A lightweight hand keypoint detection model provided by Google that outputs the coordinates of 21 hand keypoints in real time |
| Gesture Control | Maps the recognized gesture category to car motion commands (e.g., 5 fingers forward, fist stop, etc.) |
| PD Control | Proportional-derivative controller that computes the body angular velocity based on the palm center deviation and its rate of change |
| QoS | best_effort (image input + cmd_vel downlink), depth=1 |
2. Technical Architecture
/camera/image_raw (BEST_EFFORT)→ gesture_tracker_node├── Image processing: image conversion → flip → MediaPipe Hands → 21 keypoints → fingersUp() classification└── Body control timer (10Hz): pixel error → PD angular velocity (track/follow) / gesture command mapping (control)
Requires a MediaPipe Python environment (ROS 2 and workspace environment).
3. Core Topic Quick Reference
Firmware Downlink
| Topic | Message Type | QoS | Field | Range | Direction |
|---|---|---|---|---|---|
/cmd_vel | geometry_msgs/Twist | best_effort + keep_last(1) | linear.x | -0.20~0.20 m/s | += forward, −= backward |
angular.z | -0.60~0.60 rad/s | += turn left, −= turn right |
3. Experiment Steps
1. Hardware Preparation
| Hardware | Requirement |
|---|---|
| PTZ version | ❌ |
| No-PTZ version | ✅ |
| Required peripheral | ESP32 camera (bracket-mounted) |
2. Start the Agent + Camera + Joint Model (Terminal 1)
xxxxxxxxxxros2 launch microros_v2_bringup car_base.launch.py
3. Start Gesture Tracking (Terminal 2)
Tracking mode (rotation only, showing the gesture category):
xxxxxxxxxxros2 launch microros_v2_no_ptz_visual_control_pkg gesture_tracker.launch.py
4. Operation Instructions
| Key | Function |
|---|---|
| Space | Toggle tracking/standby state |
| q / Q / ESC | Exit the program |
4. Experiment Phenomenon
- When the hand moves in the frame, the car automatically rotates to track it
- The frame displays the current gesture category in real time (5 fingers open / 4 fingers / 3 fingers / 2 fingers / 1 finger / fist)
- The 21 hand keypoints and skeleton connections are visualized
- Follow mode: backs away when the hand moves closer and moves forward when it moves away
- Control mode: different gestures drive different action commands
5. Code Explanation
Source path:
- Launch (track):
~/microros_ws/src/microros_v2_no_ptz_visual_control_pkg/launch/gesture_tracker.launch.py- Node source:
~/microros_ws/src/microros_v2_no_ptz_visual_control_pkg/microros_v2_no_ptz_visual_control_pkg/gesture_tracker_node.py- Hand detector:
~/microros_ws/src/microros_v2_no_ptz_visual_control_pkg/microros_v2_no_ptz_visual_control_pkg/hand_detector.py
1. Core Node Analysis
gesture_tracker_node adds gesture classification on top of hand_tracker_node. Core differences:
- fingersUp(): computes the extension state of the 5 fingers
[thumb, index, middle, ring, pinky] - Gesture classification: maps to 6 categories based on the number of extended fingers and specific positions
- Control mode: gesture categories are directly mapped to car commands (5 fingers forward, fist stop, etc.)
2. Key Parameters
Parameter definition file:
- Launch:
~/microros_ws/src/microros_v2_no_ptz_visual_control_pkg/launch/gesture_tracker.launch.py- Node:
~/microros_ws/src/microros_v2_no_ptz_visual_control_pkg/microros_v2_no_ptz_visual_control_pkg/gesture_tracker_node.py
| Parameter | Type | Default | Description |
|---|---|---|---|
hand_detection_confidence | float | 0.8 | Hand detection confidence threshold |
deadband_x_pixel | float | 50.0 px | Horizontal deadband |
angular_kp | float | 1.2 | Body angle PD proportional coefficient |
angular_kd | float | 0.55 | Body angle PD derivative coefficient |
max_angular_z | float | 0.6 rad/s | Maximum body steering speed |
lost_frame_threshold | int | 5 | Consecutive lost-frame tolerance threshold |
enable_distance_follow | bool | false | Whether to enable distance following |
3. Node Description
| Node | Package | Description |
|---|---|---|
gesture_tracker_node | microros_v2_no_ptz_visual_control_pkg | MediaPipe gesture recognition + tracking with finger-count classification |
6. Common Problems
| Problem | Cause | Solution |
|---|---|---|
| Gesture is not recognized | Insufficient lighting or the hand is too far | Improve ambient lighting and move closer to the camera |
| Wrong gesture classification | Insufficient fingertip detection accuracy | Keep the fingers separated and clearly visible |
| Control mode does not respond | Gesture recognition confidence is too low | Lower the hand_detection_confidence threshold |