|
C++ YASMIN (Yet Another State MachINe)
|
A state class that interacts with a ROS 2 service. More...
#include <service_state.hpp>


Public Member Functions | |
| ServiceState (const std::string &srv_name, CreateRequestHandler create_request_handler, int wait_timeout=-1, int response_timeout=-1, int maximum_retry=3) | |
| Construct a ServiceState with a request handler and outcomes. | |
| ServiceState (const std::string &srv_name, CreateRequestHandler create_request_handler, const std::set< std::string > &outcomes, int wait_timeout=-1, int response_timeout=-1, int maximum_retry=3) | |
| Construct a ServiceState with a request handler and outcomes. | |
| ServiceState (const std::string &srv_name, CreateRequestHandler create_request_handler, const std::set< std::string > &outcomes, rclcpp::CallbackGroup::SharedPtr callback_group=nullptr, int wait_timeout=-1, int response_timeout=-1, int maximum_retry=3) | |
| Construct a ServiceState with a request handler and outcomes. | |
| ServiceState (const std::string &srv_name, CreateRequestHandler create_request_handler, ResponseHandler response_handler, int wait_timeout=-1, int response_timeout=-1, int maximum_retry=3) | |
| Construct a ServiceState with a request handler and response handler. | |
| ServiceState (const std::string &srv_name, CreateRequestHandler create_request_handler, const std::set< std::string > &outcomes, ResponseHandler response_handler, int wait_timeout=-1, int response_timeout=-1, int maximum_retry=3) | |
| Construct a ServiceState with a request handler and response handler. | |
| ServiceState (const rclcpp::Node::SharedPtr &node, const std::string &srv_name, CreateRequestHandler create_request_handler, const std::set< std::string > &outcomes, ResponseHandler response_handler, rclcpp::CallbackGroup::SharedPtr callback_group, int wait_timeout=-1, int response_timeout=-1, int maximum_retry=3) | |
| Construct a ServiceState with a ROS 2 node and handlers. | |
| std::string | execute (std::shared_ptr< yasmin::blackboard::Blackboard > blackboard) override |
| Execute the service call and handle the response. | |
Public Member Functions inherited from yasmin::State | |
| State (const std::set< std::string > &outcomes) | |
| Constructs a State with a set of possible outcomes. | |
| StateStatus | get_status () const |
| Gets the current status of the state. | |
| bool | is_idle () const |
| Checks if the state is idle. | |
| bool | is_running () const |
| Checks if the state is currently running. | |
| bool | is_canceled () const |
| Checks if the state has been canceled. | |
| bool | is_completed () const |
| Checks if the state has completed execution. | |
| std::string | operator() (std::shared_ptr< blackboard::Blackboard > blackboard) |
| Executes the state and returns the outcome. | |
| virtual void | cancel_state () |
| Cancels the current state execution. | |
| std::set< std::string > const & | get_outcomes () |
| Gets the set of possible outcomes for this state. | |
| virtual std::string | to_string () |
| Converts the state to a string representation. | |
Protected Attributes | |
| rclcpp::Node::SharedPtr | node_ |
| Shared pointer to the ROS 2 node. | |
Protected Attributes inherited from yasmin::State | |
| std::set< std::string > | outcomes |
| The possible outcomes of this state. | |
Private Types | |
| using | Request = typename ServiceT::Request::SharedPtr |
| Alias for the service request type. | |
| using | Response = typename ServiceT::Response::SharedPtr |
| Alias for the service response type. | |
| using | CreateRequestHandler |
| Function type for creating a request. | |
| using | ResponseHandler |
| Function type for handling a response. | |
Private Member Functions | |
| Request | create_request (std::shared_ptr< yasmin::blackboard::Blackboard > blackboard) |
| Create a service request based on the blackboard. | |
| void | response_callback (typename rclcpp::Client< ServiceT >::SharedFuture response) |
| Callback for handling the service response. | |
Private Attributes | |
| std::shared_ptr< rclcpp::Client< ServiceT > > | service_client |
| Shared pointer to the service client. | |
| CreateRequestHandler | create_request_handler |
| Function to create service requests. | |
| ResponseHandler | response_handler |
| Function to handle service responses. | |
| std::string | srv_name |
| Name of the service. | |
| int | wait_timeout |
| Maximum wait time for service availability. | |
| int | response_timeout |
| Timeout for the service response. | |
| int | maximum_retry |
| Maximum number of retries. | |
| std::condition_variable | response_done_cond |
| Condition variable for response completion. | |
| std::mutex | response_done_mutex |
| Mutex for protecting response completion. | |
| Response | service_response |
| Shared pointer to the service response. | |
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 yasmin::State class.
| ServiceT | The type of the ROS 2 service this state interacts with. |
|
private |
Function type for creating a request.
|
private |
Alias for the service request type.
|
private |
Alias for the service response type.
|
private |
Function type for handling a response.
|
inline |
Construct a ServiceState with a request handler and outcomes.
| srv_name | The name of the service to call. |
| create_request_handler | Function to create a service request. |
| wait_timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
| response_timeout | Maximum time to wait for the service response, in seconds. Default is -1 (wait indefinitely). |
| maximum_retry | (Optional) Maximum retries of the service if it returns timeout. Default is 3. |
|
inline |
Construct a ServiceState with a request handler and outcomes.
| srv_name | The name of the service to call. |
| create_request_handler | Function to create a service request. |
| outcomes | A set of possible outcomes for this state. |
| wait_timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
| response_timeout | Maximum time to wait for the service response, in seconds. Default is -1 (wait indefinitely). |
| maximum_retry | (Optional) Maximum retries of the service if it returns timeout. Default is 3. |
|
inline |
Construct a ServiceState with a request handler and outcomes.
| srv_name | The name of the service to call. |
| create_request_handler | Function to create a service request. |
| outcomes | A set of possible outcomes for this state. |
| callback_group | (Optional) The callback group for the subscription. |
| wait_timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
| response_timeout | Maximum time to wait for the service response, in seconds. Default is -1 (wait indefinitely). |
| maximum_retry | (Optional) Maximum retries of the service if it returns timeout. Default is 3. |
|
inline |
Construct a ServiceState with a request handler and response handler.
| srv_name | The name of the service to call. |
| create_request_handler | Function to create a service request. |
| response_handler | (Optional) Function to handle the service response. |
| wait_timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
| response_timeout | Maximum time to wait for the service response, in seconds. Default is -1 (wait indefinitely). |
| maximum_retry | (Optional) Maximum retries of the service if it returns timeout. Default is 3. |
|
inline |
Construct a ServiceState with a request handler and response handler.
| srv_name | The name of the service to call. |
| create_request_handler | Function to create a service request. |
| outcomes | A set of possible outcomes for this state. |
| response_handler | (Optional) Function to handle the service response. |
| wait_timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
| response_timeout | Maximum time to wait for the service response, in seconds. Default is -1 (wait indefinitely). |
| maximum_retry | (Optional) Maximum retries of the service if it returns timeout. Default is 3. |
|
inline |
Construct a ServiceState with a ROS 2 node and handlers.
| node | A shared pointer to the ROS 2 node. |
| srv_name | The name of the service to call. |
| create_request_handler | Function to create a service request. |
| outcomes | A set of possible outcomes for this state. |
| response_handler | (Optional) Function to handle the service response. |
| callback_group | (Optional) The callback group for the subscription. |
| wait_timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
| response_timeout | Maximum time to wait for the service response, in seconds. Default is -1 (wait indefinitely). |
| maximum_retry | (Optional) Maximum retries of the service if it returns timeout. Default is 3. |
| std::invalid_argument | if the create_request_handler is nullptr. |
|
inlineprivate |
Create a service request based on the blackboard.
| blackboard | A shared pointer to the blackboard containing data for request creation. |
|
inlineoverridevirtual |
Execute the service call and handle the response.
This function creates a request based on the blackboard data, waits for the service to become available, sends the request, and processes the response.
| blackboard | A shared pointer to the blackboard containing data for request creation. |
Reimplemented from yasmin::State.
|
inlineprivate |
Callback for handling the service response.
This function is called when the service response is received. It stores the response and signals the waiting thread.
| response | The response received from the service. |
|
private |
Function to create service requests.
|
private |
Maximum number of retries.
|
protected |
Shared pointer to the ROS 2 node.
|
private |
Condition variable for response completion.
|
private |
Mutex for protecting response completion.
|
private |
Function to handle service responses.
|
private |
Timeout for the service response.
|
private |
Shared pointer to the service client.
|
private |
Shared pointer to the service response.
|
private |
Name of the service.
|
private |
Maximum wait time for service availability.