Renaming PID struct typedef to avoid conflicts
This commit is contained in:
parent
261c37a0db
commit
71fe8e7ced
|
@ -9,13 +9,13 @@
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
#include "osal.h"
|
#include "osal.h"
|
||||||
|
|
||||||
#define TIME_MS (osalOsGetSystemTimeX() / (OSAL_ST_FREQUENCY / 1000))
|
#define TIME_MS ((osalOsGetSystemTimeX() * 1000) / OSAL_ST_FREQUENCY )
|
||||||
|
|
||||||
/*Constructor (...)*********************************************************
|
/*Constructor (...)*********************************************************
|
||||||
* The parameters specified here are those for for which we can't set up
|
* The parameters specified here are those for for which we can't set up
|
||||||
* reliable defaults, so we need to have the user set them.
|
* reliable defaults, so we need to have the user set them.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void pid_create(pid_t* p, float* Input, float* Output, float* Setpoint,
|
void pid_create(pidc_t* p, float* Input, float* Output, float* Setpoint,
|
||||||
float Kp, float Ki, float Kd, int POn, int Direction)
|
float Kp, float Ki, float Kd, int POn, int Direction)
|
||||||
{
|
{
|
||||||
p->output = Output;
|
p->output = Output;
|
||||||
|
@ -23,8 +23,8 @@ void pid_create(pid_t* p, float* Input, float* Output, float* Setpoint,
|
||||||
p->setPoint = Setpoint;
|
p->setPoint = Setpoint;
|
||||||
p->inAuto = false;
|
p->inAuto = false;
|
||||||
|
|
||||||
pid_setOutputLimits(p, 0, 255); // default output limit corresponds to
|
pid_setOutputLimits(p, 0, 4095); // default output limit corresponds to
|
||||||
// the arduino pwm limits
|
// the 12 bit dac limit
|
||||||
|
|
||||||
p->sampleTime = 100; // default Controller Sample Time is 100ms
|
p->sampleTime = 100; // default Controller Sample Time is 100ms
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ void pid_create(pid_t* p, float* Input, float* Output, float* Setpoint,
|
||||||
* pid Output needs to be computed. returns true when the output is computed,
|
* pid Output needs to be computed. returns true when the output is computed,
|
||||||
* false when nothing has been done.
|
* false when nothing has been done.
|
||||||
**********************************************************************************/
|
**********************************************************************************/
|
||||||
bool pid_compute(pid_t* p)
|
bool pid_compute(pidc_t* p)
|
||||||
{
|
{
|
||||||
if(!p->inAuto) return false;
|
if(!p->inAuto) return false;
|
||||||
unsigned long now = TIME_MS;
|
unsigned long now = TIME_MS;
|
||||||
|
@ -86,7 +86,7 @@ bool pid_compute(pid_t* p)
|
||||||
* it's called automatically from the constructor, but tunings can also
|
* it's called automatically from the constructor, but tunings can also
|
||||||
* be adjusted on the fly during normal operation
|
* be adjusted on the fly during normal operation
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void pid_setTunings(pid_t* p, float Kp, float Ki, float Kd, int POn)
|
void pid_setTunings(pidc_t* p, float Kp, float Ki, float Kd, int POn)
|
||||||
{
|
{
|
||||||
if (Kp < 0 || Ki < 0 || Kd < 0) return;
|
if (Kp < 0 || Ki < 0 || Kd < 0) return;
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ void pid_setTunings(pid_t* p, float Kp, float Ki, float Kd, int POn)
|
||||||
/* SetSampleTime(...) *********************************************************
|
/* SetSampleTime(...) *********************************************************
|
||||||
* sets the period, in Milliseconds, at which the calculation is performed
|
* sets the period, in Milliseconds, at which the calculation is performed
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void pid_setSampleTime(pid_t* p, int NewSampleTime)
|
void pid_setSampleTime(pidc_t* p, int NewSampleTime)
|
||||||
{
|
{
|
||||||
if (NewSampleTime > 0)
|
if (NewSampleTime > 0)
|
||||||
{
|
{
|
||||||
|
@ -132,7 +132,7 @@ void pid_setSampleTime(pid_t* p, int NewSampleTime)
|
||||||
* want to clamp it from 0-125. who knows. at any rate, that can all be done
|
* want to clamp it from 0-125. who knows. at any rate, that can all be done
|
||||||
* here.
|
* here.
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
void pid_setOutputLimits(pid_t* p, float Min, float Max)
|
void pid_setOutputLimits(pidc_t* p, float Min, float Max)
|
||||||
{
|
{
|
||||||
if(Min >= Max) return;
|
if(Min >= Max) return;
|
||||||
p->outMin = Min;
|
p->outMin = Min;
|
||||||
|
@ -153,7 +153,7 @@ void pid_setOutputLimits(pid_t* p, float Min, float Max)
|
||||||
* when the transition from manual to auto occurs, the controller is
|
* when the transition from manual to auto occurs, the controller is
|
||||||
* automatically initialized
|
* automatically initialized
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void pid_setMode(pid_t* p, int Mode)
|
void pid_setMode(pidc_t* p, int Mode)
|
||||||
{
|
{
|
||||||
bool newAuto = (Mode == PID_AUTOMATIC);
|
bool newAuto = (Mode == PID_AUTOMATIC);
|
||||||
if(newAuto && !p->inAuto)
|
if(newAuto && !p->inAuto)
|
||||||
|
@ -167,7 +167,7 @@ void pid_setMode(pid_t* p, int Mode)
|
||||||
* does all the things that need to happen to ensure a bumpless transfer
|
* does all the things that need to happen to ensure a bumpless transfer
|
||||||
* from manual to automatic mode.
|
* from manual to automatic mode.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void pid_initialize(pid_t* p)
|
void pid_initialize(pidc_t* p)
|
||||||
{
|
{
|
||||||
p->outputSum = *p->output;
|
p->outputSum = *p->output;
|
||||||
p->lastInput = *p->input;
|
p->lastInput = *p->input;
|
||||||
|
@ -181,7 +181,7 @@ void pid_initialize(pid_t* p)
|
||||||
* know which one, because otherwise we may increase the output when we should
|
* know which one, because otherwise we may increase the output when we should
|
||||||
* be decreasing. This is called from the constructor.
|
* be decreasing. This is called from the constructor.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
void pid_setDirection(pid_t* p, int Direction)
|
void pid_setDirection(pidc_t* p, int Direction)
|
||||||
{
|
{
|
||||||
if(p->inAuto && Direction != p->direction)
|
if(p->inAuto && Direction != p->direction)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,39 +40,39 @@ typedef struct {
|
||||||
bool inAuto;
|
bool inAuto;
|
||||||
bool pOnE;
|
bool pOnE;
|
||||||
|
|
||||||
} pid_t;
|
} pidc_t;
|
||||||
|
|
||||||
|
|
||||||
//commonly used functions **************************************************************************
|
//commonly used functions **************************************************************************
|
||||||
void pid_create(pid_t* p, float* Input, float* Output, float* Setpoint, // * constructor. links the PID to the Input, Output, and
|
void pid_create(pidc_t* p, float* Input, float* Output, float* Setpoint, // * constructor. links the PID to the Input, Output, and
|
||||||
float Kp, float Ki, float Kd, int POn, int Direction); // Setpoint. Initial tuning parameters are also set here.
|
float Kp, float Ki, float Kd, int POn, int Direction); // Setpoint. Initial tuning parameters are also set here.
|
||||||
// (overload for specifying proportional mode)
|
// (overload for specifying proportional mode)
|
||||||
|
|
||||||
void pid_setMode(pid_t* p, int mode); // * sets PID to either Manual (0) or Auto (non-0)
|
void pid_setMode(pidc_t* p, int mode); // * sets PID to either Manual (0) or Auto (non-0)
|
||||||
|
|
||||||
bool pid_compute(pid_t* p); // * performs the PID calculation. it should be
|
bool pid_compute(pidc_t* p); // * performs the PID calculation. it should be
|
||||||
// called every time loop() cycles. ON/OFF and
|
// called every time loop() cycles. ON/OFF and
|
||||||
// calculation frequency can be set using SetMode
|
// calculation frequency can be set using SetMode
|
||||||
// SetsampleTime respectively
|
// SetsampleTime respectively
|
||||||
|
|
||||||
void pid_setOutputLimits(pid_t* p, float Min, float Max); // * clamps the output to a specific range. 0-255 by default, but
|
void pid_setOutputLimits(pidc_t* p, float Min, float Max); // * clamps the output to a specific range. 0-255 by default, but
|
||||||
// it's likely the user will want to change this depending on
|
// it's likely the user will want to change this depending on
|
||||||
// the application
|
// the application
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//available but not commonly used functions ********************************************************
|
//available but not commonly used functions ********************************************************
|
||||||
void pid_setTunings(pid_t* p, float Kp, float Ki, float Kd, int POn); // * While most users will set the tunings once in the
|
void pid_setTunings(pidc_t* p, float Kp, float Ki, float Kd, int POn); // * While most users will set the tunings once in the
|
||||||
// constructor, this function gives the user the option
|
// constructor, this function gives the user the option
|
||||||
// of changing tunings during runtime for Adaptive control
|
// of changing tunings during runtime for Adaptive control
|
||||||
|
|
||||||
void pid_setDirection(pid_t* p, int Direction); // * Sets the Direction, or "Action" of the controller. DIRECT
|
void pid_setDirection(pidc_t* p, int Direction); // * Sets the Direction, or "Action" of the controller. DIRECT
|
||||||
// means the output will increase when error is positive. REVERSE
|
// means the output will increase when error is positive. REVERSE
|
||||||
// means the opposite. it's very unlikely that this will be needed
|
// means the opposite. it's very unlikely that this will be needed
|
||||||
// once it is set in the constructor.
|
// once it is set in the constructor.
|
||||||
void pid_setSampleTime(pid_t* p, int NewSampleTime); // * sets the frequency, in Milliseconds, with which
|
void pid_setSampleTime(pidc_t* p, int NewSampleTime); // * sets the frequency, in Milliseconds, with which
|
||||||
// the PID calculation is performed. default is 100
|
// the PID calculation is performed. default is 100
|
||||||
|
|
||||||
void pid_initialize(pid_t* p);
|
void pid_initialize(pidc_t* p);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue