//位置式PID

float Kp;
float Ki;
float Kd;

float eSum,e0,e1;

float pid_control(float now,float target)
{
    float pe,ie,de;
    float out;
    
    e0 = target - now;
    eSum += e0;
    
    pe = e0;
    ie = eSum;
    de = e0 - e1;
        
    out = pe*Kp + ie*Ki + de*Kd;
    
    out = limit(out,-LIMIT,LIMIT);

    e1 = e0;
    
    return out;
}

//增量式PID

float Kp;
float Ki;
float Kd;

float eSum,e0,e1,e2;

float pid_control(float now,float target)
{
    float pe,ie,de;
    float out;

    e0 = target - now;
    
    pe = e0 - e1;
    ie = e0;
    de = e0 - 2*e1 + e2;
    
    out = pe*Kp + ie*Ki + de*Kd;
    out = limit(out,-LIMIT,LIMIT);
    
    e2 = e1;
    e1 = e0;
    
    return out;
    
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-04-04
  • 2021-07-02
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-08-18
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案