Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1327 → Rev 1328

/trunk/fc.c
156,6 → 156,7
unsigned char RequiredMotors = 4;
unsigned char Motor[MAX_MOTORS];
signed int tmp_motorwert[MAX_MOTORS];
unsigned char LoadHandler = 0;
#define LIMIT_MIN(value, min) {if(value < min) value = min;}
#define LIMIT_MAX(value, max) {if(value > max) value = max;}
#define LIMIT_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;}
555,8 → 556,8
static long ausgleichNick, ausgleichRoll;
int IntegralNickMalFaktor,IntegralRollMalFaktor;
unsigned char i;
if(--LoadHandler == 0) LoadHandler = 5; // verteilt die Prozessorlast
Mittelwert();
 
GRN_ON;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Gaswert ermitteln
724,7 → 725,6
else delay_ausschalten = 0;
}
}
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// neue Werte von der Funke
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
969,31 → 969,14
Mess_IntegralNick2 -= IntegralFehlerNick;
Mess_IntegralRoll2 -= IntegralFehlerRoll;
 
// IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
// IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
if(EE_Parameter.Driftkomp)
{
if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
}
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
//DebugOut.Analog[24] = GierGyroFehler;
GierGyroFehler = 0;
 
 
/*DebugOut.Analog[17] = IntegralAccNick / 26;
DebugOut.Analog[18] = IntegralAccRoll / 26;
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
*/
//DebugOut.Analog[21] = MittelIntegralNick / 26;
//MittelIntegralRoll = MittelIntegralRoll;
//DebugOut.Analog[28] = ausgleichNick;
/*
DebugOut.Analog[29] = ausgleichRoll;
DebugOut.Analog[30] = LageKorrekturRoll * 10;
*/
 
