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:

<command_topic>cmd_vel</command_topic>

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

  <ros>

    <!-- Add a namespace -->
    <namespace>/test</namespace>

  </ros>

  <!-- Update rate in Hz -->
  <update_rate>50</update_rate>

  <!-- wheels -->
  <left_joint>left_wheel_joint</left_joint>
  <right_joint>right_wheel_joint</right_joint>

  <!-- kinematics -->
  <wheel_separation>1.25</wheel_separation>
  <wheel_diameter>0.6</wheel_diameter>

  <!-- limits -->
  <max_wheel_torque>20</max_wheel_torque>
  <max_wheel_acceleration>1.0</max_wheel_acceleration>

  <!-- input -->
  <command_topic>cmd_vel</command_topic>

  <!-- output -->
  <publish_odom>true</publish_odom>
  <publish_odom_tf>true</publish_odom_tf>
  <publish_wheel_tf>true</publish_wheel_tf>

  <odometry_topic>odom</odometry_topic>
  <odometry_frame>odom</odometry_frame>
  <robot_base_frame>chassis</robot_base_frame>

</plugin>

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

Regards,
Christian

2 Likes

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,
Min

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.