[MOD]: Fixed PID and Rename Struct

This commit is contained in:
but0n 2016-10-10 10:49:44 +08:00
parent f005c4fcc5
commit fa21a55474
2 changed files with 5 additions and 5 deletions

View File

@ -18,8 +18,8 @@ extern float g_Yaw, g_Pitch, g_Roll; //eular
#define KD 1 #define KD 1
typedef struct { typedef struct {
float Cache; float Last;
float *RealTime; float *Feedback;
float Erro; float Erro;
float p; float p;
float i; float i;

View File

@ -3,16 +3,16 @@
#include "motor.h" #include "motor.h"
void pid_SingleAxis(pid_pst temp, float setPoint) { void pid_SingleAxis(pid_pst temp, float setPoint) {
temp->Erro = *temp->RealTime - setPoint; temp->Erro = setPoint - *temp->Feedback;
temp->i += temp->Erro; temp->i += temp->Erro;
if (temp->i > PID_IMAX) temp->i = PID_IMAX; if (temp->i > PID_IMAX) temp->i = PID_IMAX;
else if (temp->i < PID_IMIN) temp->i = PID_IMIN; 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->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; // float g_iErro, g_sumErro = 0;