Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- import json
- import rclpy
- from rclpy.node import Node
- from std_msgs.msg import String
- from types import SimpleNamespace
- class MinimalSubscriber(Node):
- def __init__(self):
- super().__init__('minimal_subscriber')
- self.subscription = self.create_subscription(
- String,
- 'topic',
- self.listener_callback,
- 10)
- self.subscription # prevent unused variable warning
- def listener_callback(self, msg):
- self.get_logger().info('I heard: "%s"' % msg.data)
- x = json.loads(msg.data, object_hook=lambda d: SimpleNamespace(**d))
- print(x.id, x.action)
- def main(args=None):
- rclpy.init(args=args)
- minimal_subscriber = MinimalSubscriber()
- rclpy.spin(minimal_subscriber)
- # Destroy the node explicitly
- # (optional - otherwise it will be done automatically
- # when the garbage collector destroys the node object)
- minimal_subscriber.destroy_node()
- rclpy.shutdown()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement