47 PID::PID(
double p,
double i,
double d,
double i_max,
double i_min) :
81 nh.
param(
"i_clamp", i_clamp, 0.0);
82 i_max_ = std::abs(i_clamp);
83 i_min_ = -std::abs(i_clamp);
97 ROS_WARN(
"Proportional gain is not finite");
103 ROS_WARN(
"Integral gain is not finite");
109 ROS_WARN(
"Derivative gain is not finite");
115 ROS_WARN(
"Integral wind-up limit is not finite");
122 ROS_WARN(
"Integral max windup value is smaller than minimum value");
131 ROS_WARN(
"Integral gain is non-zero, but integral wind-up limit is zero");
135 ROS_WARN(
"Integral gain is zero, but wind-yup limit is zero");
161 return update(error, error_dot, dt);
166 if (!std::isfinite(error) || !std::isfinite(error_dot) || !std::isfinite(dt))
185 double d_term =
d_gain_ * error_dot;
187 return p_term +
i_term_ + d_term;
PID()
Constructor. Starts all gains and limits at zero.
double i_term_
integral wind-up term
bool checkGains()
Checks and fixes gain settings.
#define ROS_ERROR_THROTTLE(rate,...)
double error_last_
Last error value, used for calculating error_dot when not provided.
double update(double error, double dt)
Run PID calculation and return control result.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const std::string & getNamespace() const
double i_max_
integral gain min and max limits
void reset()
Reset integral wind-up term.
bool getParam(const std::string &key, std::string &s) const
double p_gain_
proportial gain
double i_gain_
integral gain
bool init(const ros::NodeHandle &nh)
initialize gain settings from ROS parameter values
double d_gain_
derivative gain