33 #ifndef CONTROL_TOOLBOX__PID_ROS_HPP_
34 #define CONTROL_TOOLBOX__PID_ROS_HPP_
39 #include "control_msgs/msg/pid_state.hpp"
41 #include "rclcpp/clock.hpp"
42 #include "rclcpp/duration.hpp"
43 #include "rclcpp/node.hpp"
45 #include "realtime_tools/realtime_buffer.hpp"
46 #include "realtime_tools/realtime_publisher.hpp"
48 #include "control_toolbox/pid.hpp"
49 #include "control_toolbox/visibility_control.hpp"
73 std::shared_ptr<NodeT> node_ptr,
74 std::string prefix = std::string(
""),
75 bool prefix_is_for_params =
false
78 node_ptr->get_node_base_interface(),
79 node_ptr->get_node_logging_interface(),
80 node_ptr->get_node_parameters_interface(),
81 node_ptr->get_node_topics_interface(),
82 prefix, prefix_is_for_params)
87 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base,
88 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging,
89 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params,
90 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface,
91 std::string prefix = std::string(
""),
bool prefix_is_for_params =
false);
104 void initPid(
double p,
double i,
double d,
double i_max,
double i_min,
bool antiwindup);
127 double computeCommand(
double error, rclcpp::Duration dt);
140 double computeCommand(
double error,
double error_dot, rclcpp::Duration dt);
159 void setGains(
double p,
double i,
double d,
double i_max,
double i_min,
bool antiwindup =
false);
173 void setCurrentCmd(
double cmd);
179 double getCurrentCmd();
185 std::shared_ptr<rclcpp::Publisher<control_msgs::msg::PidState>> getPidStatePublisher();
193 void getCurrentPIDErrors(
double & pe,
double & ie,
double & de);
204 inline rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr
207 return parameter_callback_;
211 std::string topic_prefix_;
212 std::string param_prefix_;
215 void setParameterEventCallback();
217 void publishPIDState(
double cmd,
double error, rclcpp::Duration dt);
219 void declareParam(
const std::string & param_name, rclcpp::ParameterValue param_value);
221 bool getDoubleParam(
const std::string & param_name,
double & value);
223 bool getBooleanParam(
const std::string & param_name,
bool & value);
231 void initialize(std::string topic_prefix);
233 rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr parameter_callback_;
235 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_;
236 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_;
237 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_params_;
238 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface_;
240 std::shared_ptr<realtime_tools::RealtimePublisher<control_msgs::msg::PidState>> rt_state_pub_;
241 std::shared_ptr<rclcpp::Publisher<control_msgs::msg::PidState>> state_pub_;