Exemplo n.º 1
0
 def __init__(self):
     #this line has the error,  look at basic example and update what the quoted text is to match this package
     super().__init__('minimal_client_async')
     self.cli = self.create_client(AddTwoInts, 'hero_get_command')
     while not self.cli.wait_for_service(timeout_sec=1.0):
         self.get_logger().info('service not available, waiting again...')
     self.req = AddTwoInts.Request()
Exemplo n.º 2
0
def main(args=None):

    rclpy.init(args=args)

    node = rclpy.create_node('add_two_ints_client')

    cli = node.create_client(AddTwoInts, 'add_two_ints')

    req = AddTwoInts.Request()
    req.a = 2
    req.b = 3
    while not cli.wait_for_service(timeout_sec=1.0):
        print('service not available, waiting again...')
    future = cli.call_async(req)
    while rclpy.ok():
        rclpy.spin_once(node)
        if future.done():
            if future.result() is not None:
                node.get_logger().info('Result of add_two_ints: %d' % future.result().sum)
            else:
                node.get_logger().error('Exception while calling service: %r' % future.exception())
            break

    node.destroy_node()
    rclpy.shutdown()
Exemplo n.º 3
0
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('minimal_client_async')

    cli = node.create_client(AddTwoInts, 'add_two_ints')

    req = AddTwoInts.Request()
    req.a = 41
    req.b = 1
    # TODO(mikaelarguedas) remove this once wait for service implemented
    # wait for connection to be established
    # (no wait for service in Python yet)
    time.sleep(1)
    cli.call(req)
    while rclpy.ok():
        # TODO(mikaelarguedas) This is not the final API, and this does not scale
        # for multiple pending requests. This will change once an executor model is implemented
        # In the future the response will not be stored in cli.response
        if cli.response is not None:
            print('Result of add_two_ints: for %d + %d = %d' %
                  (req.a, req.b, cli.response.sum))
            break
        rclpy.spin_once(node)

    node.destroy_node()
    rclpy.shutdown()
Exemplo n.º 4
0
    async def add_two_ints_callback(self, request, response):
        response.sum = request.a + request.b
        self.get_logger().info('Incoming request\na: %d b: %d' %
                               (request.a, request.b))
        self.cli = self.create_client(AddTwoInts,
                                      'wait',
                                      callback_group=self.cb_group)
        req = AddTwoInts.Request()
        req.a = 10
        self.future = self.cli.call_async(req)
        self.flag_stoptask = False

        while not self.flag_stoptask and not self.future.done():
            pass
        # _count = 0
        # asyncio.set_event_loop(self.loop)
        # while not self.future.done() or self.flag_stoptask:
        #     try:
        #         #await asyncio.wait_for(asyncio.shield(self.future), timeout=1.0)
        #         pass
        #     except asyncio.TimeoutError:
        #         print(f'timeout: {_count}')
        if self.flag_stoptask:
            print('stop!')
            response.sum = 404
        else:
            print('complete!')
            response.sum = 1
        return response
Exemplo n.º 5
0
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('minimal_client_async')

    cli = node.create_client(AddTwoInts, 'add_two_ints')

    req = AddTwoInts.Request()
    req.a = 41
    req.b = 1
    while not cli.wait_for_service(timeout_sec=1.0):
        node.get_logger().info('service not available, waiting again...')

    future = cli.call_async(req)
    while rclpy.ok():
        rclpy.spin_once(node)
        if future.done():
            if future.result() is not None:
                node.get_logger().info(
                    'Result of add_two_ints: for %d + %d = %d' %
                    (req.a, req.b, future.result().sum))
            else:
                node.get_logger().info('Service call failed %r' %
                                       (future.exception(), ))
            break

    node.destroy_node()
    rclpy.shutdown()
Exemplo n.º 6
0
 def __init__(self, node):
     self.cli = node.create_client(AddTwoInts, 'add_two_ints')
     # TODO(mikaelarguedas) remove this once wait for service implemented
     # wait for connection to be established
     # (no wait for service in Python yet)
     time.sleep(1)
     self.req = AddTwoInts.Request()
