Skip to content

Commit d8208af

Browse files
committed
Merge upstream and add local modifications
Pulled upstream changes and merged my previous modifications.
1 parent 1986dd6 commit d8208af

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Diff for: include/control_toolbox/pid.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,9 @@ class Pid
604604
double p_error_last_; /** Save state for derivative state calculation. */
605605
double p_error_; /** Error. */
606606
double d_error_; /** Derivative of error. */
607-
double i_term_; /** Integrator state. */
607+
double i_term_{0}; /** Integrator state. */
608608
double cmd_; /** Command to send. */
609-
double cmd_unsat_; /** command without saturation. */
609+
double cmd_unsat_; /** command without saturation. */
610610
};
611611

612612
} // namespace control_toolbox

Diff for: src/pid.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ double Pid::compute_command(double error, double error_dot, const double & dt_s)
245245
d_term = gains.d_gain_ * d_error_;
246246

247247
// Calculate integral contribution to command
248-
if (gains.antiwindup_ == true && gains.antiwindup_strat_ == "none") {
248+
if (gains.antiwindup_ && gains.antiwindup_strat_ == "none") {
249249
// Prevent i_term_ from climbing higher than permitted by i_max_/i_min_
250250
i_term_ = std::clamp(i_term_ + gains.i_gain_ * dt_s * p_error_,
251251
gains.i_min_, gains.i_max_);
252-
} else {
252+
} else if (!gains.antiwindup_ && gains.antiwindup_strat_ == "none") {
253253
i_term_ += gains.i_gain_ * dt_s * p_error_;
254+
i_term_ = std::clamp(i_term_, gains.i_min_, gains.i_max_);
254255
}
255256

256257
// Compute the command
257258
// Limit i_term so that the limit is meaningful in the output
258-
// Compute the command
259259
cmd_unsat_ = p_term + i_term_ + d_term;
260260

261261
if (gains.saturation_ == true) {
@@ -265,7 +265,7 @@ double Pid::compute_command(double error, double error_dot, const double & dt_s)
265265
cmd_ = cmd_unsat_;
266266
}
267267

268-
if (gains.antiwindup_strat_ == "back_calculation") {
268+
if (gains.antiwindup_strat_ == "back_calculation" && gains.i_gain_ != 0) {
269269
if (gains.trk_tc_ == 0.0 && gains.d_gain_ != 0.0) {
270270
// Default value for tracking time constant for back calculation technique
271271
gains.trk_tc_ = std::sqrt(gains.d_gain_/gains.i_gain_);

0 commit comments

Comments
 (0)