A technical walkthrough of an autonomous human-following module built with ROS, OpenCV, and the Google MediaPipe machine learning framework.
Building autonomous mobile robots requires a seamless blend of robust hardware pipelines and efficient computer vision algorithms. In this technical walkthrough, we're breaking down how to implement an autonomous human-following module on Elephant Robotics' myAGV platform using ROS, OpenCV, and the Google MediaPipe machine learning framework.
Prerequisites: System Initialization
Before deploying any high-level dispatch scripts, the myAGV platform requires its low-level hardware communication layers to be actively initialized.
If this is your first time booting the platform, you must complete the primary network configuration and basic dependencies installation. Please visit the official Elephant Robotics myAGV Basic Setup Guide to prepare your environment. Once your system is configured, return here for the next steps.
By combining real-time edge processing with intelligent positional kinematics, we can transform the myAGV chassis into a responsive, human-tracking system that maintains a safe and comfortable distance from the user.
Here is a comprehensive breakdown of the core mechanics powering the module.
Understanding the Vision Pipeline: Edge-Optimized Pose Estimation
For robotic platforms processing data on the edge, standard full-body bounding box models can be computationally expensive and prone to jitter. MediaPipe solves this challenge by extracting lightweight structural landmarks.
In our tracking script, the computer vision parameters are explicitly tuned for optimal edge performance:
- Node Initialization: The pipeline starts by spinning up a dedicated ROS node named multi_person_follower to manage the logic stream.
- Model Efficiency: The mp.solutions.pose tracking model is instantiated with model_complexity=0 to ensure high frame rates on edge hardware. Both min_detection_confidence and min_tracking_confidence are set to 0.5, providing a balanced threshold for recognizing and maintaining a lock on the user.
- Downscaling for Speed: Incoming 1080p camera frames are resized down to a 320x240 resolution before any mathematical processing occurs, drastically reducing the computational load.
- Torso Targeting: Instead of tracking erratic hand or head movements, the script calculates the precise X-axis center of the user's torso by averaging the location of four stable structural landmarks (shoulders at points 11 and 12; hips at points 23 and 24).
Motion Kinematics: Smoothed Tuning & Range Maintenance
Translating spatial landmark data into smooth wheel velocities is critical to avoiding structural whiplash or physical collisions with the user. The script approaches control through two distinct lenses:
-
Dynamic Angular Alignment: The code tracks the displacement (error_x) between the calculated torso center and the absolute camera center line (0.5 in normalized space).
- The Deadzone: To prevent the chassis from aggressively twitching left and right, an angular deadzone is implemented. If the alignment error is less than 0.05, rotational commands are ignored (0.0).
- Rapid Correction: If the user steps outside this deadzone, a high gain multiplier of -2.5 is applied, forcing the AGV to turn quickly and realign.
-
Proximity Boundaries: Instead of using an external LiDAR sensor, the system dynamically gauges distance by measuring the perceived pixel width between the user's shoulders.
- Chasing: If the shoulder width drops below 50 pixels, the AGV drives forward at a linear velocity of 0.2 m/s to catch up.
- Recoiling: If the width expands past 80 pixels, the chassis safely reverses at -0.2 m/s to preserve its operational buffer zones and maintain personal space.
- Stationary: When hovering within the 50–80 pixel sweet spot, linear velocity is zeroed out (0.0 m/s).
Real-Time Augmented Telemetry
To streamline testing and diagnostics, the node draws localized telemetry strings directly onto the downscaled visual matrix window:
- Center Line (Blue): A static visual reference line drawn down the exact middle of the frame (x=160).
- Target Line (Green): A dynamic line that tracks the user's calculated torso center, giving instant visual confirmation of the alignment error and system latency.
Deployment & Execution Checklist
Ready to run this build on your hardware environment? Ensure your system workspace is sourced, your dependencies (official page) are linked, and execute the following stack sequence across independent terminals:
-
Initialize the Base Kinematics & Odometry Layer:
Bashroslaunch myagv_odometry myagv_active.launch -
Boot up the Astra Pro Plus 3D Camera Node:
Bashroslaunch orbbec_camera astra_pro_plus.launchDeveloper Note: Double-check that your CvBridge subscriber topic string points accurately to the Astra Pro Plus RGB broadcast node, typically mapping to /camera/color/image_raw or /camera/rgb/image_raw depending on your environment package schema.
-
Run the Follower Module Node:
Code is available here.
Bashpython3 human_following_jm.py
Initial screen is shown as follows, a separate window opens to show the feed:
Once human is detected, following screen is seen:
Next Steps for Enterprise Applications
This fundamental tracking module lays the perfect groundwork for scaling up your mobile robotics infrastructure. Because MediaPipe tracks 33 distinct bodily landmarks, the codebase can easily be extended to trigger distinct logic chains based on human gestures — allowing you to route the myAGV, change its patrolling profiles, or initiate an emergency stop simply by raising your hand or pointing in a specific direction.
Set up your myAGV before you begin
Follow the official Elephant Robotics myAGV Basic Setup Guide first.
View Setup Guide