SLAM stands for Simultaneous Localization and Mapping. It is a computational problem in robotics and computer vision where a robot or device:
1. Localizes itself: Determines its position and orientation within an environment.
2. Maps the environment: Creates a map of its surroundings while navigating through it.
SLAM enables robots to operate autonomously in unknown environments by building a map and tracking their position on that map in real-time.
Starting SLAM from the Terminal
Here are the terminal commands for launching the SLAM toolkit.
# Start robot or robot simulator in this case I wil use the turtlebot3ros2launchturtlebot3_gazeboturtlebot3_world.launch.py
# Start nav2ros2launchnav2_bringupnavigation_launch.py
# Start SLAMros2launchslam_toolboxonline_async_launch.py
# Launch rviz2 and add the TF visualization and the map visualizationros2runrviz2rviz2
fromlaunchimportLaunchDescriptionfromlaunch.actionsimportDeclareLaunchArgument,IncludeLaunchDescriptionfromlaunch_ros.actionsimportNodefromament_index_python.packagesimportget_package_share_directoryfromlaunch.launch_description_sourcesimportPythonLaunchDescriptionSourcefromlaunch.substitutionsimportLaunchConfigurationimportosdefgenerate_launch_description():# Declare argumentsuse_sim_time=LaunchConfiguration('use_sim_time',default='False')# Get package share directoriesnav2_bringup_dir=get_package_share_directory('nav2_bringup')slam_toolbox_dir=get_package_share_directory('slam_toolbox')locker98_tools_bringup_dir=get_package_share_directory('locker98_tools_bringup')# Include the navigation launch filenavigation_launch=IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(nav2_bringup_dir,'launch','navigation_launch.py')),launch_arguments={'use_sim_time':use_sim_time}.items())# Include the SLAM toolbox launch fileslam_launch=IncludeLaunchDescription(PythonLaunchDescriptionSource(os.path.join(slam_toolbox_dir,'launch','online_async_launch.py')),launch_arguments={'use_sim_time':use_sim_time}.items())# RViz2 noderviz2_node=Node(package='rviz2',executable='rviz2',output='screen',arguments=['-d',os.path.join(locker98_tools_bringup_dir,'rviz','slam_config.rviz')])returnLaunchDescription([DeclareLaunchArgument('use_sim_time',default_value='False',description='Use simulation time'),navigation_launch,slam_launch,rviz2_node])