pid算法优化,数据处理中的crc校验逻辑优化

main
Zeng wei (曾威) 2 years ago
parent d0ede9ebe2
commit de697a4704

@ -15,12 +15,13 @@ PID pid;
u8 rs485speed[8] = {0x01, 0x06, 0x60, 0x00, 0x00, 0x09, 0xBB, 0xAA}; // speed control for compressor controller u8 rs485speed[8] = {0x01, 0x06, 0x60, 0x00, 0x00, 0x09, 0xBB, 0xAA}; // speed control for compressor controller
int min_speed_count = 1500; int min_speed_count = 1500;
int max_speed_count = 6000; int max_speed_count = 6000;
float tem_control_threshold = 0.5;
void PID_Init() 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 = 110; } if (pid.Kp < 1e-7) { pid.Kp = 40; }
if (pid.Ki < 1e-7) { pid.Ki = 0.001; } if (pid.Ki < 1e-7) { pid.Ki = 0.001; }
if (pid.Kd < 1e-7) { pid.Kd = 340; } if (pid.Kd < 1e-7) { pid.Kd = 340; }
@ -32,6 +33,20 @@ void PID_Init()
pid.C1ms = 0; pid.C1ms = 0;
} }
/**
* send speed count to compressor controller
*/
void send_speed_signal(int speed) {
rs485speed[4] = speed / 256;
rs485speed[5] = speed % 256;
RS485_3_Init(9600);
delay_xms(100);
RS485_3_Send_Data(rs485speed, 8);
delay_xms(100);
RS485_1_Init(9600);
}
void PID_Calc() // pid calc void PID_Calc() // pid calc
{ {
float DelEk; // The difference between the last two deviations float DelEk; // The difference between the last two deviations
@ -42,14 +57,15 @@ void PID_Calc() // pid calc
return; return;
} }
if (pid.set_tem > pid.now_tem) // if (pid.set_tem > pid.now_tem)
{ // {
pid.Ek = pid.set_tem - pid.now_tem; // pid.Ek = pid.set_tem - pid.now_tem;
} // }
else // else
{ // {
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.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
@ -87,61 +103,66 @@ void PID_Calc() // pid calc
pid.Ek_1 = pid.Ek; // udpate difference pid.Ek_1 = pid.Ek; // udpate difference
pid.C1ms = 0; pid.C1ms = 0;
if (pid.set_tem > pid.now_tem + 1) // speed count
int speed_count = pid.OUT / 200.0 * (max_speed_count - min_speed_count) + min_speed_count;
if (speed_count > 6000) {
speed_count = 6000;
}
if (pid.now_tem < pid.set_tem - tem_control_threshold)
{ {
// Obtain the current deviation value // Obtain the current deviation value
// when the target temperature is 1 degree Celsius higher than the actual temperature, heat up // when the target temperature is 1 degree Celsius higher than the actual temperature, heat up
// close compressor open heater // close compressor open heater
/*GPIO1->Alarm bell GPIO3->heater GPIO4->Fresh air fan GPIO5->humidifier GPIO6->compressor */ /*GPIO1->Alarm bell GPIO3->heater GPIO4->Fresh air fan GPIO5->humidifier GPIO6->compressor */
HC595_Send_Byte(gpio_state &= 0xDF);//close compressor &=1101 1111 0xDF // HC595_Send_Byte(gpio_state &= 0xDF);//close compressor &=1101 1111 0xDF
num = 0;
TIM_SetCompare3(TIM3, 0);
HC595_Send_Byte(gpio_state |= 0x04); // open heater |=0000 0100 0x04 HC595_Send_Byte(gpio_state |= 0x04); // open heater |=0000 0100 0x04
speed_count = 1000; // close compressor
hot_clod_flag = 2; hot_clod_flag = 2;
pid.Iout = 0; pid.Iout = 0;
} else if (pid.now_tem > pid.set_tem) } else if (pid.now_tem > pid.set_tem - tem_control_threshold && pid.now_tem < pid.set_tem + tem_control_threshold)
{
HC595_Send_Byte(gpio_state &= 0xFB); // close heater &=1111 1011 0xFB
speed_count = 1000; // close compressor
hot_clod_flag = 0;
// pid.Iout=0;
} else if (pid.now_tem > pid.set_tem + tem_control_threshold)
{ {
// Obtain the current deviation value // Obtain the current deviation value
// when the target temperature is lower than the actual temperature, refrigerate // when the target temperature is lower than the actual temperature, refrigerate
// open compressor close heater // open compressor close heater
HC595_Send_Byte(gpio_state &= 0xFB); // close heater &=1111 1011 0xFB HC595_Send_Byte(gpio_state &= 0xFB); // close heater &=1111 1011 0xFB
// 0-200 correspond 0-100%, if pid.out=50, percentage means 25% //num=50*400/200=100 100/400=25%
num = (((pid.OUT * 400) / pid.pwmcycle) - 1); // Conversion of pid.OUT and PWM Duty Cycle Values
TIM_SetCompare3(TIM3, num / 4); // // 0-200 correspond 0-100%, if pid.out=50, percentage means 25% //num=50*400/200=100 100/400=25%
// num = (((pid.OUT * 400) / pid.pwmcycle) - 1); // Conversion of pid.OUT and PWM Duty Cycle Values
// TIM_SetCompare3(TIM3, num / 4);
// printf("%d\r\n",num); // printf("%d\r\n",num);
HC595_Send_Byte(gpio_state|=0x20);//open compressor |=0010 0000 // HC595_Send_Byte(gpio_state|=0x20);//open compressor |=0010 0000
hot_clod_flag = 1; hot_clod_flag = 1;
// pid.Iout=0; // pid.Iout=0;
} }
if (hot_clod_flag == 1 && T <= tem - 3) // During the refrigeration process, the actual temperature drops by 0.3 degrees Celsius below the set temperature
{
HC595_Send_Byte(gpio_state&=0xDB);// close compressor and heater &=1101 1011 0xDB
num = 0;
TIM_SetCompare3(TIM3, 0); // close compressor
hot_clod_flag = 0;
}
if (hot_clod_flag == 2 && T >= tem) // while heat, T above tem send_speed_signal(speed_count);
{
HC595_Send_Byte(gpio_state&=0xDB);//close compressor and heater &=1101 1011 0xDB // if (hot_clod_flag == 1 && T <= tem - 3) // During the refrigeration process, the actual temperature drops by 0.3 degrees Celsius below the set temperature
num = 0; // {
TIM_SetCompare3(TIM3, 0); // close compressor // HC595_Send_Byte(gpio_state&=0xDB);// close compressor and heater &=1101 1011 0xDB
hot_clod_flag = 0; // // num = 0;
} // // TIM_SetCompare3(TIM3, 0); // close compressor
int out1 = pid.OUT; // speed_count = 1000;
// speed count // hot_clod_flag = 0;
int speed_count = out1 / 200.0 * (max_speed_count - min_speed_count) + min_speed_count; // }
if (speed_count > 6000) {
speed_count = 6000; // if (hot_clod_flag == 2 && T >= tem) // while heat, T above tem
} // {
rs485speed[4] = speed_count / 256; // HC595_Send_Byte(gpio_state&=0xDB);//close compressor and heater &=1101 1011 0xDB
rs485speed[5] = speed_count % 256; // num = 0;
// TIM_SetCompare3(TIM3, 0); // close compressor
// RS485_3_Init(9600); // hot_clod_flag = 0;
delay_xms(100); // }
// RS485_3_Send_Data(rs485speed, 8);
RS485_1_Send_Data_1(rs485speed, 8);
delay_xms(200);
// RS485_1_Init(9600);
// HC595_Send_Byte(gpio_state&=0xDB);// close compressor and heater &=1101 1011 0xDB // HC595_Send_Byte(gpio_state&=0xDB);// close compressor and heater &=1101 1011 0xDB
} }