Exemplo n.º 7
0
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('minimal_client_async')

    cli = node.create_client(AddTwoInts, 'add_two_ints')

    req = AddTwoInts.Request()
    req.a = 41
    req.b = 1
    while not cli.wait_for_service(timeout_sec=1.0):
        node.get_logger().info('service not available, waiting again...')

    cli.call(req)
    while rclpy.ok():
        # TODO(mikaelarguedas) This is not the final API, and this does not scale
        # for multiple pending requests. This will change once an executor model is implemented
        # In the future the response will not be stored in cli.response
        if cli.response is not None:
            node.get_logger().info('Result of add_two_ints: for %d + %d = %d' %
                                   (req.a, req.b, cli.response.sum))
            break
        rclpy.spin_once(node)

    node.destroy_node()
    rclpy.shutdown()
Exemplo n.º 8
0
def main(args=None):
    rclpy.init(args=args)

    node = Node("add_two_ints_no_oop")

    client = node.create_client(AddTwoInts, "add_two_ints")

    while not client.wait_for_service(1.0):
        node.get_logger().warn("Waiting for Server Add Two Ints...")

    request = AddTwoInts.Request()
    request.a = 3
    request.b = 8

    future = client.call_async(request)
    rclpy.spin_until_future_complete(node, future)

    try:
        response = future.result()
        node.get_logger().info(
            str(request.a) + " + " + str(request.b) + " = " +
            str(response.sum))
    except Exception as e:
        node.get_logger().error("Service call failed %r" % (e, ))

    rclpy.shutdown()
Exemplo n.º 9
0
  def __init__(self):
    super().__init__('minimal_client')
    self.client = self.create_client(AddTwoInts, 'add_two_ints')

    while not self.client.wait_for_service(timeout_sec=1.0):
      self.get_logger().info('service not available. waiting again...')
    
    self.req = AddTwoInts.Request()
Exemplo n.º 10
0
    def __init__(self):
        super().__init__('addition_client')
        self.client = self.create_client(AddTwoInts, 'add_two_ints')

        while not self.client.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('service not available, waiting again...')

        self.req = AddTwoInts.Request()
        self.get_logger().info('==== Welcome to Two Int Addition Service ====')
Exemplo n.º 11
0
    def service_client(self, a, b):
        client = self.create_client(AddTwoInts, "First_server")
        while client.wait_for_service(0.25) == False:
            self.get_logger().warn("wating for server")

        request = AddTwoInts.Request()
        request.a = a
        request.b = b
        futur_obj = client.call_async(request)
        futur_obj.add_done_callback(self.future_call)
    def call_service(self, a, b):
        while not self.client.wait_for_service(1):
            self.get_logger().info("waiting for " + self.client.srv_name)

        request = AddTwoInts.Request()
        request.a = a
        request.b = b

        future = self.client.call_async(request)
        future.add_done_callback(partial(self.done_callback, a=a, b=b))
Exemplo n.º 13
0
 def __init__(self):
     super().__init__('minimal_client_async')
     self.cli = self.create_client(AddTwoInts, 'add_two_ints')
     while not self.cli.wait_for_service(timeout_sec=1.0):
         self.get_logger().info('service not available, waiting again...')
     self.req = AddTwoInts.Request()
     self.grp_timer = MutuallyExclusiveCallbackGroup()
     self.create_timer(1.0,
                       self.send_request,
                       callback_group=self.grp_timer)
Exemplo n.º 14
0
 def call_add_two_ints(self, a, b):
     client = self.create_client(AddTwoInts, "add_two_ints")
     while not client.wait_for_service(3.0):
         self.get_logger().warn("Waiting for service add_two_ints")
     request = AddTwoInts.Request()
     request.a = a
     request.b = b
     future = client.call_async(request)
     future.add_done_callback(
         partial(self.callback_add_two_ints, input_a=a,
                 input_b=b))  # callback when future completes.
    def call_add_two_ints_server(self, a, b):
        client = self.create_client(AddTwoInts, "add_two_ints")
        while not client.wait_for_service(1.0):
            self.get_logger().warn("waiting for server Add Two Ints .....")

        request = AddTwoInts.Request()
        request.a = a
        request.b = b

        future = client.call_async(request)
        future.add_done_callback(partial(self.callback_add_two_ints, a=a, b=b))
