Skip to main content

SwitchController Class

A Behavior to call the ros2_control switch_controllers service to activate/deactivate controllers. More...

Declaration

class moveit_pro::behaviors::SwitchController { ... }

Included Headers

#include <switch_controller.hpp>

Base class

classServiceClientBehaviorBase<ServiceT>

A base class for behaviors which need to send a request to a ROS service client and wait for a result. More...

Public Constructors Index

SwitchController (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources)
SwitchController (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources, std::unique_ptr< ClientInterfaceBase< ListControllersSrv > > list_controllers_client_interface)

Public Member Functions Index

voidsetSwitchControllerClientInterface (std::unique_ptr< ClientInterfaceBase< SwitchControllerSrv > > switch_controller_client_interface)

Private Member Functions Index

tl::expected< std::string, std::string >getServiceName () override

User-provided function to get the name of the service when initializing the service client. More...

tl::expected< ListControllersSrv::Request, std::string >createRequest () override

User-provided function to create the service request. More...

tl::expected< bool, std::string >processResponse (const ListControllersSrv::Response &response) override
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...

tl::expected< std::chrono::duration< double >, std::string >getWaitForServerAvailableTimeout () override

Optional user-provided function to set the timeout used when waiting for the service server to be available. More...

Private Member Attributes Index

std::unique_ptr< ClientInterfaceBase< SwitchControllerSrv > >switch_controller_client_interface_
std::shared_future< tl::expected< bool, std::string > >response_future_

Holds the result of calling the service asynchronously. More...

Public Static Functions Index

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

Public Static Attributes Index

static constexpr autokPortActivateControllers = "activate_controllers"
static constexpr autokPortDeactivateControllers = "deactivate_controllers"
static constexpr autokPortAutomaticActivation = "automatic_activation"
static constexpr autokPortAutomaticDeactivation = "automatic_deactivation"
static constexpr autokPortStrictness = "strictness"
static constexpr autokPortActivateAsap = "activate_asap"
static constexpr autokPortTimeout = "timeout"
static constexpr autokPortListServiceName = "controller_list_action_name"
static constexpr autokPortSwitchServiceName = "controller_switch_action_name"

Description

A Behavior to call the ros2_control switch_controllers service to activate/deactivate controllers.

This Behavior switches controllers in a ros2_control controller manager. Given a list of controllers to activate/deactivate, a service request is dispatched to switch the active ros2_control controllers accordingly. It can be configured to automatically deactivate controllers that are in conflict with the ones to activate. If any of the controllers fail to start or stop, the Behavior will return failure.

The Behavior will first call the list_controllers service to get the list of controllers and their states. It will then create a request to the switch_controller service with the specified controllers to activate and deactivate. The request will also include the strictness level, whether to activate controllers as soon as their hardware dependencies are ready, and a timeout for the operation.

The Behavior will wait for the service response and return success or failure based on the response.

Data Port NamePort TypeObject Type
activate_controllersinputstd::vector<std::string>
deactivate_controllersinputstd::vector<std::string>
automatic_deactivationinputbool
strictnessinputint
activate_asapinputbool
timeoutinputstd::chrono::duration<double>
controller_list_action_nameinputstd::string
controller_switch_action_nameinputstd::string

Definition at line 120 of file switch_controller.hpp.

Public Constructors

SwitchController()

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

Declaration at line 133 of file switch_controller.hpp, definition at line 206 of file switch_controller.cpp.

SwitchController()

moveit_pro::behaviors::SwitchController::SwitchController (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & shared_resources, std::unique_ptr< ClientInterfaceBase< ListControllersSrv > > list_controllers_client_interface)
explicit

Declaration at line 137 of file switch_controller.hpp, definition at line 213 of file switch_controller.cpp.

Public Member Functions

setSwitchControllerClientInterface()

void moveit_pro::behaviors::SwitchController::setSwitchControllerClientInterface (std::unique_ptr< ClientInterfaceBase< SwitchControllerSrv > > switch_controller_client_interface)
inline

Definition at line 146 of file switch_controller.hpp.

