blob: 9d73cf814797c5ba39af2df744e1284257a0977d [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;
Potin Laie1fa8592025-08-29 15:27:08 +080034 bool ignoreFailIfHostOff;
Patrick Venturee6206562018-03-08 15:36:53 -080035};
36
37/*
Josh Lehan31058fd2023-01-13 11:06:16 -080038 * Structure for decorating an input sensor's name with additional
Josh Lehan3f0f7bc2023-02-13 01:45:29 -080039 * information, such as TempToMargin and MissingIsAcceptable.
40 * This information comes from the PID loop configuration,
41 * not from SensorConfig, in order for it to be able to work
42 * with dynamic sensors from entity-manager.
Josh Lehan31058fd2023-01-13 11:06:16 -080043 */
44struct SensorInput
45{
46 std::string name;
47 double convertMarginZero = std::numeric_limits<double>::quiet_NaN();
48 bool convertTempToMargin = false;
Josh Lehan3f0f7bc2023-02-13 01:45:29 -080049 bool missingIsAcceptable = false;
Josh Lehan31058fd2023-01-13 11:06:16 -080050};
51
52/*
Patrick Venturee6206562018-03-08 15:36:53 -080053 * Structure for holding the configuration of a PID.
54 */
Patrick Venturef3252312018-10-30 08:42:53 -070055struct ControllerInfo
Patrick Venturee6206562018-03-08 15:36:53 -080056{
57 std::string type; // fan or margin or temp?
Josh Lehan31058fd2023-01-13 11:06:16 -080058 std::vector<SensorInput> inputs; // one or more sensors.
Patrick Venture5f59c0f2018-11-11 12:55:14 -080059 double setpoint; // initial setpoint for thermal.
Bonnie Lo0e8fc392022-10-05 10:20:55 +080060 ec::pidinfo pidInfo; // pid details
61 ec::StepwiseInfo stepwiseInfo;
ykchiu9fe3a3c2023-05-11 13:43:54 +080062 double failSafePercent;
Bonnie Lo0e8fc392022-10-05 10:20:55 +080063};
64
65struct CycleTime
66{
67 /* The time interval every cycle. 0.1 seconds by default */
68 uint64_t cycleIntervalTimeMS = 100; // milliseconds
69
70 /* The interval of updating thermals. 1 second by default */
71 uint64_t updateThermalsTimeMS = 1000; // milliseconds
Patrick Venturee6206562018-03-08 15:36:53 -080072};
73
74/*
75 * General zone structure used for configuration. A zone is a list of PIDs
76 * and a set of configuration settings. This structure gets filled out with
77 * the zone configuration settings and not the PID details.
78 */
Patrick Venturef3252312018-10-30 08:42:53 -070079struct ZoneConfig
Patrick Venturee6206562018-03-08 15:36:53 -080080{
Patrick Venturef7a2dd52019-07-16 14:31:13 -070081 /* The minimum set-point value we would ever want (typically in RPM) */
James Feist3484bed2019-02-25 13:28:18 -080082 double minThermalOutput;
Patrick Venturee6206562018-03-08 15:36:53 -080083
84 /* If the sensors are in fail-safe mode, this is the percentage to use. */
Patrick Venture8e2fdb32019-02-11 09:39:59 -080085 double failsafePercent;
Bonnie Lo0e8fc392022-10-05 10:20:55 +080086
87 /* Customize time settings for every cycle */
88 CycleTime cycleTime;
Delphine CC Chiu97889632023-11-06 11:32:46 +080089
90 /* Enable accumulation of the output PWM of different controllers with same
91 * sensor */
92 bool accumulateSetPoint;
Patrick Venturee6206562018-03-08 15:36:53 -080093};
94
Patrick Venture1df9e872020-10-08 15:35:01 -070095using PIDConf = std::map<std::string, ControllerInfo>;
James Feistf81f2882019-02-26 11:26:36 -080096
Patrick Venture39199b42020-10-08 14:40:29 -070097constexpr bool DEBUG = false; // enable to print found configuration
98
James Feistf81f2882019-02-26 11:26:36 -080099} // namespace conf
Josh Lehan31058fd2023-01-13 11:06:16 -0800100
Patrick Venturea0764872020-08-08 07:48:43 -0700101} // namespace pid_control