summaryrefslogtreecommitdiffstats
path: root/control/actions.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'control/actions.hpp')
-rw-r--r--control/actions.hpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/control/actions.hpp b/control/actions.hpp
index bb98b7c..22449e0 100644
--- a/control/actions.hpp
+++ b/control/actions.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>
@@ -184,7 +187,7 @@ auto set_net_increase_speed(T&& state, T&& factor, uint64_t speedDelta)
std::get<propPos>(entry.second));
// TODO openbmc/phosphor-fan-presence#7 - Support possible
// state types for comparison
- if (value >= state)
+ if ((value >= state) && (factor != 0))
{
// Increase by at least a single delta(factor)
// to attempt bringing under 'state'
@@ -241,7 +244,7 @@ auto set_net_decrease_speed(T&& state, T&& factor, uint64_t speedDelta)
std::get<propPos>(entry.second));
// TODO openbmc/phosphor-fan-presence#7 - Support possible
// state types for comparison
- if (value < state)
+ if ((value < state) && (factor != 0))
{
if (netDelta == 0)
{
@@ -347,6 +350,41 @@ auto use_alternate_events_on_state(T&& state,
};
}
+template <typename T>
+auto run_pid_control(T&& state, T&& integrator_timestep, T&& kp, T&& ki, T&& kd)
+{
+ return [integrator_timestep = std::forward<T>(integrator_timestep),
+ kp = std::forward<T>(kp),
+ ki = std::forward<T>(ki),
+ kd = std::forward<T>(kd),
+ state = std::forward<T>(state)](auto& zone, auto& group)
+ {
+ auto error_accum = 0;
+ auto error_items = 0;
+ for (auto& entry : group)
+ {
+ try
+ {
+ T value = zone.template getPropertyValue<T>(
+ entry.first,
+ std::get<intfPos>(entry.second),
+ std::get<propPos>(entry.second));
+ error_accum += (value - state);
+ error_items++;
+ }
+ catch (const std::out_of_range& oore)
+ {
+ // Property value not found
+ }
+ }
+
+ if (error_items > 0)
+ {
+ zone.runPidLoop((error_accum / error_items), integrator_timestep, kp, ki, kd);
+ }
+ };
+}
+
} // namespace action
} // namespace control
} // namespace fan
OpenPOWER on IntegriCloud