use shared container to launch 4 camera node

This commit is contained in:
datean
2024-11-27 11:13:38 +08:00
parent 6521015f9c
commit 9bfd47969f
4 changed files with 99 additions and 24 deletions
@@ -5,7 +5,8 @@ from launch.actions import DeclareLaunchArgument, OpaqueFunction, GroupAction
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import PushRosNamespace, ComposableNodeContainer, Node
from launch_ros.descriptions import ComposableNode
from launch.conditions import UnlessCondition
from launch_ros.actions import LoadComposableNodes
def load_yaml(file_path):
with open(file_path, 'r') as f:
@@ -185,6 +186,11 @@ def generate_launch_description():
DeclareLaunchArgument('interleave_frame_enable', default_value='true'),
DeclareLaunchArgument('interleave_skip_enable', default_value='true'),
DeclareLaunchArgument('interleave_skip_index', default_value='0'), # 0:skip pattern ir 1: skip flood ir
DeclareLaunchArgument('use_intra_process_comms', default_value='false'),
DeclareLaunchArgument('attach_to_shared_component_container', default_value='false'),
DeclareLaunchArgument('component_container_name', default_value='orbbec_container'),
DeclareLaunchArgument('delta_duration', default_value='5000.0'),
DeclareLaunchArgument('delta_fps', default_value='2'),
]
def get_params(context, args):
@@ -205,25 +211,31 @@ def generate_launch_description():
)
]
else:
attach_to_shared_component_container_arg = LaunchConfiguration('attach_to_shared_component_container', default=False)
component_container_name_arg = LaunchConfiguration('component_container_name', default='orbbec_container')
orbbec_container = Node(
name=component_container_name_arg,
package='rclcpp_components',
executable='component_container_mt',
output='screen',
condition=UnlessCondition(attach_to_shared_component_container_arg)
)
return [
GroupAction([
PushRosNamespace(LaunchConfiguration("camera_name")),
ComposableNodeContainer(
name="camera_container",
namespace="",
package="rclcpp_components",
executable="component_container",
composable_node_descriptions=[
ComposableNode(
package="orbbec_camera",
plugin="orbbec_camera::OBCameraNodeDriver",
name=LaunchConfiguration("camera_name"),
parameters=params,
),
],
output="screen",
orbbec_container,
LoadComposableNodes(
target_container=component_container_name_arg,
composable_node_descriptions=[
ComposableNode(
namespace=LaunchConfiguration("camera_name"),
name=LaunchConfiguration("camera_name"),
package='orbbec_camera',
plugin='orbbec_camera::OBCameraNodeDriver',
parameters=params,
extra_arguments=[{'use_intra_process_comms': LaunchConfiguration("use_intra_process_comms")}],
)
])
]
)
]
return LaunchDescription(
@@ -4,6 +4,9 @@ from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import IncludeLaunchDescription, GroupAction, TimerAction
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.actions import DeclareLaunchArgument
from launch.conditions import UnlessCondition, IfCondition
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
# Include launch files
@@ -12,6 +15,22 @@ def generate_launch_description():
config_file_dir = os.path.join(package_dir, "config")
config_file_path = os.path.join(config_file_dir, "camera_params.yaml")
use_intra_process_comms_arg = DeclareLaunchArgument(
'use_intra_process_comms', default_value='true',
)
attach_to_shared_component_container_arg = DeclareLaunchArgument(
'attach_to_shared_component_container', default_value='true',
)
shared_container_name = "shared_orbbec_container"
shared_container = Node(
name=shared_container_name,
package='rclcpp_components',
executable='component_container_mt',
output='screen',
condition=IfCondition(LaunchConfiguration('attach_to_shared_component_container'))
)
front_camera = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(launch_file_dir, "gemini_330_series_interleave_laser_g335L.launch.py")
@@ -22,6 +41,9 @@ def generate_launch_description():
"device_num": "4",
"sync_mode": "primary",
"config_file_path": config_file_path,
'use_intra_process_comms': LaunchConfiguration("use_intra_process_comms"),
'attach_to_shared_component_container': LaunchConfiguration("attach_to_shared_component_container"),
'component_container_name': shared_container_name,
}.items(),
)
@@ -35,6 +57,9 @@ def generate_launch_description():
"device_num": "4",
"sync_mode": "secondary_synced",
"config_file_path": config_file_path,
'use_intra_process_comms': LaunchConfiguration("use_intra_process_comms"),
'attach_to_shared_component_container': LaunchConfiguration("attach_to_shared_component_container"),
'component_container_name': shared_container_name,
}.items(),
)
right_camera = IncludeLaunchDescription(
@@ -47,6 +72,9 @@ def generate_launch_description():
"device_num": "4",
"sync_mode": "secondary_synced",
"config_file_path": config_file_path,
'use_intra_process_comms': LaunchConfiguration("use_intra_process_comms"),
'attach_to_shared_component_container': LaunchConfiguration("attach_to_shared_component_container"),
'component_container_name': shared_container_name,
}.items(),
)
rear_camera = IncludeLaunchDescription(
@@ -59,16 +87,46 @@ def generate_launch_description():
"device_num": "4",
"sync_mode": "secondary_synced",
"config_file_path": config_file_path,
'use_intra_process_comms': LaunchConfiguration("use_intra_process_comms"),
'attach_to_shared_component_container': LaunchConfiguration("attach_to_shared_component_container"),
'component_container_name': shared_container_name,
}.items(),
)
# Launch description
# ld = LaunchDescription(
# [
# TimerAction(period=0.5, actions=[GroupAction([left_camera])]),
# TimerAction(period=0.5, actions=[GroupAction([right_camera])]),
# TimerAction(period=0.5, actions=[GroupAction([rear_camera])]),
# TimerAction(period=0.5, actions=[GroupAction([front_camera])]),
# ]
# )
delayed_left_camera = TimerAction(
period=0.5,
actions=[left_camera],
)
delayed_right_camera = TimerAction(
period=0.5,
actions=[right_camera],
)
delayed_rear_camera = TimerAction(
period=0.5,
actions=[rear_camera],
)
delayed_front_camera = TimerAction(
period=0.5,
actions=[front_camera],
)
ld = LaunchDescription(
[
TimerAction(period=0.5, actions=[GroupAction([left_camera])]),
TimerAction(period=0.5, actions=[GroupAction([right_camera])]),
TimerAction(period=0.5, actions=[GroupAction([rear_camera])]),
TimerAction(period=0.5, actions=[GroupAction([front_camera])]),
use_intra_process_comms_arg,
attach_to_shared_component_container_arg,
shared_container,
delayed_left_camera,
delayed_right_camera,
delayed_rear_camera,
delayed_front_camera,
]
)