1e620656cSPatrick Venture #pragma once 2e620656cSPatrick Venture 3da4a5dd1SPatrick Venture #include "pid/ec/pid.hpp" 422c257abSJames Feist #include "pid/ec/stepwise.hpp" 5da4a5dd1SPatrick Venture 631058fd3SJosh Lehan #include <limits> 7e620656cSPatrick Venture #include <map> 8e620656cSPatrick Venture #include <string> 9e620656cSPatrick Venture #include <vector> 10e620656cSPatrick Venture 11a076487aSPatrick Venture namespace pid_control 12a076487aSPatrick Venture { 1331058fd3SJosh Lehan 1475eb769dSJames Feist namespace conf 1575eb769dSJames Feist { 16f81f2886SJames Feist 17e620656cSPatrick Venture /* 18e620656cSPatrick Venture * General sensor structure used for configuration. 19e620656cSPatrick Venture */ 20f3252315SPatrick Venture struct SensorConfig 21e620656cSPatrick Venture { 2269c51061SPatrick Venture /* Used for listen if readPath is passive. */ 23e620656cSPatrick Venture std::string type; 24e620656cSPatrick Venture /* Can be a sensor path or a dbus path. */ 2569c51061SPatrick Venture std::string readPath; 2669c51061SPatrick Venture std::string writePath; 27e620656cSPatrick Venture /* min/max values for writing a percentage or error checking. */ 28e620656cSPatrick Venture int64_t min; 29e620656cSPatrick Venture int64_t max; 30e620656cSPatrick Venture int64_t timeout; 316b9f5999SPatrick Venture bool ignoreDbusMinMax; 328f73ad76SAlex.Song bool unavailableAsFailed; 33e620656cSPatrick Venture }; 34e620656cSPatrick Venture 35e620656cSPatrick Venture /* 3631058fd3SJosh Lehan * Structure for decorating an input sensor's name with additional 373f0f7bc3SJosh Lehan * information, such as TempToMargin and MissingIsAcceptable. 383f0f7bc3SJosh Lehan * This information comes from the PID loop configuration, 393f0f7bc3SJosh Lehan * not from SensorConfig, in order for it to be able to work 403f0f7bc3SJosh Lehan * with dynamic sensors from entity-manager. 4131058fd3SJosh Lehan */ 4231058fd3SJosh Lehan struct SensorInput 4331058fd3SJosh Lehan { 4431058fd3SJosh Lehan std::string name; 4531058fd3SJosh Lehan double convertMarginZero = std::numeric_limits<double>::quiet_NaN(); 4631058fd3SJosh Lehan bool convertTempToMargin = false; 473f0f7bc3SJosh Lehan bool missingIsAcceptable = false; 4831058fd3SJosh Lehan }; 4931058fd3SJosh Lehan 5031058fd3SJosh Lehan /* 51e620656cSPatrick Venture * Structure for holding the configuration of a PID. 52e620656cSPatrick Venture */ 53f3252315SPatrick Venture struct ControllerInfo 54e620656cSPatrick Venture { 55e620656cSPatrick Venture std::string type; // fan or margin or temp? 5631058fd3SJosh Lehan std::vector<SensorInput> inputs; // one or more sensors. 575f59c0fdSPatrick Venture double setpoint; // initial setpoint for thermal. 5822c257abSJames Feist ec::pidinfo pidInfo; // pid details 5922c257abSJames Feist ec::StepwiseInfo stepwiseInfo; 609fe3a3c7Sykchiu double failSafePercent; 6122c257abSJames Feist }; 620e8fc398SBonnie Lo 630e8fc398SBonnie Lo struct CycleTime 640e8fc398SBonnie Lo { 650e8fc398SBonnie Lo /* The time interval every cycle. 0.1 seconds by default */ 660e8fc398SBonnie Lo uint64_t cycleIntervalTimeMS = 100; // milliseconds 670e8fc398SBonnie Lo 680e8fc398SBonnie Lo /* The interval of updating thermals. 1 second by default */ 690e8fc398SBonnie Lo uint64_t updateThermalsTimeMS = 1000; // milliseconds 70e620656cSPatrick Venture }; 71e620656cSPatrick Venture 72e620656cSPatrick Venture /* 73e620656cSPatrick Venture * General zone structure used for configuration. A zone is a list of PIDs 74e620656cSPatrick Venture * and a set of configuration settings. This structure gets filled out with 75e620656cSPatrick Venture * the zone configuration settings and not the PID details. 76e620656cSPatrick Venture */ 77f3252315SPatrick Venture struct ZoneConfig 78e620656cSPatrick Venture { 79f7a2dd5cSPatrick Venture /* The minimum set-point value we would ever want (typically in RPM) */ 803484bedaSJames Feist double minThermalOutput; 81e620656cSPatrick Venture 82e620656cSPatrick Venture /* If the sensors are in fail-safe mode, this is the percentage to use. */ 838e2fdb34SPatrick Venture double failsafePercent; 840e8fc398SBonnie Lo 850e8fc398SBonnie Lo /* Customize time settings for every cycle */ 860e8fc398SBonnie Lo CycleTime cycleTime; 87*9788963cSDelphine CC Chiu 88*9788963cSDelphine CC Chiu /* Enable accumulation of the output PWM of different controllers with same 89*9788963cSDelphine CC Chiu * sensor */ 90*9788963cSDelphine CC Chiu bool accumulateSetPoint; 91e620656cSPatrick Venture }; 92e620656cSPatrick Venture 931df9e879SPatrick Venture using PIDConf = std::map<std::string, ControllerInfo>; 94f81f2886SJames Feist 9539199b4dSPatrick Venture constexpr bool DEBUG = false; // enable to print found configuration 9639199b4dSPatrick Venture 97f81f2886SJames Feist } // namespace conf 9831058fd3SJosh Lehan 99a076487aSPatrick Venture } // namespace pid_control 100