Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1276 → Rev 1277

/beta/Code Redesign killagreg/fc.c
1588,7 → 1588,7
static uint8_t HeightTrimmingFlag = 0x00;
 
HooverGas = (int16_t)(HooverGasEstimation/HOOVER_GAS_AVERAGE);
#define HEIGHT_CONTROL_STICKTHRESHOLD 25 * STICK_GAIN
#define HEIGHT_CONTROL_STICKTHRESHOLD 15 * STICK_GAIN
 
if(MKFlags & MKFLAG_FLY) // trim setpoint only when flying
{ // gas stick is above hoover point
1600,7 → 1600,7
SetPointHeight = ReadingHeight; // update setpoint to current heigth
}
HeightTrimmingFlag |= HEIGHT_TRIM_UP;
HeightTrimming += abs(GasMixFraction - (HooverGas - HEIGHT_CONTROL_STICKTHRESHOLD))/STICK_GAIN;
HeightTrimming += abs(GasMixFraction - (HooverGas + HEIGHT_CONTROL_STICKTHRESHOLD))/STICK_GAIN;
} // gas stick is below hoover point
else if(GasMixFraction < (HooverGas - HEIGHT_CONTROL_STICKTHRESHOLD) )
{
1632,8 → 1632,23
 
if(HooverGas == 0) HeightControlGas = GasMixFraction; // take stick gas
else HeightControlGas = HooverGas; // take hoover gas
#else // Holger original version
// start of height control algorithm
// the height control is only an attenuation of the actual gas stick.
// I.e. it wikll work only if tha gas stiock is heiger than the hover gas
// and the hover height will be allways larger than height setpoint.
if((ReadingHeight > SetPointHeight) && HeightControlActive && !(MKFlags & MKFLAG_EMERGENCY_LANDING))
{
HeightControlGas = GasMixFraction; // take stick gas
#endif // from this point the Heigth Control is identical
HeightControlGas -= ((int16_t)(ReadingHeight - SetPointHeight) * (int16_t)FCParam.HeightP) / 16; // p-part
HeightControlGas -= (FCParam.HeightD * ReadingVario) / 128; // d-part
// quadratic scaling to ReadingVario in the D-Part
int16_t vario;
vario = ReadingVario / 8;
if(vario > 8) vario = 8; // limit quadratic part on upward movement to avoid to much gas reduction
if(vario > 0) vario = ReadingVario + (vario * vario) / 4;
else vario = ReadingVario - (vario * vario) / 4;
HeightControlGas -= (FCParam.HeightD * (int32_t)(vario)) / 128L; // d-part
// acceleration sensor effect
tmp_int = ((ReadingIntegralTop / 128) * (int32_t) FCParam.Height_ACC_Effect) / (128 / STICK_GAIN);
LIMIT_MIN_MAX(tmp_int, -(70 * STICK_GAIN), 70 * STICK_GAIN); // limit acceleration sensor effect
1655,34 → 1670,7
// set GasMixFraction to HeightControlGasFilter
GasMixFraction = FilterHeightControlGas;
}// EOF height control active
#else // Holger original version
// start of height control algorithm
// the height control is only an attenuation of the actual gas stick.
// I.e. it wikll work only if tha gas stiock is heiger than the hover gas
// and the hover height will be allways larger than height setpoint.
if((ReadingHeight > SetPointHeight) && HeightControlActive && !(MKFlags & MKFLAG_EMERGENCY_LANDING))
{
HeightControlGas = GasMixFraction; // take stick gas
HeightControlGas -= ((int16_t)(ReadingHeight - SetPointHeight) * (int16_t)FCParam.HeightP) / 16; // p-part
HeightControlGas -= (FCParam.HeightD * ReadingVario) / 128; // d-part
// acceleration sensor effect
tmp_int = ((ReadingIntegralTop / 128) * (int32_t) FCParam.Height_ACC_Effect) / (128 / STICK_GAIN);
LIMIT_MIN_MAX(tmp_int, -(70 * STICK_GAIN), 70 * STICK_GAIN); // limit acceleration sensor effect
HeightControlGas -= tmp_int; // acc-part
 
// update height control gas averaging
FilterHeightControlGas = (FilterHeightControlGas * (HEIGHT_CONTROL_GAS_AVERAGE - 1) + HeightControlGas) / HEIGHT_CONTROL_GAS_AVERAGE;
// never lower than height min gas setting
LIMIT_MIN(FilterHeightControlGas, ParamSet.HeightMinGas * STICK_GAIN);
// never higher than gas stick (maybe lower than height min gas)
LIMIT_MAX(FilterHeightControlGas, GasMixFraction);
// set GasMixFraction to HeightControlGasFilter
GasMixFraction = FilterHeightControlGas;
}// EOF height control active
#endif
 
 
 
// Hoover gas estimation by averaging gas control output on small z-velocities
// this is done only if height contol option is selected in global config and aircraft is flying
if((MKFlags & MKFLAG_FLY) && !(MKFlags & MKFLAG_EMERGENCY_LANDING))
1699,9 → 1687,9
HooverGasEstimation -= HooverGasEstimation/HOOVER_GAS_AVERAGE;
HooverGasEstimation += tmp_long3;
}
DebugOut.Analog[16] = HooverGasEstimation/HOOVER_GAS_AVERAGE;
}
}// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL
 
