|
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) | |
| Shared pointer type for ServiceState. | |
| ServiceState (const std::string &srv_name, CreateRequestHandler create_request_handler, const yasmin::Outcomes &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 yasmin::Outcomes &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 yasmin::Outcomes &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 yasmin::Outcomes &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 (yasmin::Blackboard::SharedPtr blackboard) override |
| Execute the service call and handle the response. | |
| Public Member Functions inherited from yasmin::State | |
| State (const Outcomes &outcomes) | |
| Shared pointer type for State. | |
| virtual | ~State () |
| Virtual destructor. | |
| Blackboard::SharedPtr | get_parameters_blackboard () const |
| Gets the private parameter blackboard of this state. | |
| bool | is_idle () const noexcept |
| Checks if the state is idle. | |
| bool | is_running () const noexcept |
| Checks if the state is currently running. | |
| bool | is_canceled () const noexcept |
| Checks if the state has been canceled. | |
| bool | is_completed () const noexcept |
| Checks if the state has completed execution. | |
| std::string | operator() (Blackboard::SharedPtr blackboard) |
| Executes the state and returns the outcome. | |
| virtual void | configure () |
| Configures the state before execution. | |
| virtual void | cancel_state () |
| Cancels the current state execution. | |
| Outcomes const & | get_outcomes () const noexcept |
| Gets the set of possible outcomes for this state. | |
| void | set_description (const std::string &description) |
| Sets the description for this state. | |
| const std::string & | get_description () const |
| Gets the description of this state. | |
| void | set_outcome_description (const std::string &outcome, const std::string &description) |
| Sets a human-readable description for an outcome. | |
| const std::string & | get_outcome_description (const std::string &outcome) const |
| Gets the human-readable description for an outcome. | |
| const std::unordered_map< std::string, std::string > & | get_outcome_descriptions () const |
| Gets all outcome descriptions. | |
| void | add_input_key (const BlackboardKeyInfo &key_info) |
| Adds an input key to the state's metadata. | |
| void | add_input_key (const std::string &key_name) |
| Adds an input key with a name only. | |
| void | add_input_key (const std::string &key_name, const std::string &description) |
| Adds an input key with a name and description. | |
| template<typename T> | |
| void | add_input_key (const std::string &key_name, const std::string &description, T default_value) |
| Adds an input key with a name, default value and description. | |
| void | add_output_key (const BlackboardKeyInfo &key_info) |
| Adds an output key to the state's metadata. | |
| void | add_output_key (const std::string &key_name) |
| Adds an output key with a name only. | |
| void | add_output_key (const std::string &key_name, const std::string &description) |
| Adds an output key with a name and description. | |
| const std::vector< BlackboardKeyInfo > & | get_input_keys () const |
| Gets the input keys metadata. | |
| const std::vector< BlackboardKeyInfo > & | get_output_keys () const |
| Gets the output keys metadata. | |
| void | declare_parameter (const BlackboardKeyInfo ¶meter_info) |
| Declares a parameter in the state metadata. | |
| void | declare_parameter (const std::string ¶meter_name) |
| Declares a parameter with a name only. | |
| void | declare_parameter (const std::string ¶meter_name, const std::string &description) |
| Declares a parameter with a name and description. | |
| template<typename T> | |
| void | declare_parameter (const std::string ¶meter_name, const std::string &description, T default_value) |
| Declares a parameter with a name, description, and default value. | |
| bool | has_parameter (const std::string ¶meter_name) const |
| Checks if a parameter exists in the state-local parameter storage. | |
| template<typename T> | |
| T | get_parameter (const std::string ¶meter_name) const |
| Gets a parameter from the state-local parameter storage. | |
| template<typename T> | |
| void | set_parameter (const std::string ¶meter_name, T value) |
| Sets a parameter in the state-local parameter storage. | |
| bool | is_parameter_declared (const std::string ¶meter_name) const |
| Checks whether a parameter was declared in the state metadata. | |
| void | copy_parameter_from (const State &source_state, const std::string &source_parameter_name, const std::string &target_parameter_name) |
| Copies a parameter value from another state. | |
| const std::vector< BlackboardKeyInfo > & | get_parameters () const |
| Gets the declared parameter metadata. | |
| const StateMetadata & | get_metadata () const |
| Gets the complete state metadata. | |
| virtual std::string | to_string () const |
| 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 | |
| Outcomes | 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 (yasmin::Blackboard::SharedPtr 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 |
Shared pointer type for ServiceState.
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.