Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 3 | #include "ec/pid.hpp" |
| 4 | #include "fan.hpp" |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 5 | #include "pidcontroller.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 6 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 11 | namespace pid_control |
| 12 | { |
| 13 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 14 | /* |
| 15 | * A FanController is a PID controller that reads a number of fans and given |
| 16 | * the output then tries to set them to the goal values set by the thermal |
| 17 | * controllers. |
| 18 | */ |
| 19 | class FanController : public PIDController |
| 20 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 21 | public: |
| 22 | static std::unique_ptr<PIDController> |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 23 | createFanPid(ZoneInterface* owner, const std::string& id, |
Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 24 | const std::vector<std::string>& inputs, |
Patrick Venture | f77d5a5 | 2018-10-23 09:32:52 -0700 | [diff] [blame] | 25 | const ec::pidinfo& initial); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 26 | |
Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 27 | FanController(const std::string& id, const std::vector<std::string>& inputs, |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 28 | ZoneInterface* owner) : |
| 29 | PIDController(id, owner), |
| 30 | _inputs(inputs), _direction(FanSpeedDirection::NEUTRAL) |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 31 | {} |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 32 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 33 | double inputProc(void) override; |
| 34 | double setptProc(void) override; |
| 35 | void outputProc(double value) override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 36 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 37 | FanSpeedDirection getFanDirection(void) const |
| 38 | { |
| 39 | return _direction; |
| 40 | } |
Patrick Venture | 566a151 | 2018-06-12 14:51:07 -0700 | [diff] [blame] | 41 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 42 | void setFanDirection(FanSpeedDirection direction) |
| 43 | { |
| 44 | _direction = direction; |
| 45 | }; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 46 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 47 | private: |
| 48 | std::vector<std::string> _inputs; |
| 49 | FanSpeedDirection _direction; |
Bonnie Lo | c51ba91 | 2022-10-12 14:07:22 +0800 | [diff] [blame] | 50 | bool failsafePrint = true; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 51 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 52 | |
| 53 | } // namespace pid_control |