Several PID control codes in C Language

Source: Internet
Author: User

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}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.