BoooomFOC_STSPIN32G4_EVB/BoooomCTL/Common/PID/PID.c

27 lines
756 B
C
Raw Permalink Normal View History

2024-12-02 02:45:48 +08:00
////
//// Created by ZK on 2023/3/14.
////
2024-05-08 03:04:20 +08:00
//
2024-12-02 02:45:48 +08:00
//#include "PID.h"
2024-05-08 03:04:20 +08:00
//
2024-12-02 02:45:48 +08:00
//float PID_Generate(PID *pid) {
// pid->error = pid->target - pid->value;
//
// if (pid->error > pid->errMin || pid->error < -pid->errMin)
// pid->errSum += pid->error * pid->ki;
//
// if (pid->errSum > pid->errSumMax)
// pid->errSum = pid->errSumMax;
// else if (pid->errSum < -pid->errSumMax)
// pid->errSum = -pid->errSumMax;
//
// pid->errDt = pid->error - pid->lastErr;
// pid->lastErr = pid->error;
//
// pid->result = pid->kp * pid->error + pid->errSum + pid->kd * pid->errDt;
//
// if (pid->result > pid->valMax)
// pid->result = pid->valMax;
// else if (pid->result < -pid->valMax)
// pid->result = -pid->valMax;
//}