29 PID_Controller(
const PID_Controller& pid)
30 : m_v0(pid.m_v0), m_p(pid.m_p), m_i(pid.m_i), m_d(pid.m_d),
31 m_setpoint(pid.m_setpoint),
37 PID_Controller& operator=(
const PID_Controller& pid) {
45 m_setpoint = pid.m_setpoint;
56 void reset(doublereal time = 0.0, doublereal input = 0.0) {
65 doublereal setpoint(doublereal y =
Undef) {
74 return getGains(4, gains.begin());
77 bool getGains(
int n, doublereal* gains) {
89 return setGains(
int(gains.size()), gains.begin());
92 bool setGains(
int n,
const doublereal* gains) {
100 if (m_p < 0.0 || m_i < 0.0 || m_d < 0.0) {
106 void update(doublereal time, doublereal input) {
107 if (time <= m_time) {
110 doublereal err = input - m_setpoint;
111 if (fabs(err) > m_maxerr) {
112 m_maxerr = fabs(err);
114 m_dt = time - m_time;
115 m_xint += (0.5*(input + m_last) - m_setpoint) * m_dt;
118 doublereal xdot = (input - m_last)/m_dt;
119 m_out = m_v0 - m_p*(input - m_setpoint) - m_i*m_xint
123 doublereal output(doublereal input) {
125 m_out - (m_p + m_d/m_dt + 0.5*m_i*m_dt)*(input - m_last));
128 doublereal maxError() {
133 return (m_time !=
Undef
134 && m_setpoint !=
Undef