2026-01-19 17:08:49 +08:00
|
|
|
|
from launch import LaunchDescription
|
|
|
|
|
|
from launch_ros.actions import Node
|
|
|
|
|
|
from launch.actions import DeclareLaunchArgument
|
|
|
|
|
|
from launch.substitutions import LaunchConfiguration
|
|
|
|
|
|
import os
|
|
|
|
|
|
from ament_index_python.packages import get_package_share_directory
|
|
|
|
|
|
|
|
|
|
|
|
def generate_launch_description():
|
|
|
|
|
|
"""
|
|
|
|
|
|
SkyLink Bridge 启动配置
|
|
|
|
|
|
|
|
|
|
|
|
用法:
|
|
|
|
|
|
ros2 launch skylink_bridge bridge.launch.py
|
|
|
|
|
|
ros2 launch skylink_bridge bridge.launch.py target_ip:=192.168.1.100 jpeg_quality:=80
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
# 获取包共享目录
|
|
|
|
|
|
pkg_share_dir = get_package_share_directory('skylink_bridge')
|
|
|
|
|
|
config_file = os.path.join(pkg_share_dir, 'config', 'params.yaml')
|
|
|
|
|
|
|
|
|
|
|
|
# ========================================================================
|
|
|
|
|
|
# 启动参数声明 (可通过命令行覆盖)
|
|
|
|
|
|
# ========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
target_ip_arg = DeclareLaunchArgument(
|
|
|
|
|
|
'target_ip',
|
|
|
|
|
|
default_value='255.255.255.255',
|
|
|
|
|
|
description='目标 IP 地址 (广播)'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
target_port_arg = DeclareLaunchArgument(
|
|
|
|
|
|
'target_port',
|
|
|
|
|
|
default_value='9999',
|
|
|
|
|
|
description='UDP 目标端口'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
jpeg_quality_arg = DeclareLaunchArgument(
|
|
|
|
|
|
'jpeg_quality',
|
|
|
|
|
|
default_value='70',
|
|
|
|
|
|
description='JPEG 压缩质量 (1-100)'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
camera_topic_arg = DeclareLaunchArgument(
|
|
|
|
|
|
'camera_topic',
|
|
|
|
|
|
default_value='/camera/image_raw',
|
|
|
|
|
|
description='相机 Topic 名称'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
gps_topic_arg = DeclareLaunchArgument(
|
|
|
|
|
|
'gps_topic',
|
|
|
|
|
|
default_value='/mavros/global_position/global',
|
|
|
|
|
|
description='GPS Topic 名称'
|
|
|
|
|
|
)
|
2026-01-19 20:31:11 +08:00
|
|
|
|
# ========================================================================
|
2026-01-19 22:00:39 +08:00
|
|
|
|
# 相机 节点 (OpenCV 驱动)
|
2026-01-19 20:31:11 +08:00
|
|
|
|
# ========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
camera_driver_node = Node(
|
2026-01-19 22:00:39 +08:00
|
|
|
|
package='skylink_bridge',
|
|
|
|
|
|
executable='camera_driver_node',
|
2026-01-19 20:31:11 +08:00
|
|
|
|
name='camera_driver',
|
|
|
|
|
|
output='screen',
|
2026-01-19 22:00:39 +08:00
|
|
|
|
parameters=[
|
|
|
|
|
|
config_file, # 从 YAML 配置文件加载参数
|
|
|
|
|
|
{
|
|
|
|
|
|
'camera_topic': LaunchConfiguration('camera_topic'),
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
2026-01-19 20:31:11 +08:00
|
|
|
|
)
|
2026-01-19 17:08:49 +08:00
|
|
|
|
|
|
|
|
|
|
# ========================================================================
|
|
|
|
|
|
# UDP Sender 节点
|
|
|
|
|
|
# ========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
udp_sender_node = Node(
|
|
|
|
|
|
package='skylink_bridge',
|
|
|
|
|
|
executable='udp_sender_node',
|
|
|
|
|
|
name='udp_sender',
|
|
|
|
|
|
output='screen',
|
|
|
|
|
|
parameters=[
|
|
|
|
|
|
config_file, # 从 YAML 配置文件加载参数
|
|
|
|
|
|
{
|
|
|
|
|
|
'target_ip': LaunchConfiguration('target_ip'),
|
|
|
|
|
|
'target_port': LaunchConfiguration('target_port'),
|
|
|
|
|
|
'jpeg_quality': LaunchConfiguration('jpeg_quality'),
|
|
|
|
|
|
'camera_topic': LaunchConfiguration('camera_topic'),
|
|
|
|
|
|
'gps_topic': LaunchConfiguration('gps_topic'),
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
remappings=[
|
|
|
|
|
|
# 如果需要重映射 Topic,在此添加
|
|
|
|
|
|
# ('/camera/image_raw', '/my_camera/image'),
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# ========================================================================
|
|
|
|
|
|
# 构造启动描述
|
|
|
|
|
|
# ========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
return LaunchDescription([
|
|
|
|
|
|
target_ip_arg,
|
|
|
|
|
|
target_port_arg,
|
|
|
|
|
|
jpeg_quality_arg,
|
|
|
|
|
|
camera_topic_arg,
|
|
|
|
|
|
gps_topic_arg,
|
2026-01-19 20:31:11 +08:00
|
|
|
|
camera_driver_node,
|
2026-01-19 17:08:49 +08:00
|
|
|
|
udp_sender_node,
|
|
|
|
|
|
])
|