File size: 3,861 Bytes
c9ea516 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
#!/usr/bin/env python3
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, TimerAction
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import Node
def generate_launch_description():
# Declare launch arguments
json_file_arg = DeclareLaunchArgument(
'json_file',
default_value='',
description='Path to the JSON layout file'
)
rviz_config_arg = DeclareLaunchArgument(
'rviz_config',
default_value='/home/user/ws/src/db_loader/rviz/layout_view.rviz',
description='Path to RViz config file (leave empty to skip RViz)'
)
publisher_delay_arg = DeclareLaunchArgument(
'publisher_delay',
default_value='1.5',
description='Delay in seconds before starting publishers (to let subscribers connect)'
)
filled_shelves_arg = DeclareLaunchArgument(
'filled',
default_value='true',
description='Display shelves as filled transparent boxes (true/false)'
)
shelf_alpha_arg = DeclareLaunchArgument(
'alpha',
default_value='0.3',
description='Transparency level for filled shelves (0.0-1.0)'
)
# Static transform publisher for map frame
static_tf_node = Node(
package='tf2_ros',
executable='static_transform_publisher',
name='map_tf_publisher',
arguments=['0', '0', '0', '0', '0', '0', 'world', 'map'],
output='screen',
)
# Layout visualizer node with optional filled shelves arguments
layout_visualizer_node = Node(
package='db_loader',
executable='layout_visualizer',
name='layout_visualizer',
output='screen',
arguments=[
'--filled',
'--alpha',
LaunchConfiguration('alpha')
],
condition=IfCondition(
PythonExpression([
'"', LaunchConfiguration('filled'), '" == "true"'
])
),
)
# Layout visualizer node WITHOUT filled shelves (default)
layout_visualizer_wireframe_node = Node(
package='db_loader',
executable='layout_visualizer',
name='layout_visualizer',
output='screen',
condition=IfCondition(
PythonExpression([
'"', LaunchConfiguration('filled'), '" != "true"'
])
),
)
# RViz2 (only launches if rviz_config is provided)
rviz_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='screen',
arguments=['-d', LaunchConfiguration('rviz_config')],
condition=IfCondition(
PythonExpression([
'"', LaunchConfiguration('rviz_config'), '" != ""'
])
),
)
# Layout publisher node (DELAYED to ensure subscribers are ready)
layout_publisher_node = Node(
package='db_loader',
executable='layout_publisher',
name='layout_publisher',
output='screen',
arguments=[LaunchConfiguration('json_file')],
condition=IfCondition(
PythonExpression([
'"', LaunchConfiguration('json_file'), '" != ""'
])
),
)
# Wrap layout publisher in TimerAction to delay its start
delayed_layout_publisher = TimerAction(
period=LaunchConfiguration('publisher_delay'),
actions=[layout_publisher_node]
)
return LaunchDescription([
json_file_arg,
rviz_config_arg,
publisher_delay_arg,
filled_shelves_arg,
shelf_alpha_arg,
static_tf_node,
layout_visualizer_node,
layout_visualizer_wireframe_node,
rviz_node,
delayed_layout_publisher,
]) |