|
|
|
|
@ -123,8 +123,11 @@ int calc_compressor_speed(int percent, int v_min, int v_max) {
|
|
|
|
|
|
|
|
|
|
void PID_Calc() // pid calc
|
|
|
|
|
{
|
|
|
|
|
float Kp = 19.2;
|
|
|
|
|
float Ki = 0.08;
|
|
|
|
|
int min_speed_count = 1500;
|
|
|
|
|
int max_speed_count = 4500;
|
|
|
|
|
float pid_hp = 19.2;
|
|
|
|
|
float pid_cp = 14.4;
|
|
|
|
|
float pid_hi = 0.08;
|
|
|
|
|
int p_hb = 52;
|
|
|
|
|
float DelEk; // The difference between the last two deviations
|
|
|
|
|
// float td;
|
|
|
|
|
@ -135,22 +138,30 @@ void PID_Calc() // pid calc
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
float delta_t = pid.set_tem - pid.now_tem;
|
|
|
|
|
|
|
|
|
|
int p_c = calc_cp(pid.set_tem, pid.now_tem, 32, pid_cp);
|
|
|
|
|
int speed_count = calc_compressor_speed(p_c, min_speed_count, max_speed_count);
|
|
|
|
|
|
|
|
|
|
pid.Ek = pid.set_tem - pid.now_tem;
|
|
|
|
|
pid.Pout = pid.Kp * pid.Ek; // Proportional output
|
|
|
|
|
|
|
|
|
|
pid.SEk += pid.Ek; // Total historical deviation
|
|
|
|
|
|
|
|
|
|
// SEk limit, updated func
|
|
|
|
|
float delta_t = pid.set_tem - pid.now_tem;
|
|
|
|
|
float pid_hp = Kp;
|
|
|
|
|
float pid_hi = Ki;
|
|
|
|
|
if (pid.SEk < - p_hb / pid_hi) {
|
|
|
|
|
pid.SEk = - p_hb / pid_hi;
|
|
|
|
|
}
|
|
|
|
|
if (speed_count == max_speed_count) {
|
|
|
|
|
pid.SEk = 0;
|
|
|
|
|
}
|
|
|
|
|
float Error_calc = pid.SEk;
|
|
|
|
|
if (Error_calc < - (p_hb + pid_hp * delta_t) / pid_hi) {
|
|
|
|
|
Error_calc = - (p_hb + pid_hp * delta_t) / pid_hi;
|
|
|
|
|
}
|
|
|
|
|
if (speed_count == max_speed_count) {
|
|
|
|
|
Error_calc = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DelEk = pid.Ek - pid.Ek_1; // The difference between the last two deviations
|
|
|
|
|
@ -188,11 +199,12 @@ void PID_Calc() // pid calc
|
|
|
|
|
|
|
|
|
|
// heater percent
|
|
|
|
|
int heater_percent = calc_hp(pid.set_tem, pid.now_tem, Error_calc, p_hb, pid_hp, pid_hi);
|
|
|
|
|
// close heater when compressor is running in full state
|
|
|
|
|
if (speed_count == max_speed_count) {
|
|
|
|
|
heater_percent = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int p_c = calc_cp(pid.set_tem, pid.now_tem, 32, Kp);
|
|
|
|
|
int speed_count = calc_compressor_speed(p_c, 1500, 4500);
|
|
|
|
|
|
|
|
|
|
// TODO:: temply, set Ki to speed count, Kd to heater_percent, use for data upload
|
|
|
|
|
pid.Ki = speed_count;
|
|
|
|
|
pid.Kd = heater_percent;
|
|
|
|
|
|