From fa21a55474a4a710b1a56de7a96b60213b81a537 Mon Sep 17 00:00:00 2001 From: but0n Date: Mon, 10 Oct 2016 10:49:44 +0800 Subject: [PATCH] [MOD]: Fixed PID and Rename Struct --- .../Libraries/STM32F10x_StdPeriph_Driver/inc/pid.h | 4 ++-- .../Libraries/STM32F10x_StdPeriph_Driver/src/pid.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/pid.h b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/pid.h index 0eb09d0..f377225 100644 --- a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/pid.h +++ b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/inc/pid.h @@ -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; diff --git a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/pid.c b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/pid.c index 74cded6..fbd8d20 100644 --- a/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/pid.c +++ b/libs/STM32_USB-FS-Device_Lib_V4.0.0/Libraries/STM32F10x_StdPeriph_Driver/src/pid.c @@ -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;