pi测试,9.6,0.01

pid
Zeng wei (曾威) 2 years ago
parent 784b535bb7
commit 2cd372ef83

@ -20,8 +20,8 @@ void PID_Init()
{ {
// pid.set_tem=tem;// user set temperature // pid.set_tem=tem;// user set temperature
// 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 = 40; } if (pid.Kp < 1e-7) { pid.Kp = 9.6; }
if (pid.Ki < 1e-7) { pid.Ki = 0.001; } if (pid.Ki < 1e-7) { pid.Ki = 0.01; }
if (pid.Kd < 1e-7) { pid.Kd = 340; } if (pid.Kd < 1e-7) { pid.Kd = 340; }
if (pid.tem_threshold < 0.0001) { pid.tem_threshold = 0.2; } if (pid.tem_threshold < 0.0001) { pid.tem_threshold = 0.2; }
@ -61,7 +61,12 @@ void set_compressor_power(int speed) {
*/ */
void set_heater_power(int percent) { void set_heater_power(int percent) {
u8 data[8] = { 0x10, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 }; u8 data[8] = { 0x10, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 };
if (percent > 100) {
percent = 100;
}
if (percent < 0) {
percent = 0;
}
data[4] = percent / 256; data[4] = percent / 256;
data[5] = percent % 256; data[5] = percent % 256;
@ -74,23 +79,35 @@ void set_heater_power(int percent) {
/** /**
* heater power calc * heater power calc
*/ */
int calc_p(float t_t, float t_c) { int calc_p(float t_t, float t_c, float error, int p_b, float pid_p, float pid_i) {
int p_b = 52; int p = p_b + pid_p * (t_t - t_c) + pid_i * error;
if (t_t - t_c > 5) { if (p > 100) {
return 100; return 100;
} }
if (t_t - t_c < 5 && t_t > t_c) { if (p < 0) {
return p_b + (t_t - t_c) * (100 - p_b) / 5; return 0;
}
if (t_t <= t_c) {
return p_b;
} }
return 0; return p;
// int p_b = 52;
// if (t_t - t_c > 5) {
// return 100;
// }
// if (t_t - t_c < 5 && t_t > t_c) {
// return p_b + (t_t - t_c) * (100 - p_b) / 5;
// }
// if (t_t <= t_c) {
// return p_b;
// }
// return 0;
} }
void PID_Calc() // pid calc void PID_Calc() // pid calc
{ {
pid.set_tem = 37;
pid.Kp = 9.6;
pid.Ki = 0.01;
int p_base = 52;
float DelEk; // The difference between the last two deviations float DelEk; // The difference between the last two deviations
// float td; // float td;
float out; float out;
@ -107,7 +124,8 @@ void PID_Calc() // pid calc
// { // {
// pid.Ek = pid.now_tem - pid.set_tem; // pid.Ek = pid.now_tem - pid.set_tem;
// } // }
pid.Ek = pid.now_tem - pid.set_tem; // pid.Ek = pid.now_tem - pid.set_tem;
pid.Ek = pid.set_tem - pid.now_tem;
pid.Pout = pid.Kp * pid.Ek; // Proportional output pid.Pout = pid.Kp * pid.Ek; // Proportional output
pid.SEk += pid.Ek; // Total historical deviation pid.SEk += pid.Ek; // Total historical deviation
@ -146,7 +164,7 @@ void PID_Calc() // pid calc
pid.C1ms = 0; pid.C1ms = 0;
// heater percent // heater percent
int heater_percent = calc_p(pid.set_tem, pid.now_tem); int heater_percent = calc_p(pid.set_tem, pid.now_tem, pid.SEk, p_base, pid.Kp, pid.Ki);
// TODO:: temply, set Kd to heater_percent, use for data upload // TODO:: temply, set Kd to heater_percent, use for data upload
pid.Kd = heater_percent; pid.Kd = heater_percent;

@ -455,12 +455,20 @@ void RS485_1_Send_Data_2(void)
sendbuf[21] = humidity_flag; // humidity state sendbuf[21] = humidity_flag; // humidity state
sendbuf[22] = ALARM; // ALARM state sendbuf[22] = ALARM; // ALARM state
sendbuf[23] = (int)pid.Kp / 256; // Kp 110 // sendbuf[23] = (int)pid.Kp / 256; // Kp 110
sendbuf[24] = (int)pid.Kp % 256; // Kp 110 // sendbuf[24] = (int)pid.Kp % 256; // Kp 110
sendbuf[25] = ((int)(pid.Ki * 100000)) / 256; // Ti 0.001 // sendbuf[25] = ((int)(pid.Ki * 100000)) / 256; // Ti 0.001
sendbuf[26] = ((int)(pid.Ki * 100000)) % 256; // Ti 0.001 // sendbuf[26] = ((int)(pid.Ki * 100000)) % 256; // Ti 0.001
sendbuf[27] = (int)pid.Kd / 256; // Td 340 // sendbuf[27] = (int)pid.Kd / 256; // Td 340
sendbuf[28] = (int)pid.Kd % 256; // Td 340 // sendbuf[28] = (int)pid.Kd % 256; // Td 340
// TODO::temp
sendbuf[23] = (int)pid.Ek / 256; // Ek
sendbuf[24] = (int)pid.Ek % 256;
sendbuf[25] = (int)pid.SEk / 256; // SEk
sendbuf[26] = (int)pid.SEk % 256;
sendbuf[27] = (int)pid.Kd / 256; // heater percent
sendbuf[28] = (int)pid.Kd % 256;
// num = (((pid.OUT * 350) / pid.pwmcycle) - 1); // num = (((pid.OUT * 350) / pid.pwmcycle) - 1);

File diff suppressed because it is too large Load Diff

@ -1224,7 +1224,7 @@
<Window> <Window>
<RegID>50001</RegID> <RegID>50001</RegID>
<PaneID>50001</PaneID> <PaneID>50001</PaneID>
<IsVisible>0</IsVisible> <IsVisible>1</IsVisible>
<IsFloating>0</IsFloating> <IsFloating>0</IsFloating>
<IsTabbed>0</IsTabbed> <IsTabbed>0</IsTabbed>
<IsActivated>0</IsActivated> <IsActivated>0</IsActivated>
@ -1234,11 +1234,11 @@
<RecentRowIndex>0</RecentRowIndex> <RecentRowIndex>0</RecentRowIndex>
<RectRecentDocked> <RectRecentDocked>
<Len>16</Len> <Len>16</Len>
<Data>A3040000660000008D0500000C020000</Data> <Data>A10400007D0000008D05000098000000</Data>
</RectRecentDocked> </RectRecentDocked>
<RectRecentFloat> <RectRecentFloat>
<Len>16</Len> <Len>16</Len>
<Data>8A000000A10000007A0100006A010000</Data> <Data>0A0000000A0000006E0000006E000000</Data>
</RectRecentFloat> </RectRecentFloat>
</Window> </Window>
<Window> <Window>
@ -1722,7 +1722,7 @@
<Name>Debug</Name> <Name>Debug</Name>
<Buttons> <Buttons>
<Len>2373</Len> <Len>2373</Len>
<Data>00200000000000001900FFFF01001100434D4643546F6F6C426172427574746F6ECC880000000000002500000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018017800000000000002600000000000000000000000000000000010000000100000001801D800000000000002700000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001801A800000000000002800000000000000000000000000000000010000000100000001801B80000000000000290000000000000000000000000000000001000000010000000180E57F0000000000002A00000000000000000000000000000000010000000100000001801C800000000000002B00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018000890000000000002C00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180E48B0000000000002D0000000000000000000000000000000001000000010000000180F07F0000000000002E0000000000000000000000000000000001000000010000000180E8880000000000003700000000000000000000000000000000010000000100000001803B010000000000002F0000000000000000000000000000000001000000010000000180BB8A00000000000030000000000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E0E01000000000000310000000D57617463682057696E646F7773000000000000000000000000010000000100000000000000000000000100000003001380D88B00000000000031000000085761746368202631000000000000000000000000010000000100000000000000000000000100000000001380D98B00000000000031000000085761746368202632000000000000000000000000010000000100000000000000000000000100000000001380CE01000000000000FFFFFFFF0C576174636820416E63686F720000000000000000010000000000000001000000000000000000000001000000000013800F01000000000000320000000E4D656D6F72792057696E646F7773000000000000000000000000010000000100000000000000000000000100000004001380D28B00000000000032000000094D656D6F7279202631000000000000000000000000010000000100000000000000000000000100000000001380D38B00000000000032000000094D656D6F7279202632000000000000000000000000010000000100000000000000000000000100000000001380D48B00000000000032000000094D656D6F7279202633000000000000000000000000010000000100000000000000000000000100000000001380D58B00000000000032000000094D656D6F72792026340000000000000000000000000100000001000000000000000000000001000000000013801001000000000000330000000E53657269616C2057696E646F77730000000000000000000000000100000001000000000000000000000001000000040013809307000000000000330000000855415254202326310000000000000000000000000100000001000000000000000000000001000000000013809407000000000000330000000855415254202326320000000000000000000000000100000001000000000000000000000001000000000013809507000000000000330000000855415254202326330000000000000000000000000100000001000000000000000000000001000000000013809607000000000000330000001626446562756720287072696E746629205669657765720000000000000000000000000100000001000000000000000000000001000000000013803C010000000000003400000010416E616C797369732057696E646F7773000000000000000000000000010000000100000000000000000000000100000004001380658A000000000000340000000F264C6F67696320416E616C797A6572000000000000000000000000010000000100000000000000000000000100000000001380DC7F0000000000003E0000001526506572666F726D616E636520416E616C797A6572000000000000000000000000010000000100000000000000000000000100000000001380E788000000000000380000000E26436F646520436F766572616765000000000000000000000000010000000100000000000000000000000100000000001380CD01000000000000FFFFFFFF0F416E616C7973697320416E63686F7200000000000000000100000000000000010000000000000000000000010000000000138053010000000000003F0000000D54726163652057696E646F77730000000000000000000000000100000001000000000000000000000001000000010013805401000000000000FFFFFFFF115472616365204D656E7520416E63686F720000000000000000010000000000000001000000000000000000000001000000000013802901000000000000350000001553797374656D205669657765722057696E646F77730000000000000000000000000100000001000000000000000000000001000000010013804B01000000000000FFFFFFFF1453797374656D2056696577657220416E63686F720000000000000000010000000000000001000000000000000000000001000000000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000013800189000000000000360000000F26546F6F6C626F782057696E646F7700000000000000000000000001000000010000000000000000000000010000000300138044C5000000000000FFFFFFFF0E5570646174652057696E646F77730000000000000000010000000000000001000000000000000000000001000000000013800000000000000400FFFFFFFF000000000000000000010000000000000001000000000000000000000001000000000013805B01000000000000FFFFFFFF12546F6F6C626F78204D656E75416E63686F72000000000000000001000000000000000100000000000000000000000100000000000000000005446562756764020000</Data> <Data>00200000000000001900FFFF01001100434D4643546F6F6C426172427574746F6ECC880000000000002500000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018017800000000000002600000000000000000000000000000000010000000100000001801D800000000000002700000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001801A800000000000002800000000000000000000000000000000010000000100000001801B80000000000000290000000000000000000000000000000001000000010000000180E57F0000000000002A00000000000000000000000000000000010000000100000001801C800000000000002B00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018000890000000000002C00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180E48B0000000000002D0000000000000000000000000000000001000000010000000180F07F0000000000002E0000000000000000000000000000000001000000010000000180E8880000000000003700000000000000000000000000000000010000000100000001803B010000000000002F0000000000000000000000000000000001000000010000000180BB8A00000000000030000000000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E0E01000000000000310000000D57617463682057696E646F7773000000000000000000000000010000000100000000000000000000000100000003001380D88B00000000000031000000085761746368202631000000000000000000000000010000000100000000000000000000000100000000001380D98B00000000000031000000085761746368202632000000000000000000000000010000000100000000000000000000000100000000001380CE01000000000000FFFFFFFF0C576174636820416E63686F720100000000000000010000000000000001000000000000000000000001000000000013800F01000000000000320000000E4D656D6F72792057696E646F7773000000000000000000000000010000000100000000000000000000000100000004001380D28B00000000000032000000094D656D6F7279202631000000000000000000000000010000000100000000000000000000000100000000001380D38B00000000000032000000094D656D6F7279202632000000000000000000000000010000000100000000000000000000000100000000001380D48B00000000000032000000094D656D6F7279202633000000000000000000000000010000000100000000000000000000000100000000001380D58B00000000000032000000094D656D6F72792026340000000000000000000000000100000001000000000000000000000001000000000013801001000000000000330000000E53657269616C2057696E646F77730000000000000000000000000100000001000000000000000000000001000000040013809307000000000000330000000855415254202326310000000000000000000000000100000001000000000000000000000001000000000013809407000000000000330000000855415254202326320000000000000000000000000100000001000000000000000000000001000000000013809507000000000000330000000855415254202326330000000000000000000000000100000001000000000000000000000001000000000013809607000000000000330000001626446562756720287072696E746629205669657765720000000000000000000000000100000001000000000000000000000001000000000013803C010000000000003400000010416E616C797369732057696E646F7773000000000000000000000000010000000100000000000000000000000100000004001380658A000000000000340000000F264C6F67696320416E616C797A6572000000000000000000000000010000000100000000000000000000000100000000001380DC7F0000000000003E0000001526506572666F726D616E636520416E616C797A6572000000000000000000000000010000000100000000000000000000000100000000001380E788000000000000380000000E26436F646520436F766572616765000000000000000000000000010000000100000000000000000000000100000000001380CD01000000000000FFFFFFFF0F416E616C7973697320416E63686F7201000000000000000100000000000000010000000000000000000000010000000000138053010000000000003F0000000D54726163652057696E646F77730000000000000000000000000100000001000000000000000000000001000000010013805401000000000000FFFFFFFF115472616365204D656E7520416E63686F720100000000000000010000000000000001000000000000000000000001000000000013802901000000000000350000001553797374656D205669657765722057696E646F77730000000000000000000000000100000001000000000000000000000001000000010013804B01000000000000FFFFFFFF1453797374656D2056696577657220416E63686F720100000000000000010000000000000001000000000000000000000001000000000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000013800189000000000000360000000F26546F6F6C626F782057696E646F7700000000000000000000000001000000010000000000000000000000010000000300138044C5000000000000FFFFFFFF0E5570646174652057696E646F77730100000000000000010000000000000001000000000000000000000001000000000013800000000000000400FFFFFFFF000000000000000000010000000000000001000000000000000000000001000000000013805B01000000000000FFFFFFFF12546F6F6C626F78204D656E75416E63686F72010000000000000001000000000000000100000000000000000000000100000000000000000005446562756764020000</Data>
</Buttons> </Buttons>
<OriginalItems> <OriginalItems>
<Len>898</Len> <Len>898</Len>
@ -1750,7 +1750,7 @@
<Doc> <Doc>
<Name>..\myfreertos\myfreertos.c</Name> <Name>..\myfreertos\myfreertos.c</Name>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<TopLine>230</TopLine> <TopLine>213</TopLine>
<CurrentLine>214</CurrentLine> <CurrentLine>214</CurrentLine>
<Folding>1</Folding> <Folding>1</Folding>
<ContractedFolders></ContractedFolders> <ContractedFolders></ContractedFolders>
@ -1767,9 +1767,9 @@
</Doc> </Doc>
<Doc> <Doc>
<Name>..\HARDWARE\PID.c</Name> <Name>..\HARDWARE\PID.c</Name>
<ColumnNumber>23</ColumnNumber> <ColumnNumber>24</ColumnNumber>
<TopLine>136</TopLine> <TopLine>28</TopLine>
<CurrentLine>131</CurrentLine> <CurrentLine>49</CurrentLine>
<Folding>1</Folding> <Folding>1</Folding>
<ContractedFolders></ContractedFolders> <ContractedFolders></ContractedFolders>
<PaneID>0</PaneID> <PaneID>0</PaneID>

Loading…
Cancel
Save