17 #ifndef ADMITTANCE_CONTROLLER__ADMITTANCE_CONTROLLER_HPP_
18 #define ADMITTANCE_CONTROLLER__ADMITTANCE_CONTROLLER_HPP_
25 #include "admittance_controller_parameters.hpp"
27 #include "admittance_controller/admittance_rule.hpp"
28 #include "admittance_controller/visibility_control.h"
29 #include "control_msgs/msg/admittance_controller_state.hpp"
30 #include "controller_interface/chainable_controller_interface.hpp"
31 #include "hardware_interface/types/hardware_interface_type_values.hpp"
32 #include "rclcpp/duration.hpp"
33 #include "rclcpp/time.hpp"
34 #include "rclcpp_lifecycle/state.hpp"
35 #include "realtime_tools/realtime_buffer.hpp"
36 #include "realtime_tools/realtime_publisher.hpp"
37 #include "semantic_components/force_torque_sensor.hpp"
41 using ControllerStateMsg = control_msgs::msg::AdmittanceControllerState;
46 ADMITTANCE_CONTROLLER_PUBLIC
47 controller_interface::CallbackReturn
on_init()
override;
54 ADMITTANCE_CONTROLLER_PUBLIC
62 ADMITTANCE_CONTROLLER_PUBLIC
65 ADMITTANCE_CONTROLLER_PUBLIC
66 controller_interface::CallbackReturn on_configure(
67 const rclcpp_lifecycle::State & previous_state)
override;
69 ADMITTANCE_CONTROLLER_PUBLIC
70 controller_interface::CallbackReturn on_activate(
71 const rclcpp_lifecycle::State & previous_state)
override;
73 ADMITTANCE_CONTROLLER_PUBLIC
74 controller_interface::CallbackReturn on_deactivate(
75 const rclcpp_lifecycle::State & previous_state)
override;
77 ADMITTANCE_CONTROLLER_PUBLIC
78 controller_interface::CallbackReturn on_cleanup(
79 const rclcpp_lifecycle::State & previous_state)
override;
81 ADMITTANCE_CONTROLLER_PUBLIC
82 controller_interface::CallbackReturn on_error(
83 const rclcpp_lifecycle::State & previous_state)
override;
85 ADMITTANCE_CONTROLLER_PUBLIC
87 const rclcpp::Time & time,
const rclcpp::Duration & period)
override;
93 const rclcpp::Time & time,
const rclcpp::Duration & period)
override;
95 size_t num_joints_ = 0;
96 std::vector<std::string> command_joint_names_;
101 template <
typename T>
102 using InterfaceReferences = std::vector<std::vector<std::reference_wrapper<T>>>;
104 InterfaceReferences<hardware_interface::LoanedCommandInterface> joint_command_interface_;
105 InterfaceReferences<hardware_interface::LoanedStateInterface> joint_state_interface_;
107 bool has_position_state_interface_ =
false;
108 bool has_velocity_state_interface_ =
false;
109 bool has_acceleration_state_interface_ =
false;
110 bool has_position_command_interface_ =
false;
111 bool has_velocity_command_interface_ =
false;
112 bool has_acceleration_command_interface_ =
false;
113 bool has_effort_command_interface_ =
false;
117 const std::vector<std::string> allowed_interface_types_ = {
122 const std::vector<std::string> allowed_reference_interfaces_types_ = {
124 std::vector<std::reference_wrapper<double>> position_reference_;
125 std::vector<std::reference_wrapper<double>> velocity_reference_;
128 std::unique_ptr<admittance_controller::AdmittanceRule> admittance_;
131 std::unique_ptr<semantic_components::ForceTorqueSensor> force_torque_sensor_;
134 rclcpp::Subscription<trajectory_msgs::msg::JointTrajectoryPoint>::SharedPtr
135 input_joint_command_subscriber_;
136 rclcpp::Subscription<geometry_msgs::msg::WrenchStamped>::SharedPtr
137 input_wrench_command_subscriber_;
138 rclcpp::Publisher<control_msgs::msg::AdmittanceControllerState>::SharedPtr s_publisher_;
141 std::shared_ptr<admittance_controller::ParamListener> parameter_handler_;
144 std::shared_ptr<trajectory_msgs::msg::JointTrajectoryPoint> joint_command_msg_;
148 input_joint_command_;
150 std::unique_ptr<realtime_tools::RealtimePublisher<ControllerStateMsg>> state_publisher_;
152 trajectory_msgs::msg::JointTrajectoryPoint last_commanded_;
153 trajectory_msgs::msg::JointTrajectoryPoint last_reference_;
160 trajectory_msgs::msg::JointTrajectoryPoint reference_, joint_state_, reference_admittance_;
161 geometry_msgs::msg::Wrench ft_values_;
168 trajectory_msgs::msg::JointTrajectoryPoint & state_current,
169 geometry_msgs::msg::Wrench & ft_values);
Definition: admittance_controller.hpp:44
controller_interface::return_type update_reference_from_subscribers(const rclcpp::Time &time, const rclcpp::Duration &period) override
Update reference from input topics when not in chained mode.
Definition: admittance_controller.cpp:395
std::vector< hardware_interface::CommandInterface > on_export_reference_interfaces() override
Definition: admittance_controller.cpp:118
ADMITTANCE_CONTROLLER_PUBLIC controller_interface::return_type update_and_write_commands(const rclcpp::Time &time, const rclcpp::Duration &period) override
Execute calculations of the controller and update command interfaces.
Definition: admittance_controller.cpp:422
ADMITTANCE_CONTROLLER_PUBLIC controller_interface::InterfaceConfiguration command_interface_configuration() const override
Export configuration of required state interfaces.
Definition: admittance_controller.cpp:77
void read_state_from_hardware(trajectory_msgs::msg::JointTrajectoryPoint &state_current, geometry_msgs::msg::Wrench &ft_values)
Read values from hardware interfaces and set corresponding fields of state_current and ft_values.
Definition: admittance_controller.cpp:499
void write_state_to_hardware(const trajectory_msgs::msg::JointTrajectoryPoint &state_command)
Write values from state_command to claimed hardware interfaces.
Definition: admittance_controller.cpp:557
ADMITTANCE_CONTROLLER_PUBLIC controller_interface::CallbackReturn on_init() override
Extending interface with initialization method which is individual for each controller.
Definition: admittance_controller.cpp:47
void read_state_reference_interfaces(trajectory_msgs::msg::JointTrajectoryPoint &state)
Set fields of state_reference with values from controllers exported position and velocity references.
Definition: admittance_controller.cpp:585
ADMITTANCE_CONTROLLER_PUBLIC controller_interface::InterfaceConfiguration state_interface_configuration() const override
Export configuration of required state interfaces.
Definition: admittance_controller.cpp:95
Definition: chainable_controller_interface.hpp:38
Definition: admittance_controller.hpp:40
constexpr char HW_IF_ACCELERATION[]
Constant defining acceleration interface name.
Definition: hardware_interface_type_values.hpp:25
constexpr char HW_IF_VELOCITY[]
Constant defining velocity interface name.
Definition: hardware_interface_type_values.hpp:23
constexpr char HW_IF_POSITION[]
Constant defining position interface name.
Definition: hardware_interface_type_values.hpp:21
Configuring what command/state interfaces to claim.
Definition: controller_interface_base.hpp:58