Updated HW test items for SWo
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@248 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -29,6 +29,7 @@ KeyboardDevice.o \
|
||||
Logger.o \
|
||||
MAX5715.o \
|
||||
nhd0420.o \
|
||||
PID.o \
|
||||
storm700.o
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#define PID_FIXED_POINT_FACTOR (1000)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
@@ -47,10 +47,13 @@
|
||||
|
||||
struct Pid
|
||||
{
|
||||
int iTerm;
|
||||
int Kp; // proportional constant
|
||||
int Ki; // integration constant
|
||||
int Kd; // differential constant
|
||||
int input_d1; // Input t-1
|
||||
int iMin;
|
||||
int iMax;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
@@ -73,7 +76,7 @@ struct Pid
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd);
|
||||
extern ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd, int iMin, int iMax);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -81,6 +84,7 @@ extern ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd);
|
||||
* Calculate
|
||||
*
|
||||
* @param self The PID object
|
||||
* @param input The input
|
||||
* @param error the error input to calculate
|
||||
*
|
||||
* @return int calculated value
|
||||
@@ -88,6 +92,6 @@ extern ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd);
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern int PID_calculate(struct Pid* self, int error);
|
||||
extern int PID_calculate(struct Pid* self, int input, int error);
|
||||
|
||||
#endif /* INC_PID_H_ */
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "PID.h"
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -55,17 +57,29 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd)
|
||||
ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd, int iMin, int iMax)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if (!self->initialized)
|
||||
{
|
||||
self->Kd = Kd;
|
||||
self->Ki = Ki;
|
||||
self->Kp = Kp;
|
||||
self->input_d1 = 0;
|
||||
self->initialized = true;
|
||||
|
||||
if ((Kp >= 0) && (Ki >= 0) && (Kd >= 0))
|
||||
{
|
||||
self->iTerm = 0;
|
||||
self->Kd = Kd;
|
||||
self->Ki = Ki;
|
||||
self->Kp = Kp;
|
||||
self->input_d1 = 0;
|
||||
self->iMin = iMin;
|
||||
self->iMax = iMax;
|
||||
|
||||
self->initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -75,18 +89,45 @@ ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd)
|
||||
}
|
||||
|
||||
|
||||
int PID_calculate(struct Pid* self, int error)
|
||||
int PID_calculate(struct Pid* self, int input, int error)
|
||||
{
|
||||
int returnValue = 0;
|
||||
|
||||
int dTerm;
|
||||
int pTerm;
|
||||
|
||||
input *= PID_FIXED_POINT_FACTOR;
|
||||
error *= PID_FIXED_POINT_FACTOR;
|
||||
|
||||
if (self->initialized)
|
||||
{
|
||||
// Calculate integral
|
||||
self->iTerm += (self->Ki * error);
|
||||
// Control integrator
|
||||
if (self->iTerm > self->iMax)
|
||||
{
|
||||
self->iTerm = self->iMax;
|
||||
}
|
||||
else if(self->iTerm < self->iMin)
|
||||
{
|
||||
self->iTerm = self->iMin;
|
||||
}
|
||||
|
||||
// Calculate differential
|
||||
dTerm = (input - self->input_d1) * self->Kd;
|
||||
|
||||
// Calculate proportional
|
||||
pTerm = self->Kp * error;
|
||||
|
||||
|
||||
returnValue = (self->iTerm + dTerm + pTerm) / PID_FIXED_POINT_FACTOR;
|
||||
self->input_d1 = input;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = 0;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user