wideband/firmware/pid.h

27 lines
476 B
C
Raw Normal View History

2020-10-31 14:58:34 -07:00
#pragma once
class Pid
{
public:
2021-07-09 11:16:46 -07:00
Pid(float kP, float kI, float kD, float clamp, int periodMs)
2020-10-31 14:58:34 -07:00
: m_period(periodMs / 1000.0f)
, m_kp(kP)
, m_ki(kI)
2021-07-09 11:16:46 -07:00
, m_kd(kD)
2020-12-11 15:24:56 -08:00
, m_clamp(clamp)
2020-10-31 14:58:34 -07:00
{
}
float GetOutput(float setpoint, float observation);
private:
const float m_period;
const float m_kp;
const float m_ki;
2021-07-09 11:16:46 -07:00
const float m_kd;
2020-12-11 15:24:56 -08:00
const float m_clamp;
2020-10-31 14:58:34 -07:00
2023-11-13 13:51:59 -08:00
float m_lastError = 0;
float m_integrator = 0;
2020-10-31 14:58:34 -07:00
};