ROS2 Deadline QoS issue
I have the below code for ROS2 Service Server and Service Client
Server:
import rclpy
from rclpy.node import Node
from rclpy.qos import QoSProfile
from example_interfaces.srv import AddTwoInts
import time
class AddTwoIntsServer(Node):
def __init__(self):
super().__init__('add_two_ints_server')
self.srv = self.create_service(AddTwoInts, 'add_two_ints', self.add_two_ints_callback,
qos_profile=QoSProfile(depth=1, deadline=rclpy.duration.Duration(seconds=1)))
def add_two_ints_callback(self, request, response):
response.sum = request.a + request.b
self.get_logger().info('Incoming request: %d + %d' % (request.a, request.b))
time.sleep(3)
self.get_logger().info('Sending response: %d' % response.sum)
return response
def main(args=None):
rclpy.init(args=args)
server = AddTwoIntsServer()
rclpy.spin(server)
rclpy.shutdown()
if __name__ == '__main__':
main()
Client:
import rclpy
from rclpy.node import Node
from rclpy.qos import QoSProfile
from example_interfaces.srv import AddTwoInts
class AddTwoIntsClient(Node):
def __init__(self):
super().__init__('add_two_ints_client')
qos_profile.deadline.policy_kind = QoSDeadlineRequested.POLICY_KIND_DEADLINE
self.cli = self.create_client(AddTwoInts, 'add_two_ints',
qos_profile=QoSProfile(depth=1, deadline=rclpy.duration.Duration(seconds=1)))
while not self.cli.wait_for_service(timeout_sec=1.0):
self.get_logger().info('Service not available, waiting...')
def call_add_two_ints_service(self, a, b):
request = AddTwoInts.Request()
request.a = a
request.b = b
future = self.cli.call_async(request)
rclpy.spin_until_future_complete(self, future)
if future.result() is not None:
response = future.result()
self.get_logger().info('Result: %d' % response.sum)
else:
self.get_logger().error('Service call failed')
def main(args=None):
rclpy.init(args=args)
client = AddTwoIntsClient()
client.call_add_two_ints_service(2, 3)
rclpy.shutdown()
if __name__ == '__main__':
main()
I would like to replicate the situation where a deadline is missed using the QoS policy, but I am not receiving any notifications indicating a missed deadline in this particular scenario. Instead, I'm able to receive the response.
Asked by Suchitra on 2023-07-18 01:46:02 UTC
Comments