Skip to content

Commit

Permalink
use_sim_time refactoring (#3131)
Browse files Browse the repository at this point in the history
* initial commit

* fix

* fixes

* revert

* fix

* linting

* fixes

* fix format

* fixing pycodestyle

* revert typo

* add use_sim_time to costmap

* add parameter description

* fix defaults

* fix formatting
  • Loading branch information
Tony Najjar authored Aug 25, 2022
1 parent 1c74368 commit 7703c81
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ bool BtActionServer<ActionT>::on_configure()
"-r",
std::string("__node:=") +
std::string(node->get_name()) + "_" + client_node_name + "_rclcpp_node",
"-p",
"use_sim_time:=" +
std::string(node->get_parameter("use_sim_time").as_bool() ? "true" : "false"),
"--"});

// Support for handling the topic-based goal pose from rviz
Expand Down
1 change: 0 additions & 1 deletion nav2_bringup/launch/bringup_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def generate_launch_description():

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

configured_params = RewrittenYaml(
Expand Down
57 changes: 30 additions & 27 deletions nav2_bringup/launch/localization_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from launch.actions import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import LoadComposableNodes
from launch_ros.actions import LoadComposableNodes, SetParameter
from launch_ros.actions import Node
from launch_ros.descriptions import ComposableNode
from nav2_common.launch import RewrittenYaml
Expand Down Expand Up @@ -53,7 +53,6 @@ def generate_launch_description():

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

configured_params = RewrittenYaml(
Expand Down Expand Up @@ -107,6 +106,7 @@ def generate_launch_description():
load_nodes = GroupAction(
condition=IfCondition(PythonExpression(['not ', use_composition])),
actions=[
SetParameter("use_sim_time", use_sim_time),
Node(
package='nav2_map_server',
executable='map_server',
Expand All @@ -133,36 +133,39 @@ def generate_launch_description():
name='lifecycle_manager_localization',
output='screen',
arguments=['--ros-args', '--log-level', log_level],
parameters=[{'use_sim_time': use_sim_time},
{'autostart': autostart},
parameters=[{'autostart': autostart},
{'node_names': lifecycle_nodes}])
]
)

load_composable_nodes = LoadComposableNodes(
load_composable_nodes = GroupAction(
condition=IfCondition(use_composition),
target_container=container_name,
composable_node_descriptions=[
ComposableNode(
package='nav2_map_server',
plugin='nav2_map_server::MapServer',
name='map_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_amcl',
plugin='nav2_amcl::AmclNode',
name='amcl',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_lifecycle_manager',
plugin='nav2_lifecycle_manager::LifecycleManager',
name='lifecycle_manager_localization',
parameters=[{'use_sim_time': use_sim_time,
'autostart': autostart,
'node_names': lifecycle_nodes}]),
],
actions=[
SetParameter("use_sim_time", use_sim_time),
LoadComposableNodes(
target_container=container_name,
composable_node_descriptions=[
ComposableNode(
package='nav2_map_server',
plugin='nav2_map_server::MapServer',
name='map_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_amcl',
plugin='nav2_amcl::AmclNode',
name='amcl',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_lifecycle_manager',
plugin='nav2_lifecycle_manager::LifecycleManager',
name='lifecycle_manager_localization',
parameters=[{'autostart': autostart,
'node_names': lifecycle_nodes}]),
],
)
]
)

# Create the launch description and populate
Expand Down
5 changes: 2 additions & 3 deletions nav2_bringup/launch/multi_tb3_simulation_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ def generate_launch_description():
group = GroupAction([
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(launch_dir, 'rviz_launch.py')),
os.path.join(launch_dir, 'rviz_launch.py')),
condition=IfCondition(use_rviz),
launch_arguments={
'namespace': TextSubstitution(text=robot['name']),
launch_arguments={'namespace': TextSubstitution(text=robot['name']),
'use_namespace': 'True',
'rviz_config': rviz_config_file}.items()),

Expand Down
127 changes: 65 additions & 62 deletions nav2_bringup/launch/navigation_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from launch.actions import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import LoadComposableNodes
from launch_ros.actions import LoadComposableNodes, SetParameter
from launch_ros.actions import Node
from launch_ros.descriptions import ComposableNode
from nav2_common.launch import RewrittenYaml
Expand Down Expand Up @@ -58,14 +58,13 @@ def generate_launch_description():

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

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

stdout_linebuf_envvar = SetEnvironmentVariable(
'RCUTILS_LOGGING_BUFFERED_STREAM', '1')
Expand Down Expand Up @@ -108,6 +107,7 @@ def generate_launch_description():
load_nodes = GroupAction(
condition=IfCondition(PythonExpression(['not ', use_composition])),
actions=[
SetParameter("use_sim_time", use_sim_time),
Node(
package='nav2_controller',
executable='controller_server',
Expand Down Expand Up @@ -184,67 +184,70 @@ def generate_launch_description():
name='lifecycle_manager_navigation',
output='screen',
arguments=['--ros-args', '--log-level', log_level],
parameters=[{'use_sim_time': use_sim_time},
{'autostart': autostart},
parameters=[{'autostart': autostart},
{'node_names': lifecycle_nodes}]),
]
)

load_composable_nodes = LoadComposableNodes(
load_composable_nodes = GroupAction(
condition=IfCondition(use_composition),
target_container=container_name,
composable_node_descriptions=[
ComposableNode(
package='nav2_controller',
plugin='nav2_controller::ControllerServer',
name='controller_server',
parameters=[configured_params],
remappings=remappings + [('cmd_vel', 'cmd_vel_nav')]),
ComposableNode(
package='nav2_smoother',
plugin='nav2_smoother::SmootherServer',
name='smoother_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_planner',
plugin='nav2_planner::PlannerServer',
name='planner_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_behaviors',
plugin='behavior_server::BehaviorServer',
name='behavior_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_bt_navigator',
plugin='nav2_bt_navigator::BtNavigator',
name='bt_navigator',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_waypoint_follower',
plugin='nav2_waypoint_follower::WaypointFollower',
name='waypoint_follower',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_velocity_smoother',
plugin='nav2_velocity_smoother::VelocitySmoother',
name='velocity_smoother',
parameters=[configured_params],
remappings=remappings +
[('cmd_vel', 'cmd_vel_nav'), ('cmd_vel_smoothed', 'cmd_vel')]),
ComposableNode(
package='nav2_lifecycle_manager',
plugin='nav2_lifecycle_manager::LifecycleManager',
name='lifecycle_manager_navigation',
parameters=[{'use_sim_time': use_sim_time,
'autostart': autostart,
'node_names': lifecycle_nodes}]),
],
actions=[
SetParameter("use_sim_time", use_sim_time),
LoadComposableNodes(
target_container=container_name,
composable_node_descriptions=[
ComposableNode(
package='nav2_controller',
plugin='nav2_controller::ControllerServer',
name='controller_server',
parameters=[configured_params],
remappings=remappings + [('cmd_vel', 'cmd_vel_nav')]),
ComposableNode(
package='nav2_smoother',
plugin='nav2_smoother::SmootherServer',
name='smoother_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_planner',
plugin='nav2_planner::PlannerServer',
name='planner_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_behaviors',
plugin='behavior_server::BehaviorServer',
name='behavior_server',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_bt_navigator',
plugin='nav2_bt_navigator::BtNavigator',
name='bt_navigator',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_waypoint_follower',
plugin='nav2_waypoint_follower::WaypointFollower',
name='waypoint_follower',
parameters=[configured_params],
remappings=remappings),
ComposableNode(
package='nav2_velocity_smoother',
plugin='nav2_velocity_smoother::VelocitySmoother',
name='velocity_smoother',
parameters=[configured_params],
remappings=remappings +
[('cmd_vel', 'cmd_vel_nav'), ('cmd_vel_smoothed', 'cmd_vel')]),
ComposableNode(
package='nav2_lifecycle_manager',
plugin='nav2_lifecycle_manager::LifecycleManager',
name='lifecycle_manager_navigation',
parameters=[{'autostart': autostart,
'node_names': lifecycle_nodes}]),
],
)
]
)

# Create the launch description and populate
Expand Down
4 changes: 2 additions & 2 deletions nav2_bringup/launch/rviz_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def generate_launch_description():
output='screen')

namespaced_rviz_config_file = ReplaceString(
source_file=rviz_config_file,
replacements={'<robot_namespace>': ('/', namespace)})
source_file=rviz_config_file,
replacements={'<robot_namespace>': ('/', namespace)})

start_namespaced_rviz_cmd = Node(
condition=IfCondition(use_namespace),
Expand Down
50 changes: 24 additions & 26 deletions nav2_bringup/launch/slam_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, GroupAction
from launch.conditions import IfCondition, UnlessCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import Node, SetParameter
from nav2_common.launch import HasNodeParams, RewrittenYaml


Expand All @@ -43,13 +43,10 @@ def generate_launch_description():
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,
param_rewrites={},
convert_types=True)

# Declare the launch arguments
Expand Down Expand Up @@ -82,24 +79,26 @@ def generate_launch_description():

# Nodes launching commands

start_map_saver_server_cmd = Node(
package='nav2_map_server',
executable='map_saver_server',
output='screen',
respawn=use_respawn,
respawn_delay=2.0,
arguments=['--ros-args', '--log-level', log_level],
parameters=[configured_params])

start_lifecycle_manager_cmd = Node(
package='nav2_lifecycle_manager',
executable='lifecycle_manager',
name='lifecycle_manager_slam',
output='screen',
arguments=['--ros-args', '--log-level', log_level],
parameters=[{'use_sim_time': use_sim_time},
{'autostart': autostart},
{'node_names': lifecycle_nodes}])
start_map_server = GroupAction(
actions=[
SetParameter("use_sim_time", use_sim_time),
Node(
package='nav2_map_server',
executable='map_saver_server',
output='screen',
respawn=use_respawn,
respawn_delay=2.0,
arguments=['--ros-args', '--log-level', log_level],
parameters=[configured_params]),
Node(
package='nav2_lifecycle_manager',
executable='lifecycle_manager',
name='lifecycle_manager_slam',
output='screen',
arguments=['--ros-args', '--log-level', log_level],
parameters=[{'autostart': autostart},
{'node_names': lifecycle_nodes}])
])

# If the provided param file doesn't have slam_toolbox params, we must remove the 'params_file'
# LaunchConfiguration, or it will be passed automatically to slam_toolbox and will not load
Expand Down Expand Up @@ -129,8 +128,7 @@ def generate_launch_description():
ld.add_action(declare_log_level_cmd)

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

# Running SLAM Toolbox (Only one of them will be run)
ld.add_action(start_slam_toolbox_cmd)
Expand Down
Loading

0 comments on commit 7703c81

Please sign in to comment.