15#ifndef CONTROLLER_INTERFACE__CONTROLLER_INTERFACE_BASE_HPP_
16#define CONTROLLER_INTERFACE__CONTROLLER_INTERFACE_BASE_HPP_
23#include <unordered_map>
26#include "controller_interface/controller_interface_params.hpp"
27#include "hardware_interface/handle.hpp"
29#include "hardware_interface/introspection.hpp"
30#include "hardware_interface/loaned_command_interface.hpp"
31#include "hardware_interface/loaned_state_interface.hpp"
32#include "joint_limits/joint_limits.hpp"
34#include "pal_statistics/pal_statistics_utils.hpp"
35#include "rclcpp/duration.hpp"
36#include "rclcpp/node_options.hpp"
37#include "rclcpp/time.hpp"
38#include "rclcpp/version.h"
39#include "rclcpp_lifecycle/lifecycle_node.hpp"
40#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
41#include "rclcpp_lifecycle/state.hpp"
43namespace controller_interface
45using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
47enum class return_type : std::uint8_t
65enum class interface_configuration_type : std::uint8_t
70 INDIVIDUAL_BEST_EFFORT = 3,
79 interface_configuration_type type = interface_configuration_type::NONE;
80 std::vector<std::string> names = {};
91 unsigned int total_triggers;
92 unsigned int failed_triggers;
107 bool successful =
true;
108 return_type result = return_type::OK;
109 std::optional<std::chrono::nanoseconds> execution_time = std::nullopt;
110 std::optional<rclcpp::Duration> period = std::nullopt;
168 std::vector<hardware_interface::LoanedCommandInterface> && command_interfaces,
169 std::vector<hardware_interface::LoanedStateInterface> && state_interfaces);
179 "Use the init(const controller_interface::ControllerInterfaceParams & params) method instead. "
180 "This method will be removed in the future ROS 2 releases.")]]
182 const std::string & controller_name,
const std::string & urdf,
unsigned int cm_update_rate,
183 const std::string & node_namespace,
const rclcpp::NodeOptions & node_options);
192 const rclcpp_lifecycle::State &
configure();
208 virtual return_type
update(
const rclcpp::Time & time,
const rclcpp::Duration & period) = 0;
223 std::shared_ptr<rclcpp_lifecycle::LifecycleNode> get_node();
225 std::shared_ptr<const rclcpp_lifecycle::LifecycleNode> get_node()
const;
246 unsigned int get_update_rate()
const;
248 bool is_async()
const;
250 const std::string & get_robot_description()
const;
276 rclcpp::NodeOptions node_options;
278#if RCLCPP_VERSION_MAJOR >= 21
279 node_options.enable_logger_service(
true);
281 node_options.allow_undeclared_parameters(
true);
282 node_options.automatically_declare_parameters_from_overrides(
true);
294 template <
typename ParameterT>
295 auto auto_declare(
const std::string & name,
const ParameterT & default_value)
297 if (!get_node()->has_parameter(name))
299 return get_node()->declare_parameter<ParameterT>(name, default_value);
303 return get_node()->get_parameter(name).get_value<ParameterT>();
325 virtual std::vector<hardware_interface::CommandInterface::SharedPtr>
334 virtual std::vector<hardware_interface::StateInterface::ConstSharedPtr>
385 std::string get_name()
const;
431 void stop_async_handler_thread();
434 std::unique_ptr<ControllerInterfaceBaseImpl> impl_;
437 pal_statistics::RegistrationsRAII stats_registrations_;
440using ControllerInterfaceBaseSharedPtr = std::shared_ptr<ControllerInterfaceBase>;
Base interface class for an controller. The interface may not be used to implement a controller....
Definition controller_interface_base.hpp:119
virtual InterfaceConfiguration command_interface_configuration() const =0
Get configuration for controller's required command interfaces.
auto auto_declare(const std::string &name, const ParameterT &default_value)
Declare and initialize a parameter with a type.
Definition controller_interface_base.hpp:295
std::vector< hardware_interface::LoanedCommandInterface > command_interfaces_
Loaned command interfaces.
Definition controller_interface_base.hpp:409
virtual CallbackReturn on_init()=0
Extending interface with initialization method which is individual for each controller.
const std::unordered_map< std::string, joint_limits::JointLimits > & get_hard_joint_limits() const
Get the unordered map of joint limits that are defined in the robot description.
Definition controller_interface_base.cpp:420
const std::unordered_map< std::string, joint_limits::SoftJointLimits > & get_soft_joint_limits() const
Get the unordered map of soft joint limits that are defined in the robot description.
Definition controller_interface_base.cpp:426
virtual std::vector< hardware_interface::StateInterface::ConstSharedPtr > export_state_interfaces()=0
Export interfaces for a chainable controller that can be used as state interface by other controllers...
void enable_introspection(bool enable)
Enable or disable introspection of the controller.
Definition controller_interface_base.cpp:455
void wait_for_trigger_update_to_finish()
Method to wait for any running async update cycle to finish after finishing the current cycle....
Definition controller_interface_base.cpp:431
uint8_t get_lifecycle_id() const
Get the lifecycle id of the controller node that is cached internally to avoid calls to get_lifecycle...
Definition controller_interface_base.cpp:323
virtual std::vector< hardware_interface::CommandInterface::SharedPtr > export_reference_interfaces()=0
Export interfaces for a chainable controller that can be used as command interface of other controlle...
const rclcpp_lifecycle::State & get_lifecycle_state() const
Get the current lifecycle state of the controller node.
Definition controller_interface_base.cpp:314
virtual void release_interfaces()
Method that releases the Loaned interfaces from the controller.
Definition controller_interface_base.cpp:308
virtual bool is_in_chained_mode() const =0
Get information if a controller is currently in chained mode.
virtual InterfaceConfiguration state_interface_configuration() const =0
Get configuration for controller's required state interfaces.
const rclcpp_lifecycle::State & configure()
Custom configure method to read additional parameters for controller-nodes.
Definition controller_interface_base.cpp:200
ControllerUpdateStatus trigger_update(const rclcpp::Time &time, const rclcpp::Duration &period)
Trigger update method. This method is used by the controller_manager to trigger the update method of ...
Definition controller_interface_base.cpp:341
virtual void assign_interfaces(std::vector< hardware_interface::LoanedCommandInterface > &&command_interfaces, std::vector< hardware_interface::LoanedStateInterface > &&state_interfaces)
Method that assigns the Loaned interfaces to the controller.
Definition controller_interface_base.cpp:300
virtual rclcpp::NodeOptions define_custom_node_options() const
Method used by the controller_manager for base NodeOptions to instantiate the Lifecycle node of the c...
Definition controller_interface_base.hpp:274
std::vector< hardware_interface::LoanedStateInterface > state_interfaces_
Loaned state interfaces.
Definition controller_interface_base.hpp:424
virtual bool is_chainable() const =0
Get information if a controller is chainable.
void prepare_for_deactivation()
Method to prepare the controller for deactivation. This method is called by the controller manager be...
Definition controller_interface_base.cpp:439
virtual bool set_chained_mode(bool chained_mode)=0
Set chained mode of a chainable controller. This method triggers internal processes to switch a chain...
virtual return_type update(const rclcpp::Time &time, const rclcpp::Duration &period)=0
Control step update. Command interfaces are updated based on on reference inputs and current states.
Definition controller_interface_base.cpp:40
Definition controller_interface_params.hpp:44
Definition controller_interface_base.hpp:84
Definition controller_interface_base.hpp:106
Configuring what command/state interfaces to claim.
Definition controller_interface_base.hpp:78