|
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.
|
|
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.
|
|
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.
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.
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.