@ -177,7 +177,7 @@ void SN74CB3Q3253_Init(void)
} }
// RS485_1_Init->J6 ??PB5->S1,PB6->S0,PB7->USART_OE // RS485_1_Init->J6 ??PB5->S1,PB6->S0,PB7->USART_OE
// SN74CB3Q3253??·?????? - ??·???????????????????OE S1 S0???????001???1B2 2B2??? // SN74CB3Q3253??<EFBFBD><EFBFBD>?????? - ??<3F><>???????????????????OE S1 S0???????001???1B2 2B2???
// pclk1:PCLK1??????(Mhz) // pclk1:PCLK1??????(Mhz)
// bound:?????? // bound:??????
@ -233,7 +233,7 @@ void RS485_1_Init(u32 bound)
} }
// RS485_2_Init->J7 ??PB5->S1,PB6->S0,PB7->USART_OE // RS485_2_Init->J7 ??PB5->S1,PB6->S0,PB7->USART_OE
// SN74CB3Q3253??·?????? - ??·???????????????????OE S1 S0???????000???1B1 2B1??? // SN74CB3Q3253??<EFBFBD><EFBFBD>?????? - ??<3F><>???????????????????OE S1 S0???????000???1B1 2B1???
void RS485_2_Init(u32 bound) void RS485_2_Init(u32 bound)
{ {
@ -285,7 +285,7 @@ void RS485_2_Init(u32 bound)
} }
// RS485_3_Init->J7 ??PB5->S1,PB6->S0,PB7->USART_OE // RS485_3_Init->J7 ??PB5->S1,PB6->S0,PB7->USART_OE
// SN74CB3Q3253??·?????? - ??·???????????????????OE S1 S0???????010???1B3 2B3??? // SN74CB3Q3253??<EFBFBD><EFBFBD>?????? - ??<3F><>???????????????????OE S1 S0???????010???1B3 2B3???
void RS485_3_Init(u32 bound) void RS485_3_Init(u32 bound)
{ {
@ -480,12 +480,12 @@ void RS485_1_Send_Data_2(void)
sendbuf[32] = crc_num2; sendbuf[32] = crc_num2;
// only when modify happen, then send // only when modify happen, then send
//if (cmp_str(prev_sendbuf, sendbuf, 37) != 0) { if (cmp_str(prev_sendbuf, sendbuf, 37) != 0) {
RS485_1_Send_Data(sendbuf, 37); RS485_1_Send_Data(sendbuf, 37);
cp_str_to_prev(prev_sendbuf, sendbuf, 37); cp_str_to_prev(prev_sendbuf, sendbuf, 37);
//} }
} }

