diff --git a/include/control_toolbox/pid.hpp b/include/control_toolbox/pid.hpp index 86156ba..e08b901 100644 --- a/include/control_toolbox/pid.hpp +++ b/include/control_toolbox/pid.hpp @@ -343,7 +343,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid * * \returns PID command */ - [[nodiscard]] double compute_command(double error, double dt_s); + [[nodiscard]] double compute_command(double error, const double & dt_s); /*! * \brief Set the PID error and compute the PID command with nonuniform time @@ -370,7 +370,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid * * \returns PID command */ - [[nodiscard]] double compute_command(double error, rcl_duration_value_t dt_ns); + [[nodiscard]] double compute_command(double error, const rcl_duration_value_t & dt_ns); /*! * \brief Set the PID error and compute the PID command with nonuniform time @@ -382,7 +382,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid * * \returns PID command */ - [[nodiscard]] double compute_command(double error, rclcpp::Duration dt); + [[nodiscard]] double compute_command(double error, const rclcpp::Duration & dt); /*! * \brief Set the PID error and compute the PID command with nonuniform time @@ -394,7 +394,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid * * \returns PID command */ - [[nodiscard]] double compute_command(double error, std::chrono::nanoseconds dt_ns); + [[nodiscard]] double compute_command(double error, const std::chrono::nanoseconds & dt_ns); /*! * \brief Set the PID error and compute the PID command with nonuniform @@ -407,7 +407,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid * * \returns PID command */ - [[nodiscard]] double compute_command(double error, double error_dot, double dt_s); + [[nodiscard]] double compute_command(double error, double error_dot, const double & dt_s); /*! * \brief Set the PID error and compute the PID command with nonuniform @@ -436,7 +436,8 @@ class CONTROL_TOOLBOX_PUBLIC Pid * * \returns PID command */ - [[nodiscard]] double compute_command(double error, double error_dot, rcl_duration_value_t dt_ns); + [[nodiscard]] double compute_command( + double error, double error_dot, const rcl_duration_value_t & dt_ns); /*! * \brief Set the PID error and compute the PID command with nonuniform @@ -449,7 +450,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid * * \returns PID command */ - [[nodiscard]] double compute_command(double error, double error_dot, rclcpp::Duration dt); + [[nodiscard]] double compute_command(double error, double error_dot, const rclcpp::Duration & dt); /*! * \brief Set the PID error and compute the PID command with nonuniform @@ -463,7 +464,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid * \returns PID command */ [[nodiscard]] double compute_command( - double error, double error_dot, std::chrono::nanoseconds dt_ns); + double error, double error_dot, const std::chrono::nanoseconds & dt_ns); /*! * \brief Set current command for this PID controller diff --git a/include/control_toolbox/pid_ros.hpp b/include/control_toolbox/pid_ros.hpp index 7978ba5..b453601 100644 --- a/include/control_toolbox/pid_ros.hpp +++ b/include/control_toolbox/pid_ros.hpp @@ -148,7 +148,7 @@ class CONTROL_TOOLBOX_PUBLIC PidROS * * \returns PID command */ - double compute_command(double error, rclcpp::Duration dt); + double compute_command(double error, const rclcpp::Duration & dt); /*! * \brief Set the PID error and compute the PID command with nonuniform time @@ -176,7 +176,7 @@ class CONTROL_TOOLBOX_PUBLIC PidROS * * \returns PID command */ - double compute_command(double error, double error_dot, rclcpp::Duration dt); + double compute_command(double error, double error_dot, const rclcpp::Duration & dt); /*! * \brief Set the PID error and compute the PID command with nonuniform diff --git a/src/pid.cpp b/src/pid.cpp index 1beaafb..732387a 100644 --- a/src/pid.cpp +++ b/src/pid.cpp @@ -122,7 +122,7 @@ void Pid::set_gains(const Gains & gains) } } -double Pid::compute_command(double error, double dt_s) +double Pid::compute_command(double error, const double & dt_s) { if (dt_s <= 0.0 || !std::isfinite(error)) { return 0.0; @@ -135,32 +135,32 @@ double Pid::compute_command(double error, double dt_s) return compute_command(error, d_error_, dt_s); } -double Pid::compute_command(double error, rcl_duration_value_t dt_ns) { +double Pid::compute_command(double error, const rcl_duration_value_t & dt_ns) { return compute_command(error, static_cast(dt_ns)/1.e9); } -double Pid::compute_command(double error, rclcpp::Duration dt) { +double Pid::compute_command(double error, const rclcpp::Duration & dt) { return compute_command(error, dt.seconds()); } -double Pid::compute_command(double error, std::chrono::nanoseconds dt_ns) { +double Pid::compute_command(double error, const std::chrono::nanoseconds & dt_ns) { return compute_command(error, static_cast(dt_ns.count())/1.e9); } -double Pid::compute_command(double error, double error_dot, rcl_duration_value_t dt_ns) { +double Pid::compute_command(double error, double error_dot, const rcl_duration_value_t & dt_ns) { return compute_command(error, error_dot, static_cast(dt_ns)/1.e9); } -double Pid::compute_command(double error, double error_dot, rclcpp::Duration dt) { +double Pid::compute_command(double error, double error_dot, const rclcpp::Duration & dt) { return compute_command(error, error_dot, dt.seconds()); } double Pid::compute_command( - double error, double error_dot, std::chrono::nanoseconds dt_ns) { + double error, double error_dot, const std::chrono::nanoseconds & dt_ns) { return compute_command(error, error_dot, static_cast(dt_ns.count())/1.e9); } -double Pid::compute_command(double error, double error_dot, double dt_s) +double Pid::compute_command(double error, double error_dot, const double & dt_s) { // Get the gain parameters from the realtime buffer Gains gains = *gains_buffer_.readFromRT(); diff --git a/src/pid_ros.cpp b/src/pid_ros.cpp index 8c9f0d9..2d7b035 100644 --- a/src/pid_ros.cpp +++ b/src/pid_ros.cpp @@ -219,7 +219,7 @@ std::shared_ptr> PidROS::get_pid_ return state_pub_; } -double PidROS::compute_command(double error, rclcpp::Duration dt) +double PidROS::compute_command(double error, const rclcpp::Duration & dt) { double cmd = pid_.compute_command(error, dt); publish_pid_state(cmd, error, dt); @@ -227,7 +227,7 @@ double PidROS::compute_command(double error, rclcpp::Duration dt) return cmd; } -double PidROS::compute_command(double error, double error_dot, rclcpp::Duration dt) +double PidROS::compute_command(double error, double error_dot, const rclcpp::Duration & dt) { double cmd = pid_.compute_command(error, error_dot, dt); publish_pid_state(cmd, error, dt);