Skip to main content

SwitchLifecycleManagers Class

Pause a source Nav2 lifecycle manager and start a target manager, reversing the switch when halted. More...

Declaration​

class moveit_pro::behaviors::SwitchLifecycleManagers { ... }

Included Headers​

#include <switch_lifecycle_managers.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...

Private Member Typedefs Index​

usingManage = nav2_msgs::srv::ManageLifecycleNodes

Public Constructors Index​

SwitchLifecycleManagers (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &context)
SwitchLifecycleManagers (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &context, std::unique_ptr< ClientInterfaceBase< nav2_msgs::srv::ManageLifecycleNodes > > source, std::unique_ptr< ClientInterfaceBase< nav2_msgs::srv::ManageLifecycleNodes > > target)

Public 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...

Private Member Functions Index​

tl::expected< void, std::string >command (ClientInterfaceBase< Manage > &client, std::uint8_t command)
tl::expected< void, std::string >restore ()

Private Member Attributes Index​

boolsource_transition_complete_ = false
std::stringrestoration_error_
std::unique_ptr< ClientInterfaceBase< Manage > >source_
std::unique_ptr< ClientInterfaceBase< Manage > >target_
std::stringsource_service_
std::stringtarget_service_
std::stringsource_name_
std::stringtarget_name_
boolsource_paused_ = false
boolreset_source_ = false
booltarget_requested_ = false
boolhalted_ = false
std::mutexmutex_
std::condition_variablehalt_cv_
std::shared_future< tl::expected< bool, std::string > >future_

Public Static Functions Index​

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

Description​

Pause a source Nav2 lifecycle manager and start a target manager, reversing the switch when halted.

Run alongside the managed work in a Parallel. Halting resets the target before restoring the source. Set reset_source to release the source's retained publishers while the target runs; restoration then uses STARTUP. The calling Objective owns application-specific readiness checks and recovery.

Data Port NamePort TypeObject Type
source_managerinputstd::string
target_managerinputstd::string
reset_sourceinputbool
readyoutputbool
restoredoutputbool

Definition at line 31 of file switch_lifecycle_managers.hpp.

Private Member Typedefs​

Manage​

using moveit_pro::behaviors::SwitchLifecycleManagers::Manage = nav2_msgs::srv::ManageLifecycleNodes

Definition at line 47 of file switch_lifecycle_managers.hpp.

Public Constructors​

SwitchLifecycleManagers()​

moveit_pro::behaviors::SwitchLifecycleManagers::SwitchLifecycleManagers (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & context)

Declaration at line 34 of file switch_lifecycle_managers.hpp, definition at line 27 of file switch_lifecycle_managers.cpp.

SwitchLifecycleManagers()​

moveit_pro::behaviors::SwitchLifecycleManagers::SwitchLifecycleManagers (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & context, std::unique_ptr< ClientInterfaceBase< nav2_msgs::srv::ManageLifecycleNodes > > source, std::unique_ptr< ClientInterfaceBase< nav2_msgs::srv::ManageLifecycleNodes > > target)

Declaration at line 36 of file switch_lifecycle_managers.hpp, definition at line 34 of file switch_lifecycle_managers.cpp.

Public Member Functions​

doHalt()​

tl::expected< void, std::string > moveit_pro::behaviors::SwitchLifecycleManagers::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 switch_lifecycle_managers.hpp, definition at line 215 of file switch_lifecycle_managers.cpp.

doWork()​

tl::expected< bool, std::string > moveit_pro::behaviors::SwitchLifecycleManagers::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 switch_lifecycle_managers.hpp, definition at line 131 of file switch_lifecycle_managers.cpp.

getFuture()​

std::shared_future< tl::expected< bool, std::string > > & moveit_pro::behaviors::SwitchLifecycleManagers::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 switch_lifecycle_managers.hpp, definition at line 64 of file switch_lifecycle_managers.cpp.

Private Member Functions​

command()​

tl::expected< void, std::string > moveit_pro::behaviors::SwitchLifecycleManagers::command (ClientInterfaceBase< Manage > & client, std::uint8_t command)
nodiscard

Declaration at line 48 of file switch_lifecycle_managers.hpp, definition at line 69 of file switch_lifecycle_managers.cpp.

restore()​

tl::expected< void, std::string > moveit_pro::behaviors::SwitchLifecycleManagers::restore ()
nodiscard

Declaration at line 49 of file switch_lifecycle_managers.hpp, definition at line 102 of file switch_lifecycle_managers.cpp.

Private Member Attributes​

future_​

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

Definition at line 64 of file switch_lifecycle_managers.hpp.

halt_cv_​

std::condition_variable moveit_pro::behaviors::SwitchLifecycleManagers::halt_cv_

Definition at line 63 of file switch_lifecycle_managers.hpp.

halted_​

bool moveit_pro::behaviors::SwitchLifecycleManagers::halted_ = false

Definition at line 61 of file switch_lifecycle_managers.hpp.

mutex_​

std::mutex moveit_pro::behaviors::SwitchLifecycleManagers::mutex_

Definition at line 62 of file switch_lifecycle_managers.hpp.

reset_source_​

bool moveit_pro::behaviors::SwitchLifecycleManagers::reset_source_ = false

Definition at line 59 of file switch_lifecycle_managers.hpp.

restoration_error_​

std::string moveit_pro::behaviors::SwitchLifecycleManagers::restoration_error_

Definition at line 51 of file switch_lifecycle_managers.hpp.

source_​

std::unique_ptr<ClientInterfaceBase<Manage> > moveit_pro::behaviors::SwitchLifecycleManagers::source_

Definition at line 52 of file switch_lifecycle_managers.hpp.

source_name_​

std::string moveit_pro::behaviors::SwitchLifecycleManagers::source_name_

Definition at line 56 of file switch_lifecycle_managers.hpp.

source_paused_​

bool moveit_pro::behaviors::SwitchLifecycleManagers::source_paused_ = false

Definition at line 58 of file switch_lifecycle_managers.hpp.

source_service_​

std::string moveit_pro::behaviors::SwitchLifecycleManagers::source_service_

Definition at line 54 of file switch_lifecycle_managers.hpp.

source_transition_complete_​

bool moveit_pro::behaviors::SwitchLifecycleManagers::source_transition_complete_ = false

Definition at line 50 of file switch_lifecycle_managers.hpp.

target_​

std::unique_ptr<ClientInterfaceBase<Manage> > moveit_pro::behaviors::SwitchLifecycleManagers::target_

Definition at line 53 of file switch_lifecycle_managers.hpp.

target_name_​

std::string moveit_pro::behaviors::SwitchLifecycleManagers::target_name_

Definition at line 57 of file switch_lifecycle_managers.hpp.

target_requested_​

bool moveit_pro::behaviors::SwitchLifecycleManagers::target_requested_ = false

Definition at line 60 of file switch_lifecycle_managers.hpp.

target_service_​

std::string moveit_pro::behaviors::SwitchLifecycleManagers::target_service_

Definition at line 55 of file switch_lifecycle_managers.hpp.

Public Static Functions​

metadata()​

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

Declaration at line 41 of file switch_lifecycle_managers.hpp, definition at line 55 of file switch_lifecycle_managers.cpp.

providedPorts()​

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

Declaration at line 40 of file switch_lifecycle_managers.hpp, definition at line 42 of file switch_lifecycle_managers.cpp.


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


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.15.0.