ROS/ROS2Foxy

save a map using nav2_map_server

leohycho 2022. 8. 1. 17:16

Save a map while the robot is moving :

ros2 run nav2_map_server map_saver_cli -f ~/my_map  

move a robot by using the command topic of cmd_vel :

ros2 run teleop_twist_keyboard teleop_twist_keyboard

ros2 run rqt_robot_steering rqt_robot_steering

save a map as lifelong :

ros2 service call /slam_toolbox/serialize_map slam_toolbox/srv/SerializePoseGraph "filename: 'my_lifelong_map'"

my_mapper_params_lifelong.yaml :


slam_toolbox:
  ros__parameters:

    # Plugin params
    solver_plugin: solver_plugins::CeresSolver
    ceres_linear_solver: SPARSE_NORMAL_CHOLESKY
    ceres_preconditioner: SCHUR_JACOBI
    ceres_trust_strategy: LEVENBERG_MARQUARDT
    ceres_dogleg_type: TRADITIONAL_DOGLEG
    ceres_loss_function: None

    # ROS Parameters
    odom_frame: odom
    map_frame: map
    base_frame: base_footprint
    scan_topic: /scan
    mode: mapping

    # lifelong params
    lifelong_search_use_tree: false
    lifelong_minimum_score: 0.1
    lifelong_iou_match: 0.85
    lifelong_node_removal_score: 0.04
    lifelong_overlap_score_scale: 0.06
    lifelong_constraint_multiplier: 0.08
    lifelong_nearby_penalty: 0.001
    lifelong_candidates_scale: 0.03

    # if you'd like to immediately start continuing a map at a given pose
    # or at the dock, but they are mutually exclusive, if pose is given
    # will use pose
    map_file_name: my_lifelong_map
    #map_start_pose: [0.0, 0.0, 0.0]
    map_start_at_dock: true

    debug_logging: false
    throttle_scans: 1
    transform_publish_period: 0.02 #if 0 never publishes odometry
    map_update_interval: 5.0
    resolution: 0.05
    max_laser_range: 20.0 #for rastering images
    minimum_time_interval: 0.5
    transform_timeout: 0.2
    tf_buffer_duration: 10.
    stack_size_to_use: 40000000 #// program needs a larger stack size to serialize large maps

    # General Parameters
    use_scan_matching: true
    use_scan_barycenter: true
    minimum_travel_distance: 0.5
    minimum_travel_heading: 0.5
    scan_buffer_size: 10
    scan_buffer_maximum_scan_distance: 10.0
    link_match_minimum_response_fine: 0.1  
    link_scan_maximum_distance: 1.5
    loop_search_maximum_distance: 3.0
    do_loop_closing: true
    loop_match_minimum_chain_size: 10          
    loop_match_maximum_variance_coarse: 3.0  
    loop_match_minimum_response_coarse: 0.35    
    loop_match_minimum_response_fine: 0.45

    # Correlation Parameters - Correlation Parameters
    correlation_search_space_dimension: 0.5
    correlation_search_space_resolution: 0.01
    correlation_search_space_smear_deviation: 0.1

    # Correlation Parameters - Loop Closure Parameters
    loop_search_space_dimension: 8.0
    loop_search_space_resolution: 0.05
    loop_search_space_smear_deviation: 0.03

    # Scan Matcher Parameters
    distance_variance_penalty: 0.5      
    angle_variance_penalty: 1.0    

    fine_search_angle_offset: 0.00349    
    coarse_search_angle_offset: 0.349  
    coarse_angle_resolution: 0.0349        
    minimum_angle_penalty: 0.9
    minimum_distance_penalty: 0.5
    use_response_expansion: true

navigation2.launch.py :

#!/usr/bin/env python3

# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Author: Bishop Pearson

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node


def generate_launch_description():
    use_sim_time = LaunchConfiguration('use_sim_time', default='false')
    map_dir = LaunchConfiguration(
        'map',
        default=os.path.join(
            get_package_share_directory('omo_r1_navigation2'),
            'map',
            'turtlebot3_world.yaml'))

    param_file_name = 'omo_r1mini.yaml'
    param_dir = LaunchConfiguration(
        'params_file',
        default=os.path.join(
            get_package_share_directory('omo_r1_navigation2'),
            'param',
            param_file_name))

    nav2_launch_file_dir = os.path.join(get_package_share_directory('nav2_bringup'), 'launch')

    return LaunchDescription([
        DeclareLaunchArgument(
            'map',
            default_value=map_dir,
            description='Full path to map file to load'),

        DeclareLaunchArgument(
            'params_file',
            default_value=param_dir,
            description='Full path to param file to load'),

        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),

        IncludeLaunchDescription(
            PythonLaunchDescriptionSource([nav2_launch_file_dir, '/bringup_launch.py']),
            launch_arguments={
                'map': map_dir,
                'use_sim_time': use_sim_time,
                'params_file': param_dir}.items(),
        )
    ])

 

 

 

 

 

 

Reference

[1] https://navigation.ros.org/tutorials/docs/navigation2_with_slam.html

 

(SLAM) Navigating While Mapping — Navigation 2 1.0.0 documentation

0- Launch Robot Interfaces For this tutorial, we will use the turtlebot3. If you have another robot, replace with your robot specific interfaces. Typically, this includes the robot state publisher of the URDF, simulated or physical robot interfaces, contro

navigation.ros.org

[2] https://github.com/SteveMacenski/slam_toolbox.git

 

GitHub - SteveMacenski/slam_toolbox: Slam Toolbox for lifelong mapping and localization in potentially massive maps with ROS

Slam Toolbox for lifelong mapping and localization in potentially massive maps with ROS - GitHub - SteveMacenski/slam_toolbox: Slam Toolbox for lifelong mapping and localization in potentially mass...

github.com

[3] https://app.theconstructsim.com/Academy?t=2

 

Develop the Robots of the Future

Grow your robotics skills with a full-scale curriculum and real practice

app.theconstructsim.com

[4] https://bitbucket.org/theconstructcore/?page=1

 

Bitbucket

 

bitbucket.org

[5] https://github.com/omorobot/omo_r1-foxy

 

GitHub - omorobot/omo_r1-foxy

Contribute to omorobot/omo_r1-foxy development by creating an account on GitHub.

github.com

 

'ROS > ROS2Foxy' 카테고리의 다른 글

Example of ROS2 Project Package Architecture  (0) 2022.07.21
Launch arguments for a launch file in ROS2  (0) 2022.07.21
Examples of launch.py  (0) 2022.07.01
Xacro to reduce the code of URDF  (0) 2022.06.29
ROS2 Multi-Machines for RPi4B and WSL2  (0) 2022.06.23