Skip to content

Commit

Permalink
Add SLAM Toolbox and map_saver_server into launch-files (ros-navigati…
Browse files Browse the repository at this point in the history
…on#1768)

* Add SLAM launch file

Fix possible collision of laser scan with camera on waffle

* Simplifications and fixes after review

* Increase save_map_timeout to 5 sec to comply with SLAM Toolbox map rate
  • Loading branch information
AlexeyMerzlyakov authored Jun 2, 2020
1 parent 42726b3 commit be166f3
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
18 changes: 17 additions & 1 deletion nav2_bringup/bringup/launch/bringup_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
IncludeLaunchDescription, SetEnvironmentVariable)
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import PushRosNamespace


Expand All @@ -33,6 +33,7 @@ def generate_launch_description():
# Create the launch configuration variables
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
slam = LaunchConfiguration('slam')
map_yaml_file = LaunchConfiguration('map')
use_sim_time = LaunchConfiguration('use_sim_time')
params_file = LaunchConfiguration('params_file')
Expand All @@ -52,6 +53,11 @@ def generate_launch_description():
default_value='false',
description='Whether to apply a namespace to the navigation stack')

declare_slam_cmd = DeclareLaunchArgument(
'slam',
default_value='False',
description='Whether run a SLAM')

declare_map_yaml_cmd = DeclareLaunchArgument(
'map',
description='Full path to map yaml file to load')
Expand Down Expand Up @@ -83,9 +89,18 @@ def generate_launch_description():
condition=IfCondition(use_namespace),
namespace=namespace),

IncludeLaunchDescription(
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'slam_launch.py')),
condition=IfCondition(slam),
launch_arguments={'namespace': namespace,
'use_sim_time': use_sim_time,
'autostart': autostart,
'params_file': params_file}.items()),

IncludeLaunchDescription(
PythonLaunchDescriptionSource(os.path.join(launch_dir,
'localization_launch.py')),
condition=IfCondition(PythonExpression(['not ', slam])),
launch_arguments={'namespace': namespace,
'map': map_yaml_file,
'use_sim_time': use_sim_time,
Expand Down Expand Up @@ -113,6 +128,7 @@ def generate_launch_description():
# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_slam_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_use_sim_time_cmd)
ld.add_action(declare_params_file_cmd)
Expand Down
107 changes: 107 additions & 0 deletions nav2_bringup/bringup/launch/slam_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright (c) 2020 Samsung Research Russia
#
# 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.

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from nav2_common.launch import RewrittenYaml


def generate_launch_description():
# Input parameters declaration
namespace = LaunchConfiguration('namespace')
params_file = LaunchConfiguration('params_file')
use_sim_time = LaunchConfiguration('use_sim_time')
autostart = LaunchConfiguration('autostart')

# Variables
lifecycle_nodes = ['map_saver']

# Getting directories and launch-files
bringup_dir = get_package_share_directory('nav2_bringup')
slam_toolbox_dir = get_package_share_directory('slam_toolbox')
slam_launch_file = os.path.join(slam_toolbox_dir, 'launch', 'online_sync_launch.py')

# Create our own temporary YAML files that include substitutions
param_substitutions = {
'use_sim_time': use_sim_time}

configured_params = RewrittenYaml(
source_file=params_file,
root_key=namespace,
param_rewrites=param_substitutions,
convert_types=True)

# Declare the launch arguments
declare_namespace_cmd = DeclareLaunchArgument(
'namespace',
default_value='',
description='Top-level namespace')

declare_params_file_cmd = DeclareLaunchArgument(
'params_file',
default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
description='Full path to the ROS2 parameters file to use for all launched nodes')

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

declare_autostart_cmd = DeclareLaunchArgument(
'autostart', default_value='true',
description='Automatically startup the nav2 stack')

# Nodes launching commands
start_slam_toolbox_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(slam_launch_file),
launch_arguments={'use_sim_time': use_sim_time}.items())

start_map_saver_server_cmd = Node(
package='nav2_map_server',
node_executable='map_saver_server',
output='screen',
parameters=[configured_params])

start_lifecycle_manager_cmd = Node(
package='nav2_lifecycle_manager',
node_executable='lifecycle_manager',
node_name='lifecycle_manager_slam',
output='screen',
parameters=[{'use_sim_time': use_sim_time},
{'autostart': autostart},
{'node_names': lifecycle_nodes}])

ld = LaunchDescription()

# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_params_file_cmd)
ld.add_action(declare_use_sim_time_cmd)
ld.add_action(declare_autostart_cmd)

# Running SLAM Toolbox
ld.add_action(start_slam_toolbox_cmd)

# Running Map Saver Server
ld.add_action(start_map_saver_server_cmd)
ld.add_action(start_lifecycle_manager_cmd)

return ld
8 changes: 8 additions & 0 deletions nav2_bringup/bringup/launch/tb3_simulation_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def generate_launch_description():
launch_dir = os.path.join(bringup_dir, 'launch')

# Create the launch configuration variables
slam = LaunchConfiguration('slam')
namespace = LaunchConfiguration('namespace')
use_namespace = LaunchConfiguration('use_namespace')
map_yaml_file = LaunchConfiguration('map')
Expand Down Expand Up @@ -68,6 +69,11 @@ def generate_launch_description():
default_value='false',
description='Whether to apply a namespace to the navigation stack')

declare_slam_cmd = DeclareLaunchArgument(
'slam',
default_value='False',
description='Whether run a SLAM')

declare_map_yaml_cmd = DeclareLaunchArgument(
'map',
default_value=os.path.join(bringup_dir, 'maps', 'turtlebot3_world.yaml'),
Expand Down Expand Up @@ -163,6 +169,7 @@ def generate_launch_description():
PythonLaunchDescriptionSource(os.path.join(launch_dir, 'bringup_launch.py')),
launch_arguments={'namespace': namespace,
'use_namespace': use_namespace,
'slam': slam,
'map': map_yaml_file,
'use_sim_time': use_sim_time,
'params_file': params_file,
Expand All @@ -175,6 +182,7 @@ def generate_launch_description():
# Declare the launch options
ld.add_action(declare_namespace_cmd)
ld.add_action(declare_use_namespace_cmd)
ld.add_action(declare_slam_cmd)
ld.add_action(declare_map_yaml_cmd)
ld.add_action(declare_use_sim_time_cmd)
ld.add_action(declare_params_file_cmd)
Expand Down
7 changes: 7 additions & 0 deletions nav2_bringup/bringup/params/nav2_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ map_server:
use_sim_time: True
yaml_filename: "turtlebot3_world.yaml"

map_saver:
ros__parameters:
use_sim_time: True
save_map_timeout: 5000
free_thresh_default: 0.25
occupied_thresh_default: 0.65

planner_server:
ros__parameters:
planner_plugin_types: ["nav2_navfn_planner/NavfnPlanner"]
Expand Down
4 changes: 2 additions & 2 deletions nav2_bringup/bringup/worlds/waffle.model
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
<mass>0.035</mass>
</inertial>
<collision name="collision">
<pose>0 0.047 -0.004 0 0 0</pose>
<pose>0 0.047 -0.005 0 0 0</pose>
<geometry>
<box>
<size>0.008 0.130 0.022</size>
Expand Down Expand Up @@ -441,7 +441,7 @@
</sensor>

<collision name="collision">
<pose>0 0.047 -0.004 0 0 0</pose>
<pose>0 0.047 -0.005 0 0 0</pose>
<geometry>
<box>
<size>0.008 0.130 0.022</size>
Expand Down

0 comments on commit be166f3

Please sign in to comment.