blob: 8a9ea38be23e59a1976e2e59caf08648a29d6e96 [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
Josh Lehan31058fd2023-01-13 11:06:16 -08006#include <limits>
Patrick Venturee6206562018-03-08 15:36:53 -08007#include <map>
8#include <string>
9#include <vector>
10
Patrick Venturea0764872020-08-08 07:48:43 -070011namespace pid_control
12{
Josh Lehan31058fd2023-01-13 11:06:16 -080013
James Feist75eb7692019-02-25 12:50:02 -080014namespace conf
15{
James Feistf81f2882019-02-26 11:26:36 -080016
Patrick Venturee6206562018-03-08 15:36:53 -080017/*
18 * General sensor structure used for configuration.
19 */
Patrick Venturef3252312018-10-30 08:42:53 -070020struct SensorConfig
Patrick Venturee6206562018-03-08 15:36:53 -080021{
Patrick Venture69c51062019-02-11 09:46:03 -080022 /* Used for listen if readPath is passive. */
Patrick Venturee6206562018-03-08 15:36:53 -080023 std::string type;
24 /* Can be a sensor path or a dbus path. */
Patrick Venture69c51062019-02-11 09:46:03 -080025 std::string readPath;
26 std::string writePath;
Patrick Venturee6206562018-03-08 15:36:53 -080027 /* min/max values for writing a percentage or error checking. */
28 int64_t min;
29 int64_t max;
30 int64_t timeout;
Patrick Venture6b9f5992019-09-10 09:18:28 -070031 bool ignoreDbusMinMax;
Alex.Song8f73ad72021-10-07 00:18:27 +080032 bool unavailableAsFailed;
Patrick Venturee6206562018-03-08 15:36:53 -080033};
34
35/*
Josh Lehan31058fd2023-01-13 11:06:16 -080036 * Structure for decorating an input sensor's name with additional
Josh Lehan3f0f7bc2023-02-13 01:45:29 -080037 * information, such as TempToMargin and MissingIsAcceptable.
38 * This information comes from the PID loop configuration,
39 * not from SensorConfig, in order for it to be able to work
40 * with dynamic sensors from entity-manager.
Josh Lehan31058fd2023-01-13 11:06:16 -080041 */
42struct SensorInput
43{
44 std::string name;
45 double convertMarginZero = std::numeric_limits<double>::quiet_NaN();
46 bool convertTempToMargin = false;
Josh Lehan3f0f7bc2023-02-13 01:45:29 -080047 bool missingIsAcceptable = false;
Josh Lehan31058fd2023-01-13 11:06:16 -080048};
49
50/*
Patrick Venturee6206562018-03-08 15:36:53 -080051 * Structure for holding the configuration of a PID.
52 */
Patrick Venturef3252312018-10-30 08:42:53 -070053struct ControllerInfo
Patrick Venturee6206562018-03-08 15:36:53 -080054{
55 std::string type; // fan or margin or temp?
Josh Lehan31058fd2023-01-13 11:06:16 -080056 std::vector<SensorInput> inputs; // one or more sensors.
Patrick Venture5f59c0f2018-11-11 12:55:14 -080057 double setpoint; // initial setpoint for thermal.
Bonnie Lo0e8fc392022-10-05 10:20:55 +080058 ec::pidinfo pidInfo; // pid details
59 ec::StepwiseInfo stepwiseInfo;
ykchiu9fe3a3c2023-05-11 13:43:54 +080060 double failSafePercent;
Bonnie Lo0e8fc392022-10-05 10:20:55 +080061};
62
63struct CycleTime
64{
65 /* The time interval every cycle. 0.1 seconds by default */
66 uint64_t cycleIntervalTimeMS = 100; // milliseconds
67
68 /* The interval of updating thermals. 1 second by default */
69 uint64_t updateThermalsTimeMS = 1000; // milliseconds
Patrick Venturee6206562018-03-08 15:36:53 -080070};
71
72/*
73 * General zone structure used for configuration. A zone is a list of PIDs
74 * and a set of configuration settings. This structure gets filled out with
75 * the zone configuration settings and not the PID details.
76 */
Patrick Venturef3252312018-10-30 08:42:53 -070077struct ZoneConfig
Patrick Venturee6206562018-03-08 15:36:53 -080078{
Patrick Venturef7a2dd52019-07-16 14:31:13 -070079 /* The minimum set-point value we would ever want (typically in RPM) */
James Feist3484bed2019-02-25 13:28:18 -080080 double minThermalOutput;
Patrick Venturee6206562018-03-08 15:36:53 -080081
82 /* If the sensors are in fail-safe mode, this is the percentage to use. */
Patrick Venture8e2fdb32019-02-11 09:39:59 -080083 double failsafePercent;
Bonnie Lo0e8fc392022-10-05 10:20:55 +080084
85 /* Customize time settings for every cycle */
86 CycleTime cycleTime;
Delphine CC Chiu97889632023-11-06 11:32:46 +080087
88 /* Enable accumulation of the output PWM of different controllers with same
89 * sensor */
90 bool accumulateSetPoint;
Patrick Venturee6206562018-03-08 15:36:53 -080091};
92
Patrick Venture1df9e872020-10-08 15:35:01 -070093using PIDConf = std::map<std::string, ControllerInfo>;
James Feistf81f2882019-02-26 11:26:36 -080094
Patrick Venture39199b42020-10-08 14:40:29 -070095constexpr bool DEBUG = false; // enable to print found configuration
96
James Feistf81f2882019-02-26 11:26:36 -080097} // namespace conf
Josh Lehan31058fd2023-01-13 11:06:16 -080098
Patrick Venturea0764872020-08-08 07:48:43 -070099} // namespace pid_control