Skip to content

Project #2: Patrolling TB3s and gazebo worlds

Muhammad Luqman edited this page Nov 29, 2023 · 5 revisions

Issue Link #2

Project Overview

This ROS2 project simulates and controls multiple TurtleBot3 robots in a Gazebo environment. It demonstrates how to spawn multiple robots, launch them in a specific world, and control them to move in square trajectories.

Installing Dependencies

  • sudo apt install ros-humble-gazebo-ros-pkgs
  • sudo apt-get install ros-humble-turtlebot3-gazebo

Running the Project

  • Clone the repository into your ROS2 workspace (if not done already) using:
    git clone -b running_projects https://github.com/Robotisim/mobile_robotics_ROS2.git
    
  • Build your workspace and source it by running the following command (assuming you are in the workspace root directory):
    colcon build && source install/setup.bash
    
  • Export turtlebot3 model
    export TURTLEBOT3_MODEL=waffle_pi
    
  • Submodules Initialize
    git submodule init
    git submodule update
    
  • Run complete project
    ros2 launch drive_tb3 p2_c_drive_sqaure_multi_tb3.launch.py
    

Nodes

This project includes a node for driving the TurtleBot3 robots.

  • p2_multi_tb3_sqaure_drive This node publishes to the cmd_vel topic of a specific TurtleBot3 robot to command it to move in a square trajectory. The robot to control is specified by the cmd_vel_topic parameter, which defaults to /turtle1/cmd_vel. The node calculates the required linear and angular velocities for the robot to move in a square trajectory and publishes geometry_msgs::msg::Twist messages to the cmd_vel topic. It alternates between moving the robot straight and turning it.

Launch Files

  • p2_a_spawn_tb3.launch.py : This launch file starts a Gazebo simulation and spawns a TurtleBot3 model at a specified location. The position and orientation of the TurtleBot3 model at spawn, as well as its name and namespace, can be specified by arguments.
  • p2_b_multi_tb3.launch.py : This launch file starts a Gazebo simulation with a specified world and spawns four TurtleBot3 models at different locations. The positions and orientations of the TurtleBot3 models at spawn, as well as their names and namespaces, are specified within the launch file.
  • p2_d_run_multi_turtlesim_drive.launch.py : This launch file includes p2_b_multi_tb3.launch.py to spawn multiple TurtleBot3 models and then starts four p2_multi_tb3_sqaure_drive nodes to drive each TurtleBot3 model. The cmd_vel_topic parameter for each node is set to control a different robot.

Learning Outcomes

  • Sending trajectories to tb3
  • Working with multiple Robots