C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin_ros::ServiceState< ServiceT > Class Template Reference

A state class that interacts with a ROS 2 service. More...

#include <service_state.hpp>

Inheritance diagram for yasmin_ros::ServiceState< ServiceT >:
Collaboration diagram for yasmin_ros::ServiceState< ServiceT >:

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.
 

Detailed Description

template<typename ServiceT>
class yasmin_ros::ServiceState< ServiceT >

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.

Template Parameters
ServiceTThe type of the ROS 2 service this state interacts with.

Member Typedef Documentation

◆ CreateRequestHandler

template<typename ServiceT >
using yasmin_ros::ServiceState< ServiceT >::CreateRequestHandler
private
Initial value:
std::function<Request(std::shared_ptr<yasmin::blackboard::Blackboard>)>
typename ServiceT::Request::SharedPtr Request
Alias for the service request type.
Definition service_state.hpp:44

Function type for creating a request.

◆ Request

template<typename ServiceT >
using yasmin_ros::ServiceState< ServiceT >::Request = typename ServiceT::Request::SharedPtr
private

Alias for the service request type.

◆ Response

template<typename ServiceT >
using yasmin_ros::ServiceState< ServiceT >::Response = typename ServiceT::Response::SharedPtr
private

Alias for the service response type.

◆ ResponseHandler

template<typename ServiceT >
using yasmin_ros::ServiceState< ServiceT >::ResponseHandler
private
Initial value:
std::function<std::string(
std::shared_ptr<yasmin::blackboard::Blackboard>, Response)>
typename ServiceT::Response::SharedPtr Response
Alias for the service response type.
Definition service_state.hpp:46

Function type for handling a response.

Constructor & Destructor Documentation

◆ ServiceState() [1/3]

template<typename ServiceT >
yasmin_ros::ServiceState< ServiceT >::ServiceState ( std::string srv_name,
CreateRequestHandler create_request_handler,
std::set< std::string > outcomes,
int timeout = -1.0 )
inline

Construct a ServiceState with a request handler and outcomes.

Parameters
srv_nameThe name of the service to call.
create_request_handlerFunction to create a service request.
outcomesA set of possible outcomes for this state.
timeoutMaximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely).

◆ ServiceState() [2/3]

template<typename ServiceT >
yasmin_ros::ServiceState< ServiceT >::ServiceState ( std::string srv_name,
CreateRequestHandler create_request_handler,
std::set< std::string > outcomes,
ResponseHandler response_handler,
int timeout = -1.0 )
inline

Construct a ServiceState with a request handler and response handler.

Parameters
srv_nameThe name of the service to call.
create_request_handlerFunction to create a service request.
outcomesA set of possible outcomes for this state.
response_handlerFunction to handle the service response.
timeoutMaximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely).

◆ ServiceState() [3/3]

template<typename ServiceT >
yasmin_ros::ServiceState< ServiceT >::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 )
inline

Construct a ServiceState with a ROS 2 node and handlers.

Parameters
nodeA shared pointer to the ROS 2 node.
srv_nameThe name of the service to call.
create_request_handlerFunction to create a service request.
outcomesA set of possible outcomes for this state.
response_handlerFunction to handle the service response.
timeoutMaximum time to wait for the service to become available, in seconds. Default is -1 (wait indefinitely).
Exceptions
std::invalid_argumentif the create_request_handler is nullptr.

Member Function Documentation

◆ create_request()

template<typename ServiceT >
Request yasmin_ros::ServiceState< ServiceT >::create_request ( std::shared_ptr< yasmin::blackboard::Blackboard > blackboard)
inlineprivate

Create a service request based on the blackboard.

Parameters
blackboardA shared pointer to the blackboard containing data for request creation.
Returns
Request The created service request.

◆ execute()

template<typename ServiceT >
std::string yasmin_ros::ServiceState< ServiceT >::execute ( std::shared_ptr< yasmin::blackboard::Blackboard > blackboard)
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.

Parameters
blackboardA shared pointer to the blackboard containing data for request creation.
Returns
std::string The outcome of the service call, which can be SUCCEED, ABORT, or TIMEOUT.

Reimplemented from yasmin::State.

Member Data Documentation

◆ create_request_handler

template<typename ServiceT >
CreateRequestHandler yasmin_ros::ServiceState< ServiceT >::create_request_handler
private

Function to create service requests.

◆ node_

template<typename ServiceT >
rclcpp::Node::SharedPtr yasmin_ros::ServiceState< ServiceT >::node_
private

Shared pointer to the ROS 2 node.

◆ response_handler

template<typename ServiceT >
ResponseHandler yasmin_ros::ServiceState< ServiceT >::response_handler
private

Function to handle service responses.

◆ service_client

template<typename ServiceT >
std::shared_ptr<rclcpp::Client<ServiceT> > yasmin_ros::ServiceState< ServiceT >::service_client
private

Shared pointer to the service client.

◆ srv_name

template<typename ServiceT >
std::string yasmin_ros::ServiceState< ServiceT >::srv_name
private

Name of the service.

◆ timeout

template<typename ServiceT >
int yasmin_ros::ServiceState< ServiceT >::timeout
private

Maximum wait time for service availability.


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