-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathcomplex_node.py
More file actions
69 lines (57 loc) · 2.16 KB
/
complex_node.py
File metadata and controls
69 lines (57 loc) · 2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 2026 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import rclpy
from rclpy.action import ActionServer
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
from rclpy.qos import qos_profile_system_default
from test_msgs.action import Fibonacci
from test_msgs.msg import Arrays
from test_msgs.msg import Strings
from test_msgs.srv import BasicTypes
class ComplexNode(Node):
def __init__(self):
super().__init__('complex_node')
self.publisher = self.create_publisher(
Arrays, 'arrays', qos_profile_system_default
)
self.subscription = self.create_subscription(
Strings, 'strings', lambda msg: None, qos_profile_system_default
)
self.server = self.create_service(BasicTypes, 'basic', lambda req, res: res)
self.action_server = ActionServer(
self, Fibonacci, 'fibonacci', self.action_callback
)
self.timer = self.create_timer(1.0, self.pub_callback)
def destroy_node(self):
self.timer.destroy()
self.publisher.destroy()
self.subscription.destroy()
self.server.destroy()
self.action_server.destroy()
super().destroy_node()
def pub_callback(self):
self.publisher.publish(Arrays())
def action_callback(self, goal_handle):
goal_handle.succeed()
return Fibonacci.Result()
def main(args=None):
try:
with rclpy.init(args=args):
node = ComplexNode()
rclpy.spin(node)
except (KeyboardInterrupt, ExternalShutdownException):
print('node stopped cleanly')
if __name__ == '__main__':
main()