Skip to content

Commit

Permalink
update anti windup clamping
Browse files Browse the repository at this point in the history
  • Loading branch information
onionsflying authored and mathias-luedtke committed Jan 31, 2019
1 parent 5666ad9 commit 330df42
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <tinyxml.h>

#include <boost/algorithm/clamp.hpp>
#include <boost/algorithm/minmax.hpp>

namespace control_toolbox {

Expand Down Expand Up @@ -335,12 +336,11 @@ double Pid::computeCommand(double error, double error_dot, ros::Duration dt)
// Calculate the integral of the position error
i_error_ += dt.toSec() * p_error_;

if(gains.antiwindup_)
if(gains.antiwindup_ && gains.i_gain_!=0)
{
// Prevent i_error_ from climbing higher than permitted by i_max_/i_min_
i_error_ = boost::algorithm::clamp(i_error_,
gains.i_min_ / std::abs(gains.i_gain_),
gains.i_max_ / std::abs(gains.i_gain_));
boost::tuple<double, double> bounds = boost::minmax<double>(gains.i_min_ / gains.i_gain_, gains.i_max_ / gains.i_gain_);
i_error_ = boost::algorithm::clamp(i_error_, bounds.get<0>(), bounds.get<1>());
}

// Calculate integral contribution to command
Expand Down

0 comments on commit 330df42

Please sign in to comment.