blob: 6144d4903991a1456d93fdc5bff5f2cb0fbfc495 [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.
Patrick Ventured8012182018-03-08 08:21:38 -080016 */
James Feist734f9532018-11-15 12:13:18 -080017
18enum class ThermalType
19{
20 margin,
21 absolute
22};
23
Patrick Venturee94bdc42018-11-15 18:41:21 -080024/**
25 * Get the ThermalType for a given string.
26 *
27 * @param[in] typeString - a string representation of a type.
28 * @return the ThermalType representation.
29 */
30ThermalType getThermalType(const std::string& typeString);
31
32/**
33 * Is the type specified a thermal type?
34 *
35 * @param[in] typeString - a string representation of a PID type.
36 * @return true if it's a thermal PID type.
37 */
38bool isThermalType(const std::string& typeString);
39
Patrick Ventured8012182018-03-08 08:21:38 -080040class ThermalController : public PIDController
41{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042 public:
43 static std::unique_ptr<PIDController>
Patrick Venture563a3562018-10-30 09:31:26 -070044 createThermalPid(ZoneInterface* owner, const std::string& id,
Patrick Venture5f59c0f2018-11-11 12:55:14 -080045 const std::vector<std::string>& inputs,
James Feist734f9532018-11-15 12:13:18 -080046 double setpoint, const ec::pidinfo& initial,
47 const ThermalType& type);
Patrick Ventured8012182018-03-08 08:21:38 -080048
Patrick Venture4a2dc4d2018-10-23 09:02:55 -070049 ThermalController(const std::string& id,
50 const std::vector<std::string>& inputs,
James Feist734f9532018-11-15 12:13:18 -080051 const ThermalType& type, ZoneInterface* owner) :
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052 PIDController(id, owner),
James Feist734f9532018-11-15 12:13:18 -080053 _inputs(inputs), type(type)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070054 {}
Patrick Ventured8012182018-03-08 08:21:38 -080055
Patrick Venture5f59c0f2018-11-11 12:55:14 -080056 double inputProc(void) override;
57 double setptProc(void) override;
58 void outputProc(double value) override;
Patrick Ventured8012182018-03-08 08:21:38 -080059
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 private:
61 std::vector<std::string> _inputs;
James Feist734f9532018-11-15 12:13:18 -080062 ThermalType type;
Patrick Ventured8012182018-03-08 08:21:38 -080063};
Patrick Venturea0764872020-08-08 07:48:43 -070064
65} // namespace pid_control