#define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2)
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1190,7 → 1173,7
//DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
DebugOut.Analog[18] = VarioMeter;
DebugOut.Analog[19] = WinkelOut.CalcState;
DebugOut.Analog[20] = ServoValue;
DebugOut.Analog[20] = ServoNickValue;
// DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ;
// DebugOut.Analog[24] = MesswertNick/2;
// DebugOut.Analog[25] = MesswertRoll/2;
1201,7 → 1184,6
DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
DebugOut.Analog[30] = GPS_Nick;
DebugOut.Analog[31] = GPS_Roll;
 
}
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1237,17 → 1219,18
if(UBat > BattLowVoltageWarning) GasMischanteil = (GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen
GasMischanteil *= STICK_GAIN;
 
DebugOut.Analog[16] = BaroExpandActive;
// if height control is activated
J4High;
if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung
{
#define HOOVER_GAS_AVERAGE 4096L // 4096 * 2ms = 8.2s averaging
#define HC_GAS_AVERAGE 4 // 4 * 2ms= 8 ms averaging
// #define HOOVER_GAS_AVERAGE 4096L // 4096 * 2ms = 8.2s averaging
#define HOOVER_GAS_AVERAGE 1024L // 1024 * 10ms = 10s averaging
#define HC_GAS_AVERAGE 2 // 2 * 10ms= 20ms averaging
#define OPA_OFFSET_STEP 10
int HCGas, HeightDeviation;
static int HeightTrimming = 0; // rate for change of height setpoint
static int FilterHCGas = 0;
static int StickGasHoover = 120, HooverGas = 0, HooverGasMin = 0, HooverGasMax = 1023;
static int StickGasHoover = 120, HooverGas = 0, HooverGasMin = 0, HooverGasMax = 1023, LastHCGas = 0;
static unsigned long HooverGasFilter = 0;
static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
int CosAttitude; // for projection of hoover gas
1254,26 → 1237,11
long tmp_long3;
// const unsigned char GAS_TAB[31] = {128,128,128,129,129,130,131,132,133,135,136,138,140,142,145,148,151,154,158,162,167,172,178,184,191,199,208,218,229,241,255};
// get the current hooverpoint
if(LoadHandler == 1)
{
DebugOut.Analog[21] = HooverGas;
DebugOut.Analog[18] = VarioMeter;
 
// if height control is activated by an rc channel
if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert
{ // check if parameter is less than activation threshold
if(Parameter_MaxHoehe < 50) // for 3 or 2-state switch height control is disabled in lowest position
{ //height control not active
if(!delay--)
{
HoehenReglerAktiv = 0; // disable height control
SollHoehe = HoehenWert; // update SetPoint with current reading
delay = 1;
}
}
else
{ //height control is activated
HoehenReglerAktiv = 1; // enable height control
delay = 200;
}
// Expand the measurement
// measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs
if(!BaroExpandActive)
1285,8 → 1253,7
ExpandBaro -= 1;
OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down
beeptime = 300;
delay = 250;
BaroExpandActive = 250;
BaroExpandActive = 50;
}
else
{
1302,8 → 1269,7
ExpandBaro += 1;
OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up
beeptime = 300;
delay = 250;
BaroExpandActive = 250;
BaroExpandActive = 50;
}
else
{
1323,6 → 1289,24
VarioMeter = 0;
BaroExpandActive--;
}
 
// if height control is activated by an rc channel
if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert
{ // check if parameter is less than activation threshold
if(Parameter_MaxHoehe < 50) // for 3 or 2-state switch height control is disabled in lowest position
{ //height control not active
if(!delay--)
{
HoehenReglerAktiv = 0; // disable height control
SollHoehe = HoehenWert; // update SetPoint with current reading
delay = 1;
}
}
else
{ //height control is activated
HoehenReglerAktiv = 1; // enable height control
delay = 40;
}
}
else // no switchable height control
{
1331,15 → 1315,16
}
 
// calculate cos of nick and roll angle used for projection of the vertical hoover gas
J4Low;
tmp_long = IntegralNick/GIER_GRAD_FAKTOR; // nick angle in deg
tmp_long *= tmp_long;
tmp_long2 = IntegralRoll/GIER_GRAD_FAKTOR; // roll angle in deg
tmp_long2 *= tmp_long2;
 
CosAttitude = (int16_t)c_sqrt(tmp_long + tmp_long2); // phytagoras gives effective attitude angle in deg
DebugOut.Analog[16] = CosAttitude;
LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle
CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude
J4High;
if(HoehenReglerAktiv && !(MikroKopterFlags & FLAG_NOTLANDUNG))
{
#define HEIGHT_TRIM_UP 0x01
1396,9 → 1381,9
}
}
// Trim height set point
if(abs(HeightTrimming) > 512)
if(abs(HeightTrimming) > 256)
{
SollHoehe += (HeightTrimming * EE_Parameter.Hoehe_Verstaerkung)/(5 * 512 / 2); // move setpoint
SollHoehe += (HeightTrimming * EE_Parameter.Hoehe_Verstaerkung)/(512 / 2); // move setpoint
HeightTrimming = 0;
if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 75;
//update hoover gas stick value when setpoint is shifted
1411,7 → 1396,8
else
{
SollHoehe = HoehenWert - 400;
StickGasHoover = 120;
if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHoover = EE_Parameter.Hoehe_StickNeutralPoint;
else StickGasHoover = 120;
}
HCGas = HooverGas; // take hoover gas (neutral point)
}
1434,7 → 1420,7
tmp_int = ((Mess_Integral_Hoch / 128) * (long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
LIMIT_MIN_MAX(tmp_int, -127, 255);
HCGas -= tmp_int;
 
// limit deviation from hoover point within the target region
if( (abs(HeightDeviation) < 150) && (!HeightTrimming) && (HooverGas > 0)) // height setpoint is not changed and hoover gas not zero
{
1476,6 → 1462,7
else StickGasHoover = EE_Parameter.Hoehe_StickNeutralPoint;
if(StickGasHoover < 70) StickGasHoover = 70;
else if(StickGasHoover > 150) StickGasHoover = 150;
FilterHCGas = GasMischanteil;
}
 
// Hoover gas estimation by averaging gas control output on small z-velocities
1525,9 → 1512,15
}
}
}
DebugOut.Analog[25] = HooverGas;
LastHCGas = GasMischanteil;
}
else
{
GasMischanteil = LastHCGas;
}
//DebugOut.Analog[26] = HooverGasMax;
}// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL
J4Low;
 