Private Member Functions

createRequest()

tl::expected< ListControllersSrv::Request, std::string > moveit_pro::behaviors::SwitchController::createRequest ()
virtual

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.

Declaration at line 157 of file switch_controller.hpp, definition at line 296 of file switch_controller.cpp.

getFuture()

std::shared_future< tl::expected< bool, std::string > > & moveit_pro::behaviors::SwitchController::getFuture ()
inline 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.

Definition at line 165 of file switch_controller.hpp.

getServiceName()

tl::expected< std::string, std::string > moveit_pro::behaviors::SwitchController::getServiceName ()
virtual

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.

Declaration at line 154 of file switch_controller.hpp, definition at line 273 of file switch_controller.cpp.

getWaitForServerAvailableTimeout()

tl::expected< std::chrono::duration< double >, std::string > moveit_pro::behaviors::SwitchController::getWaitForServerAvailableTimeout ()
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.

Declaration at line 173 of file switch_controller.hpp, definition at line 266 of file switch_controller.cpp.

processResponse()

tl::expected< bool, std::string > moveit_pro::behaviors::SwitchController::processResponse (const ListControllersSrv::Response & response)

Declaration at line 160 of file switch_controller.hpp, definition at line 301 of file switch_controller.cpp.

Private Member Attributes

response_future_

std::shared_future<tl::expected<bool, std::string> > moveit_pro::behaviors::SwitchController::response_future_

Holds the result of calling the service asynchronously.

Definition at line 171 of file switch_controller.hpp.

switch_controller_client_interface_

std::unique_ptr<ClientInterfaceBase<SwitchControllerSrv> > moveit_pro::behaviors::SwitchController::switch_controller_client_interface_

Definition at line 163 of file switch_controller.hpp.

Public Static Functions

metadata()

BT::KeyValueVector moveit_pro::behaviors::SwitchController::metadata ()
static

Declaration at line 143 of file switch_controller.hpp, definition at line 261 of file switch_controller.cpp.

providedPorts()

BT::PortsList moveit_pro::behaviors::SwitchController::providedPorts ()
static

Declaration at line 141 of file switch_controller.hpp, definition at line 222 of file switch_controller.cpp.

Public Static Attributes

kPortActivateAsap

constexpr auto moveit_pro::behaviors::SwitchController::kPortActivateAsap = "activate_asap"
constexpr static

Definition at line 128 of file switch_controller.hpp.

kPortActivateControllers

constexpr auto moveit_pro::behaviors::SwitchController::kPortActivateControllers = "activate_controllers"
constexpr static

Definition at line 123 of file switch_controller.hpp.

kPortAutomaticActivation

constexpr auto moveit_pro::behaviors::SwitchController::kPortAutomaticActivation = "automatic_activation"
constexpr static

Definition at line 125 of file switch_controller.hpp.

kPortAutomaticDeactivation

constexpr auto moveit_pro::behaviors::SwitchController::kPortAutomaticDeactivation = "automatic_deactivation"
constexpr static

Definition at line 126 of file switch_controller.hpp.

kPortDeactivateControllers

constexpr auto moveit_pro::behaviors::SwitchController::kPortDeactivateControllers = "deactivate_controllers"
constexpr static

Definition at line 124 of file switch_controller.hpp.

kPortListServiceName

constexpr auto moveit_pro::behaviors::SwitchController::kPortListServiceName = "controller_list_action_name"
constexpr static

Definition at line 130 of file switch_controller.hpp.

kPortStrictness

constexpr auto moveit_pro::behaviors::SwitchController::kPortStrictness = "strictness"
constexpr static

Definition at line 127 of file switch_controller.hpp.

kPortSwitchServiceName

constexpr auto moveit_pro::behaviors::SwitchController::kPortSwitchServiceName = "controller_switch_action_name"
constexpr static

Definition at line 131 of file switch_controller.hpp.

kPortTimeout

constexpr auto moveit_pro::behaviors::SwitchController::kPortTimeout = "timeout"
constexpr static

Definition at line 129 of file switch_controller.hpp.


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


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.