Program Listing for File pid_loop.hpp

Return to documentation for file (rcppsw/control/pid_loop.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcppsw/rcppsw.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace rcppsw::control {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
class pid_loop {
 public:
  pid_loop(double kp, double kd, double ki, double dt, double min, double max)
      : m_kp(kp),
        m_kd(kd),
        m_ki(ki),
        m_dt(dt),
        m_min(min),
        m_max(max),
        m_istate(0),
        m_prev_error(0.0) {}

  double calculate(double setpoint, double pv);

  void reset(void) {
    m_istate = 0.0;
    m_prev_error = 0.0;
  }

  void min(double min) { m_min = min; }

  void max(double max) { m_max = max; }

 private:
  /* clang-format off */
  double m_kp;
  double m_kd;
  double m_ki;
  double m_dt;
  double m_min;
  double m_max;
  double m_istate;
  double m_prev_error;
  /* clang-format on */
};

} /* namespace rcppsw::control */