mirror of
https://github.com/avem-labs/Avem.git
synced 2023-09-01 15:18:49 +08:00
[MOD]: Fixed PID and Rename Struct
This commit is contained in:
parent
f005c4fcc5
commit
fa21a55474
@ -18,8 +18,8 @@ extern float g_Yaw, g_Pitch, g_Roll; //eular
|
||||
#define KD 1
|
||||
|
||||
typedef struct {
|
||||
float Cache;
|
||||
float *RealTime;
|
||||
float Last;
|
||||
float *Feedback;
|
||||
float Erro;
|
||||
float p;
|
||||
float i;
|
||||
|
@ -3,16 +3,16 @@
|
||||
#include "motor.h"
|
||||
|
||||
void pid_SingleAxis(pid_pst temp, float setPoint) {
|
||||
temp->Erro = *temp->RealTime - setPoint;
|
||||
temp->Erro = setPoint - *temp->Feedback;
|
||||
|
||||
temp->i += temp->Erro;
|
||||
if (temp->i > PID_IMAX) temp->i = PID_IMAX;
|
||||
else if (temp->i < PID_IMIN) temp->i = PID_IMIN;
|
||||
|
||||
temp->d = *temp->RealTime - temp->Cache;
|
||||
temp->d = *temp->Feedback - temp->Last;
|
||||
|
||||
temp->output = (short)(KP * (temp->Erro) + KI * temp->i + KD * temp->d);
|
||||
temp->Cache = *temp->RealTime;
|
||||
temp->Last = *temp->Feedback;
|
||||
}
|
||||
|
||||
// float g_iErro, g_sumErro = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user