Check in the PID controller to avoid unneeded code path

This commit is contained in:
Josh Stewart 2016-06-01 20:39:30 +10:00
parent 4cc3c9e8d2
commit 27e7d249f1
2 changed files with 4 additions and 4 deletions

View File

@ -100,10 +100,9 @@ void triggerPri_missingTooth()
//Begin the missing tooth detection
//If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap
//if ( (curTime - toothLastToothTime) > (1.5 * (toothLastToothTime - toothLastMinusOneToothTime))) { toothCurrentCount = 1; }
if(configPage2.triggerMissingTeeth == 1) { targetGap = (3 * (toothLastToothTime - toothLastMinusOneToothTime)) >> 1; } //Multiply by 1.5 (Checks for a gap 1.5x greater than the last one) (Uses bitshift to multiply by 3 then divide by 2. Much faster than multiplying by 1.5)
//else { targetGap = (10 * (toothLastToothTime - toothLastMinusOneToothTime)) >> 2; } //Multiply by 2.5 (Checks for a gap 2.5x greater than the last one)
else { targetGap = ((toothLastToothTime - toothLastMinusOneToothTime)) * 2; } //Multiply by 2 (Checks for a gap 2x greater than the last one)
if ( curGap > targetGap || toothCurrentCount > triggerActualTeeth)
{
toothCurrentCount = 1;

View File

@ -270,7 +270,7 @@ bool integerPID::Compute()
void integerPID::SetTunings(byte Kp, byte Ki, byte Kd)
{
if (Kp<0 || Ki<0 || Kd<0) return;
if ( dispKp == Kp && dispKi == Ki && dispKd == Kd ) return; //Only do anything if one of the values has changed
dispKp = Kp; dispKi = Ki; dispKd = Kd;
/*
@ -284,7 +284,7 @@ void integerPID::SetTunings(byte Kp, byte Ki, byte Kd)
ki = (long)((long)Ki * 1000) / InverseSampleTimeInSec;
kd = ((long)Kd * InverseSampleTimeInSec) / 100;
if(controllerDirection ==REVERSE)
if(controllerDirection == REVERSE)
{
kp = (0 - kp);
ki = (0 - ki);
@ -297,6 +297,7 @@ void integerPID::SetTunings(byte Kp, byte Ki, byte Kd)
******************************************************************************/
void integerPID::SetSampleTime(int NewSampleTime)
{
if (SampleTime == (unsigned long)NewSampleTime) return; //If new value = old value, no action required.
if (NewSampleTime > 0)
{
unsigned long ratioX1000 = (unsigned long)(NewSampleTime * 1000) / (unsigned long)SampleTime;