Skip to content

Instantly share code, notes, and snippets.

@emersonknapp
Created June 12, 2019 14:57
Show Gist options
  • Select an option

  • Save emersonknapp/9eab75d324d799dd198e79f3f2b8af8e to your computer and use it in GitHub Desktop.

Select an option

Save emersonknapp/9eab75d324d799dd198e79f3f2b8af8e to your computer and use it in GitHub Desktop.
Late Subscriber Py
import rclpy
from rclpy.executors import SingleThreadedExecutor
from rclpy.qos import QoSDurabilityPolicy
from rclpy.qos import QoSProfile
from rclpy.qos import QoSReliabilityPolicy
from std_msgs.msg import String
def main(args=None):
topic = 'TOPIC'
topic_type = String
rclpy.init(args=args)
qos_profile = QoSProfile(
depth=parsed_args.history,
# Guaranteed delivery is needed to send messages to late-joining subscription.
reliability=QoSReliabilityPolicy.RELIABLE,
# Store messages on the publisher so that they can be affected by Lifespan
durability=QoSDurabilityPolicy.TRANSIENT_LOCAL)
node = rclpy.node.Node('listener')
sub = node.create_subscription(
String,
topic,
topic_type,
lambda msg: print(msg),
qos_profile)
rclpy.spin(node)
rclpy.shutdown()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment