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

Subscription (ROS 2) vs Subscriber (ROS 1)

asked 2021-08-26 18:20:18 -0500

swiz23 gravatar image

updated 2021-08-27 02:56:23 -0500

gvdhoorn gravatar image

This is really more of a conceptual question, but as I was going through the ROS 2 tutorials, I noticed that when declaring an instance of a Subscriber in Cpp, you do rclcpp::Subscription instead of rclcpp::Subscriber (like was done in ROS 1). Just was curious as to the reasoning behind that.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-08-27 02:07:06 -0500

gvdhoorn gravatar image

updated 2021-08-27 02:07:36 -0500

I remember some earlier discussion about this, but can't find (or link) it right now.

If I remember correctly, the rationale was that in ROS 1, you never really created subcribers, you already created subscriptions.

This is evidenced by the fact you cannot create any additional subscriptions using a ros::Subscriber instance in ROS 1, which would have made sense. You do that via your ros::NodeHandle.

The only things you can do with a ros::Subscriber are (from the C++ API):

  • ask it which topic it's subscribed to
  • ask it how many publishers are publishing to that topic
  • compare it to other ros::Subscriber instances (which then compares the topic it's subscribed to, among other things) and copy it
  • shut it down (ie: unsubscribe)

that all sounds really more like things you'd do with a subscription.

The class' documentation also states this:

Manages an subscription callback on a specific topic.

Which again reinforces the idea that ros::Subscriber was really actually a ros::Subscription all along. The name of the class just didn't reflect that fact, so using the latter as the name of the class in ROS 2 just made more sense.

edit flag offensive delete link more


I'm still not sure I understand the difference between the two.

Shouldn't the same hold true by a ros 2 publisher? Instead of instantiating a rclcpp::Publisher, it should be a rclcpp::Publication?

In ROS 1, you also cannot create additional publishers using a ros::Publisher instance. Instead, you would use a ros::NodeHandle. Additionally, looking at its class reference - it's very comparable to a ros::Subscriber

  • ask which topic it's publishing too
  • get number of subscribers to a topic
  • compare with other ros::Publisher instances
  • shut it down
  • check if it's latched

The detailed description says it Manages an advertisement on a specific topic. By using advertisement as opposed to advertiser - that seems more synonymous with Publication as opposed to Publisher?

swiz23 gravatar image swiz23  ( 2021-08-27 12:09:51 -0500 )edit

I'm not sure what you're asking.

You asked why ROS 2 has subscriptions instead of subscribers. I answered.

I was not involved in the design of these parts of the infrastructure, so I cannot comment on whether it is or why it isn't consistent with other parts.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-27 14:58:50 -0500 )edit

Question Tools



Asked: 2021-08-26 18:20:18 -0500

Seen: 712 times

Last updated: Aug 27 '21