Tracks / keypoint-db /ws /src /db_loader /launch /layout_visualization_launch.py
Luis Yoichi Morales
adding the ROS2 container and the playing and visualization scripts
c9ea516
#!/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,
])