yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble yashar_turtle_chase

Repository Summary

Description This repo is made for an assignment of "Robotics Lab" course, instructed in Department of Mechanical Engineering, at Sharif University of Technology.
Checkout URI https://github.com/yaswhar/yashar_turtle_chase.git
VCS Type git
VCS Version main
Last Updated 2025-04-20
Dev Status DEVELOPED
CI status No Continuous Integration
Released UNRELEASED
Tags robotics ros2 turtlesim ros2-humble
Contributing Help Wanted (0)
Good First Issues (0)
Pull Requests to Review (0)

Packages

Name Version
yashar_turtle_chase 0.0.0

README

This package and README file is written for the Robotics-Lab HW2. Yashar Zafari - Student Number: 99106209, Sharif University of Technology. email

๐Ÿข yashar_turtle_chase

A dynamic leader-follower demo using ROS2โ€™s turtlesim, where multiple turtles can follow a designated leader with real-time leader switching capability.

๐Ÿ“ฆ Overview

This package demonstrates a multi-turtle simulation where:

  • Multiple turtles are spawned in the turtlesim environment.
  • One turtle acts as the leader, controllable via keyboard.
  • Other turtles follow the leader using proportional control.
  • The leader can be switched dynamically at runtime.

๐Ÿงฐ Features

  • Dynamic Turtle Spawning: Automatically spawns a specified number of turtles at random, non-overlapping positions.
  • Leader-Follower Mechanism: Implements a simple proportional controller for followers to track the leaderโ€™s position.
  • Real-Time Leader Switching: Change the leader turtle during runtime using a ROS 2 topic.
  • Launch File: Convenient launch file to start the entire setup, including turtlesim, turtle spawner, follower logic, and teleoperation.

๐Ÿš€ Installation

  1. Clone the Repository:
   cd ~/ros2_ws/src
   git clone https://github.com/your_username/yashar_turtle_chase.git

2. **Install Dependencies**:

   
```bash
   cd ~/ros2_ws
   rosdep install --from-paths src --ignore-src -r -y
   
  1. Build the Package:
   colcon build --packages-select yashar_turtle_chase
   source install/setup.bash
   

๐Ÿงช Usage

Launch the Simulation

ros2 launch yashar_turtle_chase dynamic_chase.launch.py

This will:

  • Start the turtlesim_node.
  • Spawn the specified number of turtles (default is 2).
  • Initiate the dynamic follower node.
  • Teleoperate the leader in the command window opened.
  • Switch the leader in another terminal.

Control the Leader Turtle

Use the keyboard in the teleoperation terminal to move the leader turtle.

Switch the Leader Turtle

Publish a new leader name to the /switch_leader topic:

ros2 topic pub /switch_leader std_msgs/String "{data: 'turtle2'}"

Replace 'turtle2' with the desired turtle name (e.g., 'turtle1', 'turtle3', etc.).

๐Ÿง  Implementation Details

Follower Logic

The dynamic_follower.py node:

  • Subscribes to the /turtleX/pose topics to get the positions of all turtles.
  • Publishes velocity commands to /turtleY/cmd_vel for follower turtles.
  • Calculates the distance and angle to the leader and applies proportional control to follow.

Leader Detection

The current leader is stored as a variable within the node. It can be updated at runtime by publishing to the /switch_leader topic.

Challenges Faced

  • Dynamic Spawning: Ensuring turtles spawn at non-overlapping positions required implementing a check against existing positions.
  • Real-Time Leader Switching: Maintaining smooth transitions when changing leaders without disrupting follower behavior.

๐Ÿ“น Demonstration

https://github.com/user-attachments/assets/0013b428-5731-40c6-85f9-7b0369217965

In the demo, observe how the follower turtle tracks the leader and how switching the leader affects the behavior.

๐Ÿ“ License

This project is licensed under the Apache License 2.0.


For more information on ROS 2 and turtlesim, refer to the official ROS 2 tutorials.

CONTRIBUTING

No CONTRIBUTING.md found.

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble

yashar_turtle_chase repository

robotics ros2 turtlesim ros2-humble