Home

ROS2 Basics Applied: Autonomous Patrol with Turtlebot3 (I)

Developing and Testing an Obstacle-Avoidance Robot in Simulation and Real-World Scenarios

20 March 2024

Introduction

Embarking on a journey to bridge the gap between theoretical knowledge and practical application, this project showcases the culmination of skills acquired from the ROS2 basic concepts. By commanding a Turtlebot3 robot, both in a simulated environment and in reality, the project demonstrates the capability to develop autonomous behaviors that enable a robot to patrol a designated area while adeptly avoiding obstacles.

Objectives

  • To program a robot with patrol behavior using ROS2 and C++ in a simulated environment.
  • To apply and test the developed program on a real Turtlebot3 robot.

Tools and Technologies

  • Programming Languages: C++
  • Frameworks and Libraries: ROS2
  • Simulation Environment: Gazebo
  • Robot Hardware: Turtlebot3
  • Version Control: Git

Source Code

Process and Development

The development process is segmented into initial simulation setup, programming the patrol behavior, and real-world testing.

Simulation Setup

Initial Actions: The simulation environment in Gazebo is set up to mimic real-world scenarios, where the robot’s patrol behavior can be tested and refined. This involves launching the simulation through ROS2 commands and ensuring the virtual Turtlebot3 is ready for programming.

Programming the Patrol Behavior

Creating the ROS2 Package: A package named robot_patrol was developed, containing a C++ file patrol.cpp that defines the patrol behavior. This includes subscribing to laser sensor topics to navigate and avoid obstacles based on the data received.

Algorithm Implementation: A simplistic algorithm was designed to analyze 180 degrees in front of the robot, determining the safest direction by identifying the largest distance free of obstacles. This direction informs the robot’s movement, ensuring continuous patrolling without collisions.

Real-world Testing

Testing in Simulation: Before real-world deployment, the patrol behavior was rigorously tested in the simulation to ensure reliable obstacle avoidance.

Deployment on the Real Robot: With successful simulation tests, the program was then executed on an actual Turtlebot3 robot. This real-world test was conducted remotely, with the robot located in Barcelona, Spain. Adjustments and debugging were carried out in real-time to adapt the patrol behavior to the nuances of the physical environment.

Results

The project achieved its goal of developing an autonomous patrol behavior that effectively navigates and avoids obstacles, both in a simulated environment and in real-world testing. The seamless transition from simulation to real-world application underscores the robustness of the developed program and the adaptability of ROS2 for robot programming.

Key Insights

  • The project highlighted the importance of simulation in robotics development, serving as a critical step before real-world application.
  • The adaptability of ROS2 in integrating with both simulated and real environments was evident, showcasing its potential for developing complex robotic behaviors, after just minor tweaks in the code.
  • Future enhancements could include refining the obstacle avoidance algorithm for more complex environments and integrating more sensors for enhanced environmental awareness.