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, Node node=None, float timeout=None)
 
str execute (self, Blackboard blackboard)
 
- Public Member Functions inherited from yasmin.state.State
str __call__ (self, Blackboard blackboard=None)
 
str __str__ (self)
 
None cancel_state (self)
 
bool is_canceled (self)
 
bool is_running (self)
 
Set[str] get_outcomes (self)
 

Protected Attributes

Callable[[Blackboard], Any] _create_request_handler = create_request_handler
 A function that creates the service request.
 
Callable[[Blackboard, Any], str] _response_handler = response_handler
 A function that processes the service response.
 
float _timeout = timeout
 Timeout duration for the service call.
 
Node _node = node
 The ROS node used to communicate with the service.
 
str _srv_name = srv_name
 The name of the service to call.
 
Client _service_client = self._node.create_client(srv_type, srv_name)
 The client used to call the service.
 
- Protected Attributes inherited from yasmin.state.State
Set _outcomes = set()
 A set of valid outcomes for this state.
 
bool _running = False
 A flag indicating whether the state is currently running.
 
bool _canceled = False
 A flag indicating whether the state has been canceled.
 

Detailed Description

A state representing a service call in a behavior tree.

This state manages the communication with a ROS service, creating and sending
requests, and handling responses. It can handle timeouts and custom outcomes.

Attributes:
    _node (Node): The ROS 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]): A function that creates the service request.
    _response_handler (Callable[[Blackboard, Any], str]): A function that processes the service response.
    _timeout (float): Timeout duration for the service call.

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,
Node node = None,
float timeout = None )
Initializes the ServiceState with the provided parameters.

Parameters:
    srv_type (Type): The type of the service.
    srv_name (str): The name of the service to be called.
    create_request_handler (Callable[[Blackboard], Any]): A handler to create the request based on the blackboard data.
    outcomes (Set[str], optional): A set of additional outcomes for this state.
    response_handler (Callable[[Blackboard, Any], str], optional): A handler to process the service response.
    node (Node, optional): A ROS node instance; if None, a default instance is used.
    timeout (float, optional): Timeout duration for waiting on the service.

Raises:
    ValueError: If the create_request_handler is not provided.

Reimplemented from yasmin.state.State.

Reimplemented in yasmin_demos.service_client_demo.AddTwoIntsState.

Member Function Documentation

◆ execute()

str yasmin_ros.service_state.ServiceState.execute ( self,
Blackboard blackboard )
Executes the service call.

This method prepares the request using the provided blackboard,
waits for the service to become available, and sends the request.
It also handles the response and can process outcomes based on the
response handler.

Parameters:
    blackboard (Blackboard): The blackboard object that holds the data for request creation.

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

Exceptions:
    Exception: Catches all exceptions during the service call and returns ABORT.

Reimplemented from yasmin.state.State.

Member Data Documentation

◆ _create_request_handler

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

A function that creates the service request.

◆ _node

Node yasmin_ros.service_state.ServiceState._node = node
protected

The ROS node used to communicate with the service.

◆ _response_handler

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

A function that processes the service response.

◆ _service_client

Client yasmin_ros.service_state.ServiceState._service_client = self._node.create_client(srv_type, srv_name)
protected

The client used to call the service.

◆ _srv_name

str yasmin_ros.service_state.ServiceState._srv_name = srv_name
protected

The name of the service to call.

◆ _timeout

yasmin_ros.service_state.ServiceState._timeout = timeout
protected

Timeout duration for the service call.


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