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 (std::string srv_name, CreateRequestHandler create_request_handler, std::set< std::string > outcomes, int timeout=-1.0) | |
Construct a ServiceState with a request handler and outcomes. | |
ServiceState (std::string srv_name, CreateRequestHandler create_request_handler, std::set< std::string > outcomes, ResponseHandler response_handler, int timeout=-1.0) | |
Construct a ServiceState with a request handler and response handler. | |
ServiceState (const rclcpp::Node::SharedPtr &node, std::string srv_name, CreateRequestHandler create_request_handler, std::set< std::string > outcomes, ResponseHandler response_handler, int timeout=-1.0) | |
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 (std::set< std::string > outcomes) | |
Constructs a State with a set of possible outcomes. | |
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. | |
bool | is_canceled () const |
Checks if the state has been canceled. | |
bool | is_running () const |
Checks if the state is currently running. | |
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. | |
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. | |
Private Attributes | |
rclcpp::Node::SharedPtr | node_ |
Shared pointer to the ROS 2 node. | |
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 | timeout |
Maximum wait time for service availability. | |
Additional Inherited Members | |
Protected Attributes inherited from yasmin::State | |
std::set< std::string > | outcomes |
The possible outcomes of this state. | |
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. |
outcomes | A set of possible outcomes for this state. |
timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
|
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 | Function to handle the service response. |
timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
|
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 | Function to handle the service response. |
timeout | Maximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely). |
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.
|
private |
Function to create service requests.
|
private |
Shared pointer to the ROS 2 node.
|
private |
Function to handle service responses.
|
private |
Shared pointer to the service client.
|
private |
Name of the service.
|
private |
Maximum wait time for service availability.