Пример #1
0
 def _set_mouse_lifecycle_state(self, transition_id):
     request = ChangeState.Request()
     request.transition.id = transition_id
     future = self._client_change_state.call_async(request)
     executor = rclpy.executors.SingleThreadedExecutor(context=self.context)
     rclpy.spin_until_future_complete(self, future, executor=executor)
     return future.result().success
Пример #2
0
def change_state(lifecycle_node, change_state_args=''):
    node = rclpy.create_node('lc_client_py')

    service_name = lifecycle_node + '/change_state'
    cli = node.create_client(ChangeState, service_name)
    if not cli.wait_for_service(timeout_sec=5.0):
        node.get_logger().warn('Unable to call service %s' % service_name)
        return

    req = ChangeState.Request()
    if change_state_args == 'configure':
        req.transition.id = Transition.TRANSITION_CONFIGURE
    elif change_state_args == 'cleanup':
        req.transition.id = Transition.TRANSITION_CLEANUP
    elif change_state_args == 'shutdown':
        req.transition.id = Transition.TRANSITION_SHUTDOWN
    elif change_state_args == 'activate':
        req.transition.id = Transition.TRANSITION_ACTIVATE
    elif change_state_args == 'deactivate':
        req.transition.id = Transition.TRANSITION_DEACTIVATE
    future = cli.call_async(req)
    rclpy.spin_until_future_complete(node, future)
    if future.result() is not None:
        resp = future.result()
        if resp.success:
            node.get_logger().info('%s successfully triggered transition %s' %
                                   (lifecycle_node, change_state_args))
        else:
            node.get_logger().info('%s failed to triggered transition %s' %
                                   (lifecycle_node, change_state_args))
    else:
        node.get_logger.error(
            'Exception %r during call %s in transition %s' %
            (future.exception(), lifecycle_node, change_state_args))
 def __init__(self):
     super().__init__('gz_srv_disable')
     self.cli = self.create_client(ChangeState,
                                   '/joint_state_controller/change_state')
     while not self.cli.wait_for_service(timeout_sec=5.0):
         self.get_logger().info('service not available, waiting again...')
     self.req = ChangeState.Request()
Пример #4
0
def change_state(lifecycle_node, change_state_args=''):
    node = rclpy.create_node('lc_client_py')

    service_name = lifecycle_node + '/change_state'
    cli = node.create_client(ChangeState, service_name)
    if not cli.wait_for_service(timeout_sec=5.0):
        node.get_logger().warn('Unable to call service %s' % service_name)
        return

    req = ChangeState.Request()
    if change_state_args == 'configure':
        req.transition.id = Transition.TRANSITION_CONFIGURE
    elif change_state_args == 'cleanup':
        req.transition.id = Transition.TRANSITION_CLEANUP
    elif change_state_args == 'shutdown':
        req.transition.id = Transition.TRANSITION_SHUTDOWN
    elif change_state_args == 'activate':
        req.transition.id = Transition.TRANSITION_ACTIVATE
    elif change_state_args == 'deactivate':
        req.transition.id = Transition.TRANSITION_DEACTIVATE
    cli.call(req)
    cli.wait_for_future()
    if cli.response.success:
        node.get_logger().info('%s successfully triggered transition %s' %
                               (lifecycle_node, change_state_args))
    else:
        node.get_logger().info('%s failed to triggered transition %s' %
                               (lifecycle_node, change_state_args))
    def set_lifecycle_state(self, transition_id):
        """
        Set lifecycle state.

        Arguments
        ---------
        transition_id : int

        Returns
        -------
        success : bool

        """
        request = ChangeState.Request()
        request.transition.id = transition_id
        future = self.client_change_state.call_async(request)
        rclpy.spin_until_future_complete(self,
                                         future,
                                         executor=self.executor,
                                         timeout_sec=self.timeout_sec)
        if future.result() is None:
            raise RuntimeError(
                "Interpreter tried to set current lifecycle state, but failed."
            )
        return future.result().success
Пример #6
0
 def do_transition_(self, id):
     req = ChangeState.Request()
     req.transition = Transition()
     req.transition.id = id
     fut = self.change_state_client_.call_async(req)
     rclpy.spin_until_future_complete(self.node_, fut, executor=self.exe_)
     resp = fut.result()
     self.assertTrue(resp is not None)
     self.assertTrue(resp.success)
Пример #7
0
    def __init__(self):
        super().__init__('system_modes_test_client')

        self.clis = self.create_client(ChangeState, '/sys/change_state')
        while not self.clis.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('service not available, waiting again...')
        self.reqs = ChangeState.Request()

        self.clim = self.create_client(ChangeMode, '/sys/change_mode')
        while not self.clim.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('service not available, waiting again...')
        self.reqm = ChangeMode.Request()
Пример #8
0
def change_state(lifecycle_node, change_state_args=''):
    node = rclpy.create_node('lc_client_py')

    cli = node.create_client(ChangeState, lifecycle_node + '/change_state')
    req = ChangeState.Request()
    if change_state_args == 'configure':
        req.transition.id = Transition.TRANSITION_CONFIGURE
    elif change_state_args == 'cleanup':
        req.transition.id = Transition.TRANSITION_CLEANUP
    elif change_state_args == 'shutdown':
        req.transition.id = Transition.TRANSITION_SHUTDOWN
    elif change_state_args == 'activate':
        req.transition.id = Transition.TRANSITION_ACTIVATE
    elif change_state_args == 'deactivate':
        req.transition.id = Transition.TRANSITION_DEACTIVATE
    cli.call(req)
    cli.wait_for_future()
    if cli.response.success:
        print('%s successfully triggered transition %s' % (lifecycle_node, change_state_args))
    else:
        print('%s failed to triggered transition %s' % (lifecycle_node, change_state_args))
Пример #9
0
def call_change_states(*, node, transitions):
    clients = {}
    futures = {}
    # create clients
    for node_name in transitions.keys():
        client = node.create_client(
            ChangeState, '/{node_name}/change_state'.format_map(locals()))
        clients[node_name] = client

    # wait until all clients have been called
    while True:
        for node_name in [n for n in transitions.keys() if n not in futures]:
            # call as soon as ready
            client = clients[node_name]
            if client.service_is_ready():
                request = ChangeState.Request()
                request.node_name = node_name
                request.transition = transitions[node_name]
                future = client.call_async(request)
                futures[node_name] = future

        if len(futures) == len(clients):
            break
        rclpy.spin_once(node, timeout_sec=1.0)

    # wait for all responses
    for future in futures.values():
        rclpy.spin_until_future_complete(node, future)

    # return success flag or exception for each node
    results = {}
    for node_name, future in futures.items():
        if future.result() is not None:
            response = future.result()
            results[node_name] = response.success
        else:
            results[node_name] = future.exception()
    return results