44 #include <boost/algorithm/clamp.hpp> 45 #include <boost/algorithm/minmax.hpp> 51 Pid::Pid(
double p,
double i,
double d,
double i_max,
double i_min,
bool antiwindup)
52 : dynamic_reconfig_initialized_(false)
54 setGains(p,i,d,i_max,i_min,antiwindup);
73 void Pid::initPid(
double p,
double i,
double d,
double i_max,
double i_min,
83 void Pid::initPid(
double p,
double i,
double d,
double i_max,
double i_min,
bool antiwindup,
86 initPid(p, i, d, i_max, i_min, antiwindup);
93 void Pid::initPid(
double p,
double i,
double d,
double i_max,
double i_min,
bool antiwindup)
95 setGains(p,i,d,i_max,i_min, antiwindup);
103 return init(nh, quiet);
126 nh.
param(
"i_clamp", i_clamp, 0.0);
127 gains.
i_max_ = std::abs(i_clamp);
128 gains.
i_min_ = -std::abs(i_clamp);
163 i_clamp = config->Attribute(
"iClamp") ? atof(config->Attribute(
"iClamp")) : 0.0;
166 config->Attribute(
"p") ? atof(config->Attribute(
"p")) : 0.0,
167 config->Attribute(
"i") ? atof(config->Attribute(
"i")) : 0.0,
168 config->Attribute(
"d") ? atof(config->Attribute(
"d")) : 0.0,
171 config->Attribute(
"antiwindup") ? atof(config->Attribute(
"antiwindup")) :
false 206 void Pid::getGains(
double &p,
double &i,
double &d,
double &i_max,
double &i_min)
209 getGains(p, i, d, i_max, i_min, antiwindup);
212 void Pid::getGains(
double &p,
double &i,
double &d,
double &i_max,
double &i_min,
bool &antiwindup)
229 void Pid::setGains(
double p,
double i,
double d,
double i_max,
double i_min,
bool antiwindup)
231 Gains gains(p,i,d,i_max,i_min, antiwindup);
251 control_toolbox::ParametersConfig config;
254 getGains(config.p, config.i, config.d, config.i_clamp_max, config.i_clamp_min, config.antiwindup);
265 control_toolbox::ParametersConfig config;
268 config.p = gains_config.
p_gain_;
269 config.i = gains_config.
i_gain_;
270 config.d = gains_config.
d_gain_;
271 config.i_clamp_max = gains_config.
i_max_;
272 config.i_clamp_min = gains_config.
i_min_;
295 setGains(config.p, config.i, config.d, config.i_clamp_max, config.i_clamp_min, config.antiwindup);
301 if (dt ==
ros::Duration(0.0) || std::isnan(error) || std::isinf(error))
307 if (dt.
toSec() > 0.0)
326 double p_term, d_term, i_term;
330 if (dt ==
ros::Duration(0.0) || std::isnan(error) || std::isinf(error) || std::isnan(error_dot) || std::isinf(error_dot))
359 cmd_ = p_term + i_term + d_term;
416 <<
" P Gain: " << gains.
p_gain_ <<
"\n" 417 <<
" I Gain: " << gains.
i_gain_ <<
"\n" 418 <<
" D Gain: " << gains.
d_gain_ <<
"\n" 419 <<
" I_Max: " << gains.
i_max_ <<
"\n" 420 <<
" I_Min: " << gains.
i_min_ <<
"\n" 426 <<
" Command: " <<
cmd_
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_INFO_STREAM_NAMED(name, args)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const std::string & getNamespace() const
static const T & clamp(const T &a, const T &b, const T &c)
bool getParam(const std::string &key, std::string &s) const
bool hasParam(const std::string &key) const