@@ -111,7 +111,14 @@ void Pid::reset(bool save_i_term)
111111 }
112112}
113113
114+ <<<<<<< HEAD:control_toolbox/src/pid.cpp
114115void Pid::clear_saved_iterm () { i_error_ = 0.0 ; }
116+ =======
117+ void Pid::clear_saved_iterm ()
118+ {
119+ i_term_ = 0.0 ;
120+ }
121+ >>>>>>> 37a12e8 ([Pid] Save `i_term` instead of error integral (#294 )):src/pid.cpp
115122
116123void Pid::get_gains(double & p, double & i, double & d, double & i_max, double & i_min)
117124{
@@ -202,7 +209,7 @@ double Pid::compute_command(double error, double error_dot, const double & dt_s)
202209 // Get the gain parameters from the realtime buffer
203210 Gains gains = *gains_buffer_.readFromRT ();
204211
205- double p_term, d_term, i_term ;
212+ double p_term, d_term;
206213 p_error_ = error; // this is error = target - state
207214 d_error_ = error_dot;
208215
@@ -219,6 +226,7 @@ double Pid::compute_command(double error, double error_dot, const double & dt_s)
219226 // Calculate proportional contribution to command
220227 p_term = gains.p_gain_ * p_error_;
221228
229+ <<<<<<< HEAD:control_toolbox/src/pid.cpp
222230 // Calculate the integral of the position error
223231 i_error_ += dt_s * p_error_;
224232
@@ -237,13 +245,23 @@ double Pid::compute_command(double error, double error_dot, const double & dt_s)
237245 {
238246 // Limit i_term so that the limit is meaningful in the output
239247 i_term = std::clamp (i_term, gains.i_min_ , gains.i_max_ );
248+ =======
249+ // Calculate integral contribution to command
250+ if (gains.antiwindup_ ) {
251+ // Prevent i_term_ from climbing higher than permitted by i_max_/i_min_
252+ i_term_ = std::clamp (i_term_ + gains.i_gain_ * dt_s * p_error_,
253+ gains.i_min_ , gains.i_max_ );
254+ } else {
255+ i_term_ += gains.i_gain_ * dt_s * p_error_;
256+ >>>>>>> 37a12e8 ([Pid] Save `i_term` instead of error integral (#294 )):src/pid.cpp
240257 }
241258
242259 // Calculate derivative contribution to command
243260 d_term = gains.d_gain_ * d_error_;
244261
245262 // Compute the command
246- cmd_ = p_term + i_term + d_term;
263+ // Limit i_term so that the limit is meaningful in the output
264+ cmd_ = p_term + std::clamp (i_term_, gains.i_min_ , gains.i_max_ ) + d_term;
247265
248266 return cmd_;
249267}
@@ -255,7 +273,7 @@ double Pid::get_current_cmd() { return cmd_; }
255273void Pid::get_current_pid_errors (double & pe, double & ie, double & de)
256274{
257275 pe = p_error_;
258- ie = i_error_ ;
276+ ie = i_term_ ;
259277 de = d_error_;
260278}
261279
0 commit comments