File diff suppressed because it is too large Load Diff

@ -77,8 +77,8 @@
<flags>2</flags> <flags>2</flags>
<showCmd>3</showCmd> <showCmd>3</showCmd>
<MinPosition> <MinPosition>
<xPos>-1</xPos> <xPos>-32000</xPos>
<yPos>-1</yPos> <yPos>-32000</yPos>
</MinPosition> </MinPosition>
<MaxPosition> <MaxPosition>
<xPos>-1</xPos> <xPos>-1</xPos>
@ -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>
@ -1768,8 +1768,8 @@
<Doc> <Doc>
<Name>..\HARDWARE\PID.c</Name> <Name>..\HARDWARE\PID.c</Name>
<ColumnNumber>64</ColumnNumber> <ColumnNumber>64</ColumnNumber>
<TopLine>95</TopLine> <TopLine>96</TopLine>
<CurrentLine>124</CurrentLine> <CurrentLine>125</CurrentLine>
<Folding>1</Folding> <Folding>1</Folding>
<ContractedFolders></ContractedFolders> <ContractedFolders></ContractedFolders>
<PaneID>0</PaneID> <PaneID>0</PaneID>
@ -1803,9 +1803,9 @@
</Doc> </Doc>
<Doc> <Doc>
<Name>..\HARDWARE\rs485.c</Name> <Name>..\HARDWARE\rs485.c</Name>
<ColumnNumber>49</ColumnNumber> <ColumnNumber>16</ColumnNumber>
<TopLine>461</TopLine> <TopLine>380</TopLine>
<CurrentLine>474</CurrentLine> <CurrentLine>398</CurrentLine>
<Folding>1</Folding> <Folding>1</Folding>
<ContractedFolders></ContractedFolders> <ContractedFolders></ContractedFolders>
<PaneID>0</PaneID> <PaneID>0</PaneID>

