diff options
author | Raptor Engineering Development Team <support@raptorengineering.com> | 2018-04-29 07:31:49 -0500 |
---|---|---|
committer | Raptor Engineering Development Team <support@raptorengineering.com> | 2019-04-19 22:07:46 +0000 |
commit | 1d0acc187668066d83f365b8be9463e9ad315a7b (patch) | |
tree | 244536f6131b22e2b66e422bb172b6e3423fb35d /control/zone.hpp | |
parent | a964223bba361d62e14621137b353daaf3dacdc8 (diff) | |
download | phosphor-fan-presence-1d0acc187668066d83f365b8be9463e9ad315a7b.tar.gz phosphor-fan-presence-1d0acc187668066d83f365b8be9463e9ad315a7b.zip |
Add PID control option to fan controller
Diffstat (limited to 'control/zone.hpp')
-rw-r--r-- | control/zone.hpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/control/zone.hpp b/control/zone.hpp index ec0d9bb..1739930 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -1,3 +1,6 @@ +// PID controls (c) 2018 Raptor Engineering, LLC +// Licensed for use with Raptor Computing Systems machines only + #pragma once #include <algorithm> #include <cassert> @@ -335,6 +338,18 @@ class Zone : public ThermalObject void requestSpeedDecrease(uint64_t targetDelta); /** + * @brief Run PID algorithm based on provided error, Kp, Ki, and Kd + * values. + * + * @param[in] error - Current error value + * @param[in] integrator_timestep - Integrator time step + * @param[in] kp - PID proportional constant + * @param[in] ki - PID integral constant + * @param[in] kd - PID derivative constant + */ + void runPidLoop(int64_t error, uint64_t integrator_timestep, int64_t kp, int64_t ki, int64_t kd); + + /** * @brief Callback function for the increase timer that delays * processing of requested speed increases while fans are increasing */ @@ -347,6 +362,11 @@ class Zone : public ThermalObject void decTimerExpired(); /** + * @brief Callback function for the PID timer + */ + void pidTimerExpired(); + + /** * @brief Get the event loop used with this zone's timers * * @return - The event loop for timers @@ -638,6 +658,31 @@ class Zone : public ThermalObject uint64_t _requestSpeedBase = 0; /** + * PID active + */ + bool _pidActive = false; + bool _pidActivePrev = false; + + /** + * PID integrator + */ + int64_t _pidIntegrator = 0; + + /** + * PID values + */ + int64_t _pidLastError = 0; + uint64_t _pidLastIntegratorTimestep = 0; + int64_t _pidLastKp = 0; + int64_t _pidLastKi = 0; + int64_t _pidLastKd = 0; + + /** + * PID prior state tracker + */ + int64_t _pidPrevError = 0; + + /** * Speed increase delay in seconds */ std::chrono::seconds _incDelay; @@ -658,6 +703,11 @@ class Zone : public ThermalObject Timer _decTimer; /** + * The PID timer object + */ + Timer _pidTimer; + + /** * Event loop used on set speed event timers */ sdeventplus::Event _eventLoop; |