blob: ac551d2468931e76cd3d6d9c896707d0ce3ad51f [file] [log] [blame]
Patrick Ventured8012182018-03-08 08:21:38 -08001#pragma once
2
Josh Lehan31058fd2023-01-13 11:06:16 -08003#include "conf.hpp"
Patrick Ventured8012182018-03-08 08:21:38 -08004#include "ec/pid.hpp"
James Feist22c257a2018-08-31 14:07:12 -07005#include "pidcontroller.hpp"
Patrick Ventured8012182018-03-08 08:21:38 -08006
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07007#include <memory>
8#include <string>
9#include <vector>
Patrick Ventured8012182018-03-08 08:21:38 -080010
Patrick Venturea0764872020-08-08 07:48:43 -070011namespace pid_control
12{
13
Patrick Ventured8012182018-03-08 08:21:38 -080014/*
15 * A ThermalController is a PID controller that reads a number of sensors and
Patrick Venture7280e272019-02-11 10:45:32 -080016 * provides the setpoints for the fans.
Josh Lehan23e22b92022-11-12 22:37:58 -080017 * With addition of support for power sensors, this name is misleading,
18 * as it now works for power sensors also, not just thermal sensors.
19 * If rewritten today, a better name would be "ComputationType".
Patrick Ventured8012182018-03-08 08:21:38 -080020 */
James Feist734f9532018-11-15 12:13:18 -080021
22enum class ThermalType
23{
24 margin,
Josh Lehan23e22b92022-11-12 22:37:58 -080025 absolute,
26 summation
James Feist734f9532018-11-15 12:13:18 -080027};
28
Patrick Venturee94bdc42018-11-15 18:41:21 -080029/**
30 * Get the ThermalType for a given string.
31 *
32 * @param[in] typeString - a string representation of a type.
33 * @return the ThermalType representation.
34 */
35ThermalType getThermalType(const std::string& typeString);
36
37/**
38 * Is the type specified a thermal type?
39 *
40 * @param[in] typeString - a string representation of a PID type.
41 * @return true if it's a thermal PID type.
42 */
43bool isThermalType(const std::string& typeString);
44
Patrick Ventured8012182018-03-08 08:21:38 -080045class ThermalController : public PIDController
46{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070047 public:
Josh Lehan31058fd2023-01-13 11:06:16 -080048 static std::unique_ptr<PIDController> createThermalPid(
49 ZoneInterface* owner, const std::string& id,
50 const std::vector<pid_control::conf::SensorInput>& inputs,
51 double setpoint, const ec::pidinfo& initial, const ThermalType& type);
Patrick Ventured8012182018-03-08 08:21:38 -080052
Patrick Venture4a2dc4d2018-10-23 09:02:55 -070053 ThermalController(const std::string& id,
Josh Lehan31058fd2023-01-13 11:06:16 -080054 const std::vector<pid_control::conf::SensorInput>& 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:
Josh Lehan31058fd2023-01-13 11:06:16 -080065 std::vector<pid_control::conf::SensorInput> _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