// limit gas to parameter setting
LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN);
/trunk/flight.pnproj
1,0 → 0,0
<Project name="Flight-Ctrl"><File path="uart.h"></File><File path="main.c"></File><File path="main.h"></File><File path="makefile"></File><File path="uart.c"></File><File path="printf_P.h"></File><File path="printf_P.c"></File><File path="timer0.c"></File><File path="timer0.h"></File><File path="old_macros.h"></File><File path="twimaster.c"></File><File path="version.txt"></File><File path="twimaster.h"></File><File path="rc.c"></File><File path="rc.h"></File><File path="fc.h"></File><File path="menu.h"></File><File path="menu.c"></File><File path="_Settings.h"></File><File path="analog.c"></File><File path="analog.h"></File><File path="GPS.c"></File><File path="gps.h"></File><File path="License.txt"></File><File path="eeprom.c"></File><File path="spi.h"></File><File path="spi.c"></File><File path="led.h"></File><File path="led.c"></File><File path="fc.c"></File><File path="Spectrum.c"></File><File path="Spectrum.h"></File></Project>
<Project name="Flight-Ctrl"><File path="uart.h"></File><File path="main.c"></File><File path="main.h"></File><File path="makefile"></File><File path="uart.c"></File><File path="printf_P.h"></File><File path="printf_P.c"></File><File path="timer0.c"></File><File path="timer0.h"></File><File path="old_macros.h"></File><File path="twimaster.c"></File><File path="version.txt"></File><File path="twimaster.h"></File><File path="rc.c"></File><File path="rc.h"></File><File path="fc.h"></File><File path="menu.h"></File><File path="menu.c"></File><File path="_Settings.h"></File><File path="analog.c"></File><File path="analog.h"></File><File path="GPS.c"></File><File path="gps.h"></File><File path="License.txt"></File><File path="eeprom.c"></File><File path="spi.h"></File><File path="spi.c"></File><File path="led.h"></File><File path="led.c"></File><File path="fc.c"></File><File path="Spectrum.c"></File><File path="Spectrum.h"></File><File path="mymath.c"></File><File path="mymath.h"></File></Project>
/trunk/led.c
17,7 → 17,6
J17Blinkcount = 0; J17Mask = 128;
}
 
 
// called in UpdateMotors() every 2ms
void LED_Update(void)
{
40,7 → 39,7
J17Bitmask = EE_Parameter.J17Bitmask;
}
 
if((EE_Parameter.J16Timing > 250) && (Parameter_J16Timing > 230) || (EE_Parameter.BitConfig & CFG_MOTOR_BLINK && !MotorenEin)) {if(J16Bitmask & 128) J16_ON; else J16_OFF;}
if(((EE_Parameter.J16Timing > 250) && (Parameter_J16Timing > 230)) || (EE_Parameter.BitConfig & CFG_MOTOR_BLINK && !MotorenEin)) {if(J16Bitmask & 128) J16_ON; else J16_OFF;}
else
if((EE_Parameter.J16Timing > 250) && (Parameter_J16Timing < 10)) {if(J16Bitmask & 128) J16_OFF; else J16_ON;}
else
50,7 → 49,7
if(J16Mask == 1) J16Mask = 128; else J16Mask /= 2;
if(J16Mask & J16Bitmask) J16_ON; else J16_OFF;
}
if((EE_Parameter.J17Timing > 250) && (Parameter_J17Timing > 230) || (EE_Parameter.BitConfig & CFG_MOTOR_BLINK && !MotorenEin)) {if(J17Bitmask & 128) J17_ON; else J17_OFF;}
if(((EE_Parameter.J17Timing > 250) && (Parameter_J17Timing > 230)) || (EE_Parameter.BitConfig & CFG_MOTOR_BLINK && !MotorenEin)) {if(J17Bitmask & 128) J17_ON; else J17_OFF;}
else
if((EE_Parameter.J17Timing > 250) && (Parameter_J17Timing < 10)) {if(J17Bitmask & 128) J17_OFF; else J17_ON;}
else
/trunk/main.c
347,9 → 347,11
if(UpdateMotor && AdReady) // ReglerIntervall
{
UpdateMotor=0;
J3High;
if(WinkelOut.CalcState) CalMk3Mag();
else MotorRegler();
SendMotorData();
J3Low;
ROT_OFF;
if(SenderOkay) SenderOkay--;
else TIMSK1 |= _BV(ICIE1); // enable PPM-Input
/trunk/makefile
5,7 → 5,7
#-------------------------------------------------------------------
VERSION_MAJOR = 0
VERSION_MINOR = 75
VERSION_PATCH = 13
VERSION_PATCH = 14
 
VERSION_SERIAL_MAJOR = 10 # Serial Protocol
VERSION_SERIAL_MINOR = 1 # Serial Protocol
/trunk/menu.c
135,7 → 135,7
case 10:
LCD_printfxy(0,0,"Servo " );
LCD_printfxy(0,1,"Setpoint %3i",Parameter_ServoNickControl);
LCD_printfxy(0,2,"Stellung: %3i",ServoValue);
LCD_printfxy(0,2,"Stellung: %3i",ServoNickValue);
LCD_printfxy(0,3,"Range:%3i-%3i",EE_Parameter.ServoNickMin,EE_Parameter.ServoNickMax);
break;
case 11:
/trunk/mymath.c
102,3 → 102,24
return (root >> 1);
}
 
