Skip to content

Commit 926b024

Browse files
committed
Resolving conflicts
1 parent 788b1cf commit 926b024

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

control_toolbox/include/control_toolbox/pid.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,9 @@ class Pid
605605
double p_error_last_; /** Save state for derivative state calculation. */
606606
double p_error_; /** Error. */
607607
double d_error_; /** Derivative of error. */
608-
double i_term_; /** Integrator state. */
608+
double i_term_{0}; /** Integrator state. */
609609
double cmd_; /** Command to send. */
610-
double cmd_unsat_; /** command without saturation. */
610+
double cmd_unsat_; /** command without saturation. */
611611
};
612612

613613
} // namespace control_toolbox

control_toolbox/src/pid.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,17 @@ double Pid::compute_command(double error, double error_dot, const double & dt_s)
272272
d_term = gains.d_gain_ * d_error_;
273273

274274
// Calculate integral contribution to command
275-
if (gains.antiwindup_ == true && gains.antiwindup_strat_ == "none") {
275+
if (gains.antiwindup_ && gains.antiwindup_strat_ == "none") {
276276
// Prevent i_term_ from climbing higher than permitted by i_max_/i_min_
277-
i_term_ = std::clamp(i_term_ + gains.i_gain_ * dt_s * p_error_, gains.i_min_, gains.i_max_);
278-
}
279-
else
280-
{
277+
i_term_ = std::clamp(i_term_ + gains.i_gain_ * dt_s * p_error_,
278+
gains.i_min_, gains.i_max_);
279+
} else if (!gains.antiwindup_ && gains.antiwindup_strat_ == "none") {
281280
i_term_ += gains.i_gain_ * dt_s * p_error_;
281+
i_term_ = std::clamp(i_term_, gains.i_min_, gains.i_max_);
282282
}
283283

284284
// Compute the command
285285
// Limit i_term so that the limit is meaningful in the output
286-
// Compute the command
287286
cmd_unsat_ = p_term + i_term_ + d_term;
288287

289288
if (gains.saturation_ == true) {
@@ -293,7 +292,7 @@ double Pid::compute_command(double error, double error_dot, const double & dt_s)
293292
cmd_ = cmd_unsat_;
294293
}
295294

296-
if (gains.antiwindup_strat_ == "back_calculation") {
295+
if (gains.antiwindup_strat_ == "back_calculation" && gains.i_gain_ != 0) {
297296
if (gains.trk_tc_ == 0.0 && gains.d_gain_ != 0.0) {
298297
// Default value for tracking time constant for back calculation technique
299298
gains.trk_tc_ = std::sqrt(gains.d_gain_/gains.i_gain_);

0 commit comments

Comments
 (0)