Navigation in ROS2: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 73: | Zeile 73: | ||
occupied_thresh: 0.65 | occupied_thresh: 0.65 | ||
free_thresh: 0.25 | free_thresh: 0.25 | ||
mage: Name of the file containing the image of the generated map. | |||
resolution: Resolution of the map (in meters/pixel). | |||
origin: Coordinates of the lower-left pixel on the map. These coordinates are given in 2D (x, y, z). The third value indicates rotation. If there is no rotation, the value will be 0. | |||
occupied_thresh: Pixels with a value greater than this value will be considered an occupied zone (marked as an obstacle) | |||
free_thresh: Pixels with a value smaller than this will be considered a completely free zone. | |||
negate: Inverts the colors of the map. By default, white means completely free, and black means completely occupied. |
Version vom 9. Januar 2023, 14:56 Uhr
Map building in ROS2
A map is a picture of the area in which the robot is working. A map is used by the robot to plan and localize its trajectories. An occupancy grid map is what a map is in ROS. In plain English, each map cell represents an obstacle by having a certain value. We require a robot with LIDAR, odometry, and the robot environment in order to create a map.
SLAM Simultaneous Localization and Mapping (SLAM) will locate the robot while also making a map. SLAM algorithms are used to make maps of uncharted environments while simultaneously being aware of where the robot is. Cartographer and SLAM-Toolbox are two excellent SLAMs for ROS2.
Cartographer
Cartographer (https://opensource.google/projects/cartographer) is a system that offers real-time simultaneous localization and mapping (SLAM) in 2D and 3D across numerous platforms and sensor configurations. Google creates cartographer, and they have been mapping building interiors using Google Street View.
Cartographer ros is a ROS wrapper for cartographer that enables integration with ROS (https://google-cartographer-ros.readthedocs.io/en/latest/). This is fantastic since you can utilize only the pre-built packages and precisely configure them for your robot. In this unit, this procedure is detailed.
This section will describe the robot's launch file for the cartographer. The primary advantage of a launch file is the ability to launch many nodes from a single file and set a node-specific parameter. The parameters may be supplied in the launch file or loaded from a YAML file. We must launch two nodes in order to launch "cartographer."
1. Launch of the cartographer_node
- The cartographer_node is provided by the package cartographer_ros
- The executable is called cartographer_node
- The parameters it requires are: 1. use_sim_time : is a boolean indicating whether the node must synchronize its time with the simulation
The arguments are: 1. configuration_directory : the directory where to find the configuration files 2. configuration_basename : the config file name
package='cartographer_ros' executable='cartographer_node', name='cartographer_node', output='screen', parameters=[{'use_sim_time': True}], arguments=['-configuration_directory', cartographer_config_dir, '-configuration_basename', configuration_basename]
- Create a new package in ros2_ws workspace named cartographer_slam inside the src/ directory.
- Create launch & config directories at ros2_ws/src/cartographer_slam
- Write a launch file to launch cartographer with the name cartographer.launch.py where the two nodes are launched
- Create an LUA file named cartographer.lua in the config directory with the following config parameters:
- Compile everything
- Launch your program
- code
- ros2 launch cartographer_slam cartographer.launch.py
- Launch RVIZ to see the map being created. You will configure RVIZ to show the data you want to control
- Add the map display in RVIZ and configure it to see the map you are generating
You must launch an executable named map saver, which launches a map saver node from nav2 map server, in order to save the map you've made. When saving the map, call the node inside the directory.
cd ~/ros2_ws/src/cartographer_slam/config ros2 run nav2_map_server map_saver_cli -f turtlebot_area
Note:: Never invoke the map saver before closing the Cartographer node. If not, you will lose the map you made.
The command to save will produce two files: The map is represented by the occupancy grid image in the name.pgm file. The name.yaml file gives information about the map's resolution.
Example of YAML File of the Map.
image: turtlebot_area.pgm mode: trinary resolution: 0.05 origin: [-5.9, -5.22, 0] negate: 0 occupied_thresh: 0.65 free_thresh: 0.25
mage: Name of the file containing the image of the generated map. resolution: Resolution of the map (in meters/pixel). origin: Coordinates of the lower-left pixel on the map. These coordinates are given in 2D (x, y, z). The third value indicates rotation. If there is no rotation, the value will be 0. occupied_thresh: Pixels with a value greater than this value will be considered an occupied zone (marked as an obstacle) free_thresh: Pixels with a value smaller than this will be considered a completely free zone. negate: Inverts the colors of the map. By default, white means completely free, and black means completely occupied.