Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 3 | #include "pid/ec/pid.hpp" |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 4 | #include "pid/ec/stepwise.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 5 | |
Josh Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 6 | #include <limits> |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 11 | namespace pid_control |
| 12 | { |
Josh Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 13 | |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 14 | namespace conf |
| 15 | { |
James Feist | f81f288 | 2019-02-26 11:26:36 -0800 | [diff] [blame] | 16 | |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 17 | /* |
| 18 | * General sensor structure used for configuration. |
| 19 | */ |
Patrick Venture | f325231 | 2018-10-30 08:42:53 -0700 | [diff] [blame] | 20 | struct SensorConfig |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 21 | { |
Patrick Venture | 69c5106 | 2019-02-11 09:46:03 -0800 | [diff] [blame] | 22 | /* Used for listen if readPath is passive. */ |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 23 | std::string type; |
| 24 | /* Can be a sensor path or a dbus path. */ |
Patrick Venture | 69c5106 | 2019-02-11 09:46:03 -0800 | [diff] [blame] | 25 | std::string readPath; |
| 26 | std::string writePath; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 27 | /* min/max values for writing a percentage or error checking. */ |
| 28 | int64_t min; |
| 29 | int64_t max; |
| 30 | int64_t timeout; |
Patrick Venture | 6b9f599 | 2019-09-10 09:18:28 -0700 | [diff] [blame] | 31 | bool ignoreDbusMinMax; |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 32 | bool unavailableAsFailed; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | /* |
Josh Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 36 | * Structure for decorating an input sensor's name with additional |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 37 | * 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 Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 41 | */ |
| 42 | struct SensorInput |
| 43 | { |
| 44 | std::string name; |
| 45 | double convertMarginZero = std::numeric_limits<double>::quiet_NaN(); |
| 46 | bool convertTempToMargin = false; |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 47 | bool missingIsAcceptable = false; |
Josh Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /* |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 51 | * Structure for holding the configuration of a PID. |
| 52 | */ |
Patrick Venture | f325231 | 2018-10-30 08:42:53 -0700 | [diff] [blame] | 53 | struct ControllerInfo |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 54 | { |
| 55 | std::string type; // fan or margin or temp? |
Josh Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 56 | std::vector<SensorInput> inputs; // one or more sensors. |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 57 | double setpoint; // initial setpoint for thermal. |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 58 | ec::pidinfo pidInfo; // pid details |
| 59 | ec::StepwiseInfo stepwiseInfo; |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 60 | double failSafePercent; |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | struct 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 Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 70 | }; |
| 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 Venture | f325231 | 2018-10-30 08:42:53 -0700 | [diff] [blame] | 77 | struct ZoneConfig |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 78 | { |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 79 | /* The minimum set-point value we would ever want (typically in RPM) */ |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 80 | double minThermalOutput; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 81 | |
| 82 | /* If the sensors are in fail-safe mode, this is the percentage to use. */ |
Patrick Venture | 8e2fdb3 | 2019-02-11 09:39:59 -0800 | [diff] [blame] | 83 | double failsafePercent; |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 84 | |
| 85 | /* Customize time settings for every cycle */ |
| 86 | CycleTime cycleTime; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Patrick Venture | 1df9e87 | 2020-10-08 15:35:01 -0700 | [diff] [blame] | 89 | using PIDConf = std::map<std::string, ControllerInfo>; |
James Feist | f81f288 | 2019-02-26 11:26:36 -0800 | [diff] [blame] | 90 | |
Patrick Venture | 39199b4 | 2020-10-08 14:40:29 -0700 | [diff] [blame] | 91 | constexpr bool DEBUG = false; // enable to print found configuration |
| 92 | |
James Feist | f81f288 | 2019-02-26 11:26:36 -0800 | [diff] [blame] | 93 | } // namespace conf |
Josh Lehan | 31058fd | 2023-01-13 11:06:16 -0800 | [diff] [blame] | 94 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 95 | } // namespace pid_control |