blob: 752c1059a41d53bd7f43511dec7d384c2150a210 [file] [log] [blame]
Patrick Ventured8012182018-03-08 08:21:38 -08001#pragma once
2
Patrick Ventured8012182018-03-08 08:21:38 -08003#include "ec/pid.hpp"
James Feist22c257a2018-08-31 14:07:12 -07004#include "pidcontroller.hpp"
Patrick Ventured8012182018-03-08 08:21:38 -08005
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07006#include <memory>
7#include <string>
8#include <vector>
Patrick Ventured8012182018-03-08 08:21:38 -08009
Patrick Venturea0764872020-08-08 07:48:43 -070010namespace pid_control
11{
12
Patrick Ventured8012182018-03-08 08:21:38 -080013/*
14 * A ThermalController is a PID controller that reads a number of sensors and
Patrick Venture7280e272019-02-11 10:45:32 -080015 * provides the setpoints for the fans.
Josh Lehan23e22b92022-11-12 22:37:58 -080016 * With addition of support for power sensors, this name is misleading,
17 * as it now works for power sensors also, not just thermal sensors.
18 * If rewritten today, a better name would be "ComputationType".
Patrick Ventured8012182018-03-08 08:21:38 -080019 */
James Feist734f9532018-11-15 12:13:18 -080020
21enum class ThermalType
22{
23 margin,
Josh Lehan23e22b92022-11-12 22:37:58 -080024 absolute,
25 summation
James Feist734f9532018-11-15 12:13:18 -080026};
27
Patrick Venturee94bdc42018-11-15 18:41:21 -080028/**
29 * Get the ThermalType for a given string.
30 *
31 * @param[in] typeString - a string representation of a type.
32 * @return the ThermalType representation.
33 */
34ThermalType getThermalType(const std::string& typeString);
35
36/**
37 * Is the type specified a thermal type?
38 *
39 * @param[in] typeString - a string representation of a PID type.
40 * @return true if it's a thermal PID type.
41 */
42bool isThermalType(const std::string& typeString);
43
Patrick Ventured8012182018-03-08 08:21:38 -080044class ThermalController : public PIDController
45{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046 public:
47 static std::unique_ptr<PIDController>
Patrick Venture563a3562018-10-30 09:31:26 -070048 createThermalPid(ZoneInterface* owner, const std::string& id,
Patrick Venture5f59c0f2018-11-11 12:55:14 -080049 const std::vector<std::string>& inputs,
James Feist734f9532018-11-15 12:13:18 -080050 double setpoint, const ec::pidinfo& initial,
51 const ThermalType& type);
Patrick Ventured8012182018-03-08 08:21:38 -080052
Patrick Venture4a2dc4d2018-10-23 09:02:55 -070053 ThermalController(const std::string& id,
54 const std::vector<std::string>& inputs,
James Feist734f9532018-11-15 12:13:18 -080055 const ThermalType& type, ZoneInterface* owner) :
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070056 PIDController(id, owner),
James Feist734f9532018-11-15 12:13:18 -080057 _inputs(inputs), type(type)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070058 {}
Patrick Ventured8012182018-03-08 08:21:38 -080059
Patrick Venture5f59c0f2018-11-11 12:55:14 -080060 double inputProc(void) override;
61 double setptProc(void) override;
62 void outputProc(double value) override;
Patrick Ventured8012182018-03-08 08:21:38 -080063
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070064 private:
65 std::vector<std::string> _inputs;
James Feist734f9532018-11-15 12:13:18 -080066 ThermalType type;
Patrick Ventured8012182018-03-08 08:21:38 -080067};
Patrick Venturea0764872020-08-08 07:48:43 -070068
69} // namespace pid_control