Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
SingleHumidistat.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2
3#include "SingleHumidistat.h"
4#include "imath.h"
5
6SingleHumidistat::SingleHumidistat(HumiditySensor *hs, const ConfigStore *cs, etl::array<uint8_t, 2> pins_solenoid,
7 uint8_t pwmRes)
8 : Humidistat(cs, hs, cs->HC_Kp, cs->HC_Ki, cs->HC_Kd, cs->HC_Kf, cs->dt, cs->S_lowValue, 1),
9 pins_solenoid{pins_solenoid[0], pins_solenoid[1]}, pwmRes(pwmRes) {}
10
12 runCycle();
13
14 // Actuate solenoids (convert normalised double CV to integer PWM value)
15 analogWrite(pins_solenoid[0], static_cast<int>(cv * ipow(2, pwmRes)));
16 analogWrite(pins_solenoid[1], static_cast<int>((pid.cvMin + 1 - cv) * ipow(2, pwmRes)));
17}
18
const ConfigStore & cs
Definition Controller.h:14
double cv
Control variable.
Definition Controller.h:23
Base class for a humidistat. Holds a reference to a HumiditySensor instance.
Definition Humidistat.h:10
void runCycle()
Run a cycle of the controller. Reads a sample from the humidity controller and runs PID.
double cvMin
Definition PID.h:34
void setGains(double Kp, double Ki, double Kd, double Kf, uint16_t dt)
Set the gains and timestep.
Definition PID.cpp:59
SingleHumidistat(HumiditySensor *hs, const ConfigStore *cs, etl::array< uint8_t, 2 > pins_solenoid, uint8_t pwmRes)
Constructor.
const uint8_t pwmRes
const uint8_t pins_solenoid[2]
constexpr T ipow(T base, unsigned int pow)
Constexpr function for computing integer power.
Definition imath.h:10
const uint8_t pwmRes
Definition main.cpp:44
Config store containing variables, which can be stored in EEPROM.
Definition EEPROMConfig.h:7
double HC_Kp
Humidity controller PID parameters.
double S_lowValue
Minimum solenoid duty cycle (deadband)
uint16_t dt
Global interval for PID/logger (based on polling rate of sensor, in millis)