Skip to content

Commit b7c5751

Browse files
authored
Add headless and use_rviz LaunchConfigurations to demo launch files (#3527)
* Add headless and use_rviz LaunchConfigurations in nav2_simple_commander demo launch files for whether to start rviz or gzclient to simplify their use in headless environments * Fix headless logic to match tb3_simulation_launch.py for launch arg consistency
1 parent ae887b1 commit b7c5751

9 files changed

+198
-9
lines changed

‎nav2_simple_commander/launch/assisted_teleop_example_launch.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
from ament_index_python.packages import get_package_share_directory
1919

2020
from launch import LaunchDescription
21-
from launch.actions import ExecuteProcess, IncludeLaunchDescription
21+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
22+
from launch.conditions import IfCondition
2223
from launch.launch_description_sources import PythonLaunchDescriptionSource
24+
from launch.substitutions import LaunchConfiguration, PythonExpression
2325
from launch_ros.actions import Node
2426

2527

@@ -31,12 +33,28 @@ def generate_launch_description():
3133
map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
3234
world = os.path.join(python_commander_dir, 'warehouse.world')
3335

36+
# Launch configuration variables
37+
use_rviz = LaunchConfiguration('use_rviz')
38+
headless = LaunchConfiguration('headless')
39+
40+
# Declare the launch arguments
41+
declare_use_rviz_cmd = DeclareLaunchArgument(
42+
'use_rviz',
43+
default_value='True',
44+
description='Whether to start RVIZ')
45+
46+
declare_simulator_cmd = DeclareLaunchArgument(
47+
'headless',
48+
default_value='False',
49+
description='Whether to execute gzclient)')
50+
3451
# start the simulation
3552
start_gazebo_server_cmd = ExecuteProcess(
3653
cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
3754
cwd=[warehouse_dir], output='screen')
3855

3956
start_gazebo_client_cmd = ExecuteProcess(
57+
condition=IfCondition(PythonExpression(['not ', headless])),
4058
cmd=['gzclient'],
4159
cwd=[warehouse_dir], output='screen')
4260

@@ -52,6 +70,7 @@ def generate_launch_description():
5270
rviz_cmd = IncludeLaunchDescription(
5371
PythonLaunchDescriptionSource(
5472
os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
73+
condition=IfCondition(use_rviz),
5574
launch_arguments={'namespace': '',
5675
'use_namespace': 'False'}.items())
5776

@@ -69,6 +88,8 @@ def generate_launch_description():
6988
output='screen')
7089

7190
ld = LaunchDescription()
91+
ld.add_action(declare_use_rviz_cmd)
92+
ld.add_action(declare_simulator_cmd)
7293
ld.add_action(start_gazebo_server_cmd)
7394
ld.add_action(start_gazebo_client_cmd)
7495
ld.add_action(start_robot_state_publisher_cmd)

‎nav2_simple_commander/launch/follow_path_example_launch.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from ament_index_python.packages import get_package_share_directory
1818

1919
from launch import LaunchDescription
20-
from launch.actions import ExecuteProcess, IncludeLaunchDescription
20+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
21+
from launch.conditions import IfCondition
2122
from launch.launch_description_sources import PythonLaunchDescriptionSource
23+
from launch.substitutions import LaunchConfiguration, PythonExpression
2224
from launch_ros.actions import Node
2325

2426

@@ -30,12 +32,28 @@ def generate_launch_description():
3032
map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
3133
world = os.path.join(python_commander_dir, 'warehouse.world')
3234

35+
# Launch configuration variables
36+
use_rviz = LaunchConfiguration('use_rviz')
37+
headless = LaunchConfiguration('headless')
38+
39+
# Declare the launch arguments
40+
declare_use_rviz_cmd = DeclareLaunchArgument(
41+
'use_rviz',
42+
default_value='True',
43+
description='Whether to start RVIZ')
44+
45+
declare_simulator_cmd = DeclareLaunchArgument(
46+
'headless',
47+
default_value='False',
48+
description='Whether to execute gzclient)')
49+
3350
# start the simulation
3451
start_gazebo_server_cmd = ExecuteProcess(
3552
cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
3653
cwd=[warehouse_dir], output='screen')
3754

3855
start_gazebo_client_cmd = ExecuteProcess(
56+
condition=IfCondition(PythonExpression(['not ', headless])),
3957
cmd=['gzclient'],
4058
cwd=[warehouse_dir], output='screen')
4159

@@ -51,6 +69,7 @@ def generate_launch_description():
5169
rviz_cmd = IncludeLaunchDescription(
5270
PythonLaunchDescriptionSource(
5371
os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
72+
condition=IfCondition(use_rviz),
5473
launch_arguments={'namespace': '',
5574
'use_namespace': 'False'}.items())
5675

@@ -68,6 +87,8 @@ def generate_launch_description():
6887
output='screen')
6988

7089
ld = LaunchDescription()
90+
ld.add_action(declare_use_rviz_cmd)
91+
ld.add_action(declare_simulator_cmd)
7192
ld.add_action(start_gazebo_server_cmd)
7293
ld.add_action(start_gazebo_client_cmd)
7394
ld.add_action(start_robot_state_publisher_cmd)

‎nav2_simple_commander/launch/inspection_demo_launch.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from ament_index_python.packages import get_package_share_directory
1818

1919
from launch import LaunchDescription
20-
from launch.actions import ExecuteProcess, IncludeLaunchDescription
20+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
21+
from launch.conditions import IfCondition
2122
from launch.launch_description_sources import PythonLaunchDescriptionSource
23+
from launch.substitutions import LaunchConfiguration, PythonExpression
2224
from launch_ros.actions import Node
2325

2426

@@ -30,12 +32,28 @@ def generate_launch_description():
3032
map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
3133
world = os.path.join(python_commander_dir, 'warehouse.world')
3234

35+
# Launch configuration variables
36+
use_rviz = LaunchConfiguration('use_rviz')
37+
headless = LaunchConfiguration('headless')
38+
39+
# Declare the launch arguments
40+
declare_use_rviz_cmd = DeclareLaunchArgument(
41+
'use_rviz',
42+
default_value='True',
43+
description='Whether to start RVIZ')
44+
45+
declare_simulator_cmd = DeclareLaunchArgument(
46+
'headless',
47+
default_value='False',
48+
description='Whether to execute gzclient)')
49+
3350
# start the simulation
3451
start_gazebo_server_cmd = ExecuteProcess(
3552
cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
3653
cwd=[warehouse_dir], output='screen')
3754

3855
start_gazebo_client_cmd = ExecuteProcess(
56+
condition=IfCondition(PythonExpression(['not ', headless])),
3957
cmd=['gzclient'],
4058
cwd=[warehouse_dir], output='screen')
4159

@@ -51,6 +69,7 @@ def generate_launch_description():
5169
rviz_cmd = IncludeLaunchDescription(
5270
PythonLaunchDescriptionSource(
5371
os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
72+
condition=IfCondition(use_rviz),
5473
launch_arguments={'namespace': '',
5574
'use_namespace': 'False'}.items())
5675

@@ -68,6 +87,8 @@ def generate_launch_description():
6887
output='screen')
6988

7089
ld = LaunchDescription()
90+
ld.add_action(declare_use_rviz_cmd)
91+
ld.add_action(declare_simulator_cmd)
7192
ld.add_action(start_gazebo_server_cmd)
7293
ld.add_action(start_gazebo_client_cmd)
7394
ld.add_action(start_robot_state_publisher_cmd)

‎nav2_simple_commander/launch/nav_through_poses_example_launch.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from ament_index_python.packages import get_package_share_directory
1818

1919
from launch import LaunchDescription
20-
from launch.actions import ExecuteProcess, IncludeLaunchDescription
20+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
21+
from launch.conditions import IfCondition
2122
from launch.launch_description_sources import PythonLaunchDescriptionSource
23+
from launch.substitutions import LaunchConfiguration, PythonExpression
2224
from launch_ros.actions import Node
2325

2426

@@ -30,12 +32,28 @@ def generate_launch_description():
3032
map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
3133
world = os.path.join(python_commander_dir, 'warehouse.world')
3234

35+
# Launch configuration variables
36+
use_rviz = LaunchConfiguration('use_rviz')
37+
headless = LaunchConfiguration('headless')
38+
39+
# Declare the launch arguments
40+
declare_use_rviz_cmd = DeclareLaunchArgument(
41+
'use_rviz',
42+
default_value='True',
43+
description='Whether to start RVIZ')
44+
45+
declare_simulator_cmd = DeclareLaunchArgument(
46+
'headless',
47+
default_value='False',
48+
description='Whether to execute gzclient)')
49+
3350
# start the simulation
3451
start_gazebo_server_cmd = ExecuteProcess(
3552
cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
3653
cwd=[warehouse_dir], output='screen')
3754

3855
start_gazebo_client_cmd = ExecuteProcess(
56+
condition=IfCondition(PythonExpression(['not ', headless])),
3957
cmd=['gzclient'],
4058
cwd=[warehouse_dir], output='screen')
4159

@@ -51,6 +69,7 @@ def generate_launch_description():
5169
rviz_cmd = IncludeLaunchDescription(
5270
PythonLaunchDescriptionSource(
5371
os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
72+
condition=IfCondition(use_rviz),
5473
launch_arguments={'namespace': '',
5574
'use_namespace': 'False'}.items())
5675

@@ -68,6 +87,8 @@ def generate_launch_description():
6887
output='screen')
6988

7089
ld = LaunchDescription()
90+
ld.add_action(declare_use_rviz_cmd)
91+
ld.add_action(declare_simulator_cmd)
7192
ld.add_action(start_gazebo_server_cmd)
7293
ld.add_action(start_gazebo_client_cmd)
7394
ld.add_action(start_robot_state_publisher_cmd)

‎nav2_simple_commander/launch/nav_to_pose_example_launch.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from ament_index_python.packages import get_package_share_directory
1818

1919
from launch import LaunchDescription
20-
from launch.actions import ExecuteProcess, IncludeLaunchDescription
20+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
21+
from launch.conditions import IfCondition
2122
from launch.launch_description_sources import PythonLaunchDescriptionSource
23+
from launch.substitutions import LaunchConfiguration, PythonExpression
2224
from launch_ros.actions import Node
2325

2426

@@ -30,12 +32,28 @@ def generate_launch_description():
3032
map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
3133
world = os.path.join(python_commander_dir, 'warehouse.world')
3234

35+
# Launch configuration variables
36+
use_rviz = LaunchConfiguration('use_rviz')
37+
headless = LaunchConfiguration('headless')
38+
39+
# Declare the launch arguments
40+
declare_use_rviz_cmd = DeclareLaunchArgument(
41+
'use_rviz',
42+
default_value='True',
43+
description='Whether to start RVIZ')
44+
45+
declare_simulator_cmd = DeclareLaunchArgument(
46+
'headless',
47+
default_value='False',
48+
description='Whether to execute gzclient)')
49+
3350
# start the simulation
3451
start_gazebo_server_cmd = ExecuteProcess(
3552
cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
3653
cwd=[warehouse_dir], output='screen')
3754

3855
start_gazebo_client_cmd = ExecuteProcess(
56+
condition=IfCondition(PythonExpression(['not ', headless])),
3957
cmd=['gzclient'],
4058
cwd=[warehouse_dir], output='screen')
4159

@@ -51,6 +69,7 @@ def generate_launch_description():
5169
rviz_cmd = IncludeLaunchDescription(
5270
PythonLaunchDescriptionSource(
5371
os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
72+
condition=IfCondition(use_rviz),
5473
launch_arguments={'namespace': '',
5574
'use_namespace': 'False'}.items())
5675

@@ -68,6 +87,8 @@ def generate_launch_description():
6887
output='screen')
6988

7089
ld = LaunchDescription()
90+
ld.add_action(declare_use_rviz_cmd)
91+
ld.add_action(declare_simulator_cmd)
7192
ld.add_action(start_gazebo_server_cmd)
7293
ld.add_action(start_gazebo_client_cmd)
7394
ld.add_action(start_robot_state_publisher_cmd)

‎nav2_simple_commander/launch/picking_demo_launch.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from ament_index_python.packages import get_package_share_directory
1818

1919
from launch import LaunchDescription
20-
from launch.actions import ExecuteProcess, IncludeLaunchDescription
20+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
21+
from launch.conditions import IfCondition
2122
from launch.launch_description_sources import PythonLaunchDescriptionSource
23+
from launch.substitutions import LaunchConfiguration, PythonExpression
2224
from launch_ros.actions import Node
2325

2426

@@ -30,12 +32,28 @@ def generate_launch_description():
3032
map_yaml_file = os.path.join(warehouse_dir, 'maps', '005', 'map.yaml')
3133
world = os.path.join(python_commander_dir, 'warehouse.world')
3234

35+
# Launch configuration variables
36+
use_rviz = LaunchConfiguration('use_rviz')
37+
headless = LaunchConfiguration('headless')
38+
39+
# Declare the launch arguments
40+
declare_use_rviz_cmd = DeclareLaunchArgument(
41+
'use_rviz',
42+
default_value='True',
43+
description='Whether to start RVIZ')
44+
45+
declare_simulator_cmd = DeclareLaunchArgument(
46+
'headless',
47+
default_value='False',
48+
description='Whether to execute gzclient)')
49+
3350
# start the simulation
3451
start_gazebo_server_cmd = ExecuteProcess(
3552
cmd=['gzserver', '-s', 'libgazebo_ros_factory.so', world],
3653
cwd=[warehouse_dir], output='screen')
3754

3855
start_gazebo_client_cmd = ExecuteProcess(
56+
condition=IfCondition(PythonExpression(['not ', headless])),
3957
cmd=['gzclient'],
4058
cwd=[warehouse_dir], output='screen')
4159

@@ -51,6 +69,7 @@ def generate_launch_description():
5169
rviz_cmd = IncludeLaunchDescription(
5270
PythonLaunchDescriptionSource(
5371
os.path.join(nav2_bringup_dir, 'launch', 'rviz_launch.py')),
72+
condition=IfCondition(use_rviz),
5473
launch_arguments={'namespace': '',
5574
'use_namespace': 'False'}.items())
5675

@@ -68,6 +87,8 @@ def generate_launch_description():
6887
output='screen')
6988

7089
ld = LaunchDescription()
90+
ld.add_action(declare_use_rviz_cmd)
91+
ld.add_action(declare_simulator_cmd)
7192
ld.add_action(start_gazebo_server_cmd)
7293
ld.add_action(start_gazebo_client_cmd)
7394
ld.add_action(start_robot_state_publisher_cmd)

0 commit comments

Comments
 (0)