Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 3 | #include "ec/pid.hpp" |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 4 | #include "pidcontroller.hpp" |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 5 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 6 | #include <memory> |
| 7 | #include <string> |
| 8 | #include <vector> |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 9 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 10 | namespace pid_control |
| 11 | { |
| 12 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 13 | /* |
| 14 | * A ThermalController is a PID controller that reads a number of sensors and |
Patrick Venture | 7280e27 | 2019-02-11 10:45:32 -0800 | [diff] [blame] | 15 | * provides the setpoints for the fans. |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 16 | */ |
James Feist | 734f953 | 2018-11-15 12:13:18 -0800 | [diff] [blame] | 17 | |
| 18 | enum class ThermalType |
| 19 | { |
| 20 | margin, |
| 21 | absolute |
| 22 | }; |
| 23 | |
Patrick Venture | e94bdc4 | 2018-11-15 18:41:21 -0800 | [diff] [blame] | 24 | /** |
| 25 | * Get the ThermalType for a given string. |
| 26 | * |
| 27 | * @param[in] typeString - a string representation of a type. |
| 28 | * @return the ThermalType representation. |
| 29 | */ |
| 30 | ThermalType getThermalType(const std::string& typeString); |
| 31 | |
| 32 | /** |
| 33 | * Is the type specified a thermal type? |
| 34 | * |
| 35 | * @param[in] typeString - a string representation of a PID type. |
| 36 | * @return true if it's a thermal PID type. |
| 37 | */ |
| 38 | bool isThermalType(const std::string& typeString); |
| 39 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 40 | class ThermalController : public PIDController |
| 41 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 42 | public: |
| 43 | static std::unique_ptr<PIDController> |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 44 | createThermalPid(ZoneInterface* owner, const std::string& id, |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 45 | const std::vector<std::string>& inputs, |
James Feist | 734f953 | 2018-11-15 12:13:18 -0800 | [diff] [blame] | 46 | double setpoint, const ec::pidinfo& initial, |
| 47 | const ThermalType& type); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 48 | |
Patrick Venture | 4a2dc4d | 2018-10-23 09:02:55 -0700 | [diff] [blame] | 49 | ThermalController(const std::string& id, |
| 50 | const std::vector<std::string>& inputs, |
James Feist | 734f953 | 2018-11-15 12:13:18 -0800 | [diff] [blame] | 51 | const ThermalType& type, ZoneInterface* owner) : |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 52 | PIDController(id, owner), |
James Feist | 734f953 | 2018-11-15 12:13:18 -0800 | [diff] [blame] | 53 | _inputs(inputs), type(type) |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 54 | {} |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 55 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 56 | double inputProc(void) override; |
| 57 | double setptProc(void) override; |
| 58 | void outputProc(double value) override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 59 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 60 | private: |
| 61 | std::vector<std::string> _inputs; |
James Feist | 734f953 | 2018-11-15 12:13:18 -0800 | [diff] [blame] | 62 | ThermalType type; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 63 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 64 | |
| 65 | } // namespace pid_control |