-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
40 lines (32 loc) · 1.16 KB
/
test.py
File metadata and controls
40 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import rclpy
from rclpy.node import Node
from multi_agent_mapping.msg import GlobalDescriptor
class MyNode(Node):
def __init__(self):
super().__init__('my_node')
# Create publisher
self.pub_descriptors = self.create_publisher(GlobalDescriptor,
'a/distributedMapping/globalDescriptors', 10) # QoS depth of 10
# Create subscriber
self.sub_descriptors = self.create_subscription(
GlobalDescriptor,
'a/distributedMapping/globalDescriptors',
self.listener_callback,
10 # QoS depth of 10
)
# Publish a message for testing
self.publish_message()
def publish_message(self):
msg = GlobalDescriptor()
msg.index = 1 # Example index
self.get_logger().info(f'Publishing Global Descriptor with index: {msg.index}')
self.pub_descriptors.publish(msg)
def listener_callback(self, msg):
self.get_logger().info(f'Received Global Descriptor with index: {msg.index}')
def main(args=None):
rclpy.init(args=args)
my_node = MyNode()
rclpy.spin(my_node)
rclpy.shutdown()
if __name__ == '__main__':
main()