Skip to main content

CallService Class

Calls a ROS service whose type and JSON request are selected at runtime. More...

Declaration​

class moveit_pro::behaviors::CallService { ... }

Included Headers​

#include <call_service.hpp>

Base class​

classAsyncBehaviorBase

A base class for behaviors which need to asynchronously run a function that might take a long time to complete. More...

Public Constructors Index​

CallService (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources)

Private Member Functions Index​

tl::expected< bool, std::string >doWork () override

User-implemented function which handles executing the potentially-long-running process. More...

tl::expected< void, std::string >doHalt () override

Optionally implement additional work needed to cleanly interrupt the async process. More...

std::shared_future< tl::expected< bool, std::string > > &getFuture () override

Gets the shared future which is used to monitor the progress of the async process. More...

BT::Expected< std::string >getRequest () const

Private Member Attributes Index​

std::atomic_boolcanceled_ { false }
std::shared_future< tl::expected< bool, std::string > >future_

Public Static Functions Index​

static BT::PortsListprovidedPorts ()
static BT::KeyValueVectormetadata ()

Description​

Calls a ROS service whose type and JSON request are selected at runtime.

Requires installed C++ type support for the service package. Halting stops waiting; it cannot undo server work.

Data Port NamePort TypeObject Type
service_nameinputstd::string
service_typeinputstd::string
requestinputstd::string
response_timeoutinputdouble
wait_for_server_timeoutinputdouble
success_fieldinputstd::string
responseoutputstd::string

Definition at line 27 of file call_service.hpp.

Public Constructors​

CallService()​

moveit_pro::behaviors::CallService::CallService (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & shared_resources)
Parameters
name

Behavior instance name.

config

Behavior Tree ports and blackboard.

shared_resources

Shared ROS node and logger.

Declaration at line 35 of file call_service.hpp, definition at line 92 of file call_service.cpp.

Private Member Functions​

doHalt()​

tl::expected< void, std::string > moveit_pro::behaviors::CallService::doHalt ()
nodiscard virtual

Optionally implement additional work needed to cleanly interrupt the async process.

The default implementation of this function is a no-op which will not interrupt the async process. This will mean that onHalted will wait until the process finishes before returning.

Returns

Return an empty tl::expected<void, std::string> if the additional work to halt was successful. Return an error message if something failed while doing additional work to halt.

Declaration at line 43 of file call_service.hpp, definition at line 246 of file call_service.cpp.

doWork()​

tl::expected< bool, std::string > moveit_pro::behaviors::CallService::doWork ()
nodiscard virtual

User-implemented function which handles executing the potentially-long-running process.

This function is called within an async process in a separate thread.

Returns

A tl::expected which contains a bool indicating task success if the process completed successfully or was canceled, or an error message if the process failed unexpectedly.

Declaration at line 42 of file call_service.hpp, definition at line 148 of file call_service.cpp.

getFuture()​

std::shared_future< tl::expected< bool, std::string > > & moveit_pro::behaviors::CallService::getFuture ()
nodiscard virtual

Gets the shared future which is used to monitor the progress of the async process.

Classes derived from AsyncBehaviorBase must implement getFuture() so that it returns a shared_future class member.

This exists to prevent destruction of the derived class while the async process is still in-progress. If the derived class is destroyed, the definitions of the functions used within doWork() will be destroyed too, which will result in the virtual functions in the base class being called instead and cause a fault.

This function will force derived classes to add an instance of this type and return a reference to it. The base class can then use this virtual function to access the shared future in functions like onStart.

By adding this virtual function we're properly demonstrating how this future depends on things from the derived class and the natural flow of object lifetimes will do the hard work for us. The std::shared_future destructor will get the value of the future before the derived class is destructed assuming it's the last reference to the shared state. Doing it this way means neither the base nor derived class should need to implement a destructor which is a nice property to have.

Returns

Returns the shared_future, which should be owned by the child class.

Declaration at line 44 of file call_service.hpp, definition at line 252 of file call_service.cpp.

getRequest()​

BT::Expected< std::string > moveit_pro::behaviors::CallService::getRequest ()
nodiscard

Declaration at line 45 of file call_service.hpp, definition at line 127 of file call_service.cpp.

Private Member Attributes​

canceled_​

std::atomic_bool moveit_pro::behaviors::CallService::canceled_ { false }

Definition at line 47 of file call_service.hpp.

future_​

std::shared_future<tl::expected<bool, std::string> > moveit_pro::behaviors::CallService::future_

Definition at line 49 of file call_service.hpp.

Public Static Functions​

metadata()​

BT::KeyValueVector moveit_pro::behaviors::CallService::metadata ()
nodiscard static

Declaration at line 39 of file call_service.hpp, definition at line 115 of file call_service.cpp.

providedPorts()​

BT::PortsList moveit_pro::behaviors::CallService::providedPorts ()
nodiscard static

Declaration at line 38 of file call_service.hpp, definition at line 98 of file call_service.cpp.


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


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.15.0.