ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

gazebo-ros2 communication : make an entity in a gazebo sim subscribe to ros2 messages?

asked 2022-07-06 13:44:16 -0600

r_gerson gravatar image

Hello, I am trying to implement communication between ros2 and Gazebo: make a simple sphere move in Gazebo, with its velocity coming from ROS2 twist messages. I have the gazebo sim open but the sphere remains stationary even though ros2 messages are being published. This is because the sphere sdf isn't "connected" to the setup. How to "connect" or "plug-in" an sdf to a ros2-ign-bridge system like the one shown below? in other words, how to make an entity in an sdf subscribe to ros2 messages?

the setup:

#terminal A 
ros2 run ros_ign_bridge parameter_bridge velo@geometry_msgs/msg/Twist@ignition.msgs.Twist
#terminal B
ign topic -e -t /velo

#terminal C
. /opt/ros/foxy/setup.bash
ros2 topic pub /velo geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}" 

#terminal D
ign gazebo sphere.sdf  #how to I make THIS subscribe to ros2 messages?
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-07-07 08:00:01 -0600

ljaniec gravatar image

updated 2022-07-07 08:00:39 -0600

I think you are looking for the Gazebo ROS plugin (Model Plugin to be exact):

Adding a ModelPlugin

In short, the ModelPlugin is inserted in the URDF inside the <robot> element. It is wrapped with the <gazebo> pill, to indicate information passed to Gazebo. For example:

<robot>
  ... robot description ...
  <gazebo>
    <plugin name="differential_drive_controller"
      filename="libdiffdrive_plugin.so">
      ... plugin parameters ...
    </plugin>
  </gazebo>
  ... robot description ...
</robot>

Upon loading the robot model within Gazebo, the diffdrive_plugin code will be given a reference to the model itself, allowing it to manipulate it. Also, it will be give a reference to the SDF element of itself, in order to read the plugin parameters passed to it.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2022-07-06 13:44:16 -0600

Seen: 202 times

Last updated: Jul 07 '22