Skip to content

Commit

Permalink
Applied more suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Whalex451 authored and destogl committed Feb 11, 2024
1 parent 2fa429a commit 0d196f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion include/control_toolbox/pid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ namespace control_toolbox
be subclassed to provide more specific controls
based on a particular control loop.
This class also allows for retention of integral
term on reset. This is useful for control loops
that are enabled/disabled with a constant steady-state
external disturbance. Once the integrator cancels
out the external disturbance, disabling/resetting/
re-enabling closed-loop control does not require
the integrator to wind up again.
In particular, this class implements the standard
pid equation:
Expand All @@ -83,6 +91,8 @@ namespace control_toolbox
\param i_clamp Min/max bounds for the integral windup, the clamp is applied to the \f$i_{term}\f$
\param save_iterm boolean indicating if integral term is retained on reset()
\section Usage
To use the Pid class, you should first call some version of init()
Expand Down Expand Up @@ -119,7 +129,7 @@ class CONTROL_TOOLBOX_PUBLIC Pid
save_iterm_(false)
{
}
// Optional constructor for passing in values
// Optional constructor for passing in values without save i-term
Gains(double p, double i, double d, double i_max, double i_min, bool antiwindup)
: p_gain_(p), i_gain_(i), d_gain_(d), i_max_(i_max), i_min_(i_min), antiwindup_(antiwindup),
save_iterm_(false)
Expand Down
2 changes: 1 addition & 1 deletion src/pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void Pid::reset()
cmd_ = 0.0;

// If last integral error is already zero, just return
if (std::fabs(i_error_) < std::numeric_limits<double>::epsilon())
if (std::fabs(i_error_) < std::numeric_limits<double>::epsilon())
{
return;
}
Expand Down
6 changes: 3 additions & 3 deletions test/pid_parameters_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void check_set_parameters(
const double I_MAX = 10.0;
const double I_MIN = -10.0;
const bool ANTIWINDUP = true;
const bool SAVE_ITERM = false;
const bool SAVE_ITERM = true;

ASSERT_NO_THROW(pid.initPid(P, I, D, I_MAX, I_MIN, ANTIWINDUP, SAVE_ITERM));

Expand Down Expand Up @@ -93,7 +93,7 @@ void check_set_parameters(
ASSERT_EQ(gains.i_max_, I_MAX);
ASSERT_EQ(gains.i_min_, I_MIN);
ASSERT_TRUE(gains.antiwindup_);
ASSERT_FALSE(gains.save_iterm_);
ASSERT_TRUE(gains.save_iterm_);
}

TEST(PidParametersTest, InitPidTest)
Expand Down Expand Up @@ -322,7 +322,7 @@ TEST(PidParametersTest, GetParametersTest)
const double I_MAX = 10.0;
const double I_MIN = -10.0;
const bool ANTIWINDUP = true;
const bool SAVE_ITERM = false;
const bool SAVE_ITERM = true;

pid.initPid(0.0, 0.0, 0.0, 0.0, 0.0, false, false);
pid.setGains(P, I, D, I_MAX, I_MIN, ANTIWINDUP, SAVE_ITERM);
Expand Down

0 comments on commit 0d196f2

Please sign in to comment.