Created
June 12, 2019 14:57
-
-
Save emersonknapp/9eab75d324d799dd198e79f3f2b8af8e to your computer and use it in GitHub Desktop.
Late Subscriber Py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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