Controller able to claim resources from multiple hardware interfaces. More...
#include <multi_interface_controller.h>
Public Member Functions | |
MultiInterfaceController (bool allow_optional_interfaces=false) | |
Public Member Functions inherited from controller_interface::ControllerBase | |
ControllerBase ()=default | |
ControllerBase (const ControllerBase &)=delete | |
ControllerBase (ControllerBase &&)=delete | |
ControllerBase & | operator= (const ControllerBase &)=delete |
ControllerBase & | operator= (ControllerBase &&)=delete |
virtual | ~ControllerBase ()=default |
virtual void | starting (const ros::Time &) |
This is called from within the realtime thread just before the first call to update. More... | |
virtual void | update (const ros::Time &time, const ros::Duration &period)=0 |
This is called periodically by the realtime thread when the controller is running. More... | |
virtual void | stopping (const ros::Time &) |
This is called from within the realtime thread just after the last update call before the controller is stopped. More... | |
virtual void | waiting (const ros::Time &) |
This is called from within the realtime thread while the controller is waiting to start. More... | |
virtual void | aborting (const ros::Time &) |
This is called from within the realtime thread when the controller needs to be aborted. More... | |
bool | isInitialized () const |
Check if the controller is initialized. More... | |
bool | isRunning () const |
Check if the controller is running. More... | |
bool | isStopped () const |
Check if the controller is stopped. More... | |
bool | isWaiting () const |
Check if the controller is waiting. More... | |
bool | isAborted () const |
Check if the controller is aborted. More... | |
void | updateRequest (const ros::Time &time, const ros::Duration &period) |
Calls update only if this controller is running. More... | |
bool | startRequest (const ros::Time &time) |
Calls starting unless this controller is just constructed. More... | |
bool | stopRequest (const ros::Time &time) |
Calls stopping unless this controller is just constructed. More... | |
bool | waitRequest (const ros::Time &time) |
Calls waiting unless this controller is just constructed. More... | |
bool | abortRequest (const ros::Time &time) |
Calls abort unless this controller is just constructed. More... | |
Non Real-Time Safe Functions | |
hardware_interface::RobotHW | robot_hw_ctrl_ |
bool | allow_optional_interfaces_ |
virtual bool | init (hardware_interface::RobotHW *, ros::NodeHandle &) |
Custom controller initialization logic. More... | |
virtual bool | init (hardware_interface::RobotHW *, ros::NodeHandle &, ros::NodeHandle &) |
Custom controller initialization logic. More... | |
bool | initRequest (hardware_interface::RobotHW *robot_hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh, ClaimedResources &claimed_resources) override |
Initialize the controller from a RobotHW pointer. More... | |
static bool | hasRequiredInterfaces (hardware_interface::RobotHW *robot_hw) |
Check if robot hardware abstraction contains all required interfaces. More... | |
static void | clearClaims (hardware_interface::RobotHW *robot_hw) |
Clear claims from all hardware interfaces requested by this controller. More... | |
static void | extractInterfaceResources (hardware_interface::RobotHW *robot_hw_in, hardware_interface::RobotHW *robot_hw_out) |
Extract all hardware interfaces requested by this controller from robot_hw_in , and add them also to robot_hw_out . More... | |
static void | populateClaimedResources (hardware_interface::RobotHW *robot_hw, ClaimedResources &claimed_resources) |
Extract all hardware interfaces requested by this controller from robot_hw_in , and add them also to robot_hw_out . More... | |
Additional Inherited Members | |
Public Types inherited from controller_interface::ControllerBase | |
enum | ControllerState { ControllerState::CONSTRUCTED, ControllerState::INITIALIZED, ControllerState::RUNNING, ControllerState::STOPPED, ControllerState::WAITING, ControllerState::ABORTED } |
typedef std::vector< hardware_interface::InterfaceResources > | ClaimedResources |
Public Attributes inherited from controller_interface::ControllerBase | |
ControllerState | state_ = ControllerState::CONSTRUCTED |
The current execution state of the controller. More... | |
Controller able to claim resources from multiple hardware interfaces.
This particular controller implementation allows to claim resources from one up to four different hardware interfaces. The types of these hardware interfaces are specified as template parameters.
An example multi-interface controller could claim, for instance, resources from a position-controlled arm and velocity-controlled wheels. Another example would be a controller claiming both position and effort interfaces for the same robot resources, but this would require a robot with a custom (non-exclusive) resource handling policy.
By default, all specified hardware interfaces are required, and their existence will be enforced by initRequest. It is possible to make hardware interfaces optional by means of the allow_optional_interfaces
constructor parameter. This allows to write controllers where some interfaces are mandatory, and others, if present, improve controller performance, but whose absence does not prevent the controller from running.
The following is an example of a controller claiming resources from velocity- and effort-controlled joints.
The following fragment is a modified version of the above example, where controller interfaces are not required. It is left to the controller implementer to verify interface validity. Only the initialization code is shown.
T... | Hardware interface types. This parameter is required. |
Definition at line 149 of file multi_interface_controller.h.
|
inline |
allow_optional_interfaces | If set to true, initRequest will not fail if one or more of the requested interfaces is not present. If set to false (the default), all requested interfaces are required. |
Definition at line 157 of file multi_interface_controller.h.
|
inlinestaticprotected |
Clear claims from all hardware interfaces requested by this controller.
robot_hw | Robot hardware abstraction containing the interfaces whose claims will be cleared. |
Definition at line 302 of file multi_interface_controller.h.
|
inlinestaticprotected |
Extract all hardware interfaces requested by this controller from robot_hw_in
, and add them also to robot_hw_out
.
[in] | robot_hw_in | Robot hardware abstraction containing the interfaces requested by this controller, and potentially others. |
[out] | robot_hw_out | Robot hardware abstraction containing only the interfaces requested by this controller. |
Definition at line 315 of file multi_interface_controller.h.
|
inlinestaticprotected |
Check if robot hardware abstraction contains all required interfaces.
robot_hw | Robot hardware abstraction. |
robot_hw
, false otherwise. Definition at line 292 of file multi_interface_controller.h.
|
inlinevirtual |
Custom controller initialization logic.
In this method resources from different interfaces are claimed, and other non real-time initialization is performed, such as setup of ROS interfaces and resource pre-allocation.
robot_hw | Robot hardware abstraction containing a subset of the entire robot. If MultiInterfaceController was called with allow_optional_interfaces set to false (the default), this parameter contains all the interfaces requested by the controller. If allow_optional_interfaces was set to false , this parameter may contain none, some or all interfaces requested by the controller, depending on whether the robot exposes them. Please refer to the code examples in the class description. |
controller_nh | A NodeHandle in the namespace from which the controller should read its configuration, and where it should set up its ROS interface. |
Definition at line 187 of file multi_interface_controller.h.
|
inlinevirtual |
Custom controller initialization logic.
In this method resources from different interfaces are claimed, and other non real-time initialization is performed, such as setup of ROS interfaces and resource pre-allocation.
robot_hw | Robot hardware abstraction containing a subset of the entire robot. If MultiInterfaceController was called with allow_optional_interfaces set to false (the default), this parameter contains all the interfaces requested by the controller. If allow_optional_interfaces was set to false , this parameter may contain none, some or all interfaces requested by the controller, depending on whether the robot exposes them. Please refer to the code examples in the class description. |
root_nh | A NodeHandle in the root of the controller manager namespace. This is where the ROS interfaces are setup (publishers, subscribers, services). |
controller_nh | A NodeHandle in the namespace of the controller. This is where the controller-specific configuration resides. |
Definition at line 217 of file multi_interface_controller.h.
|
inlineoverrideprotectedvirtual |
Initialize the controller from a RobotHW pointer.
This calls init with a RobotHW that is a subset of the input robot_hw
parameter, containing only the requested hardware interfaces (all or some, depending on the value of allow_optional_interfaces
passed to the constructor).
robot_hw | The robot hardware abstraction. | |
root_nh | A NodeHandle in the root of the controller manager namespace. This is where the ROS interfaces are setup (publishers, subscribers, services). | |
controller_nh | A NodeHandle in the namespace of the controller. This is where the controller-specific configuration resides. | |
[out] | claimed_resources | The resources claimed by this controller. They can belong to multiple hardware interfaces. |
Implements controller_interface::ControllerBase.
Definition at line 245 of file multi_interface_controller.h.
|
inlinestaticprotected |
Extract all hardware interfaces requested by this controller from robot_hw_in
, and add them also to robot_hw_out
.
[in] | robot_hw_in | Robot hardware abstraction containing the interfaces requested by this controller, and potentially others. |
[out] | claimed_resources | The resources claimed by this controller. They can belong to multiple hardware interfaces. |
Definition at line 329 of file multi_interface_controller.h.
|
protected |
Flag to indicate if hardware interfaces are considered optional (i.e. non-required).
Definition at line 339 of file multi_interface_controller.h.
|
protected |
Robot hardware abstraction containing only the subset of interfaces requested by the controller.
Definition at line 336 of file multi_interface_controller.h.