void PID_Parameter_Init(PID *sptr) { sptr->SumError = 0; sptr->LastError = 0; sptr->PrevError = 0; sptr->LastData = 0; } int PID_Realize(PID *sptr, float *PID, int NowData, int Point) { int Realize; sptr->Dis_Err = Point - NowData; sptr->SumError += PID[KI] * sptr->Dis_Err; if (sptr->SumError >= PID[KT]) { sptr->SumError = PID[KT]; } else if (sptr->SumError <= -PID[KT]) { sptr->SumError = -PID[KT]; } Realize = PID[KP] * sptr->Dis_Err + sptr->SumError + PID[KD] *(sptr->Dis_Err - sptr->LastError); // + PID[KB] * ( NowData- sptr->LastData); sptr->PrevError = sptr->LastError; sptr->LastError = sptr->Dis_Err; sptr->LastData = NowData; return Realize; } int PID_Increase(PID *sptr, float *PID, int NowData, int Point) { int iError, Increase; iError = Point - NowData; Increase = PID[KP] * (iError - sptr->LastError) + PID[KI] * iError + PID[KD] * (iError - 2 * sptr->LastError + sptr->PrevError); sptr->PrevError = sptr->LastError; sptr->LastError = iError; sptr->LastData = NowData; return Increase; } Left_Acc = templ_pluse - Left_Old; Right_Acc = tempr_pluse - Right_Old; if (Left_Acc > 50) { Left_Old = Left_Old + 50; templ_pluse = Left_Old; } else if (Left_Acc < -50) { Left_Old = Left_Old - 50; templ_pluse = Left_Old; } else { templ_pluse = Left_Old; } if (Right_Acc > 50) { Right_Old = Right_Old + 50; tempr_pluse = Right_Old; } else if (Right_Acc < -50) { Right_Old = Right_Old - 50; tempr_pluse = Right_Old; } else { tempr_pluse = Right_Old; } RealSpeed_Old = ZJZ; ZJZ = (templ_pluse + tempr_pluse) * 0.5;
时间: 2024-04-16 07:25:37 浏览: 188
PID实现算法
根据你提供的代码,出现错误的原因可能是 `templ_pluse` 和 `tempr_pluse` 变量未被声明或未初始化。请确保在使用这两个变量之前,它们已经被正确地声明和初始化。
此外,在这段代码中的 `PID_Realize` 和 `PID_Increase` 函数中使用了 `PID` 数组,但是并未看到这个数组的定义。请确保 `PID` 数组已经在代码的其他地方正确地定义和初始化。
如果你仍然遇到错误,请提供更多的错误提示信息以便进一步分析。
阅读全文