Gazebo仿真gazebo转ROS2消息
基本配置
Ubuntu 22.04
ROS2 humble
Gazebo Harmonic 版本 8.14.0
实现转换
基于ROS软件ros_gz_bridge,
bash
sudo apt install ros-humble-ros-gz-bridge
Python实现,
python
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
gz_bridge = Node(
package="ros_gz_bridge",
executable="parameter_bridge",
name="simple_lidar_bridge",
arguments=[
"<gz的点云消息>@sensor_msgs/msg/PointCloud2[gz.msgs.PointCloudPacked"
],
output="screen",
)
gz_imu_bridge = Node(
package="ros_gz_bridge",
executable="parameter_bridge",
name="simple_imu_bridge",
arguments=["<gz的IMU消息>@sensor_msgs/msg/Imu[gz.msgs.IMU"],
output="screen",
)
gz_clock_bridge = Node(
package="ros_gz_bridge",
executable="parameter_bridge",
name="simple_clock_bridge",
arguments=["/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock"],
output="screen",
)
return LaunchDescription([gz_bridge, gz_imu_bridge, gz_clock_bridge])
启动gazebo仿真后,执行ros2 launch <脚本>
ROS2消息没有数据
ros-humble-ros-gz-bridge 是基于旧的 Ignition 消息库编译的,而gz-sim8
使用的是新的 Gazebo 消息库。虽然两者都注册了 gz.msgs.* 类型,但底层的
transport 层在序列化/反序列化时类型描述符不兼容,导致 Unknown message type 错误。
安装与 gz-sim8 匹配的 harmonic 版本桥接器:
bash
sudo apt install ros-humble-ros-gzharmonic-bridge