Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* Configuration. */ |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 18 | #include "zone.hpp" |
| 19 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 20 | #include "conf.hpp" |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 21 | #include "failsafeloggers/failsafe_logger_utility.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 22 | #include "pid/controller.hpp" |
| 23 | #include "pid/ec/pid.hpp" |
| 24 | #include "pid/fancontroller.hpp" |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 25 | #include "pid/stepwisecontroller.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 26 | #include "pid/thermalcontroller.hpp" |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 27 | #include "pid/tuning.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 28 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 29 | #include <algorithm> |
| 30 | #include <chrono> |
| 31 | #include <cstring> |
| 32 | #include <fstream> |
| 33 | #include <iostream> |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 34 | #include <memory> |
Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 35 | #include <sstream> |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 36 | #include <string> |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 37 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 38 | using tstamp = std::chrono::high_resolution_clock::time_point; |
| 39 | using namespace std::literals::chrono_literals; |
| 40 | |
Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 41 | // Enforces minimum duration between events |
| 42 | // Rreturns true if event should be allowed, false if disallowed |
| 43 | bool allowThrottle(const tstamp& now, const std::chrono::seconds& pace) |
| 44 | { |
| 45 | static tstamp then; |
| 46 | static bool first = true; |
| 47 | |
| 48 | if (first) |
| 49 | { |
| 50 | // Special case initialization |
| 51 | then = now; |
| 52 | first = false; |
| 53 | |
| 54 | // Initialization, always allow |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | auto elapsed = now - then; |
| 59 | if (elapsed < pace) |
| 60 | { |
| 61 | // Too soon since last time, disallow |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | // It has been long enough, allow |
| 66 | then = now; |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | namespace pid_control |
| 71 | { |
| 72 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 73 | double DbusPidZone::getMaxSetPointRequest(void) const |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 74 | { |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 75 | return _maximumSetPoint; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 78 | bool DbusPidZone::getManualMode(void) const |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 79 | { |
| 80 | return _manualMode; |
| 81 | } |
| 82 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 83 | void DbusPidZone::setManualMode(bool mode) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 84 | { |
| 85 | _manualMode = mode; |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 86 | |
| 87 | // If returning to automatic mode, need to restore PWM from PID loop |
| 88 | if (!mode) |
| 89 | { |
| 90 | _redundantWrite = true; |
| 91 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 94 | bool DbusPidZone::getFailSafeMode(void) const |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 95 | { |
| 96 | // If any keys are present at least one sensor is in fail safe mode. |
| 97 | return !_failSafeSensors.empty(); |
| 98 | } |
| 99 | |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 100 | FailSafeSensorsMap DbusPidZone::getFailSafeSensors(void) const |
| 101 | { |
| 102 | return _failSafeSensors; |
| 103 | } |
| 104 | |
| 105 | void DbusPidZone::markSensorMissing(const std::string& name, |
| 106 | const std::string& failReason) |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 107 | { |
| 108 | if (_missingAcceptable.find(name) != _missingAcceptable.end()) |
| 109 | { |
| 110 | // Disallow sensors in MissingIsAcceptable list from causing failsafe |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 111 | outputFailsafeLogWithZone(_zoneId, this->getFailSafeMode(), name, |
| 112 | "The sensor is missing but is acceptable."); |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 113 | return; |
| 114 | } |
| 115 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 116 | if (_sensorFailSafePercent[name] == 0) |
| 117 | { |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 118 | _failSafeSensors[name] = std::pair(failReason, _zoneFailSafePercent); |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 119 | } |
| 120 | else |
| 121 | { |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 122 | _failSafeSensors[name] = |
| 123 | std::pair(failReason, _sensorFailSafePercent[name]); |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | if (debugEnabled) |
| 127 | { |
| 128 | std::cerr << "Sensor " << name << " marked missing\n"; |
| 129 | } |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 132 | int64_t DbusPidZone::getZoneID(void) const |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 133 | { |
| 134 | return _zoneId; |
| 135 | } |
| 136 | |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 137 | void DbusPidZone::addSetPoint(double setPoint, const std::string& name) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 138 | { |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 139 | /* exclude disabled pidloop from _maximumSetPoint calculation*/ |
| 140 | if (!isPidProcessEnabled(name)) |
| 141 | { |
| 142 | return; |
| 143 | } |
| 144 | |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 145 | auto profileName = name; |
| 146 | if (getAccSetPoint()) |
| 147 | { |
| 148 | /* |
| 149 | * If the name of controller is Linear_Temp_CPU0. |
| 150 | * The profile name will be Temp_CPU0. |
| 151 | */ |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 152 | profileName = name.substr(name.find('_') + 1); |
| 153 | setPoints[profileName] += setPoint; |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 154 | } |
| 155 | else |
| 156 | { |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 157 | if (setPoints[profileName] < setPoint) |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 158 | { |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 159 | setPoints[profileName] = setPoint; |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 163 | /* |
| 164 | * if there are multiple thermal controllers with the same |
| 165 | * value, pick the first one in the iterator |
| 166 | */ |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 167 | if (_maximumSetPoint < setPoints[profileName]) |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 168 | { |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 169 | _maximumSetPoint = setPoints[profileName]; |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 170 | _maximumSetPointName = profileName; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 171 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 174 | void DbusPidZone::addRPMCeiling(double ceiling) |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 175 | { |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 176 | rpmCeilings.push_back(ceiling); |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 179 | void DbusPidZone::clearRPMCeilings(void) |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 180 | { |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 181 | rpmCeilings.clear(); |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 184 | void DbusPidZone::clearSetPoints(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 185 | { |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 186 | setPoints.clear(); |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 187 | _maximumSetPoint = 0; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 188 | _maximumSetPointName.clear(); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 191 | double DbusPidZone::getFailSafePercent(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 192 | { |
Eric Yang | d59ccac | 2025-06-05 19:18:03 +0800 | [diff] [blame] | 193 | if (_failSafeSensors.empty()) |
| 194 | { |
| 195 | return _zoneFailSafePercent; |
| 196 | } |
| 197 | |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 198 | FailSafeSensorsMap::iterator maxData = std::max_element( |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 199 | _failSafeSensors.begin(), _failSafeSensors.end(), |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 200 | [](const FailSafeSensorPair& firstData, |
| 201 | const FailSafeSensorPair& secondData) { |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 202 | return firstData.second.second < secondData.second.second; |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 203 | }); |
| 204 | |
| 205 | // In dbus/dbusconfiguration.cpp, the default sensor failsafepercent is 0 if |
| 206 | // there is no setting in json. |
| 207 | // Therfore, if the max failsafe duty in _failSafeSensors is 0, set final |
| 208 | // failsafe duty to _zoneFailSafePercent. |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 209 | if ((*maxData).second.second == 0) |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 210 | { |
| 211 | return _zoneFailSafePercent; |
| 212 | } |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 213 | |
| 214 | return (*maxData).second.second; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 217 | double DbusPidZone::getMinThermalSetPoint(void) const |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 218 | { |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 219 | return _minThermalOutputSetPt; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 222 | uint64_t DbusPidZone::getCycleIntervalTime(void) const |
| 223 | { |
| 224 | return _cycleTime.cycleIntervalTimeMS; |
| 225 | } |
| 226 | |
| 227 | uint64_t DbusPidZone::getUpdateThermalsCycle(void) const |
| 228 | { |
| 229 | return _cycleTime.updateThermalsTimeMS; |
| 230 | } |
| 231 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 232 | void DbusPidZone::addFanPID(std::unique_ptr<Controller> pid) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 233 | { |
| 234 | _fans.push_back(std::move(pid)); |
| 235 | } |
| 236 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 237 | void DbusPidZone::addThermalPID(std::unique_ptr<Controller> pid) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 238 | { |
| 239 | _thermals.push_back(std::move(pid)); |
| 240 | } |
| 241 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 242 | double DbusPidZone::getCachedValue(const std::string& name) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 243 | { |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 244 | return _cachedValuesByName.at(name).scaled; |
| 245 | } |
| 246 | |
| 247 | ValueCacheEntry DbusPidZone::getCachedValues(const std::string& name) |
| 248 | { |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 249 | return _cachedValuesByName.at(name); |
| 250 | } |
| 251 | |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 252 | void DbusPidZone::setOutputCache(std::string_view name, |
| 253 | const ValueCacheEntry& values) |
| 254 | { |
| 255 | _cachedFanOutputs[std::string{name}] = values; |
| 256 | } |
| 257 | |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 258 | void DbusPidZone::addFanInput(const std::string& fan, bool missingAcceptable) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 259 | { |
| 260 | _fanInputs.push_back(fan); |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 261 | |
| 262 | if (missingAcceptable) |
| 263 | { |
| 264 | _missingAcceptable.emplace(fan); |
| 265 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 268 | void DbusPidZone::addThermalInput(const std::string& therm, |
| 269 | bool missingAcceptable) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 270 | { |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 271 | /* |
| 272 | * One sensor may have stepwise and PID at the same time. |
| 273 | * Searching the sensor name before inserting it to avoid duplicated sensor |
| 274 | * names. |
| 275 | */ |
| 276 | if (std::find(_thermalInputs.begin(), _thermalInputs.end(), therm) == |
| 277 | _thermalInputs.end()) |
| 278 | { |
| 279 | _thermalInputs.push_back(therm); |
| 280 | } |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 281 | |
| 282 | if (missingAcceptable) |
| 283 | { |
| 284 | _missingAcceptable.emplace(therm); |
| 285 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 288 | // Updates desired RPM setpoint from optional text file |
| 289 | // Returns true if rpmValue updated, false if left unchanged |
| 290 | static bool fileParseRpm(const std::string& fileName, double& rpmValue) |
| 291 | { |
| 292 | static constexpr std::chrono::seconds throttlePace{3}; |
| 293 | |
| 294 | std::string errText; |
| 295 | |
| 296 | try |
| 297 | { |
| 298 | std::ifstream ifs; |
| 299 | ifs.open(fileName); |
| 300 | if (ifs) |
| 301 | { |
| 302 | int value; |
| 303 | ifs >> value; |
| 304 | |
| 305 | if (value <= 0) |
| 306 | { |
| 307 | errText = "File content could not be parsed to a number"; |
| 308 | } |
| 309 | else if (value <= 100) |
| 310 | { |
| 311 | errText = "File must contain RPM value, not PWM value"; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | rpmValue = static_cast<double>(value); |
| 316 | return true; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | catch (const std::exception& e) |
| 321 | { |
| 322 | errText = "Exception: "; |
| 323 | errText += e.what(); |
| 324 | } |
| 325 | |
| 326 | // The file is optional, intentionally not an error if file not found |
| 327 | if (!(errText.empty())) |
| 328 | { |
| 329 | tstamp now = std::chrono::high_resolution_clock::now(); |
| 330 | if (allowThrottle(now, throttlePace)) |
| 331 | { |
| 332 | std::cerr << "Unable to read from '" << fileName << "': " << errText |
| 333 | << "\n"; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | return false; |
| 338 | } |
| 339 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 340 | void DbusPidZone::determineMaxSetPointRequest(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 341 | { |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 342 | std::vector<double>::iterator result; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 343 | double minThermalThreshold = getMinThermalSetPoint(); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 344 | |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 345 | if (rpmCeilings.size() > 0) |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 346 | { |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 347 | result = std::min_element(rpmCeilings.begin(), rpmCeilings.end()); |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 348 | // if Max set point is larger than the lowest ceiling, reset to lowest |
| 349 | // ceiling. |
| 350 | if (*result < _maximumSetPoint) |
| 351 | { |
| 352 | _maximumSetPoint = *result; |
| 353 | // When using lowest ceiling, controller name is ceiling. |
| 354 | _maximumSetPointName = "Ceiling"; |
| 355 | } |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 358 | /* |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 359 | * Combine the maximum SetPoint Name if the controllers have same profile |
| 360 | * name. e.g., PID_BB_INLET_TEMP_C + Stepwise_BB_INLET_TEMP_C. |
| 361 | */ |
| 362 | if (getAccSetPoint()) |
| 363 | { |
| 364 | auto profileName = _maximumSetPointName; |
| 365 | _maximumSetPointName = ""; |
| 366 | |
| 367 | for (auto& p : _thermals) |
| 368 | { |
| 369 | auto controllerID = p->getID(); |
| 370 | auto found = controllerID.find(profileName); |
| 371 | if (found != std::string::npos) |
| 372 | { |
| 373 | if (_maximumSetPointName.empty()) |
| 374 | { |
| 375 | _maximumSetPointName = controllerID; |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | _maximumSetPointName += " + " + controllerID; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /* |
Patrick Venture | 7280e27 | 2019-02-11 10:45:32 -0800 | [diff] [blame] | 386 | * If the maximum RPM setpoint output is below the minimum RPM |
| 387 | * setpoint, set it to the minimum. |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 388 | */ |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 389 | if (minThermalThreshold >= _maximumSetPoint) |
| 390 | { |
| 391 | _maximumSetPoint = minThermalThreshold; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 392 | _maximumSetPointName = "Minimum"; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 393 | } |
| 394 | else if (_maximumSetPointName.compare(_maximumSetPointNamePrev)) |
| 395 | { |
| 396 | std::cerr << "PID Zone " << _zoneId << " max SetPoint " |
| 397 | << _maximumSetPoint << " requested by " |
| 398 | << _maximumSetPointName; |
| 399 | for (const auto& sensor : _failSafeSensors) |
| 400 | { |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 401 | if (sensor.first.find("Fan") == std::string::npos) |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 402 | { |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 403 | std::cerr << " " << sensor.first; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | std::cerr << "\n"; |
| 407 | _maximumSetPointNamePrev.assign(_maximumSetPointName); |
| 408 | } |
Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 409 | if (tuningEnabled) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 410 | { |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 411 | /* |
| 412 | * We received no setpoints from thermal sensors. |
| 413 | * This is a case experienced during tuning where they only specify |
| 414 | * fan sensors and one large fan PID for all the fans. |
| 415 | */ |
| 416 | static constexpr auto setpointpath = "/etc/thermal.d/setpoint"; |
Patrick Venture | df766f2 | 2018-10-13 09:30:58 -0700 | [diff] [blame] | 417 | |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 418 | fileParseRpm(setpointpath, _maximumSetPoint); |
Josh Lehan | 55ccad6 | 2020-09-20 23:57:49 -0700 | [diff] [blame] | 419 | |
| 420 | // Allow per-zone setpoint files to override overall setpoint file |
| 421 | std::ostringstream zoneSuffix; |
| 422 | zoneSuffix << ".zone" << _zoneId; |
| 423 | std::string zoneSetpointPath = setpointpath + zoneSuffix.str(); |
| 424 | |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 425 | fileParseRpm(zoneSetpointPath, _maximumSetPoint); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 426 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 427 | return; |
| 428 | } |
| 429 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 430 | void DbusPidZone::initializeLog(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 431 | { |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 432 | /* Print header for log file: |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 433 | * epoch_ms,setpt,fan1,fan1_raw,fan1_pwm,fan1_pwm_raw,fan2,fan2_raw,fan2_pwm,fan2_pwm_raw,fanN,fanN_raw,fanN_pwm,fanN_pwm_raw,sensor1,sensor1_raw,sensor2,sensor2_raw,sensorN,sensorN_raw,failsafe |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 434 | */ |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 435 | |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 436 | _log << "epoch_ms,setpt,requester"; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 437 | |
Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 438 | for (const auto& f : _fanInputs) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 439 | { |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 440 | _log << "," << f << "," << f << "_raw"; |
| 441 | _log << "," << f << "_pwm," << f << "_pwm_raw"; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 442 | } |
Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 443 | for (const auto& t : _thermalInputs) |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 444 | { |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 445 | _log << "," << t << "," << t << "_raw"; |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 446 | } |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 447 | |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 448 | _log << ",failsafe"; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 449 | _log << std::endl; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 452 | void DbusPidZone::writeLog(const std::string& value) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 453 | { |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 454 | _log << value; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 455 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 456 | |
| 457 | /* |
| 458 | * TODO(venture) This is effectively updating the cache and should check if the |
| 459 | * values they're using to update it are new or old, or whatnot. For instance, |
| 460 | * if we haven't heard from the host in X time we need to detect this failure. |
| 461 | * |
| 462 | * I haven't decided if the Sensor should have a lastUpdated method or whether |
| 463 | * that should be for the ReadInterface or etc... |
| 464 | */ |
| 465 | |
| 466 | /** |
| 467 | * We want the PID loop to run with values cached, so this will get all the |
| 468 | * fan tachs for the loop. |
| 469 | */ |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 470 | void DbusPidZone::updateFanTelemetry(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 471 | { |
| 472 | /* TODO(venture): Should I just make _log point to /dev/null when logging |
| 473 | * is disabled? I think it's a waste to try and log things even if the |
| 474 | * data is just being dropped though. |
| 475 | */ |
Tom Tung | df1f183 | 2022-11-14 19:26:52 +0800 | [diff] [blame] | 476 | const auto now = std::chrono::high_resolution_clock::now(); |
Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 477 | if (loggingEnabled) |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 478 | { |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 479 | _log << std::chrono::duration_cast<std::chrono::milliseconds>( |
| 480 | now.time_since_epoch()) |
| 481 | .count(); |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 482 | _log << "," << _maximumSetPoint; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 483 | _log << "," << _maximumSetPointName; |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 484 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 485 | |
Tom Tung | df1f183 | 2022-11-14 19:26:52 +0800 | [diff] [blame] | 486 | processSensorInputs</* fanSensorLogging */ true>(_fanInputs, now); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 487 | |
Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 488 | if (loggingEnabled) |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 489 | { |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 490 | for (const auto& t : _thermalInputs) |
| 491 | { |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 492 | const auto& v = _cachedValuesByName[t]; |
| 493 | _log << "," << v.scaled << "," << v.unscaled; |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 494 | } |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 495 | } |
Patrick Venture | 5f02ad2 | 2018-04-24 10:18:40 -0700 | [diff] [blame] | 496 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 500 | void DbusPidZone::updateSensors(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 501 | { |
Tom Tung | df1f183 | 2022-11-14 19:26:52 +0800 | [diff] [blame] | 502 | processSensorInputs</* fanSensorLogging */ false>( |
| 503 | _thermalInputs, std::chrono::high_resolution_clock::now()); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 504 | |
| 505 | return; |
| 506 | } |
| 507 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 508 | void DbusPidZone::initializeCache(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 509 | { |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 510 | auto nan = std::numeric_limits<double>::quiet_NaN(); |
| 511 | |
Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 512 | for (const auto& f : _fanInputs) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 513 | { |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 514 | _cachedValuesByName[f] = {nan, nan}; |
| 515 | _cachedFanOutputs[f] = {nan, nan}; |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 516 | |
| 517 | // Start all fans in fail-safe mode. |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 518 | markSensorMissing(f, ""); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 521 | for (const auto& t : _thermalInputs) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 522 | { |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 523 | _cachedValuesByName[t] = {nan, nan}; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 524 | |
| 525 | // Start all sensors in fail-safe mode. |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 526 | markSensorMissing(t, ""); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 530 | void DbusPidZone::dumpCache(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 531 | { |
| 532 | std::cerr << "Cache values now: \n"; |
Patrick Venture | 2a50eda | 2020-08-16 08:26:35 -0700 | [diff] [blame] | 533 | for (const auto& [name, value] : _cachedValuesByName) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 534 | { |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame] | 535 | std::cerr << name << ": " << value.scaled << " " << value.unscaled |
| 536 | << "\n"; |
| 537 | } |
| 538 | |
| 539 | std::cerr << "Fan outputs now: \n"; |
| 540 | for (const auto& [name, value] : _cachedFanOutputs) |
| 541 | { |
| 542 | std::cerr << name << ": " << value.scaled << " " << value.unscaled |
| 543 | << "\n"; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 547 | void DbusPidZone::processFans(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 548 | { |
| 549 | for (auto& p : _fans) |
| 550 | { |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 551 | p->process(); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 552 | } |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 553 | |
| 554 | if (_redundantWrite) |
| 555 | { |
| 556 | // This is only needed once |
| 557 | _redundantWrite = false; |
| 558 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 561 | void DbusPidZone::processThermals(void) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 562 | { |
| 563 | for (auto& p : _thermals) |
| 564 | { |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 565 | p->process(); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 569 | Sensor* DbusPidZone::getSensor(const std::string& name) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 570 | { |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 571 | return _mgr.getSensor(name); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 572 | } |
| 573 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 574 | std::vector<std::string> DbusPidZone::getSensorNames(void) |
| 575 | { |
| 576 | return _thermalInputs; |
| 577 | } |
| 578 | |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 579 | bool DbusPidZone::getRedundantWrite(void) const |
| 580 | { |
| 581 | return _redundantWrite; |
| 582 | } |
| 583 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 584 | bool DbusPidZone::manual(bool value) |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 585 | { |
| 586 | std::cerr << "manual: " << value << std::endl; |
| 587 | setManualMode(value); |
| 588 | return ModeObject::manual(value); |
| 589 | } |
| 590 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 591 | bool DbusPidZone::failSafe() const |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 592 | { |
| 593 | return getFailSafeMode(); |
| 594 | } |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 595 | |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 596 | void DbusPidZone::addPidControlProcess( |
| 597 | const std::string& name, const std::string& type, double setpoint, |
| 598 | sdbusplus::bus_t& bus, const std::string& objPath, bool defer) |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 599 | { |
| 600 | _pidsControlProcess[name] = std::make_unique<ProcessObject>( |
| 601 | bus, objPath.c_str(), |
| 602 | defer ? ProcessObject::action::defer_emit |
| 603 | : ProcessObject::action::emit_object_added); |
| 604 | // Default enable setting = true |
| 605 | _pidsControlProcess[name]->enabled(true); |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 606 | _pidsControlProcess[name]->setpoint(setpoint); |
| 607 | |
| 608 | if (type == "temp") |
| 609 | { |
| 610 | _pidsControlProcess[name]->classType("Temperature"); |
| 611 | } |
| 612 | else if (type == "margin") |
| 613 | { |
| 614 | _pidsControlProcess[name]->classType("Margin"); |
| 615 | } |
| 616 | else if (type == "power") |
| 617 | { |
| 618 | _pidsControlProcess[name]->classType("Power"); |
| 619 | } |
| 620 | else if (type == "powersum") |
| 621 | { |
| 622 | _pidsControlProcess[name]->classType("PowerSum"); |
| 623 | } |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 624 | } |
| 625 | |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 626 | bool DbusPidZone::isPidProcessEnabled(const std::string& name) |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 627 | { |
| 628 | return _pidsControlProcess[name]->enabled(); |
| 629 | } |
| 630 | |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame^] | 631 | void DbusPidZone::addPidFailSafePercent(const std::vector<std::string>& inputs, |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 632 | double percent) |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 633 | { |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 634 | for (const auto& sensorName : inputs) |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 635 | { |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 636 | if (_sensorFailSafePercent.find(sensorName) != |
| 637 | _sensorFailSafePercent.end()) |
| 638 | { |
| 639 | _sensorFailSafePercent[sensorName] = |
| 640 | std::max(_sensorFailSafePercent[sensorName], percent); |
| 641 | if (debugEnabled) |
| 642 | { |
| 643 | std::cerr << "Sensor " << sensorName |
| 644 | << " failsafe percent updated to " |
| 645 | << _sensorFailSafePercent[sensorName] << "\n"; |
| 646 | } |
| 647 | } |
| 648 | else |
| 649 | { |
| 650 | _sensorFailSafePercent[sensorName] = percent; |
| 651 | if (debugEnabled) |
| 652 | { |
| 653 | std::cerr << "Sensor " << sensorName |
| 654 | << " failsafe percent set to " << percent << "\n"; |
| 655 | } |
| 656 | } |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 657 | } |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 658 | } |
| 659 | |
Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame] | 660 | std::string DbusPidZone::leader() const |
| 661 | { |
| 662 | return _maximumSetPointName; |
| 663 | } |
| 664 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 665 | void DbusPidZone::updateThermalPowerDebugInterface( |
| 666 | std::string pidName, std::string leader, double input, double output) |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 667 | { |
| 668 | if (leader.empty()) |
| 669 | { |
| 670 | _pidsControlProcess[pidName]->output(output); |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | _pidsControlProcess[pidName]->leader(leader); |
| 675 | _pidsControlProcess[pidName]->input(input); |
| 676 | } |
| 677 | } |
| 678 | |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 679 | bool DbusPidZone::getAccSetPoint(void) const |
| 680 | { |
| 681 | return _accumulateSetPoint; |
| 682 | } |
| 683 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 684 | } // namespace pid_control |