第二次调节,好像有些问题

check
Zeng wei (曾威) 2 years ago
parent 7cd839ffe0
commit 203b1e60f6

@ -22,6 +22,10 @@ int max_speed_count = 4800;
*/ */
void PID_Init() void PID_Init()
{ {
if (abs(pid.out_tem) < 1e-5 && abs(pid.out_humidity) < 1e-5) {
return;
}
// // if flash have not a vaild value, just set a default value // // if flash have not a vaild value, just set a default value
// if (pid.Kp < 1e-7) { pid.Kp = 9.6; } // if (pid.Kp < 1e-7) { pid.Kp = 9.6; }
// if (pid.Ki < 1e-7) { pid.Ki = 0.01; } // if (pid.Ki < 1e-7) { pid.Ki = 0.01; }
@ -61,6 +65,11 @@ void PID_Init()
pid.hd_l = 0; pid.hd_l = 0;
pid.h_base_l = 53; pid.h_base_l = 53;
pid.hp = 7.2;
pid.hi = 0.04;
pid.hd = 0;
pid.h_base = 53;
pid.cp = 4; pid.cp = 4;
pid.ci = 0.01; pid.ci = 0.01;
pid.cd = 0; pid.cd = 0;
@ -174,25 +183,25 @@ void PID_Calc() // pid calc
float delta_t = pid.set_tem - pid.now_tem; float delta_t = pid.set_tem - pid.now_tem;
float hp = pid.hp_h; pid.hp = pid.hp_h;
float hi = pid.hi_h; pid.hi = pid.hi_h;
float hd = pid.hd_h; pid.hd = pid.hd_h;
int h_base = pid.h_base_h; pid.h_base = pid.h_base_h;
// if now temp is close to set temp, the heater will be less power // if now temp is close to set temp, the heater will be less power
if (pid.set_tem - pid.now_tem < 3) { if (pid.set_tem - pid.now_tem < 3) {
hp = pid.hp_h * 0.6; pid.hp = pid.hp_h * 0.6;
} }
if (pid.set_tem - pid.now_tem < 1) { if (pid.set_tem - pid.now_tem < 1) {
hp = pid.hp_h * 0.3; pid.hp = pid.hp_h * 0.3;
} }
// l mode // l mode
if (pid.set_tem <= pid.max_compressor_tem) { if (pid.set_tem <= pid.max_compressor_tem) {
hp = pid.hp_l; pid.hp = pid.hp_l;
hi = pid.hi_l; pid.hi = pid.hi_l;
hd = pid.hd_l; pid.hd = pid.hd_l;
h_base = pid.h_base_l; pid.h_base = pid.h_base_l;
} }
pid.Ek = pid.set_tem - pid.now_tem; pid.Ek = pid.set_tem - pid.now_tem;
@ -210,15 +219,15 @@ void PID_Calc() // pid calc
// SEk limit, updated func, remain a little heater power when the compressor is running in full state // SEk limit, updated func, remain a little heater power when the compressor is running in full state
if (pid.SEk < - (h_base / 2) / hi) { if (pid.SEk < - (pid.h_base / 2) / pid.hi) {
pid.SEk = - (h_base / 2) / hi; pid.SEk = - (pid.h_base / 2) / pid.hi;
} }
if (pid.c_speed == max_speed_count) { if (pid.c_speed == max_speed_count) {
pid.SEk = 0; pid.SEk = 0;
} }
float Error_calc = pid.SEk; float Error_calc = pid.SEk;
if (Error_calc < - (h_base + hp * delta_t) / hi) { if (Error_calc < - (pid.h_base + pid.hp * delta_t) / pid.hi) {
Error_calc = - (h_base + hp * delta_t) / hi; Error_calc = - (pid.h_base + pid.hp * delta_t) / pid.hi;
} }
if (pid.c_speed == max_speed_count) { if (pid.c_speed == max_speed_count) {
Error_calc = 0; Error_calc = 0;
@ -261,7 +270,7 @@ void PID_Calc() // pid calc
} else { } else {
// if outer temp is got, we calc pid by outer temp // if outer temp is got, we calc pid by outer temp
if (abs(pid.out_tem) > 1e-5) { if (abs(pid.out_tem) > 1e-5) {
pid.cp = (pid.out_tem - pid.set_tem) * 0.26 + 0.3; pid.cp = (pid.out_tem - pid.set_tem) * 0.28;
} }
// use nagetive error and error diff when calc compressor power // use nagetive error and error diff when calc compressor power
int p_c = calc_cp(delta_t, - Error_calc, - DelEk, pid.c_base, pid.cp, pid.ci, pid.cd); int p_c = calc_cp(delta_t, - Error_calc, - DelEk, pid.c_base, pid.cp, pid.ci, pid.cd);
@ -269,7 +278,7 @@ void PID_Calc() // pid calc
} }
// heater percent // heater percent
pid.h_percent = calc_hp(delta_t, Error_calc, DelEk, h_base, hp, hi, hd); pid.h_percent = calc_hp(delta_t, Error_calc, DelEk, pid.h_base, pid.hp, pid.hi, pid.hd);
// close heater when compressor is running in full state // close heater when compressor is running in full state
if (pid.c_speed == max_speed_count) { if (pid.c_speed == max_speed_count) {
pid.h_percent = 0; pid.h_percent = 0;

@ -27,6 +27,12 @@ typedef struct Pid
float hi_l; float hi_l;
float hd_l; float hd_l;
int h_base_l; // base power percent in l mode int h_base_l; // base power percent in l mode
float hp;
float hi;
float hd;
int h_base;
int h_percent; int h_percent;

@ -460,23 +460,30 @@ void RS485_1_Upload_Params(void)
sendbuf[25] = 0; // ALARM state sendbuf[25] = 0; // ALARM state
sendbuf[26] = ALARM; // ALARM state sendbuf[26] = ALARM; // ALARM state
if (pid.set_tem > pid.max_compressor_tem) { // if (pid.set_tem > pid.max_compressor_tem) {
// h mode // // h mode
sendbuf[27] = (int)(pid.hp_h * 1000) / 256; // Kp 110 // sendbuf[27] = (int)(pid.hp_h * 1000) / 256; // Kp 110
sendbuf[28] = (int)(pid.hp_h * 1000) % 256; // Kp 110 // sendbuf[28] = (int)(pid.hp_h * 1000) % 256; // Kp 110
sendbuf[29] = ((int)(pid.hi_h * 100000)) / 256; // Ti 0.001 // sendbuf[29] = ((int)(pid.hi_h * 100000)) / 256; // Ti 0.001
sendbuf[30] = ((int)(pid.hi_h * 100000)) % 256; // Ti 0.001 // sendbuf[30] = ((int)(pid.hi_h * 100000)) % 256; // Ti 0.001
sendbuf[31] = (int)(pid.hd_h * 1000) / 256; // Td 340 // sendbuf[31] = (int)(pid.hd_h * 1000) / 256; // Td 340
sendbuf[32] = (int)(pid.hd_h * 1000) % 256; // Td 340 // sendbuf[32] = (int)(pid.hd_h * 1000) % 256; // Td 340
} else { // } else {
// l mode // // l mode
sendbuf[27] = (int)(pid.hp_l * 1000) / 256; // Kp 110 // sendbuf[27] = (int)(pid.hp_l * 1000) / 256; // Kp 110
sendbuf[28] = (int)(pid.hp_l * 1000) % 256; // Kp 110 // sendbuf[28] = (int)(pid.hp_l * 1000) % 256; // Kp 110
sendbuf[29] = ((int)(pid.hi_l * 100000)) / 256; // Ti 0.001 // sendbuf[29] = ((int)(pid.hi_l * 100000)) / 256; // Ti 0.001
sendbuf[30] = ((int)(pid.hi_l * 100000)) % 256; // Ti 0.001 // sendbuf[30] = ((int)(pid.hi_l * 100000)) % 256; // Ti 0.001
sendbuf[31] = (int)(pid.hd_l * 1000) / 256; // Td 340 // sendbuf[31] = (int)(pid.hd_l * 1000) / 256; // Td 340
sendbuf[32] = (int)(pid.hd_l * 1000) % 256; // Td 340 // sendbuf[32] = (int)(pid.hd_l * 1000) % 256; // Td 340
} // }
sendbuf[27] = (int)(pid.hp * 1000) / 256;
sendbuf[28] = (int)(pid.hp * 1000) % 256;
sendbuf[29] = ((int)(pid.hi * 100000)) / 256;
sendbuf[30] = ((int)(pid.hi * 100000)) % 256;
sendbuf[31] = (int)(pid.hd * 1000) / 256;
sendbuf[32] = (int)(pid.hd * 1000) % 256;
sendbuf[33] = pid.h_percent / 256; // h_percent sendbuf[33] = pid.h_percent / 256; // h_percent
sendbuf[34] = pid.h_percent % 256; // h_percent sendbuf[34] = pid.h_percent % 256; // h_percent

@ -77,8 +77,8 @@
<flags>2</flags> <flags>2</flags>
<showCmd>3</showCmd> <showCmd>3</showCmd>
<MinPosition> <MinPosition>
<xPos>-32000</xPos> <xPos>-1</xPos>
<yPos>-32000</yPos> <yPos>-1</yPos>
</MinPosition> </MinPosition>
<MaxPosition> <MaxPosition>
<xPos>-1</xPos> <xPos>-1</xPos>
@ -1758,9 +1758,9 @@
</Doc> </Doc>
<Doc> <Doc>
<Name>../HARDWARE/PID.c</Name> <Name>../HARDWARE/PID.c</Name>
<ColumnNumber>19</ColumnNumber> <ColumnNumber>38</ColumnNumber>
<TopLine>28</TopLine> <TopLine>20</TopLine>
<CurrentLine>53</CurrentLine> <CurrentLine>46</CurrentLine>
<Folding>1</Folding> <Folding>1</Folding>
<ContractedFolders></ContractedFolders> <ContractedFolders></ContractedFolders>
<PaneID>0</PaneID> <PaneID>0</PaneID>

@ -241,8 +241,10 @@ int hot = 0;
void HotTestRequestTask(void *pvParameters) { void HotTestRequestTask(void *pvParameters) {
while (1) { while (1) {
if (!(T == 0 && H == 0)) { if (!(T == 0 && H == 0)) {
PID_Calc(); if (!(abs(pid.out_tem) < 1e-5 && abs(pid.out_humidity) < 1e-5)) {
RS485_1_Upload_Params(); PID_Calc();
RS485_1_Upload_Params();
}
} }
vTaskDelay(5000); vTaskDelay(5000);
} }

Loading…
Cancel
Save