Skip to content

Commit

Permalink
Moved PID compute to non-blocking delay
Browse files Browse the repository at this point in the history
  • Loading branch information
EnUfor committed Dec 2, 2020
1 parent c33c897 commit f685735
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
20 changes: 20 additions & 0 deletions Classes/ESP0.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ESP0

unsigned long MQTT_publish_timer;

unsigned long PID_timer;

/*
* Connects ESP8266 to Wi-Fi
*/
Expand Down Expand Up @@ -82,6 +84,7 @@ class ESP0

MQTT_reconnect_timer = millis();
MQTT_publish_timer = millis();
PID_timer = millis();
}
/*
* Loop Routine
Expand Down Expand Up @@ -114,6 +117,23 @@ class ESP0
client.publish(PUB_OUTLET_FAN, String(rack.outlet.fanSpeed).c_str());
}
}

if (millis() - PID_timer >= 500) {
PID_timer = millis();

rack.readSensors();
// rack.printSensors();

if (!rack.manualFans) {
currentTemp = rack.outlet.temp;
setTemp = rack.inlet.temp + 5.0;
pid.Compute();
rack.setFans((int)pidSpeed);
}

Serial.println((String)"pidSpeed: " + pidSpeed);
Serial.println((String)"currentTemp: " + currentTemp);
}

handleSerial();
client.loop();
Expand Down
22 changes: 0 additions & 22 deletions app.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "config.h" // Must be defined after PubSubClient
#include "Classes/ESP0.h" // Must be defined after config

unsigned long printDelay;

ESP0 esp0;

void callback(char* topic, uint8_t* payload, unsigned int length) {
Expand Down Expand Up @@ -45,28 +43,8 @@ void setup() {

esp0.client.setCallback(callback);
esp0.setup();

printDelay = millis();
}

void loop() {
if (millis() - printDelay >= 500) {
printDelay = millis();

rack.readSensors();
// rack.printSensors();

if (!rack.manualFans) {
esp0.currentTemp = rack.outlet.temp;
esp0.setTemp = rack.inlet.temp + 5.0;
esp0.pid.Compute();
rack.setFans((int)esp0.pidSpeed);
}

Serial.println((String)"pidSpeed: " + esp0.pidSpeed);
Serial.println((String)"currentTemp: " + esp0.currentTemp);

}

esp0.loop();
}

0 comments on commit f685735

Please sign in to comment.