blob: 796f80e7f9d0cee743db19e0bc733e6de9417af4 [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001#pragma once
2
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07003#include "pid/ec/pid.hpp"
James Feist22c257a2018-08-31 14:07:12 -07004#include "pid/ec/stepwise.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005
Ed Tanousf8b6e552025-06-27 13:27:50 -07006#include <cstdint>
Josh Lehan31058fd2023-01-13 11:06:16 -08007#include <limits>
Patrick Venturee6206562018-03-08 15:36:53 -08008#include <map>
9#include <string>
10#include <vector>
11
Patrick Venturea0764872020-08-08 07:48:43 -070012namespace pid_control
13{
Josh Lehan31058fd2023-01-13 11:06:16 -080014
James Feist75eb7692019-02-25 12:50:02 -080015namespace conf
16{
James Feistf81f2882019-02-26 11:26:36 -080017
Patrick Venturee6206562018-03-08 15:36:53 -080018/*
19 * General sensor structure used for configuration.
20 */
Patrick Venturef3252312018-10-30 08:42:53 -070021struct SensorConfig
Patrick Venturee6206562018-03-08 15:36:53 -080022{
Patrick Venture69c51062019-02-11 09:46:03 -080023 /* Used for listen if readPath is passive. */
Patrick Venturee6206562018-03-08 15:36:53 -080024 std::string type;
25 /* Can be a sensor path or a dbus path. */
Patrick Venture69c51062019-02-11 09:46:03 -080026 std::string readPath;
27 std::string writePath;
Patrick Venturee6206562018-03-08 15:36:53 -080028 /* min/max values for writing a percentage or error checking. */
29 int64_t min;
30 int64_t max;
31 int64_t timeout;
Patrick Venture6b9f5992019-09-10 09:18:28 -070032 bool ignoreDbusMinMax;
Alex.Song8f73ad72021-10-07 00:18:27 +080033 bool unavailableAsFailed;
Patrick Venturee6206562018-03-08 15:36:53 -080034};
35
36/*
Josh Lehan31058fd2023-01-13 11:06:16 -080037 * Structure for decorating an input sensor's name with additional
Josh Lehan3f0f7bc2023-02-13 01:45:29 -080038 * information, such as TempToMargin and MissingIsAcceptable.
39 * This information comes from the PID loop configuration,
40 * not from SensorConfig, in order for it to be able to work
41 * with dynamic sensors from entity-manager.
Josh Lehan31058fd2023-01-13 11:06:16 -080042 */
43struct SensorInput
44{
45 std::string name;
46 double convertMarginZero = std::numeric_limits<double>::quiet_NaN();
47 bool convertTempToMargin = false;
Josh Lehan3f0f7bc2023-02-13 01:45:29 -080048 bool missingIsAcceptable = false;
Josh Lehan31058fd2023-01-13 11:06:16 -080049};
50
51/*
Patrick Venturee6206562018-03-08 15:36:53 -080052 * Structure for holding the configuration of a PID.
53 */
Patrick Venturef3252312018-10-30 08:42:53 -070054struct ControllerInfo
Patrick Venturee6206562018-03-08 15:36:53 -080055{
56 std::string type; // fan or margin or temp?
Josh Lehan31058fd2023-01-13 11:06:16 -080057 std::vector<SensorInput> inputs; // one or more sensors.
Patrick Venture5f59c0f2018-11-11 12:55:14 -080058 double setpoint; // initial setpoint for thermal.
Bonnie Lo0e8fc392022-10-05 10:20:55 +080059 ec::pidinfo pidInfo; // pid details
60 ec::StepwiseInfo stepwiseInfo;
ykchiu9fe3a3c2023-05-11 13:43:54 +080061 double failSafePercent;
Bonnie Lo0e8fc392022-10-05 10:20:55 +080062};
63
64struct CycleTime
65{
66 /* The time interval every cycle. 0.1 seconds by default */
67 uint64_t cycleIntervalTimeMS = 100; // milliseconds
68
69 /* The interval of updating thermals. 1 second by default */
70 uint64_t updateThermalsTimeMS = 1000; // milliseconds
Patrick Venturee6206562018-03-08 15:36:53 -080071};
72
73/*
74 * General zone structure used for configuration. A zone is a list of PIDs
75 * and a set of configuration settings. This structure gets filled out with
76 * the zone configuration settings and not the PID details.
77 */
Patrick Venturef3252312018-10-30 08:42:53 -070078struct ZoneConfig
Patrick Venturee6206562018-03-08 15:36:53 -080079{
Patrick Venturef7a2dd52019-07-16 14:31:13 -070080 /* The minimum set-point value we would ever want (typically in RPM) */
James Feist3484bed2019-02-25 13:28:18 -080081 double minThermalOutput;
Patrick Venturee6206562018-03-08 15:36:53 -080082
83 /* If the sensors are in fail-safe mode, this is the percentage to use. */
Patrick Venture8e2fdb32019-02-11 09:39:59 -080084 double failsafePercent;
Bonnie Lo0e8fc392022-10-05 10:20:55 +080085
86 /* Customize time settings for every cycle */
87 CycleTime cycleTime;
Delphine CC Chiu97889632023-11-06 11:32:46 +080088
89 /* Enable accumulation of the output PWM of different controllers with same
90 * sensor */
91 bool accumulateSetPoint;
Patrick Venturee6206562018-03-08 15:36:53 -080092};
93
Patrick Venture1df9e872020-10-08 15:35:01 -070094using PIDConf = std::map<std::string, ControllerInfo>;
James Feistf81f2882019-02-26 11:26:36 -080095
Patrick Venture39199b42020-10-08 14:40:29 -070096constexpr bool DEBUG = false; // enable to print found configuration
97
James Feistf81f2882019-02-26 11:26:36 -080098} // namespace conf
Josh Lehan31058fd2023-01-13 11:06:16 -080099
Patrick Venturea0764872020-08-08 07:48:43 -0700100} // namespace pid_control