Exemplo n.º 16
0
    def __init__(self):
        super().__init__('async_service_client')
        self.logger = self.get_logger()

        self._cli = self.create_client(AddTwoInts, 'add_two_ints')
        while not self._cli.wait_for_service(timeout_sec=1.0):
            self.logger.info('service not available, waiting again...')
        self.future = None
        self.req = AddTwoInts.Request()

        self.logger.info('----- [action_client]Start! -----')
Exemplo n.º 17
0
    def call_add_two_ints_server(self, a, b):
        while not self.client_.wait_for_service(1.0):
            self.get_logger().warn("Waiting for add_two_ints Server...")

        request = AddTwoInts.Request()
        request.a = a
        request.b = b

        future = self.client_.call_async(request)
        future.add_done_callback(
            partial(self.callback_call_add_two_ints, a=a, b=b))
Exemplo n.º 18
0
    def __send_srv_request(self):
        req = AddTwoInts.Request()

        self.srv_seq_itr = self.srv_seq_itr + 1

        req.a = self.srv_seq_itr
        req.b = 0
        self.future01 = self.cli01.call_async(req)
        self.future02 = self.cli02.call_async(req)
        self.future03 = self.cli03.call_async(req)

        dtstr = self.__get_time_now() - self._dtstr
        self.logger.info("[%s]:Service Send(%d)" % (dtstr, self.srv_seq_itr))
Exemplo n.º 19
0
    def call_add_two_ints_server(self, a, b):
        client = self.create_client(AddTwoInts, "add_two_ints")
        while not client.wait_for_service(1.0):
            self.get_logger().warn("Waiting for server Add Two Ints...")

        request = AddTwoInts.Request()
        request.a = a
        request.b = b

        future = client.call_async(request)
        # use func_tools.partial to be able to pass additional parameters
        future.add_done_callback(partial(self.handle_server_response, a=a,
                                         b=b))
Exemplo n.º 20
0
 async def call_service():
     nonlocal cli, node, did_run, did_get_result
     did_run = True
     try:
         req = AddTwoInts.Request()
         req.a = 41
         req.b = 1
         future = cli.call_async(req)
         result = await future
         node.get_logger().info('Result of add_two_ints: for %d + %d = %d' %
                                (req.a, req.b, result.sum))
     finally:
         did_get_result = True
Exemplo n.º 21
0
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('add_two_ints_client')

    cli = node.create_client(AddTwoInts, 'add_two_ints')
    max_iter = 3
    i = 0
    while rclpy.ok() and i < max_iter:
        req = AddTwoInts.Request()
        req.a = i
        req.b = i + 1
        cli.call(req)
        cli.wait_for_future()
        print('Result of add_two_ints: %d' % cli.response.sum)
        i += 1
Exemplo n.º 22
0
    def send_request(self):
        # Cancel timer and send a request only once
        self.timer.cancel()

        # Wait for server
        while not self.client.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('server not available, waiting again...')

        # Define a service request
        self.req = AddTwoInts.Request()
        self.req.a = int(sys.argv[1])
        self.req.b = int(sys.argv[2])

        # Call call_async() method
        self.future = self.client.call_async(self.req)
        self.future.add_done_callback(self.get_result_callback)
Exemplo n.º 23
0
def main (args=None):
    rclpy.init(args=args)
    client=Node("My_client_node")
    client_obj=client.create_client(AddTwoInts,"First_server")
    while client_obj.wait_for_service(0.5)== False:
        client.get_logger().warn("wait for server node")

    req=AddTwoInts.Request()
    req.a=15
    req.b=10
    future_obj=client_obj.call_async(req)
    rclpy.spin_until_future_complete(client,future_obj)
    reponse=future_obj.result()
    client.get_logger().error(str(reponse.sum))

    
    rclpy.shutdown()
