summaryrefslogtreecommitdiffstats
path: root/control/zone.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'control/zone.hpp')
-rw-r--r--control/zone.hpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/control/zone.hpp b/control/zone.hpp
index 2185afa..fad2ae6 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 <chrono>
#include <vector>
@@ -328,6 +331,18 @@ class Zone
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
*/
@@ -340,6 +355,11 @@ class Zone
void decTimerExpired();
/**
+ * @brief Callback function for the PID timer
+ */
+ void pidTimerExpired();
+
+ /**
* @brief Get the event pointer used with this zone's timers
*
* @return - The Dbus event pointer for timers
@@ -502,6 +522,31 @@ class Zone
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;
@@ -522,6 +567,11 @@ class Zone
phosphor::fan::util::Timer _decTimer;
/**
+ * The PID timer object
+ */
+ phosphor::fan::util::Timer _pidTimer;
+
+ /**
* Dbus event used on set speed event timers
*/
phosphor::fan::event::EventPtr& _sdEvents;
OpenPOWER on IntegriCloud