ros_gz_bridge - Grisson/ros2_learning_notes GitHub Wiki

ros_gz_bridge exchanges messages between ROS2 and Gazebo.

Supprted message type is limited. README

ros_gz_sim_demos

Initialize bidirectional bridge.

Launching manually:

    ros2 run ros_gz_bridge parameter bridge /scan@sensor_msgs/msg/[email protected] 
  • Message syntax /TOPIC@ROS_MSG@GZ_MSG
  • scan is Gazebo topic.
  • sensor_msgs/msg/LaserScan is ROS message type.
  • gz.msgs.LaserScan is the Gazebo message type.
  • Between ROS message and Gazebo message: @, [, ]

Launching with launch file

ros_gz_bridge.launch.py from ros_gz_bridge

    ros2 launch ros_gz_bridge ros_gz_bridge.launch.py 
         bridge_name:=ros_gz_bridge 
         config_file:=<path_to_your_YAML_file> 
         use_composition:=True 
         create_own_container:=True 

Launching with custom python launch file

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration, TextSubstitution
from ros_gz_bridge.actions import RosGzBridge


def generate_launch_description():

    bridge_name = LaunchConfiguration('bridge_name')
    config_file = LaunchConfiguration('config_file')

    declare_bridge_name_cmd = DeclareLaunchArgument(
        'bridge_name', description='Name of ros_gz_bridge node'
    )

    declare_config_file_cmd = DeclareLaunchArgument(
        'config_file', description='YAML config file'
    )

    # Create the launch description and populate
    ld = LaunchDescription([
        RosGzBridge(
            bridge_name=LaunchConfiguration('bridge_name'),
            config_file=LaunchConfiguration('config_file'),
        ),
    ])

    # Declare the launch options
    ld.add_action(declare_bridge_name_cmd)
    ld.add_action(declare_config_file_cmd)

    return ld