ServiceClientBehaviorBase Class Template
A base class for behaviors which need to send a request to a ROS service client and wait for a result. More...
Declaration
class moveit_pro::behaviors::ServiceClientBehaviorBase<ServiceT> { ... }
Included Headers
Base class
| class | AsyncBehaviorBase |
|
A base class for behaviors which need to asynchronously run a function that might take a long time to complete. More... | |
Public Constructors Index
template <typename ServiceT> | |
| ServiceClientBehaviorBase (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources) | |
|
Constructs ServiceClientBehaviorBase using the RclcppClientInterface. More... | |
template <typename ServiceT> | |
| ServiceClientBehaviorBase (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources, std::unique_ptr< ClientInterfaceBase< ServiceT > > client_interface) | |
|
Constructs ServiceClientBehaviorBase using a user-provided implementation of ClientInterfaceBase. More... | |
Public Destructor Index
template <typename ServiceT> | |
| ~ServiceClientBehaviorBase () override=default | |
Public Member Functions Index
template <typename ServiceT> | |
| auto | getServiceName ()=0 -> tl::expected< std::string, std::string > |
|
User-provided function to get the name of the service when initializing the service client. More... | |
template <typename ServiceT> | |
| auto | getResponseTimeout () -> tl::expected< std::chrono::duration< double >, std::string > |
|
Optional user-provided function to set the timeout used when waiting for the service response. More... | |
template <typename ServiceT> | |
| auto | getWaitForServerAvailableTimeout () -> tl::expected< std::chrono::duration< double >, std::string > |
|
Optional user-provided function to set the timeout used when waiting for the service server to be available. More... | |
template <typename ServiceT> | |
| auto | createRequest ()=0 -> tl::expected< typename ServiceT::Request, std::string > |
|
User-provided function to create the service request. More... | |
template <typename ServiceT> | |
| auto | processResponse (const typename ServiceT::Response &) -> tl::expected< bool, std::string > |
|
Optional user-provided function to process the service response after the service has finished. More... | |
template <typename ServiceT> | |
| auto | doHalt () override -> tl::expected< void, std::string > |
|
Handles halting logic which is specific to the service client behavior implementation. More... | |
Private Member Functions Index
template <typename ServiceT> | |
| auto | doWork () override -> tl::expected< bool, std::string > |
|
Handles executing the service. More... | |
Private Member Attributes Index
template <typename ServiceT> | |
| std::unique_ptr< ClientInterfaceBase< ServiceT > > | client_interface_ |
|
Interface to the service client. More... | |
Public Static Attributes Index
template <typename ServiceT> | |
| static constexpr std::chrono::seconds | kTimeoutWaitForServiceServer { 3 } |
Description
A base class for behaviors which need to send a request to a ROS service client and wait for a result.
Important: If a halt is requested before the service request is sent to the service server, the behavior will wait to halt until the service response has been received or the timeout duration has elapsed.
- Template Parameters
-
ServiceT ROS service message type used to specialize this class for a specific service.
Definition at line 25 of file service_client_behavior_base.hpp.
Public Constructors
ServiceClientBehaviorBase()
|
Constructs ServiceClientBehaviorBase using the RclcppClientInterface.
Declaration at line 29 of file service_client_behavior_base.hpp, definition at line 19 of file service_client_behavior_base_impl.hpp.
ServiceClientBehaviorBase()
|
Constructs ServiceClientBehaviorBase using a user-provided implementation of ClientInterfaceBase.
Declaration at line 33 of file service_client_behavior_base.hpp, definition at line 28 of file service_client_behavior_base_impl.hpp.
Public Destructor
~ServiceClientBehaviorBase()
| default |
Definition at line 37 of file service_client_behavior_base.hpp.
Public Member Functions
createRequest()
|
User-provided function to create the service request.
- Returns
Returns a service request message. If not successful, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.
Definition at line 77 of file service_client_behavior_base.hpp.
doHalt()
| virtual |
Handles halting logic which is specific to the service client behavior implementation.
This cancels the in-progress service request when the behavior is halted.
- Returns
Always return void, since there isn't anything special to do if the cancel request is rejected other than wait for doWork() to time out or finish on its own.
Declaration at line 122 of file service_client_behavior_base.hpp, definition at line 89 of file service_client_behavior_base_impl.hpp.
getResponseTimeout()
| inline virtual |
Optional user-provided function to set the timeout used when waiting for the service response.
If no user-defined implementation is provided, the default implementation returns a negative duration, which will cause the service client to wait for the response without timing out.
- Returns
Returns the service response timeout duration. If not successful, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.
Definition at line 55 of file service_client_behavior_base.hpp.
getServiceName()
|
User-provided function to get the name of the service when initializing the service client.
- Returns
Returns the name of the service. If not successful, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.
Definition at line 46 of file service_client_behavior_base.hpp.
getWaitForServerAvailableTimeout()
| inline virtual |
Optional user-provided function to set the timeout used when waiting for the service server to be available.
If no user-defined implementation is provided, the default implementation returns 3.0 seconds, which will be the timeout duration for waiting for the service server to become available.
- Returns
Returns the service server wait timeout duration. If not successful, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.
Definition at line 67 of file service_client_behavior_base.hpp.
processResponse()
| inline virtual |
Optional user-provided function to process the service response after the service has finished.
If no user-defined implementation is provided, then no additional processing will be performed on succeeding service responses and this function will always return void.
- Parameters
-
response Service response message to process.
- Returns
Returns true or false depending on the user's implementation if the service response could be processed successfully. If the service response could not be processed, returns an error message. Note that the criteria for success or failure is defined by the user's implementation of this function.
Definition at line 88 of file service_client_behavior_base.hpp.
Private Member Functions
doWork()
| virtual |
Handles executing the service.
This function is called within an async process in a separate thread.
It calls the user-defined getResponseTimeout, getServiceName, createRequest, and processResponse functions to initialize the service client, create and send a service request, and then handle the service response, respectively.
If getResponseTimeout returns a negative duration, then this function will wait forever for the service response to be returned from the server. If a positive duration is returned, then this function will wait for that duration before returning an error result.
- Returns
A tl::expected which contains true if the service completed successfully or was canceled. Returns false if the user's implementation of processResponse returned false, which indicates that the service response could be processed successfully but its contents indicate a failure. Returns an error result if the service failed to initialize, timed out, or failed within the server.
Declaration at line 110 of file service_client_behavior_base.hpp, definition at line 37 of file service_client_behavior_base_impl.hpp.
Private Member Attributes
client_interface_
|
Interface to the service client.
Definition at line 113 of file service_client_behavior_base.hpp.
Public Static Attributes
kTimeoutWaitForServiceServer
| constexpr static |
Definition at line 39 of file service_client_behavior_base.hpp.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.