zoukankan      html  css  js  c++  java
  • PID控制算法C源码

    感觉代码不错,以后肯定会用到,侵删

    #include <reg52.h>  
    #include <string.h>             //C语言中memset函数头文件 
    #define unsigned int uint        
    typedef struct PID {   
    double SetPoint;      // 设定目标Desired value   
    double Proportion;    // 比例常数Proportional Const  
    double Integral;      // 积分常数Integral Const  
    double Derivative;    // 微分常数Derivative Const  
    double LastError;     // Error[-1]    
    double PrevError;    // Error[-2]   
    double SumError;    // Sums of Errors  
    }PID;   
    /*================================================
    ====================================================PID计算部分 =======================
    ==============================================================================
    */ double PIDCalc( PID *pp, double NextPoint ) { double dError, Error; Error = pp->SetPoint - NextPoint; // 偏差 pp->SumError += Error; // 积分 dError = Error - pp->LastError; // 当前微分 pp->PrevError = pp->LastError; pp->LastError = Error; return (pp->Proportion * Error // 比例项 + pp->Integral * pp->SumError // 积分项 + pp->Derivative * dError // 微分项 ); } /*=======================================================
    ============================================= Initialize PID Structure PID参数初始化 =============
    ========================================================================================
    */ void PIDInit (PID *pp) { memset ( pp,0,sizeof(PID)); }
    /*======================================================
    ============================================== Main Program 主程序 ===================
    ==================================================================================
    */ double sensor (void) // Dummy Sensor Function { return 100.0; } //void actuator(double rDelta) // Dummy Actuator Function //{} void main(void) { PID sPID; // PID Control Structure double rOut; // PID Response (Output) double rIn; // PID Feedback (Input) PIDInit ( &sPID ); // Initialize Structure sPID.Proportion = 0.5; // Set PID Coefficients sPID.Integral = 0.5; sPID.Derivative = 0.0; sPID.SetPoint = 100.0; // Set PID Setpoint for (;;) { // Mock Up of PID Processing rIn = sensor (); // Read Input rOut = PIDCalc ( &sPID,rIn ); // Perform PID Interation //actuator ( rOut ); // Effect Needed Changes } }
  • 相关阅读:
    什么是CDN?哪些是流行的jQuery CDN?使用CDN有什么好处?
    jQuery 中$.get()和$.post()提交有区别吗?
    window.onload()函数和jQuery中的document.ready()区别
    js相等(==)与全等(===)的区别
    用javascript改变onclick调用的函数
    null,undefined,undeclared的区别
    JavaScript重定向到其他网页
    C Programing Environment
    转:JMir——Java版热血传奇2之资源文件与地图
    PHP内容管理项目函数列表
  • 原文地址:https://www.cnblogs.com/MnsterLu/p/5518411.html
Copyright © 2011-2022 走看看