Bridge image (GET /image → sensor_msgs/Image), IMU (GET /imu → sensor_msgs/Imu), and cmd_vel (Twist → POST /cmd) between Origincar simulation and ROS2. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
import os
|
|
|
|
from launch import LaunchDescription
|
|
from launch.actions import DeclareLaunchArgument
|
|
from launch.substitutions import LaunchConfiguration
|
|
from launch_ros.actions import Node
|
|
|
|
|
|
def generate_launch_description():
|
|
"""启动 origincar_bridge 节点,所有参数可通过命令行覆盖。"""
|
|
|
|
# 声明 launch 参数(名称, 默认值, 说明)
|
|
declare_http_host = DeclareLaunchArgument(
|
|
"http_host",
|
|
default_value="192.168.11.159",
|
|
description="仿真机 IP 地址",
|
|
)
|
|
declare_http_port = DeclareLaunchArgument(
|
|
"http_port",
|
|
default_value="8765",
|
|
description="HTTP API 端口",
|
|
)
|
|
declare_image_topic = DeclareLaunchArgument(
|
|
"image_topic",
|
|
default_value="/image",
|
|
description="图像发布话题",
|
|
)
|
|
declare_imu_topic = DeclareLaunchArgument(
|
|
"imu_topic",
|
|
default_value="/imu",
|
|
description="IMU 发布话题",
|
|
)
|
|
declare_cmd_vel_topic = DeclareLaunchArgument(
|
|
"cmd_vel_topic",
|
|
default_value="/cmd_vel",
|
|
description="控制指令订阅话题",
|
|
)
|
|
declare_image_rate = DeclareLaunchArgument(
|
|
"image_rate",
|
|
default_value="30.0",
|
|
description="图像拉取频率 (Hz)",
|
|
)
|
|
declare_imu_rate = DeclareLaunchArgument(
|
|
"imu_rate",
|
|
default_value="30.0",
|
|
description="IMU 拉取频率 (Hz)",
|
|
)
|
|
declare_timeout = DeclareLaunchArgument(
|
|
"timeout",
|
|
default_value="1.0",
|
|
description="HTTP 请求超时 (秒)",
|
|
)
|
|
|
|
# 节点
|
|
bridge_node = Node(
|
|
package="origincar_bridge",
|
|
executable="bridge_node",
|
|
name="origincar_bridge",
|
|
output="screen",
|
|
parameters=[
|
|
{
|
|
"http_host": LaunchConfiguration("http_host"),
|
|
"http_port": LaunchConfiguration("http_port"),
|
|
"image_topic": LaunchConfiguration("image_topic"),
|
|
"imu_topic": LaunchConfiguration("imu_topic"),
|
|
"cmd_vel_topic": LaunchConfiguration("cmd_vel_topic"),
|
|
"image_rate": LaunchConfiguration("image_rate"),
|
|
"imu_rate": LaunchConfiguration("imu_rate"),
|
|
"timeout": LaunchConfiguration("timeout"),
|
|
}
|
|
],
|
|
)
|
|
|
|
return LaunchDescription(
|
|
[
|
|
declare_http_host,
|
|
declare_http_port,
|
|
declare_image_topic,
|
|
declare_imu_topic,
|
|
declare_cmd_vel_topic,
|
|
declare_image_rate,
|
|
declare_imu_rate,
|
|
declare_timeout,
|
|
bridge_node,
|
|
]
|
|
)
|