pid代码

2022-07-13 10:15:15   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《pid代码》,欢迎阅读!
代码,pid
下面提供一组最简单的pid伪代码和C代码

previous_error = 0 integral = 0 start:

error = setpoint_speed - actual_speed integral = integral + (error*dt)

derivative = (error - previous_error)/dt

output = (Kp*error) + (Ki*integral) + (Kd*derivative) previous_error = error wait(dt) goto start C

typedef struct {

double dState; // Last position input double iState; // Integrator state double iMax, iMin;

// Maximum and minimum allowable integrator state


double iGain, // integral gain pGain, // proportional gain dGain; // derivative gain } SPid;

double UpdatePID(SPid * pid, double error, double position) {

double pTerm, dTerm, iTerm;

pTerm = pid->pGain * error; // calculate the proportional term

// calculate the integral state with appropriate limiting pid->iState += error;

if (pid->iState > pid->iMax) pid->iState = pid->iMax; else if (pid->iState <

pid->iMin) pid->iState = pid->iMin;

iTerm = pid->iGain * iState; // calculate the integral term dTerm = pid->dGain * (position - pid->dState); pid->dState = position;

return pTerm + iTerm - dTerm; }


本文来源:https://www.wddqxz.cn/bd6aa90a581b6bd97f19ea81.html

相关推荐