def verify_estop(robot):
    """Verify the robot is not estopped"""
    client = robot.ensure_client(EstopClient.default_service_name)
    if client.get_status().stop_level != estop_pb2.ESTOP_LEVEL_NONE:
        error_message = "Robot is estopped. Please use an external E-Stop client, such as the" \
        " estop SDK example, to configure E-Stop."
        robot.logger.error(error_message)
        raise Exception(error_message)
Beispiel #2
0
def monitor_status_until_complete_or_failed(request_id, client, capability_name, action_name,
                                            verbose):
    """Helper status that monitors the status (using the GetStatus RPC) for the acquisition request until it
    completes, fails, or times out.

    Args:
        request_id (int): The request_id for the acquisition request (returned by the AcquireData RPC).
        client (DataAcquisitionClient): The client for the data acquisition service running on robot.
        capability_name (string): The data source name being acquired.
        action_name (string): The action name from the AcquireData RPC being monitored.
        verbose (boolean): Print additional logging information on failure.

    Returns:
        A boolean indicating that the GetStatus RPC eventually received a "complete" status.
    """
    start_time = time.time()
    should_continue = time.time() - start_time < kMonitorStatusTimeoutSecs
    while should_continue:
        get_status_response = None
        try:
            get_status_response = client.get_status(request_id)
        except ResponseError as err:
            _LOGGER.error(
                "Exception raised when monitoring the status of request %s for data '%s' with action_name '%s'.",
                request_id, capability_name, action_name)
            if verbose:
                log_debug_information(err)
            return False

        if get_status_response.status in kAcquisitionSucceededStatuses:
            return True
        elif get_status_response.status in kAcquisitionFailedStatuses:
            _LOGGER.error(
                "Request %s for data '%s' with action_name '%s' failed the GetStatus RPC with status %s.",
                request_id, capability_name, action_name,
                data_acquisition_pb2.GetStatusResponse.Status.Name(get_status_response.status))
            if verbose:
                _LOGGER.info("The full GetStatus response: %s", get_status_response)
            return False
        elif get_status_response.status in kAcquisitionContinuesStatuses:
            # Sleep briefly, then re-attempt to make a GetStatus RPC to see if the acquisition has completed.
            time.sleep(0.2)
            should_continue = time.time() - start_time < kMonitorStatusTimeoutSecs
            continue
        else:
            _LOGGER.error(
                "Unexpected status %s when monitoring request %s for data '%s' with action_name '%s'.",
                data_acquisition_pb2.GetStatusResponse.Status.Name(get_status_response.status),
                request_id, capability_name, action_name)
            if verbose:
                _LOGGER.info("The full GetStatus response: %s", get_status_response)
            return False

    _LOGGER.warning(
        "No result to the GetStatus RPC within %s seconds for request %s of data '%s' with action_name '%s'.",
        kMonitorStatusTimeoutSecs, request_id, capability_name, action_name)
    return True
Beispiel #3
0
def call_and_check(client, endpoint, expected_level, sync):
    if sync:
        if expected_level == StopLevel.ESTOP_LEVEL_CUT:
            endpoint.stop()
        if expected_level == StopLevel.ESTOP_LEVEL_NONE:
            endpoint.allow()
    else:
        if expected_level == StopLevel.ESTOP_LEVEL_CUT:
            fut = endpoint.stop_async()
        if expected_level == StopLevel.ESTOP_LEVEL_NONE:
            fut = endpoint.allow_async()
        fut.result()

    stop_level = client.get_status().stop_level
    assert stop_level == expected_level.value
    _LOGGER.info('Stop level: %s', StopLevel(stop_level))
