A Behavior to call the ros2_control switch_controllers service to activate/deactivate controllers. More...
Declaration
class moveit_pro::behaviors::SwitchController { ... }
#include <switch_controller.hpp>
Base class
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
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
Public Static Functions Index
Public Static Attributes Index
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 Name | Port Type | Object Type |
|---|
| activate_controllers | input | std::vector<std::string> |
| deactivate_controllers | input | std::vector<std::string> |
| automatic_deactivation | input | bool |
| strictness | input | int |
| activate_asap | input | bool |
| timeout | input | std::chrono::duration<double> |
| controller_list_action_name | input | std::string |
| controller_switch_action_name | input | std::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
|
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
|
Public Member Functions
setSwitchControllerClientInterface()
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) |
|
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_ |
|
Public Static Functions
metadata()
| BT::KeyValueVector moveit_pro::behaviors::SwitchController::metadata () |
|
static
|
providedPorts()
| BT::PortsList moveit_pro::behaviors::SwitchController::providedPorts () |
|
static
|
Public Static Attributes
kPortActivateAsap
| constexpr auto moveit_pro::behaviors::SwitchController::kPortActivateAsap = "activate_asap" |
|
constexpr
static
|
kPortActivateControllers
| constexpr auto moveit_pro::behaviors::SwitchController::kPortActivateControllers = "activate_controllers" |
|
constexpr
static
|
kPortAutomaticActivation
| constexpr auto moveit_pro::behaviors::SwitchController::kPortAutomaticActivation = "automatic_activation" |
|
constexpr
static
|
kPortAutomaticDeactivation
| constexpr auto moveit_pro::behaviors::SwitchController::kPortAutomaticDeactivation = "automatic_deactivation" |
|
constexpr
static
|
kPortDeactivateControllers
| constexpr auto moveit_pro::behaviors::SwitchController::kPortDeactivateControllers = "deactivate_controllers" |
|
constexpr
static
|
kPortListServiceName
| constexpr auto moveit_pro::behaviors::SwitchController::kPortListServiceName = "controller_list_action_name" |
|
constexpr
static
|
kPortStrictness
| constexpr auto moveit_pro::behaviors::SwitchController::kPortStrictness = "strictness" |
|
constexpr
static
|
kPortSwitchServiceName
| constexpr auto moveit_pro::behaviors::SwitchController::kPortSwitchServiceName = "controller_switch_action_name" |
|
constexpr
static
|
kPortTimeout
| constexpr auto moveit_pro::behaviors::SwitchController::kPortTimeout = "timeout" |
|
constexpr
static
|
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.