Department of Electrical Engineering
Faculty Member: <> Date: <>
Semester: <> Group: <>
EE381 Robotics
Lab 13: Leader Follower using ROS
PLO5 PLO5 PLO5
CLO4 CLO4 CLO5
Viva / Quiz Analysis of Modern
Student Name Reg. No / Demo Data in Tool
Report Usage
5 Marks 5 Marks 5 Marks
EE-381 Robotics
Introduction
This laboratory exercise focuses on the practical application of the publish/subscribe
mechanism to coordinate multiple robots. A 'Leader-Follower' configuration is a
fundamental multi-robot behavior where a follower robot mimics or chases the
trajectory of a leader robot.
Objectives
The following are the main objectives of this lab:
• Managing multiple robot instances in a single simulation environment
• Subscribing to multiple pose topics simultaneously
• Implementing proportional control for distance and orientation
• Calculating Euclidean distance and heading errors in real-time
Lab Conduct
• Respect faculty and peers through speech and actions
• The lab faculty will be available to assist the students. In case some aspect
of the lab experiment is not understood, the students are advised to seek
help from the faculty.
• In the tasks, there are commented lines such as #YOUR CODE STARTS
HERE# where you have to provide the code. You must put the code
between the #START and #END parts of these commented lines. Do NOT
remove the commented lines.
• Use the tab key to provide the indentation in python.
• When you provide the code in the report, keep the font size at 12
Theory
To implement a follower, we must calculate the relative position of the leader
with respect to the follower. This involves calculating:
EE-381 Robotics
1. Distance Error: The straight-line distance between the two robots.
2. Angle Error: The difference between the follower's current heading and the
angle required to point directly at the leader.
The terminal commands are given as:
cd <directory> change directory
cd.. go back to previous directory
pwd print the current directory
ls list the contents of the current directory
mkdir <directory> create a directory
python3 <[Link]> execute python script
A brief summary of the terminal commands needed for working in ROS are
provided below:
colcon build
build the workspace whenever a node is created or modified
. install/[Link]
makes the terminal “aware” of the workspace (notice the dot and the space)
ros2 pkg create --build-type ament_python <package>
create a new package (must be done in src directory)
ros2 run <package> <node>
execute a node
In the first and second task, you will create simple publisher and subscriber nodes
by following the instructions and using your knowledge from the previous labs. Pay
EE-381 Robotics
careful attention to the steps involved as they will be needed in the third and fourth
tasks.
Lab Task 1 – Multi-Robot Initialization_________________________________________
In this task, you will initialize the environment with two turtles. The first turtle
(turtle1) exists by default. You must spawn the second turtle (turtle2) via a
service call.
Run the turtlesim node:
ros2 run turtlesim turtlesim_node
In a new terminal, call the spawn service to place turtle2 at (2.0, 2.0).
### TASK 1 Terminal STARTS HERE ###
### TASK Terminal ENDS HERE ###
### TASK 1 SCREENSHOT STARTS HERE ###
### TASK 1 SCREENSHOT ENDS HERE ###
Lab Task 2 – Distance Tracking__________________________________________________
Create a node [Link]. This node must subscribe to both /turtle1/pose and
/turtle2/pose. In this task, you only need to calculate and display (log) the
Euclidean distance between them as turtle1 is moved using teleop.
### TASK 2 CODE STARTS HERE ###
EE-381 Robotics
### TASK 2 CODE ENDS HERE ###
### TASK 2 SCREENSHOT STARTS HERE ###
### TASK 2 SCREENSHOT ENDS HERE ###
Lab Task 3 – Autonomous Following Control___________________________________
Update the [Link] node to publish velocity commands to /turtle2/cmd_vel.
Use proportional control to make turtle2 chase turtle1. The follower should
stop if it is within 1.0 units of the leader.
### TASK 3 PUB CLASS DEFINTION CODE STARTS HERE ###
### TASK 3 PUB CLASS DEFINTION CODE ENDS HERE ###
### TASK 3 SUB CLASS DEFINTION CODE STARTS HERE ###
### TASK 3 SUB CLASS DEFINTION CODE ENDS HERE ###
### TASK 3 SCREENSHOT STARTS HERE ###
### TASK 3 SCREENSHOT ENDS HERE ###
Lab Task 4 – Shadow Mimicking________________________________________
Use the teleop node to drive turtle1 to draw the initials of all group members in
the Turtlesim window. Modify your follower code so that turtle2 follows the
EE-381 Robotics
path of turtle1 but stays exactly 2 units behind and to the left of the leader's
current position. Use the rosservice call /turtle1/set_pen and /turtle2/set_pen to
give each turtle a different colored trail so the initials and the "shadow" path
are clearly visible.
### TASK 3 PUB CLASS DEFINTION CODE STARTS HERE ###
### TASK 3 PUB CLASS DEFINTION CODE ENDS HERE ###
### TASK 3 SUB CLASS DEFINTION CODE STARTS HERE ###
### TASK 3 SUB CLASS DEFINTION CODE ENDS HERE ###
### TASK 4 SCREENSHOT STARTS HERE ###
### TASK 4 SCREENSHOT ENDS HERE ###
Must submit the video proof of your task 4 along with your submissions.
EE-381 Robotics