-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeServer.py
43 lines (29 loc) · 1.04 KB
/
NodeServer.py
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
41
42
43
import rclpy
from rclpy.node import Node
import rclpy.time
from rclpy.executors import MultiThreadedExecutor
from rclpy.callback_groups import ReentrantCallbackGroup
from std_srvs.srv import Trigger
import asyncio
class NodeServer(Node):
def __init__(self):
super().__init__('node_server', start_parameter_services=True)
self.cb_group = ReentrantCallbackGroup()
self.Service = self.create_service(
Trigger, '~/Service', self.ConnectCallback)
self.get_logger().info(f"Initialized {self.get_name()}")
def ConnectCallback(self, request, response: Trigger.Response):
self.get_logger().warning("Request handler")
response.success = True
return response
def main(args=None):
rclpy.init(args=args)
minimal_client = NodeServer()
executor = MultiThreadedExecutor()
executor.add_node(minimal_client)
executor.spin()
minimal_client.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())