uint16_t c_sqrt_int(uint16_t a)
{
uint16_t rem = 0;
uint16_t root = 0;
uint8_t i;
for(i = 0; i < 16; i++)
{
root <<= 1;
rem = ((rem << 2) + (a >> 30));
a <<= 2;
root++;
if(root <= rem)
{
rem -= root;
root++;
}
else root--;
}
return (root >> 1);
}
 
/trunk/mymath.h
7,5 → 7,5
extern int16_t c_cos_8192(int16_t angle);
extern int16_t c_atan2(int16_t y, int16_t x);
extern uint32_t c_sqrt(uint32_t a);
 
extern uint16_t c_sqrt_int(uint16_t a);
#endif // _MYMATH_H
/trunk/rc.c
156,8 → 156,6
}
}
}
DebugOut.Analog[16] = okay_cnt;
DebugOut.Analog[17] = PPM_in[2];
}
}
 
/trunk/timer0.c
9,7 → 9,6
volatile unsigned char SendSPI = 0, ServoActive = 0;
 
unsigned int BeepMuster = 0xffff;
int ServoValue = 0;
 
volatile int16_t ServoNickValue = 0;
volatile int16_t ServoRollValue = 0;
253,7 → 252,6
RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position
 
ServoNickValue /= MULTIPLYER;
DebugOut.Analog[20] = ServoNickValue;
 
// range servo pulse width
if(RemainingPulse > MAXSERVOPULSE ) RemainingPulse = MAXSERVOPULSE; // upper servo pulse limit
315,7 → 313,6
}
RemainingPulse += ServoNickValue - (256 / 2) * MULTIPLYER; // shift ServoNickValue to center position
ServoNickValue /= MULTIPLYER;
DebugOut.Analog[20] = ServoNickValue;
break;
case 2: // Roll Compensation Servo
ServoRollOffset = (ServoRollOffset * 3 + (int16_t) Parameter_ServoRollControl * MULTIPLYER) / 4; // lowpass offset
/trunk/timer0.h
15,6 → 15,7
extern volatile unsigned char UpdateMotor;
extern volatile unsigned int beeptime;
extern volatile unsigned int cntKompass;
extern int ServoValue;
extern unsigned int BeepMuster;
extern volatile unsigned char SendSPI, ServoActive;
extern volatile int16_t ServoNickValue;
extern volatile int16_t ServoRollValue;
/trunk/version.txt
274,7 → 274,7
- Bugfix Messbereichsumschaltung des Luftdrucksensors springt
- Auflösung des Luftdrucks nun bis auf 1 cm (5mal feiner) zur genaueren Berechnung des D-Anteils
- Unterstützung von Warnings-Bitmasks für die J16, J17-Outputs bei Unterspannung
- Unterspannung für einezelne Zelle´n von 3.2V auf 3.3V angehoben (9.6V --> 9.9V für 3S)
- Unterspannung für einzelne Zelle´n von 3.2V auf 3.3V angehoben (9.6V --> 9.9V für 3S)
0.75d H.Buss 13.8.2009
- RC-Routine: Empfangsausfall soll sicherer erkannt werden
321,3 → 321,7
- Baro-Messbereichserweiterung auch bei aktiviertem Höhenregler
- Gyro_Gier_P und Gyro_Gier_I eingeführt
- I2C_fehler-Zähler jetzt in den Analogdaten
 
0.75o H.Buss 01.10.2009
- der Höhenregler wird jetzt nur alle 10ms bearbeitet
- Baro-Messbereichserweiterung auch bei Poti als Sollwert