Imagine stepping into your new role as a robotics engineer. Your project lead, acting as your personal GPS, guides you through the labyrinth of the office, pointing out vital landmarks like the sacred coffee machine and the elusive supply closet where wrenches dwell. You trail behind, mentally sketching the map of your new habitat, ensuring you won't mistake the janitor's closet for the conference room.
Now, picture a robot embarking on a similar journey. Instead of manually steering it through every corridor and cubicle to chart its course, you simply stroll ahead, and it faithfully follows, mapping the terrain as it goes. This approach isn't just efficient; it's a game-changer.
This is what I am going to demonstrate in this article. Going ahead this article requires you have a basic understanding of ROS2 and a bit of Ubuntu knowledge.
1. TurtleBot-3
TurtleBot3 is a compact, affordable, and programmable mobile robot developed by ROBOTIS in collaboration with the Open-Source Robotics Foundation (OSRF). Designed for education, research, hobby projects, and product prototyping, it operates on the Robot Operating System (ROS), providing a versatile platform for robotics development.
This is the best tool for testing scenarios like this. The simulation setup instructions can be found on this website: TurtleBot3 Setup Instructions
2. Checking out the repository
Great! Now you have a working turtlebot3 simulation. So how to add our world and scripts to the workspace that you created.
First check out this repository I created: GitHub Project Repo
Now I will explain the files in the repo.
3. Main Control Script
The first and most important script is the human_cam_following_turtle.py.
This script controls the different aspects of the project. It creates a Node called Human Follower which has a command velocity publisher and image/camera feed subscriber.
i) img_callback() function takes the camera frame and calculates the pose for the human target. Then a simple PD (Proportional Derivative) type controller is used to calculate velocity commands.
How does this work? So, we take the center point of the image here the variable self.controlX and self.controlY.
![]() |
A Sample Frame |
The blue dot (xb,yb) represents center of the image frame captured from the turtlebot camera. The white dot (xw,yw) represents the center of the captured pose points. Now this is the formula used for proportional gain:
P = euclidian_dist ((xb,yb) , (xw,yw)) * kp
The D term is not exactly a derivative term but depends on the yw. So, in a way it's also a proportional term. Further improvements can be done to create a true PID controller.
D = (yb-yw) * kd
This is done for the linear velocity term. Similarly angular gains can be calculated for angular velocity term.
ii) publish_control() function publishes the linear and angular velocities after doing the above calculations.
4. The gazebo world file
This file human_follower_project.world specifies the world setup to be loaded in the Gazebo simulator. This file should be placed in the respective world folder and later should be used in the launch file.
5. The launch file
The launch files in ROS2 help in opening up the nodes and other related processes using a single python script. turtlebot3_human_follower_project.launch.py should be placed in the launch folder of the turtlebot3 workspace.
This file loads the world, robot and its state publisher and opens it in Gazebo.
6. MoveNet model
MoveNet is an advanced, ultra-fast, and accurate human pose detection model developed by Google Research. It is designed to identify 17 key body points—such as the shoulders, elbows, wrists, hips, knees, and ankles—in real-time applications. This capability makes it particularly suitable for scenarios requiring immediate feedback, including fitness tracking, health monitoring, and interactive applications.
![]() |
MoveNet Architecture |
The human_pose.tflite is the tflite model of the movenet which can be run even on edge devices but with a lower accuracy as compared to a normal tf model.
This model is utilized in the pose_estimation_movenet_tflite.py file where the function predicts the pose points given an image frame.
7. Working
Finally, all the components are ready to be tested.
i) Run the launch file (after building and sourcing the workspace) in one terminal
ii) Open rviz2 and setup the nav2 stack.
iii) Once gazebo is loaded and you see the simulation running, open another terminal and run the human_cam_following_turtle.py script.
Now watch how the turtlebot follows the human target and meanwhile the cartographer creates a map simultaneously.
8. Improvements
So, this project was done a few years back and I wanted to revisit it because it has an intriguing concept. But what improvements can be done now:
i) Include a proper PID controller.
ii) Use a better version of MoveNet instead of tflite version.
iii) Write a package for the project instead of running it through a python script.
Hopefully some of you wanting to work on this can contribute to the github repo and make it a wonderful addition.
Don't forget to sub to our channel and check out my portfolio website for more details.
Thanks a Lot For Chipping In.
See You Later.
Comments
Post a Comment