Tracking down compile errors.

This commit is contained in:
Chris Giacofei 2024-05-01 16:13:35 -04:00
parent b3255d94d4
commit d565cded53
2 changed files with 30 additions and 34 deletions

View File

@ -102,7 +102,7 @@ int PID::ComputeTune() {
} }
unsigned long now = millis(); unsigned long now = millis();
if((now-lastTime)<sampleTime) return false; if((now-lastTime)<SampleTime) return false;
lastTime = now; lastTime = now;
double refVal = *myInput; double refVal = *myInput;
@ -118,10 +118,7 @@ int PID::ComputeTune() {
autotune_running = true; autotune_running = true;
outputStart = *myOutput; outputStart = *myOutput;
*myOutput = outputStart+oStep; *myOutput = outputStart+oStep;
} else { } else {
if(refVal>absMax)absMax=refVal;
if(refVal<absMin)absMin=refVal;
} else {
if(refVal>absMax)absMax=refVal; if(refVal>absMax)absMax=refVal;
if(refVal<absMin)absMin=refVal; if(refVal<absMin)absMin=refVal;
} }
@ -222,7 +219,7 @@ void PID::SetTunings(double Kp, double Ki, double Kd){
/* 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::SampleTime(int NewSampleTime){ void PID::SetSampleTime(int NewSampleTime){
if (NewSampleTime > 0){ if (NewSampleTime > 0){
double ratio = (double)NewSampleTime double ratio = (double)NewSampleTime
/ (double)SampleTime; / (double)SampleTime;
@ -309,30 +306,30 @@ void PID::Direction(int Direction){
* functions query the internal state of the PID. they're here for display * functions query the internal state of the PID. they're here for display
* purposes. this are the functions the PID Front-end uses for example * purposes. this are the functions the PID Front-end uses for example
******************************************************************************/ ******************************************************************************/
double PID::Kp(){ return Kp; } double PID::Kp(){ return kp; }
double PID::Ki(){ return Ki;} double PID::Ki(){ return ki;}
double PID::Kd(){ return Kd;} double PID::Kd(){ return kd;}
int PID::Mode(){ return OpMode;} modes PID::Mode(){ return OpMode;}
int PID::Direction(){ return controllerDirection;} int PID::Direction(){ return controllerDirection;}
void PID::Cancel(){ autotune_running = false;} void PID::Cancel(){ autotune_running = false;}
double PID::TunedKp(){ return 0.6 * Ku;} double PID::TunedKp(){ return 0.6 * Ku;}
double PID::TunedKi(){ return 1.2*Ku / Pu ; // Ki = Kc/Ti} double PID::TunedKi(){ return 1.2*Ku / Pu ;} // Ki = Kc/Ti}
double PID::TunedKd(){ return 0.075 * Ku * Pu; //Kd = Kc * Td} double PID::TunedKd(){ return 0.075 * Ku * Pu;} //Kd = Kc * Td}
void PID::SetOutputStep(double Step){ oStep = Step;} void PID::OutputStep(double Step){ oStep = Step;}
double PID::GetOutputStep(){ return oStep;} double PID::OutputStep(){ return oStep;}
void PID::SetNoiseBand(double Band){ noise_band = Band;} void PID::NoiseBand(double Band){ noise_band = Band;}
double PID::GetNoiseBand(){ return noise_band;} double PID::NoiseBand(){ return noise_band;}
void PID::LookbackSec(int value){ void PID::LookbackSec(int value){
if (value<1) value = 1; if (value<1) value = 1;
if(value<25) { if(value<25) {
nLookBack = value * 4; nLookBack = value * 4;
sampleTime = 250; SampleTime = 250;
} else { } else {
nLookBack = 100; nLookBack = 100;
sampleTime = value*10; SampleTime = value*10;
} }
} }
int PID::LookbackSec(){ return nLookBack * sampleTime / 1000;} int PID::LookbackSec(){ return nLookBack * SampleTime / 1000;}

View File

@ -46,7 +46,7 @@ class PID
// 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 SampleTime(int); // * sets the frequency, in Milliseconds, with which void SetSampleTime(int); // * sets the frequency, in Milliseconds, with which
// the PID calculation is performed. default is 100 // the PID calculation is performed. default is 100
//Display functions **************************************************************** //Display functions ****************************************************************
@ -59,14 +59,14 @@ class PID
// Auto Tune Public // Auto Tune Public
void Cancel(); // * Stops the AutoTune void Cancel(); // * Stops the AutoTune
void SetOutputStep(double); // * how far above and below the starting value will the output step? void OutputStep(double); // * how far above and below the starting value will the output step?
double GetOutputStep(); // double OutputStep(); //
void LookbackSec(int); // * how far back are we looking to identify peaks void LookbackSec(int); // * how far back are we looking to identify peaks
int LookbackSec(); // int LookbackSec(); //
void SetNoiseBand(double); // * the autotune will ignore signal chatter smaller than this value void NoiseBand(double); // * the autotune will ignore signal chatter smaller than this value
double GetNoiseBand(); // this should be acurately set double NoiseBand(); // this should be acurately set
double TunedKp(); // * once autotune is complete, these functions contain the double TunedKp(); // * once autotune is complete, these functions contain the
double TunedKi(); // computed tuning parameters. double TunedKi(); // computed tuning parameters.
@ -90,7 +90,6 @@ class PID
unsigned long lastTime; unsigned long lastTime;
double outputSum, lastInput; double outputSum, lastInput;
unsigned long SampleTime;
double outMin, outMax; double outMin, outMax;
bool inAuto, pOnE; bool inAuto, pOnE;
modes OpMode; modes OpMode;
@ -101,7 +100,7 @@ class PID
double noise_band; double noise_band;
bool autotune_running; bool autotune_running;
unsigned long peak1, peak2; unsigned long peak1, peak2;
int sampleTime; int SampleTime;
int nLookBack; int nLookBack;
int peakType; int peakType;
double lastInputs[101]; double lastInputs[101];