@ -247,38 +247,38 @@ void Sensor_Communication_task(void *pvParameters)
process_sensor_data(temp_data); process_sensor_data(temp_data);
RX_BUF_Transfer(0, 23); RX_BUF_Transfer(0, 23);
} }
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x01) else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x01 && CRC16_check(RS485_RX_BUF_COPY, 16) == 1)
{ {
// batch update params in a stage // batch update params in a stage
// total length: 18 // total length: 18
if (CRC16_check(RS485_RX_BUF_COPY, 16) == 1) { // if (CRC16_check(RS485_RX_BUF_COPY, 16) == 1) {
Batch_synchronization(&n, RS485_RX_BUF_COPY); Batch_synchronization(&n, RS485_RX_BUF_COPY);
Array(&now_stage, &hour, &min, &tem, &hum, &red, &blue, &white); // update param correspond to current stage Array(&now_stage, &hour, &min, &tem, &hum, &red, &blue, &white); // update param correspond to current stage
bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 18); bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 18);
bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 18, 22); bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 18, 22);
// RS485_1_Send_Data_1(RS485_DATA_TMP, 22); // RS485_1_Send_Data_1(RS485_DATA_TMP, 22);
} // }
RX_BUF_Transfer(0, 18); RX_BUF_Transfer(0, 18);
} }
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x03) else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x03 && CRC16_check(RS485_RX_BUF_COPY, 7) == 1)
{ {
// update single environment param // update single environment param
// total length: 9 // total length: 9
if (CRC16_check(RS485_RX_BUF_COPY, 7) == 1) { // if (CRC16_check(RS485_RX_BUF_COPY, 7) == 1) {
Analysis(&n, &i, RS485_RX_BUF_COPY); Analysis(&n, &i, RS485_RX_BUF_COPY);
Array(&now_stage, &hour, &min, &tem, &hum, &red, &blue, &white); // update param correspond to current stage Array(&now_stage, &hour, &min, &tem, &hum, &red, &blue, &white); // update param correspond to current stage
Write_Init(); Write_Init();
bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 9); bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 9);
bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 9, 13); bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 9, 13);
RS485_1_Send_Data_1(RS485_DATA_TMP, 13); RS485_1_Send_Data_1(RS485_DATA_TMP, 13);
} // }
RX_BUF_Transfer(0, 9); RX_BUF_Transfer(0, 9);
} }
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x04) else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x04 && CRC16_check(RS485_RX_BUF_COPY, 4) == 1)
{ {
// change running stage // change running stage
// total length: 6 // total length: 6
if (CRC16_check(RS485_RX_BUF_COPY, 4) == 1) { // if (CRC16_check(RS485_RX_BUF_COPY, 4) == 1) {
int target_stage = RS485_RX_BUF_COPY[3]; int target_stage = RS485_RX_BUF_COPY[3];
RTC_synchronization_ins(2023, 9, 1, 0, 00, 00); RTC_synchronization_ins(2023, 9, 1, 0, 00, 00);
now_stage = target_stage; now_stage = target_stage;
@ -289,14 +289,14 @@ void Sensor_Communication_task(void *pvParameters)
RS485_1_Send_Data_1(RS485_DATA_TMP, 10); RS485_1_Send_Data_1(RS485_DATA_TMP, 10);
delay_ms(10); delay_ms(10);
RS485_1_Send_Data_2(); // ÉÏ´«²ÎÊý RS485_1_Send_Data_2(); // ÉÏ´«²ÎÊý
} // }
RX_BUF_Transfer(0, 6); RX_BUF_Transfer(0, 6);
} }
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x05) else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB6 && RS485_RX_BUF_COPY[2] == 0x05 && CRC16_check(RS485_RX_BUF_COPY, 4) == 1)
{ {
// change pid params // change pid params
// total length: 8 // total length: 8
if (CRC16_check(RS485_RX_BUF_COPY, 6) == 1) { // if (CRC16_check(RS485_RX_BUF_COPY, 4) == 1) {
int param_index = RS485_RX_BUF_COPY[3]; int param_index = RS485_RX_BUF_COPY[3];
switch(param_index) { switch(param_index) {
case 0x01: case 0x01:
@ -319,7 +319,7 @@ void Sensor_Communication_task(void *pvParameters)
bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 8); bufcut_Init(RS485_DATA_TMP, RS485_RX_BUF_COPY, 0, 8);
bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 8, 12); bufcut_Init(RS485_DATA_TMP + 8, RS485_SUFFIX, 8, 12);
RS485_1_Send_Data_1(RS485_DATA_TMP, 12); RS485_1_Send_Data_1(RS485_DATA_TMP, 12);
} // }
RX_BUF_Transfer(0, 8); RX_BUF_Transfer(0, 8);
} }
else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB1 && RS485_RX_BUF_COPY[2] == 0x11 && RS485_RX_BUF_COPY[15] == 0xFF && RS485_RX_BUF[16] == 0xFF) else if (RS485_RX_BUF_COPY[0] == 0xEE && RS485_RX_BUF_COPY[1] == 0xB1 && RS485_RX_BUF_COPY[2] == 0x11 && RS485_RX_BUF_COPY[15] == 0xFF && RS485_RX_BUF[16] == 0xFF)
@ -358,8 +358,6 @@ void Sensor_Communication_task(void *pvParameters)
if (red <= 1000 && blue <= 1000) if (red <= 1000 && blue <= 1000)
{ {
@ -415,13 +413,6 @@ void process_sensor_data(u8 *data) {
PID_Calc(); PID_Calc();
// send sign to 485 // send sign to 485
// out: 0-200 // out: 0-200
// num=(((pid.OUT*400)/pid.pwmcycle)-1);//请问这个pid.OUT与pwm占空比的值是如何换算过来的
// TIM_SetCompare3(TIM3,num);
// TIM_SetCompare3(TIM3,0.845*num);
// printf("%d\r\n",num);
// 0-200对应0-100%如果pid.out=50,占空比就是25%//num=50*400/200=100100/400=25%
// printf("%d ,%d ,%d ,%d ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,%.3f\r\n",T,H,C,num,(pid.set_tem*10),pid.Kp,ki,kd,pid.Pout,pid.Iout,pid.Dout,num/399.0);
current_T = T; current_T = T;
} }
} }

Loading…
Cancel
Save