Exercise 31 - Where is the definition of subscriber?

In the solutions of exercise 31, we only defined publisher, could you please tell me how the robots in the simulation environment subscribed the topic? Is that defined somewhere else?

Before I ran the program exercise31, the subscriber was None, but once I started to run it, the subscriber was the robot in the simulation env.

Hi @min.wang.1997.01.13,

The subscribers are present in the URDF/Xacro file of the simulated robot. Generally, we make use of Gazebo plugins such as the Differential Drive for wheeled robots. Below is a sample usage code of this plugin which I directly referenced from the official repository of the gazebo_ros package. You can see in one snippet of the code below, we defined the topic where we will get commands for our robot under the line:


You can access these through this link: gazebo_ros_pkgs/gazebo_plugins/include/gazebo_plugins/gazebo_ros_diff_drive.hpp at ros2 · ros-simulation/gazebo_ros_pkgs · GitHub


    <!-- Add a namespace -->


  <!-- Update rate in Hz -->

  <!-- wheels -->

  <!-- kinematics -->

  <!-- limits -->

  <!-- input -->

  <!-- output -->



For more info about this, you can try exploring the couse on URDF. Hope this helps!



Thank you, Christian!

Do you mean it is an advanced topic in URDF?
What’s the difference between <command_topic>cmd_vel</command_topic> and the rospy.Publisher/Subscriber functions?

The rospy.subscriber is used for reading messages and doing some actions (such as printing or calculation etc that are not related to the robot control in the simulation environment) while the URDF file is used to control the simulated robot,
Is my understanding correct?

Best regards,

Hi @min.wang.1997.01.13,

The line <command_topic>cmd_vel</command_topic> is used by the gazebo plugin in order to subscribe to the cmd_vel topic and publish these velocities into equivalent motion in the simulation environment. Essentially, you can think of it as a bridge between the information being processed in ROS through your nodes and your robot in Gazebo.

For your second question, yes. The URDF (Unified Robot Description Format) is used to design robots – the structure, the physics, joint and components, etc; essentially, the hardware; now, for the ROS nodes (e.g. subscriber, publisher, client and servers), we can think of these as the software end of our robots – since through these components, our main goal is to process the acquire and process the data from say sensors for instance and then translate them into a robot behavior that we want.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.