Exemplo n.º 24
0
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('add_two_ints_client')

    cli = node.create_client(AddTwoInts, 'add_two_ints')
    while not cli.wait_for_service(timeout_sec=1.0):
        print('service not available, waiting again...')
    req = AddTwoInts.Request()
    req.a = 2
    req.b = 3
    cli.call(req)
    cli.wait_for_future()
    node.get_logger().info('Result of add_two_ints: %d' % cli.response.sum)

    node.destroy_node()
    rclpy.shutdown()
Exemplo n.º 25
0
 async def call_service():
     nonlocal cli, node, did_run, did_get_result
     did_run = True
     try:
         req = AddTwoInts.Request()
         req.a = 41
         req.b = 1
         future = cli.call_async(req)
         result = await future
         if result is not None:
             node.get_logger().info(
                 'Result of add_two_ints: for %d + %d = %d' %
                 (req.a, req.b, result.sum))
         else:
             node.get_logger().info('Service call failed %r' % (future.exception(),))
     finally:
         did_get_result = True
Exemplo n.º 26
0
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('add_two_ints_client')

    cli = node.create_client(AddTwoInts, 'add_two_ints')
    # TODO(mikaelarguedas) No wait for service in Python
    # need to leave some time for the connection to be established
    time.sleep(1)
    req = AddTwoInts.Request()
    req.a = 2
    req.b = 3
    cli.call(req)
    cli.wait_for_future()
    node.get_logger().info('Result of add_two_ints: %d' % cli.response.sum)

    node.destroy_node()
    rclpy.shutdown()
Exemplo n.º 27
0
def main(args=None):
    rclpy.init(args=args)
    node = rclpy.create_node('minimal_client')
    cli = node.create_client(AddTwoInts, 'add_two_ints')

    req = AddTwoInts.Request()
    req.a = 41
    req.b = 1
    while not cli.wait_for_service(timeout_sec=1.0):
        node.get_logger().info('service not available, waiting again...')

    future = cli.call_async(req)
    rclpy.spin_until_future_complete(node, future)

    result = future.result()
    node.get_logger().info('Result of add_two_ints: for %d + %d = %d' %
                           (req.a, req.b, result.sum))

    node.destroy_node()
    rclpy.shutdown()
def main(args=None):
    rclpy.init(args=args)
    node = Node("add_nums_client")
    client = node.create_client(AddTwoInts, "add_nums_service")
    while not client.wait_for_service(1):
        node.get_logger().info("waiting for " + client.srv_name)
    request = AddTwoInts.Request()
    request.a = 1
    request.b = 2

    future = client.call_async(request)

    rclpy.spin_until_future_complete(node, future)

    try:
        response = future.result()
        node.get_logger().info("Got " + str(response.sum))
    except Exception as e:
        node.get.get_logger().error("Service error %r" % (e,))


    rclpy.shutdown()
Exemplo n.º 29
0
def main(args=None):
    rclpy.init(args)
    node = rclpy.create_node('minimal_client')
    cli = node.create_client(AddTwoInts, 'add_two_ints')

    req = AddTwoInts.Request()
    req.a = 41
    req.b = 1
    # TODO(mikaelarguedas) remove this once wait for service implemented
    # wait for connection to be established
    # (no wait for service in Python yet)
    time.sleep(1)

    cli.call(req)
    # when calling wait for future
    # spin should not be called in the main loop
    cli.wait_for_future()
    # TODO(mikaelarguedas) This is not the final API, and this does not scale
    # for multiple pending requests. This will change once an executor model is implemented
    # In the future the response will not be stored in cli.response
    print('Result of add_two_ints: for %d + %d = %d' %
          (req.a, req.b, cli.response.sum))
def main(args=None):

    rclpy.init(args=args)

    node = rclpy.create_node('add_two_ints_client')

    cli = node.create_client(AddTwoInts, 'add_two_ints')

    req = AddTwoInts.Request()
    req.a = 2
    req.b = 3
    # TODO(mikaelarguedas) No wait for service in Python
    # need to leave some time for the connection to be established
    time.sleep(1)
    cli.call(req)
    while rclpy.ok():
        rclpy.spin_once(node)
        if cli.response is not None:
            print('Result of add_two_ints: %d' % cli.response.sum)
            break

    node.destroy_node()
    rclpy.shutdown()