1. incremental PID control algorithm
Void pid_control (void) {offside1 = standard_speed-actual_speed; // calculate the current speed deviation R1 = Kp * (offside1-offside2); r2 = Ki * offside1; pid_result = (unsigned char) (R1 + R2); // The floating point number is forcibly converted to the hexadecimal number offside2 = offside1 ;}
2. PID control algorithm for integral separation
Void pid_control (void) {offside1 = standard_speed-actual_speed; // calculate the current speed deviation R1 = Kp * (offside1-offside2); If (offside1 <threshold) // calculate the separation of the integral part r2 = Ki * offside1; // threshold as the threshold else r2 = 0; pid_result = (unsigned char) (R1 + R2 ); // The floating point number is forcibly converted to the hexadecimal number offside2 = offside1 ;}
3. Variable Speed integral PID control algorithm
Void pid_control (void) {float F; offside1 = standard_speed-actual_speed; // calculate the deviation between theoretical velocity and actual velocity R1 = Kp * (offside1-offside2 ); // calculate the p Parameter section if (offisde1 <= threshold1) // is the speed deviation smaller than the threshold threshold1? F = 1; // Yes, mark F = 1 else if (offside1> threshold1 + threshold2) // No, then compare whether the deviation exceeds threshold1 + threshold2? F = 0; // Yes, flag f = 0 else f = (threshold1 + threshold2-offside1)/threshold2; // No, recalculate F r2 = Ki * offside1 * F; // calculate the I parameter section pid_result = R1 + r2 + R3; // calculate the PID calculation result. The D parameter section (r3) considers 0offside2 = offside1; // calculate the deviation of the Velocity Deviation}