// limit gas to parameter setting
LIMIT_MIN(GasMixFraction, (ParamSet.GasMin + 10) * STICK_GAIN);
LIMIT_MAX(GasMixFraction, (ParamSet.GasMax - 20) * STICK_GAIN);
/beta/Code Redesign killagreg/makefile
5,7 → 5,7
#-------------------------------------------------------------------
VERSION_MAJOR = 0
VERSION_MINOR = 75
VERSION_PATCH = 4
VERSION_PATCH = 5
 
VERSION_SERIAL_MAJOR = 10 # Serial Protocol Major Version
VERSION_SERIAL_MINOR = 1 # Serial Protocol Minor Version
/beta/Code Redesign killagreg/rc.c
124,12 → 124,12
/********************************************************************/
/* t-Frame
<----------------------------------------------------------------------->
____ ______ _____ ________ ______ sync gap ____
| | | | | | | | | | |
| | | | | | | | | | |
___| |_| |_| |_| |_.............| |________________|
<-----><-------><------><--------> <------> <---
t0 t1 t2 t4 tn t0
____ ______ _____ ________ ___ ________________ ____
| | | | | | | | | | | | |
| | | | | | | | | | | sync gap | |
___| |_| |_| |_| |_............_| |_| |_|
<-----><-------><------><--------> <-----> <---
t0 t1 t2 t4 tn t0
 
The PPM-Frame length is 22.5 ms.
Channel high pulse width range is 0.7 ms to 1.7 ms completed by an 0.3 ms low pulse.
147,6 → 147,7
static uint8_t index = 1;
static uint8_t okay_cnt = 0;
static uint16_t oldICR1 = 0;
static int16_t old_ppm_in[MAX_CHANNELS];
static int16_t ppm_in[MAX_CHANNELS];
static int16_t ppm_diff[MAX_CHANNELS];
 
165,21 → 166,28
// if a sync gap happens and there where at least 4 channels decoded
// and the number of channes decoded since the last sync gap matches the expectation
// then the NewPpmData flag is reset indicating valid data in the PPM_in[] array.
index--; // no next channel because the sync gap was detected
if(index >= 4 && index == RC_Channels)
{
if(okay_cnt > 5) // at least 5 frames in line ok
if(okay_cnt > 10) // at least 10 frames in line ok
{
for(i=0; i<MAX_CHANNELS; i++)
 
for(i=0; i < MAX_CHANNELS; i++)
{
PPM_in[i]= ppm_in[i];
if(okay_cnt > 30) // at least 30 frames ok
{
old_ppm_in[i] = PPM_in[i]; // backup data
}
PPM_in[i] = ppm_in[i];
PPM_diff[i] = ppm_diff[i];
}
NewPpmData = 0; // Null means NewData for at least the first 4 channels
}
if(okay_cnt < 255) okay_cnt++;
}
} // eof if(index >= 4 && index == RC_Channels)
else if(okay_cnt > 100) okay_cnt = 10;
else okay_cnt = 0;
// store max channels
// store max channels transmitted
if(!(MKFlags & MKFLAG_MOTOR_RUN)) RC_Channels = index;
// reset channel index
index = 1;
197,8 → 205,9
// check for stable signal
if(abs(signal - ppm_in[index]) < 6)
{
if(RC_Quality < 200) RC_Quality +=10;
else RC_Quality = 200;
if(okay_cnt > 25) RC_Quality +=10;
else if(okay_cnt > 10) RC_Quality += 2;
if(RC_Quality > 200) RC_Quality = 200;
}
// calculate exponential history for signal
tmp = (3 * (ppm_in[index]) + signal) / 4;
222,12 → 231,22
}
index++; // next channel
}
else// (index > MAX_CHANNELS)
else // (index >= MAX_CHANNELS)
{
RED_ON;
}
}
DebugOut.Analog[23] = okay_cnt;
if(index == MAX_CHANNELS)
{
for(i = 0; i < MAX_CHANNELS; i++)
{
PPM_in[i] = old_ppm_in[i]; // restore old valid values
PPM_diff[i] = 0;
}
index++;
}
} // eof (index >= MAX_CHANNELS)
} // eof within the PPM frame
DebugOut.Analog[16] = okay_cnt;
DebugOut.Analog[17] = PPM_in[2];
}
 
 
/beta/Code Redesign killagreg/uart0.c
143,8 → 143,8
"Motor Rear ",
"Motor Left ",
"Motor Right ", //15
"Hoover Gas ",
" ",
" ",
"Vario ",
"CompassCalState ",
"NickServo ", //20
/beta/Code Redesign killagreg/version.txt
289,9 → 289,14
- LED-Blinken kann an die Motoren gekoppelt werden
- Feinabstimmung des Höhenreglers
 
Anpassungen bzgl. V0.75e
G.Stobrawa 18.8.2009:
0.75f H.Buss 27.8.2009
- D-Anteil des Höhenreglers jetzt mit Quadratischer Komponente
- Lagewinkel wirkt jetzt mit 1/Cos(x) mit in den Höhenregler
- leichte Modifikation der RC-Empfangroutine
 
Anpassungen bzgl. V0.75f
G.Stobrawa 27.8.2009:
 
- Code stärker modularisiert und restrukturiert
- viele Kommentare zur Erklärug eingefügt
- konsequent englische Variablennamen