Beispiel #4
0
def cancel_request_and_monitor_status(request_id, client, capability_name,
                                      action_name, verbose):
    """Helper status that monitors the status (using the GetStatus RPC) for the acquisition request after it
    is cancelled until it recieves a "cancellation complete" status, or fails and times out.

    Args:
        request_id (int): The request_id for the acquisition request (returned by the AcquireData RPC).
        client (DataAcquisitionClient): The client for the data acquisition service running on robot.
        capability_name (string): The data source name being acquired.
        action_name (string): The action name from the AcquireData RPC being monitored.
        verbose (boolean): Print additional logging information on failure.

    Returns:
        A boolean indicating that the GetStatus RPC eventually recieved a "cancellation complete" status.
    """
    try:
        cancel_res = client.cancel_acquisition(request_id)
    except CancellationFailedError as err:
        _LOGGER.error(
            "The CancelAcquisition RPC for request %s of data '%s' with action_name '%s' failed. "
            "Check that the CancelAcquisition RPC is implemented and working in the plugin service.",
            request_id, capability_name, action_name)
        if verbose:
            log_debug_information(err)
        return False
    except RequestIdDoesNotExistError as err:
        _LOGGER.error(
            "The request ID %s for data '%s' with action_name '%s' does not exist. Something may have "
            "gone wrong with the AcquireData request or the id was not saved/deleted by the plugin service.",
            request_id, capability_name, action_name)
        if verbose:
            log_debug_information(err)
        return False
    except ResponseError as err:
        _LOGGER.error(
            "Exception raised when cancelling request %s for data '%s' with action_name '%s'.",
            request_id, capability_name, action_name)
        if verbose:
            log_debug_information(err)
        return False

    start_time = time.time()
    should_continue = time.time() - start_time < kMonitorStatusTimeoutSecs
    first_time_warning = True
    while should_continue:
        get_status_response = None
        try:
            get_status_response = client.get_status(request_id)
        except ResponseError as err:
            _LOGGER.error(
                "Exception raised when monitoring the cancellation status of request %s for data '%s'"
                " with action_name '%s'.", request_id, capability_name,
                action_name)
            if verbose:
                log_debug_information(err)
            return False

        if get_status_response.status in kAcquisitionCancellationSucceededStatuses:
            return True
        elif get_status_response.status in kAcquisitionCancellationContinuesStatuses:
            # Sleep breifly, then re-attempt to make a GetStatus RPC to see if the acquisition has cancelled.
            time.sleep(0.2)
        elif get_status_response.status in kAcquisitionContinuesStatuses:
            # Warning that plugin did not update status to reflect that cancel rpc was recieved.
            if first_time_warning:
                _LOGGER.warning(
                    "The plugin did not update the status to reflect that a CancelAcquisition RPC was recieved. Try "
                    "setting the status as STATUS_CANCEL_IN_PROGRESS after responding to the RPC."
                )
                _LOGGER.info("Request %s for data '%s' with action_name '%s",
                             request_id, capability_name, action_name)
                if verbose:
                    _LOGGER.info(
                        "Request %s for data '%s' with action_name '%s",
                        request_id, capability_name, action_name)
                    _LOGGER.info("The full GetStatus response: %s",
                                 get_status_response)
                first_time_warning = False
            # Sleep breifly, then re-attempt to make a GetStatus RPC to see if the acquisition has cancelled.
            time.sleep(0.2)
        elif get_status_response.status in kAcquisitionCancellationFailedStatuses:
            # Cancellation-specific failure.
            _LOGGER.error(
                "The cancellation request %s for data '%s' with action_name '%s' failed the GetStatus "
                "RPC with status %s.", request_id, capability_name,
                action_name,
                data_acquisition_pb2.GetStatusResponse.Status.Name(
                    get_status_response.status))
            if verbose:
                _LOGGER.info("The full GetStatus response: %s",
                             get_status_response)
            return False
        elif get_status_response.status in kAcquisitionFailedStatuses:
            # Failed for reason other than cancellation failed statuses.
            _LOGGER.error(
                "The cancellation request %s for data '%s' with action_name '%s' failed the GetStatus RPC with status %s."
                "This is not an expected failure status after a CancelAcquisition RPC.",
                request_id, capability_name, action_name,
                data_acquisition_pb2.GetStatusResponse.Status.Name(
                    get_status_response.status))
            if verbose:
                _LOGGER.info("The full GetStatus response: %s",
                             get_status_response)
            return False
        else:
            _LOGGER.error(
                "Unexpected status %s when monitoring cancellation request %s for data '%s' with action_name '%s'.",
                data_acquisition_pb2.GetStatusResponse.Status.Name(
                    get_status_response.status), request_id, capability_name,
                action_name)
            if verbose:
                _LOGGER.info("The full GetStatus response: %s",
                             get_status_response)
            return False

        should_continue = time.time() - start_time < kMonitorStatusTimeoutSecs

    _LOGGER.warning(
        "Did not get a result for the GetStatus RPC within %s seconds for request %s of data '%s' with "
        "action_name '%s'.", kMonitorStatusTimeoutSecs, request_id,
        capability_name, action_name)
    return True
Beispiel #5
0
def verify_estop(robot):
    client = robot.ensure_client(EstopClient.default_service_name)
    if client.get_status().stop_level != estop_pb2.ESTOP_LEVEL_NONE:
        error_message = "Robot is estopped. Can't continue calibration."
        robot.logger.error(error_message)
        raise Exception(error_message)