Python YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin_ros.service_state.ServiceState Class Reference
Inheritance diagram for yasmin_ros.service_state.ServiceState:
Collaboration diagram for yasmin_ros.service_state.ServiceState:

Public Member Functions

None __init__ (self, Type srv_type, str srv_name, Callable create_request_handler, Set[str] outcomes=None, Callable response_handler=None, CallbackGroup callback_group=None, Node node=None, float wait_timeout=None, float response_timeout=None, int maximum_retry=3)
 
str execute (self, Blackboard blackboard)
 
None response_callback (self, Future future)
 

Public Attributes

 response_callback = self._service_client.call_async(request)
 

Protected Attributes

Callable[[Blackboard], Any] _create_request_handler = create_request_handler
 Function to create service requests.
 
Callable[[Blackboard, Any], str] _response_handler = response_handler
 Function to handle service responses.
 
float _wait_timeout = wait_timeout
 Maximum wait time for service availability.
 
float _response_timeout = response_timeout
 Timeout for the service response.
 
Node _node = node
 The ROS 2 node used to communicate with the service.
 
str _srv_name = srv_name
 Name of the service.
 
Client _service_client
 Shared pointer to the service client.
 
Any _response = None
 The response received from the service.
 
int _maximum_retry = maximum_retry
 Maximum number of retries.
 
Event _response_received_event = Event()
 Event to signal when the service response is received.
 

Detailed Description

A state class that interacts with a ROS 2 service.

This class manages communication with a specified ROS 2 service,
allowing it to send requests and handle responses. It extends
the base State class.

Attributes:
    _node (Node): The ROS 2 node used to communicate with the service.
    _srv_name (str): The name of the service to call.
    _service_client (Client): The client used to call the service.
    _create_request_handler (Callable[[Blackboard], Any]): Function to create service requests.
    _response (Any): The response received from the service.
    _response_handler (Callable[[Blackboard, Any], str]): Function to handle service responses.
    _wait_timeout (float): Maximum wait time for service availability.
    _response_timeout (float): Timeout for the service response.
    _maximum_retry (int): Maximum number of retries.
    _response_received_event (Event): Event to signal when the service response is received.

Constructor & Destructor Documentation

◆ __init__()

None yasmin_ros.service_state.ServiceState.__init__ ( self,
Type srv_type,
str srv_name,
Callable create_request_handler,
Set[str] outcomes = None,
Callable response_handler = None,
CallbackGroup callback_group = None,
Node node = None,
float wait_timeout = None,
float response_timeout = None,
int maximum_retry = 3 )
Initializes the ServiceState with the provided parameters.

Args:
    srv_type (Type): The type of the service.
    srv_name (str): The name of the service to call.
    create_request_handler (Callable[[Blackboard], Any]): Function to create a service request.
    outcomes (Set[str], optional): A set of possible outcomes for this state.
    response_handler (Callable[[Blackboard, Any], str], optional): Function to handle the service response.
    callback_group (CallbackGroup, optional): The callback group for the service client.
    node (Node, optional): A ROS 2 node instance; if None, a default instance is used.
    wait_timeout (float, optional): Maximum time to wait for the service to become available. Default is None (wait indefinitely).
    response_timeout (float, optional): Maximum time to wait for the service response. Default is None (wait indefinitely).
    maximum_retry (int, optional): Maximum retries of the service if it returns timeout. Default is 3.

Raises:
    ValueError: If the create_request_handler is not provided.

Member Function Documentation

◆ execute()

str yasmin_ros.service_state.ServiceState.execute ( self,
Blackboard blackboard )
Execute the service call and handle the response.

This method creates a request based on the blackboard data, waits for the
service to become available, sends the request asynchronously, and waits for
the response using a threading Event.

Args:
    blackboard (Blackboard): A shared pointer to the blackboard containing data for
        request creation.

Returns:
    str: The outcome of the service call, which can be SUCCEED, ABORT, or TIMEOUT.

◆ response_callback()

None yasmin_ros.service_state.ServiceState.response_callback ( self,
Future future )
Callback function to process the service response.

This method is called when the service response is received. It stores
the response and signals the waiting thread by setting the event.

Args:
    future (Future): The future object containing the service response.

Member Data Documentation

◆ _create_request_handler

Callable[[Blackboard], Any] yasmin_ros.service_state.ServiceState._create_request_handler = create_request_handler
protected

Function to create service requests.

◆ _maximum_retry

int yasmin_ros.service_state.ServiceState._maximum_retry = maximum_retry
protected

Maximum number of retries.

◆ _node

Node yasmin_ros.service_state.ServiceState._node = node
protected

The ROS 2 node used to communicate with the service.

◆ _response

Any yasmin_ros.service_state.ServiceState._response = None
protected

The response received from the service.

◆ _response_handler

Callable[[Blackboard, Any], str] yasmin_ros.service_state.ServiceState._response_handler = response_handler
protected

Function to handle service responses.

◆ _response_received_event

Event yasmin_ros.service_state.ServiceState._response_received_event = Event()
protected

Event to signal when the service response is received.

◆ _response_timeout

yasmin_ros.service_state.ServiceState._response_timeout = response_timeout
protected

Timeout for the service response.

◆ _service_client

Client yasmin_ros.service_state.ServiceState._service_client
protected
Initial value:
= ROSClientsCache.get_or_create_service_client(
self._node,
srv_type,
srv_name,
callback_group=callback_group,
)

Shared pointer to the service client.

◆ _srv_name

str yasmin_ros.service_state.ServiceState._srv_name = srv_name
protected

Name of the service.

◆ _wait_timeout

float yasmin_ros.service_state.ServiceState._wait_timeout = wait_timeout
protected

Maximum wait time for service availability.

◆ response_callback

yasmin_ros.service_state.ServiceState.response_callback = self._service_client.call_async(request)

The documentation for this class was generated from the following file: