Until now, I just used examples of the ros documentation e.g. for the publisher

self.publisher_ = self.create_publisher(String, 'topic', 10)

and it all worked well. It looks like 10 could mean, in that case, the number of kept history items - but I'm not sure !?

In the rclpy documentation, there is no hint about what 10 could mean in that case.

I even looked at the source code but I don't get it.

Can anyone clarify where to really look, to understand what the proper values are for the third parameter?


1 Answer 1


For C++

I might be wrong, but (for C++ not Python) from rclcpp::Node Class Reference

std::shared_ptr< PublisherT >     create_publisher (const std::string &topic_name, size_t qos_history_depth, std::shared_ptr< Alloc > allocator=nullptr)


std::shared_ptr< PublisherT >     create_publisher (const std::string &topic_name, const rmw_qos_profile_t &qos_profile=rmw_qos_profile_default, std::shared_ptr< Alloc > allocator=nullptr)

In both cases, the last parameter is

std::shared_ptr< Alloc > allocator=nullptr

Then from create_publisher(), it says that the third parameter is

[in] allocator Optional custom allocator.


For Python

Actually, above, I was wrong.

From the link to the rclpy documentation that you posted, click on the API link in the left hand side bar.

Then click on the Publisher link (under "Topics"):

Read the warning (ignore the typo):


Users should not create a publisher with this constuctor, instead they should call Node.create_publisher().

Click the link to Node.create_publisher()

Looking at

create_publisher(msg_type, topic, qos_profile, *, callback_group=None, event_callbacks=None, qos_overriding_options=None)

The third parameter is

  • qos_profile (Union[QoSProfile, int]) – A QoSProfile or a history depth to apply to the publisher. In the case that a history depth is provided, the QoS history is set to KEEP_LAST, the QoS history depth is set to the value of the parameter, and all other QoS settings are set to their default values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.