GyverPID
This commit is contained in:
parent
673fbc03d8
commit
8f9584a818
@ -3,7 +3,6 @@
|
|||||||
#define TempSensorDallas
|
#define TempSensorDallas
|
||||||
|
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <PID_v1.h>
|
|
||||||
#include <GyverOLED.h>
|
#include <GyverOLED.h>
|
||||||
#include "GyverEncoder.h"
|
#include "GyverEncoder.h"
|
||||||
|
|
||||||
@ -80,9 +79,12 @@ bool isInTransition = false;
|
|||||||
bool inSelectionMode = true;
|
bool inSelectionMode = true;
|
||||||
|
|
||||||
// PID Control variables
|
// PID Control variables
|
||||||
|
// double Kp = 0.5, Ki = 1, Kd = 0.05;
|
||||||
|
// PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
|
||||||
|
|
||||||
|
#include "GyverPID.h"
|
||||||
double Setpoint, Input, Output;
|
double Setpoint, Input, Output;
|
||||||
double Kp = 0.5, Ki = 1, Kd = 0.05;
|
GyverPID regulator(1, 0.5, 0, 1000);
|
||||||
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
|
|
||||||
|
|
||||||
// Timing variables
|
// Timing variables
|
||||||
long phaseStartTime;
|
long phaseStartTime;
|
||||||
@ -118,9 +120,9 @@ void setup() {
|
|||||||
oled.init(); // Initialize the OLED
|
oled.init(); // Initialize the OLED
|
||||||
oled.clear(); // Clear the display
|
oled.clear(); // Clear the display
|
||||||
readEEPROM();
|
readEEPROM();
|
||||||
myPID.SetMode(AUTOMATIC);
|
regulator.setDirection(NORMAL); // направление регулирования (NORMAL/REVERSE). ПО УМОЛЧАНИЮ СТОИТ NORMAL
|
||||||
myPID.SetOutputLimits(0, 100);
|
regulator.setLimits(0, 100); // пределы (ставим для 8 битного ШИМ). ПО УМОЛЧАНИЮ СТОЯТ 0 И 255
|
||||||
// myPID.SetSampleTime(1000);
|
regulator.setpoint = 0;
|
||||||
|
|
||||||
#ifdef TempSensorDallas
|
#ifdef TempSensorDallas
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
@ -296,7 +298,10 @@ void handleExecution() {
|
|||||||
if (isnan(Input)) {
|
if (isnan(Input)) {
|
||||||
Input = 0;
|
Input = 0;
|
||||||
}
|
}
|
||||||
myPID.Compute();
|
regulator.input = (float)Input;
|
||||||
|
regulator.setpoint = Setpoint;
|
||||||
|
regulator.getResult();
|
||||||
|
Output = regulator.output;
|
||||||
|
|
||||||
if (isComplete && currentPhase >= activeProfile.numPhases && !finishTime) {
|
if (isComplete && currentPhase >= activeProfile.numPhases && !finishTime) {
|
||||||
finishTime = currentTime;
|
finishTime = currentTime;
|
||||||
@ -311,8 +316,7 @@ void startExecution() {
|
|||||||
inSelectionMode = false; // Switch to execution mode
|
inSelectionMode = false; // Switch to execution mode
|
||||||
phaseStartTime = totalStartTime = millis(); // Start the timer
|
phaseStartTime = totalStartTime = millis(); // Start the timer
|
||||||
totalElapsedTime = 0;
|
totalElapsedTime = 0;
|
||||||
myPID.SetMode(AUTOMATIC);
|
regulator.setpoint = 0;
|
||||||
myPID.SetOutputLimits(0, 100); // SSR is either ON or OFF
|
|
||||||
// digitalWrite(ssrPin, HIGH); // Start with heater on
|
// digitalWrite(ssrPin, HIGH); // Start with heater on
|
||||||
ssrLastSwitchTime = millis();
|
ssrLastSwitchTime = millis();
|
||||||
calculateTotalTime();
|
calculateTotalTime();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user