41 kP(tensControl ? -p : p),
42 kI(tensControl ? -i : i),
43 kD(tensControl ? -d : d),
44 startingSetPoint(setPoint)
48 throw std::invalid_argument(
"Value for p is negative");
52 throw std::invalid_argument(
"Integral gain is negative.");
56 throw std::invalid_argument(
"Derivative gain is negative.");
60 assert ( (
kP >= 0.0 &&
kI >= 0.0 &&
kD >= 0.0) ||
61 (
kP <= 0.0 &&
kI <= 0.0 &&
kD <= 0.0));
72 assert(controllable != NULL);
84 throw std::runtime_error (
"Timestep must be positive.");
90 m_intError += (error + m_prevError) / 2.0 * dt;
91 double dError = (error - m_prevError) / dt;
92 double result = m_config.
kP * error + m_config.
kI * m_intError +
104 throw std::runtime_error (
"Timestep must be positive.");
115 m_sensorData = sensorData;
Config(double p=1.0, double i=0.0, double d=0.0, bool tensControl=false, double setPoint=0.0)
tgControllable * m_controllable
virtual void setControlInput(double input)=0
Definition of the tgControllable abstract base class.
virtual void control(double dt)
virtual void setNewSetPoint(double newSetPoint)
virtual ~tgPIDController()
Definition of the tgPIDController class.
virtual void setSensorData(double sensorData)
tgPIDController(tgControllable *controllable, tgPIDController::Config config)