Initial Commit
This commit is contained in:
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Reflow Plate
|
||||||
|
Custom Reflow Plate inspired by [UnexpectedMaker
|
||||||
|
ReflowMaster](https://github.com/UnexpectedMaker/ReflowMaster)
|
||||||
|
[Pro](https://reflowmasterpro.com)
|
||||||
|
using [PID](https://en.wikipedia.org/wiki/Proportional%E2%80%93integral%E2%80%93derivative_controller)
|
||||||
|
to control a simple grill.
|
||||||
38
src/pid.cpp
Normal file
38
src/pid.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const float k_p = 1.0;
|
||||||
|
const float k_i = 3.0;
|
||||||
|
const float k_d = 0.2;
|
||||||
|
const float tick_millis = 30'000;
|
||||||
|
|
||||||
|
float target;
|
||||||
|
float measured;
|
||||||
|
float error;
|
||||||
|
float error_last;
|
||||||
|
float output;
|
||||||
|
float i;
|
||||||
|
float d;
|
||||||
|
|
||||||
|
unsigned long time_last_millis;
|
||||||
|
unsigned long time_cur_millis;
|
||||||
|
unsigned long time_delta_millis;
|
||||||
|
|
||||||
|
float pid(float error, float error_last, unsigned long delta){
|
||||||
|
float p = k_p * error;
|
||||||
|
float i = i + (k_i * delta * error);
|
||||||
|
float d = k_d * (error - error_last) / delta;
|
||||||
|
return p+i+d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
time_last_millis = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
time_cur_millis = millis();
|
||||||
|
time_delta_millis = time_cur_millis - time_last_millis;
|
||||||
|
if (time_delta_millis > tick_millis) {
|
||||||
|
time_last_millis = time_cur_millis;
|
||||||
|
error_last = error;
|
||||||
|
error = target - measured;
|
||||||
|
output = pid(error, error_last, time_delta_millis);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user