This ROS1 Python script demonstrates obstacle mapping using a Turtlebot3 robot in the Gazebo simulation environment.
- The robot moves forward until it detects an obstacle within a user-specified minimum distance.
- The robot then rotates to align its orientation with the direction of the nearest obstacle.
- The script maps the position of the detected obstacle in the world coordinate frame and plots it on a 2D graph.
- The resulting map is saved as a PNG file.
- ROS1 (Melodic or Noetic)
- Turtlebot3 packages
- Python 3
- Matplotlib library
-
Install the required ROS packages and Matplotlib library.
-
Place the provided Python script in your ROS workspace's src directory.
-
Build the ROS workspace using catkin_make or catkin build.
-
Run the script:
Copy
rosrun <your_package_name> obstacle_mapping.py
-
When prompted, enter the minimum distance (in meters) that the robot should maintain from obstacles.
-
The robot will start moving and mapping the obstacles it detects. The resulting map will be saved as map.png in the current directory.
A demonstration video showcasing the obstacle mapping functionality can be found in the repo (demo).
demo.mp4
- The script initializes a ROS node and subscribes to the /odom and /scan topics to obtain the robot's position and sensor data, respectively.
- The move_minimum_distance() function moves the robot forward until it detects an obstacle within the specified minimum distance.
- The rotate_goal() function rotates the robot to align its orientation with the direction of the nearest obstacle.
- The obj_coor() function calculates the world coordinates of the detected obstacle based on the robot's position and the sensor data.
- The map_object() function continuously moves the robot forward, detects obstacles, and plots their positions on a 2D graph using Matplotlib.
- Finally, the script saves the resulting map as a PNG file and displays it.
This project was developed as part of a ROS learning exercise. The Turtlebot3 package and Gazebo simulation environment were used to create the demo.