Topics
Publisher
- class rclpy.publisher.Publisher(publisher_impl: rpyutils.import_c_library.Publisher, msg_type: MsgType, topic: str, qos_profile: rclpy.qos.QoSProfile, event_callbacks: PublisherEventCallbacks, callback_group: CallbackGroup)
Create a container for a ROS publisher.
Warning
Users should not create a publisher with this constuctor, instead they should call
Node.create_publisher()
.A publisher is used as a primary means of communication in a ROS system by publishing messages on a ROS topic.
- Parameters:
publisher_impl – Publisher wrapping the underlying
rcl_publisher_t
object.msg_type – The type of ROS messages the publisher will publish.
topic – The name of the topic the publisher will publish to.
qos_profile – The quality of service profile to apply to the publisher.
- assert_liveliness() None
Manually assert that this Publisher is alive.
If the QoS Liveliness policy is set to MANUAL_BY_TOPIC, the application must call this at least as often as
QoSProfile.liveliness_lease_duration
.
- destroy()
- get_subscription_count() int
Get the amount of subscribers that this publisher has.
- property handle
- publish(msg: MsgType | bytes) None
Send a message to the topic for the publisher.
- Parameters:
msg – The ROS message to publish.
- Raises:
TypeError if the type of the passed message isn’t an instance of the provided type when the publisher was constructed.
- property topic_name: str
- wait_for_all_acked(timeout: rclpy.duration.Duration = rclpy.duration.Duration) bool
Wait until all published message data is acknowledged or until the timeout elapses.
If the timeout is negative then this function will block indefinitely until all published message data is acknowledged. If the timeout is 0 then it will check if all published message has been acknowledged without waiting. If the timeout is greater than 0 then it will return after that period of time has elapsed or all published message data is acknowledged. This function only waits for acknowledgments if the publisher’s QOS profile is RELIABLE. Otherwise this function will immediately return true.
- Parameters:
timeout – the duration to wait for all published message data to be acknowledged.
- Returns:
true if all published message data is acknowledged before the timeout, otherwise false.
Subscription
- class rclpy.subscription.Subscription(subscription_impl: rpyutils.import_c_library.Subscription, msg_type: MsgType, topic: str, callback: Callable, callback_group: CallbackGroup, qos_profile: rclpy.qos.QoSProfile, raw: bool, event_callbacks: SubscriptionEventCallbacks)
Create a container for a ROS subscription.
Warning
Users should not create a subscription with this constructor, instead they should call
Node.create_subscription()
.- Parameters:
subscription_impl –
Subscription
wrapping the underlyingrcl_subscription_t
object.msg_type – The type of ROS messages the subscription will subscribe to.
topic – The name of the topic the subscription will subscribe to.
callback – A user-defined callback function that is called when a message is received by the subscription.
callback_group – The callback group for the subscription. If
None
, then the nodes default callback group is used.qos_profile – The quality of service profile to apply to the subscription.
raw – If
True
, then received messages will be stored in raw binary representation.
- property callback
- destroy()
- get_publisher_count() int
Get the number of publishers that this subscription has.
- property handle
- property topic_name