11"""
22MIT LICENSE
33
4- Copyright (C) 2023 Murilo Marques Marinho (www.murilomarinho.info)
4+ Copyright (C) 2023-2025 Murilo Marques Marinho (www.murilomarinho.info)
55
66Permission is hereby granted, free of charge, to any person obtaining a copy
77of this software and associated documentation files (the "Software"), to deal
2828from rclpy .task import Future
2929from rclpy .node import Node
3030
31- from package_with_interfaces .srv import WhatIsThePoint
31+ from package_with_interfaces .srv import AddPoints
3232
3333
34- class WhatIsThePointServiceClientNode (Node ):
35- """A ROS2 Node with a Service Client for WhatIsThePoint ."""
34+ class AddPointsServiceClientNode (Node ):
35+ """A ROS2 Node with a Service Client for AddPoints ."""
3636
3737 def __init__ (self ):
38- super ().__init__ ('what_is_the_point_service_client ' )
38+ super ().__init__ ('add_points_service_client ' )
3939
4040 self .service_client = self .create_client (
41- srv_type = WhatIsThePoint ,
42- srv_name = '/what_is_the_point ' )
41+ srv_type = AddPoints ,
42+ srv_name = '/add_points ' )
4343
4444 while not self .service_client .wait_for_service (timeout_sec = 1.0 ):
4545 self .get_logger ().info (f'service { self .service_client .srv_name } not available, waiting...' )
@@ -54,19 +54,13 @@ def __init__(self):
5454 def timer_callback (self ):
5555 """Method that is periodically called by the timer."""
5656
57- request = WhatIsThePoint .Request ()
58- if random .uniform (0 , 1 ) < 0.5 :
59- request .quote .quote = "I wonder about the Ultimate Question of Life, the Universe, and Everything."
60- request .quote .philosopher_name = "Creators of Deep Thought"
61- request .quote .id = 1979
62- else :
63- request .quote .quote = """[...] your living... it is always potatoes. I dream of potatoes."""
64- request .quote .philosopher_name = "a young Maltese potato farmer"
65- request .quote .id = 2013
57+ request = AddPoints .Request ()
58+ request .a = random .uniform (0 , 1000 )
59+ request .b = random .uniform (0 , 1000 )
6660
6761 if self .future is not None and not self .future .done ():
6862 self .future .cancel () # Cancel the future. The callback will be called with Future.result == None.
69- self .get_logger ().info ("Service Future canceled. The Node took too long to process the service call."
63+ self .get_logger ().warn ("Service Future canceled. The Node took too long to process the service call."
7064 "Is the Service Server still alive?" )
7165 self .future = self .service_client .call_async (request )
7266 self .future .add_done_callback (self .process_response )
@@ -75,15 +69,9 @@ def process_response(self, future: Future):
7569 """Callback for the future, that will be called when it is done"""
7670 response = future .result ()
7771 if response is not None :
78- self .get_logger ().info (dedent (f"""
79- We have thus received the point of our quote.
80-
81- { (response .point .x , response .point .y , response .point .z )}
82- """ ))
72+ self .get_logger ().info (f"The result was { (response .result .x , response .result .y , response .result .z )} " )
8373 else :
84- self .get_logger ().info (dedent ("""
85- The response was None. :(
86- """ ))
74+ self .get_logger ().info ("The response was None." )
8775
8876
8977def main (args = None ):
@@ -95,9 +83,9 @@ def main(args=None):
9583 try :
9684 rclpy .init (args = args )
9785
98- what_is_the_point_service_client_node = WhatIsThePointServiceClientNode ()
86+ add_points_service_client_node = AddPointsServiceClientNode ()
9987
100- rclpy .spin (what_is_the_point_service_client_node )
88+ rclpy .spin (add_points_service_client_node )
10189 except KeyboardInterrupt :
10290 pass
10391 except Exception as e :
0 commit comments