Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 700 → Rev 701

/branches/V0.68d Code Redesign killagreg/GPS.c
6,22 → 6,22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "main.h"
 
signed int GPS_Nick = 0;
signed int GPS_Pitch = 0;
signed int GPS_Roll = 0;
long GpsAktuell_X = 0;
long GpsAktuell_Y = 0;
long GpsZiel_X = 0;
long GpsZiel_Y = 0;
long GpsReading_X = 0;
long GpsReading_Y = 0;
long GpsTarget_X = 0;
long GpsTarget_Y = 0;
 
void GPS_Neutral(void)
{
GpsZiel_X = GpsAktuell_X;
GpsZiel_Y = GpsAktuell_Y;
GpsTarget_X = GpsReading_X;
GpsTarget_Y = GpsReading_Y;
}
 
void GPS_BerechneZielrichtung(void)
void GPS_CalcTargetDirection(void)
{
GPS_Nick = 0;
GPS_Pitch = 0;
GPS_Roll = 0;
}
 
/branches/V0.68d Code Redesign killagreg/analog.c
15,18 → 15,18
#include "printf_P.h"
#include "eeprom.h"
 
volatile int16_t Current_Nick = 0, Current_Roll = 0, Current_Gier = 0;
volatile int16_t Current_Pitch = 0, Current_Roll = 0, Current_Yaw = 0;
volatile int16_t Current_AccX = 0, Current_AccY = 0, Current_AccZ = 0;
volatile int16_t UBat = 100;
volatile int16_t AdValueGyrNick = 0, AdValueGyrRoll = 0, AdValueGyrGier = 0;
volatile int16_t AdValueAccRoll = 0, AdValueAccNick = 0, AdValueAccTop = 0;
volatile int16_t AdValueGyrPitch = 0, AdValueGyrRoll = 0, AdValueGyrYaw = 0;
volatile int16_t AdValueAccRoll = 0, AdValueAccPitch = 0, AdValueAccTop = 0;
volatile uint8_t messanzahl_AccHoch = 0;
volatile int32_t Luftdruck = 32000;
volatile int16_t StartLuftdruck;
volatile uint16_t MessLuftdruck = 1023;
volatile int32_t AirPressure = 32000;
volatile int16_t StartAirPressure;
volatile uint16_t ReadingAirPressure = 1023;
uint8_t DruckOffsetSetting;
volatile int16_t HoeheD = 0;
volatile int16_t tmpLuftdruck;
volatile int16_t tmpAirPressure;
volatile uint16_t ZaehlMessungen = 0;
 
/*****************************************************/
59,7 → 59,7
SREG = sreg;
}
 
void SucheLuftruckOffset(void)
void SearchAirPressureOffset(void)
{
uint8_t off;
off = GetParamByte(PID_LAST_OFFSET);
66,13 → 66,13
if(off > 20) off -= 10;
OCR0A = off;
Delay_ms_Mess(100);
if(MessLuftdruck < 850) off = 0;
if(ReadingAirPressure < 850) off = 0;
for(; off < 250;off++)
{
OCR0A = off;
Delay_ms_Mess(50);
printf(".");
if(MessLuftdruck < 900) break;
if(ReadingAirPressure < 900) break;
}
SetParamByte(PID_LAST_OFFSET, off);
DruckOffsetSetting = off;
86,7 → 86,7
ISR(ADC_vect)
{
static uint8_t adc_channel = 0, state = 0;
static uint16_t gier1, roll1, nick1;
static uint16_t yaw1, roll1, pitch1;
static uint8_t messanzahl_Druck = 0;
// disable further AD conversion
ADC_Disable();
94,16 → 94,16
switch(state++)
{
case 0:
gier1 = ADC; // get Gyro Gier Voltage 1st sample
yaw1 = ADC; // get Gyro Yaw Voltage 1st sample
adc_channel = 1; // set next channel to ADC1 = ROLL GYRO
ZaehlMessungen++; // increment total measurement counter
break;
case 1:
roll1 = ADC; // get Gyro Roll Voltage 1st sample
adc_channel = 2; // set next channel to ADC2 = NICK GYRO
adc_channel = 2; // set next channel to ADC2 = PITCH GYRO
break;
case 2:
nick1 = ADC; // get Gyro Nick Voltage 1st sample
pitch1 = ADC; // get Gyro Pitch Voltage 1st sample
adc_channel = 4; // set next channel to ADC4 = UBAT
break;
case 3:
118,25 → 118,25
break;
case 5:
Current_AccX = ADC - NeutralAccX; // get acceleration in X direction
AdValueAccNick = Current_AccX;
adc_channel = 0; // set next channel to ADC7 = GIER GYRO
AdValueAccPitch = Current_AccX;
adc_channel = 0; // set next channel to ADC7 = YAW GYRO
break;
case 6:
// average over two samples to create current ADValueGier
if(BoardRelease == 10) AdValueGyrGier = (ADC + gier1) / 2;
else AdValueGyrGier = ADC + gier1; // gain is 2 times lower on FC 1.1
// average over two samples to create current AdValueGyrYaw
if(BoardRelease == 10) AdValueGyrYaw = (ADC + yaw1) / 2;
else AdValueGyrYaw = ADC + yaw1; // gain is 2 times lower on FC 1.1
adc_channel = 1; // set next channel to ADC7 = ROLL GYRO
break;
case 7:
// average over two samples to create current ADValueRoll
// average over two samples to create current ADValueGyrRoll
if(BoardRelease == 10) AdValueGyrRoll = (ADC + roll1) / 2;
else AdValueGyrRoll = ADC + roll1; // gain is 2 times lower on FC 1.1
adc_channel = 2; // set next channel to ADC2 = NICK GYRO
adc_channel = 2; // set next channel to ADC2 = PITCH GYRO
break;
case 8:
// average over two samples to create current ADValueNick
if(BoardRelease == 10) AdValueGyrNick = (ADC + nick1) / 2;
else AdValueGyrNick = ADC + nick1; // gain is 2 times lower on FC 1.1
// average over two samples to create current ADValuePitch
if(BoardRelease == 10) AdValueGyrPitch = (ADC + pitch1) / 2;
else AdValueGyrPitch = ADC + pitch1; // gain is 2 times lower on FC 1.1
adc_channel = 5; // set next channel to ADC5 = ACC_Z
break;
case 9:
153,20 → 153,20
}
messanzahl_AccHoch = 1;
Current_AccZ = ADC;
Mess_Integral_Hoch += AdValueAccTop; // Integrieren
Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen
Reading_Integral_Top += AdValueAccTop; // Integrieren
Reading_Integral_Top -= Reading_Integral_Top / 1024; // dämfen
adc_channel = 3; // set next channel to ADC3 = air pressure
break;
case 10:
tmpLuftdruck += ADC; // sum vadc values
tmpAirPressure += ADC; // sum vadc values
if(++messanzahl_Druck >= 5) // if 5 values are summerized for averaging
{
MessLuftdruck = ADC; // update measured air pressure
ReadingAirPressure = ADC; // update measured air pressure
messanzahl_Druck = 0; // reset air pressure measurement counter
HoeheD = (int16_t)(StartLuftdruck - tmpLuftdruck - HoehenWert); // D-Anteil = neuerWert - AlterWert
Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; // averaging using history
HoehenWert = StartLuftdruck - Luftdruck;
tmpLuftdruck = 0;
HoeheD = (int16_t)(StartAirPressure - tmpAirPressure - ReadingHight); // D-Anteil = neuerWert - AlterWert
AirPressure = (tmpAirPressure + 3 * AirPressure) / 4; // averaging using history
ReadingHight = StartAirPressure - AirPressure;
tmpAirPressure = 0;
}
adc_channel = 0; // set next channel to ADC0 = GIER GYRO
state = 0; // reset state
/branches/V0.68d Code Redesign killagreg/analog.h
4,19 → 4,19
#include <inttypes.h>
 
extern volatile int16_t UBat;
extern volatile int16_t AdValueGyrNick, AdValueGyrRoll, AdValueGyrGier;
extern volatile int16_t AdValueAccRoll, AdValueAccNick, AdValueAccTop;
extern volatile int16_t Current_Nick, Current_Roll, Current_Gier;
extern volatile int16_t AdValueGyrPitch, AdValueGyrRoll, AdValueGyrYaw;
extern volatile int16_t AdValueAccRoll, AdValueAccPitch, AdValueAccTop;
extern volatile int16_t Current_Pitch, Current_Roll, Current_Yaw;
extern volatile int16_t Current_AccX, Current_AccY, Current_AccZ;
extern volatile int32_t Luftdruck;
extern volatile int32_t AirPressure;
extern volatile int8_t messanzahl_Druck;
extern volatile uint16_t ZaehlMessungen;
extern uint8_t DruckOffsetSetting;
extern volatile int16_t HoeheD;
extern volatile uint16_t MessLuftdruck;
extern volatile int16_t StartLuftdruck;
extern volatile uint16_t ReadingAirPressure;
extern volatile int16_t StartAirPressure;
 
extern void SucheLuftruckOffset(void);
extern void SearchAirPressureOffset(void);
 
extern void ADC_Init(void);
 
/branches/V0.68d Code Redesign killagreg/eeprom.c
29,28 → 29,28
/***************************************************/
void ParamSet_DefaultSet1(void) // sport
{
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_PITCH] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_GIER] = 4;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE;//CFG_HEIGHT_CONTROL | /*CFG_HEIGHT_SWITCH |*/ CFG_COMPASS_ACTIVE | CFG_COMPASS_FIX;//0x01;
ParamSet.Hoehe_MinGas = 30;
ParamSet.MaxHoehe = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Hoehe_P = 10; // Wert : 0-32
ParamSet.Luftdruck_D = 30; // Wert : 0-250
ParamSet.Hoehe_ACC_Wirkung = 30; // Wert : 0-250
ParamSet.Hoehe_Verstaerkung = 4; // Wert : 0-50
ParamSet.Hight_MinGas = 30;
ParamSet.MaxHight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Hight_P = 10; // Wert : 0-32
ParamSet.AirPressure_D = 30; // Wert : 0-250
ParamSet.Hight_ACC_Effect = 30; // Wert : 0-250
ParamSet.Hight_Gain = 4; // Wert : 0-50
ParamSet.Stick_P = 4; //2 // Wert : 1-6
ParamSet.Stick_D = 8; //8 // Wert : 0-64
ParamSet.Gier_P = 12; // Wert : 1-20
ParamSet.Yaw_P = 12; // Wert : 1-20
ParamSet.Gas_Min = 15; // Wert : 0-32
ParamSet.Gas_Max = 250; // Wert : 33-250
ParamSet.GyroAccFaktor = 30; // Wert : 1-64
ParamSet.KompassWirkung = 128; // Wert : 0-250
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 80; // Wert : 0-250
ParamSet.Gyro_I = 150; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
66,12 → 66,12
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.ServoPitchControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoPitchComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoPitchCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoPitchMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoPitchMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoPitchRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
78,9 → 78,9
ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt
ParamSet.AchsKopplung1 = 90;
ParamSet.AchsGegenKopplung1 = 5;
ParamSet.WinkelUmschlagNick = 100;
ParamSet.WinkelUmschlagRoll = 100;
ParamSet.GyroAccAbgleich = 16; // 1/k
ParamSet.AngleTurnOverPitch = 100;
ParamSet.AngleTurnOverRoll = 100;
ParamSet.GyroAccTrim = 16; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 100;
memcpy(ParamSet.Name, "Sport\0", 12);
92,28 → 92,28
/***************************************************/
void ParamSet_DefaultSet2(void) // normal
{
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_PITCH] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_GIER] = 4;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
ParamSet.GlobalConfig = CFG_AXIS_COUPLING_ACTIVE;//CFG_HEIGHT_CONTROL | /*CFG_HEIGHT_SWITCH |*/ CFG_COMPASS_ACTIVE;//0x01;
ParamSet.Hoehe_MinGas = 30;
ParamSet.MaxHoehe = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Hoehe_P = 10; // Wert : 0-32
ParamSet.Luftdruck_D = 30; // Wert : 0-250
ParamSet.Hoehe_ACC_Wirkung = 30; // Wert : 0-250
ParamSet.Hoehe_Verstaerkung = 3; // Wert : 0-50
ParamSet.Hight_MinGas = 30;
ParamSet.MaxHight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Hight_P = 10; // Wert : 0-32
ParamSet.AirPressure_D = 30; // Wert : 0-250
ParamSet.Hight_ACC_Effect = 30; // Wert : 0-250
ParamSet.Hight_Gain = 3; // Wert : 0-50
ParamSet.Stick_P = 3; //2 // Wert : 1-6
ParamSet.Stick_D = 4; //8 // Wert : 0-64
ParamSet.Gier_P = 6; // Wert : 1-20
ParamSet.Yaw_P = 6; // Wert : 1-20
ParamSet.Gas_Min = 15; // Wert : 0-32
ParamSet.Gas_Max = 250; // Wert : 33-250
ParamSet.GyroAccFaktor = 30; // Wert : 1-64
ParamSet.KompassWirkung = 128; // Wert : 0-250
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 80; // Wert : 0-250
ParamSet.Gyro_I = 120; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
129,21 → 129,21
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.ServoPitchControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoPitchComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoPitchCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoPitchMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoPitchMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoPitchRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
ParamSet.AchsKopplung1 = 90; // Faktor, mit dem Gier die Achsen Roll und Nick verkoppelt
ParamSet.AchsKopplung1 = 90; // Faktor, mit dem Yaw die Achsen Roll und Pitch verkoppelt
ParamSet.AchsGegenKopplung1 = 5;
ParamSet.WinkelUmschlagNick = 100;
ParamSet.WinkelUmschlagRoll = 100;
ParamSet.GyroAccAbgleich = 32; // 1/k
ParamSet.AngleTurnOverPitch = 100;
ParamSet.AngleTurnOverRoll = 100;
ParamSet.GyroAccTrim = 32; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 75;
memcpy(ParamSet.Name, "Normal\0", 12);
155,28 → 155,28
/***************************************************/
void ParamSet_DefaultSet3(void) // beginner
{
ParamSet.ChannelAssignment[CH_NICK] = 1;
ParamSet.ChannelAssignment[CH_PITCH] = 1;
ParamSet.ChannelAssignment[CH_ROLL] = 2;
ParamSet.ChannelAssignment[CH_GAS] = 3;
ParamSet.ChannelAssignment[CH_GIER] = 4;
ParamSet.ChannelAssignment[CH_YAW] = 4;
ParamSet.ChannelAssignment[CH_POTI1] = 5;
ParamSet.ChannelAssignment[CH_POTI2] = 6;
ParamSet.ChannelAssignment[CH_POTI3] = 7;
ParamSet.ChannelAssignment[CH_POTI4] = 8;
ParamSet.GlobalConfig = CFG_ROTARY_RATE_LIMITER | CFG_AXIS_COUPLING_ACTIVE;///*CFG_HEIGHT_SWITCH |*/ CFG_COMPASS_ACTIVE;//0x01;
ParamSet.Hoehe_MinGas = 30;
ParamSet.MaxHoehe = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Hoehe_P = 10; // Wert : 0-32
ParamSet.Luftdruck_D = 30; // Wert : 0-250
ParamSet.Hoehe_ACC_Wirkung = 30; // Wert : 0-250
ParamSet.Hoehe_Verstaerkung = 2; // Wert : 0-50
ParamSet.Hight_MinGas = 30;
ParamSet.MaxHight = 251; // Wert : 0-250 251 -> Poti1
ParamSet.Hight_P = 10; // Wert : 0-32
ParamSet.AirPressure_D = 30; // Wert : 0-250
ParamSet.Hight_ACC_Effect = 30; // Wert : 0-250
ParamSet.Hight_Gain = 2; // Wert : 0-50
ParamSet.Stick_P = 2; //2 // Wert : 1-6
ParamSet.Stick_D = 4; //8 // Wert : 0-64
ParamSet.Gier_P = 6; // Wert : 1-20
ParamSet.Yaw_P = 6; // Wert : 1-20
ParamSet.Gas_Min = 15; // Wert : 0-32
ParamSet.Gas_Max = 250; // Wert : 33-250
ParamSet.GyroAccFaktor = 30; // Wert : 1-64
ParamSet.KompassWirkung = 128; // Wert : 0-250
ParamSet.CompassYawEffect = 128; // Wert : 0-250
ParamSet.Gyro_P = 100; // Wert : 0-250
ParamSet.Gyro_I = 140; // Wert : 0-250
ParamSet.LowVoltageWarning = 94; // Wert : 0-250
192,21 → 192,21
ParamSet.UserParam6 = 0; // zur freien Verwendung
ParamSet.UserParam7 = 0; // zur freien Verwendung
ParamSet.UserParam8 = 0; // zur freien Verwendung
ParamSet.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoNickMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoNickMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoNickRefresh = 5;
ParamSet.ServoPitchControl = 100; // Wert : 0-250 // Stellung des Servos
ParamSet.ServoPitchComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo
ParamSet.ServoPitchCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo
ParamSet.ServoPitchMin = 50; // Wert : 0-250 // Anschlag
ParamSet.ServoPitchMax = 150; // Wert : 0-250 // Anschlag
ParamSet.ServoPitchRefresh = 5;
ParamSet.LoopGasLimit = 50;
ParamSet.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag
ParamSet.LoopHysteresis = 50;
ParamSet.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts
ParamSet.AchsKopplung1 = 90; // Faktor, mit dem Gier die Achsen Roll und Nick verkoppelt
ParamSet.AchsKopplung1 = 90; // Faktor, mit dem Yaw die Achsen Roll und Pitch verkoppelt
ParamSet.AchsGegenKopplung1 = 5;
ParamSet.WinkelUmschlagNick = 100;
ParamSet.WinkelUmschlagRoll = 100;
ParamSet.GyroAccAbgleich = 32; // 1/k
ParamSet.AngleTurnOverPitch = 100;
ParamSet.AngleTurnOverRoll = 100;
ParamSet.GyroAccTrim = 32; // 1/k
ParamSet.DriftComp = 4;
ParamSet.DynamicStability = 50;
memcpy(ParamSet.Name, "Beginner\0", 12);
/branches/V0.68d Code Redesign killagreg/eeprom.h
7,7 → 7,7
#define PID_VERSION 1 // byte
#define PID_ACTIVE_SET 2 // byte
#define PID_LAST_OFFSET 3 // byte
#define PID_ACC_NICK 4 // word
#define PID_ACC_PITCH 4 // word
#define PID_ACC_ROLL 6 // word
#define PID_ACC_Z 8 // word
 
38,10 → 38,10
#define CFG_LOOP_RIGHT 0x08
 
// defines for lookup mk_param_struct.ChannelAssignment
#define CH_NICK 0
#define CH_PITCH 0
#define CH_ROLL 1
#define CH_GAS 2
#define CH_GIER 3
#define CH_YAW 3
#define CH_POTI1 4
#define CH_POTI2 5
#define CH_POTI3 6
53,19 → 53,19
{
uint8_t ChannelAssignment[8]; // see upper defines for details
uint8_t GlobalConfig; // see upper defines for bitcoding
uint8_t Hoehe_MinGas; // Wert : 0-100
uint8_t Luftdruck_D; // Wert : 0-250
uint8_t MaxHoehe; // Wert : 0-32
uint8_t Hoehe_P; // Wert : 0-32
uint8_t Hoehe_Verstaerkung; // Wert : 0-50
uint8_t Hoehe_ACC_Wirkung; // Wert : 0-250
uint8_t Hight_MinGas; // Wert : 0-100
uint8_t AirPressure_D; // Wert : 0-250
uint8_t MaxHight; // Wert : 0-32
uint8_t Hight_P; // Wert : 0-32
uint8_t Hight_Gain; // Wert : 0-50
uint8_t Hight_ACC_Effect; // Wert : 0-250
uint8_t Stick_P; // Wert : 1-6
uint8_t Stick_D; // Wert : 0-64
uint8_t Gier_P; // Wert : 1-20
uint8_t Yaw_P; // Wert : 1-20
uint8_t Gas_Min; // Wert : 0-32
uint8_t Gas_Max; // Wert : 33-250
uint8_t GyroAccFaktor; // Wert : 1-64
uint8_t KompassWirkung; // Wert : 0-32
uint8_t CompassYawEffect; // Wert : 0-32
uint8_t Gyro_P; // Wert : 10-250
uint8_t Gyro_I; // Wert : 0-250
uint8_t LowVoltageWarning; // Wert : 0-250
77,19 → 77,19
uint8_t UserParam2; // Wert : 0-250
uint8_t UserParam3; // Wert : 0-250
uint8_t UserParam4; // Wert : 0-250
uint8_t ServoNickControl; // Wert : 0-250 // Stellung des Servos
uint8_t ServoNickComp; // Wert : 0-250 // Einfluss Gyro/Servo
uint8_t ServoNickMin; // Wert : 0-250 // Anschlag
uint8_t ServoNickMax; // Wert : 0-250 // Anschlag
uint8_t ServoNickRefresh; //
uint8_t ServoPitchControl; // Wert : 0-250 // Stellung des Servos
uint8_t ServoPitchComp; // Wert : 0-250 // Einfluss Gyro/Servo
uint8_t ServoPitchMin; // Wert : 0-250 // Anschlag
uint8_t ServoPitchMax; // Wert : 0-250 // Anschlag
uint8_t ServoPitchRefresh; //
uint8_t LoopGasLimit; // Wert: 0-250 max. Gas während Looping
uint8_t LoopThreshold; // Wert: 0-250 Schwelle für Stickausschlag
uint8_t LoopHysteresis; // Wert: 0-250 Hysterese für Stickausschlag
uint8_t AchsKopplung1; // Wert: 0-250 Faktor, mit dem Gier die Achsen Roll und Nick koppelt (NickRollMitkopplung)
uint8_t AchsGegenKopplung1; // Wert: 0-250 Faktor, mit dem Gier die Achsen Roll und Nick Gegenkoppelt (NickRollGegenkopplung)
uint8_t WinkelUmschlagNick; // Wert: 0-250 180°-Punkt
uint8_t WinkelUmschlagRoll; // Wert: 0-250 180°-Punkt
uint8_t GyroAccAbgleich; // 1/k (Koppel_ACC_Wirkung)
uint8_t AchsKopplung1; // Wert: 0-250 Faktor, mit dem Yaw die Achsen Roll und Pitch koppelt (PitchRollMitkopplung)
uint8_t AchsGegenKopplung1; // Wert: 0-250 Faktor, mit dem Yaw die Achsen Roll und Pitch Gegenkoppelt (PitchRollGegenkopplung)
uint8_t AngleTurnOverPitch; // Wert: 0-250 180°-Punkt
uint8_t AngleTurnOverRoll; // Wert: 0-250 180°-Punkt
uint8_t GyroAccTrim; // 1/k (Koppel_ACC_Wirkung)
uint8_t DriftComp;
uint8_t DynamicStability;
uint8_t UserParam5; // Wert : 0-250
97,7 → 97,7
uint8_t UserParam7; // Wert : 0-250
uint8_t UserParam8; // Wert : 0-250
uint8_t LoopConfig; // see upper defines for bitcoding
uint8_t ServoNickCompInvert; // Wert : 0-250 0 oder 1 // WICHTIG!!! am Ende lassen
uint8_t ServoPitchCompInvert; // Wert : 0-250 0 oder 1 // WICHTIG!!! am Ende lassen
uint8_t Reserved[4];
int8_t Name[12];
} paramset_t;
/branches/V0.68d Code Redesign killagreg/fc.c
68,47 → 68,47
 
unsigned char h,m,s;
volatile unsigned int I2CTimeout = 100;
volatile int MesswertNick,MesswertRoll,MesswertGier;
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
volatile int ReadingPitch, ReadingRoll, ReadingYaw;
volatile int AdNeutralPitch = 0,AdNeutralRoll = 0,AdNeutralYaw = 0, StartNeutralRoll = 0, StartNeutralPitch = 0;
volatile int Mean_AccPitch, Mean_AccRoll, Mean_AccTop, NeutralAccX=0, NeutralAccY=0;
volatile float NeutralAccZ = 0;
volatile long IntegralNick = 0,IntegralNick2 = 0;
volatile long IntegralPitch = 0,IntegralPitch2 = 0;
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
volatile long Integral_Gier = 0;
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
volatile long Mess_Integral_Hoch = 0;
volatile int KompassValue = 0;
volatile int KompassStartwert = 0;
volatile int KompassRichtung = 0;
volatile long IntegralAccPitch = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
volatile long Integral_Yaw = 0;
volatile long Reading_IntegralPitch = 0,Reading_IntegralPitch2 = 0;
volatile long Reading_IntegralRoll = 0,Reading_IntegralRoll2 = 0;
volatile long Reading_Integral_Yaw = 0,Reading_Integral_Yaw2 = 0;
volatile long MeanIntegralPitch, MeanIntegralRoll, MeanIntegralPitch2, MeanIntegralRoll2;
volatile long Reading_Integral_Top = 0;
volatile int CompassHeading = 0;
volatile int CompassCourse = 0;
volatile int CompassOffCourse = 0;
unsigned char MAX_GAS,MIN_GAS;
unsigned char Notlandung = 0;
unsigned char HoehenReglerAktiv = 0;
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
unsigned char EmergencyLanding = 0;
unsigned char HightControlActive = 0;
long TurnOver180Pitch = 250000L, TurnOver180Roll = 250000L;
 
float GyroFaktor;
float IntegralFaktor;
volatile int DiffNick,DiffRoll;
float GyroFactor;
float IntegralFactor;
volatile int DiffPitch,DiffRoll;
int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
unsigned char MotorWert[5];
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
char MotorenEin = 0;
int HoehenWert = 0;
int SollHoehe = 0;
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
volatile unsigned char Motor_Front, Motor_Rear, Motor_Right, Motor_Left, Count;
unsigned char MotorValue[5];
int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickGas = 0;
char MotorsOn = 0;
int ReadingHight = 0;
int SetPointHight = 0;
int AttitudeCorrectionRoll = 0, AttitudeCorrectionPitch = 0;
float Ki = FAKTOR_I;
unsigned char Looping_Nick = 0,Looping_Roll = 0;
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
unsigned char Looping_Pitch = 0, Looping_Roll = 0;
unsigned char Looping_Left = 0, Looping_Right = 0, Looping_Down = 0, Looping_Top = 0;
 
unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250
unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250
unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250
unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250
unsigned char Parameter_CompassYawEffect = 64; // Wert : 0-250
unsigned char Parameter_Gyro_P = 150; // Wert : 10-250
unsigned char Parameter_Gyro_I = 150; // Wert : 0-250
unsigned char Parameter_Gier_P = 2; // Wert : 1-20
121,20 → 121,20
unsigned char Parameter_UserParam6 = 0;
unsigned char Parameter_UserParam7 = 0;
unsigned char Parameter_UserParam8 = 0;
unsigned char Parameter_ServoNickControl = 100;
unsigned char Parameter_ServoPitchControl = 100;
unsigned char Parameter_LoopGasLimit = 70;
unsigned char Parameter_AchsKopplung1 = 0;
unsigned char Parameter_AchsGegenKopplung1 = 0;
unsigned char Parameter_DynamicStability = 100;
 
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
int MaxStickNick = 0,MaxStickRoll = 0;
signed int ExternStickPitch = 0, ExternStickRoll = 0,ExternStickYaw = 0, ExternHightValue = -20;
int MaxStickPitch = 0, MaxStickRoll = 0;
 
void Piep(unsigned char Anzahl)
{
while(Anzahl--)
{
if(MotorenEin) return; //auf keinen Fall im Flug!
if(MotorsOn) return; //auf keinen Fall im Flug!
BeepTime = 100;
Delay_ms(250);
}
148,145 → 148,145
NeutralAccX = 0;
NeutralAccY = 0;
NeutralAccZ = 0;
AdNeutralNick = 0;
AdNeutralPitch = 0;
AdNeutralRoll = 0;
AdNeutralGier = 0;
AdNeutralYaw = 0;
Parameter_AchsKopplung1 = 0;
Parameter_AchsGegenKopplung1 = 0;
CalibrierMittelwert();
CalibMean();
Delay_ms_Mess(100);
CalibrierMittelwert();
CalibMean();
if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung aktiviert?
{
if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
if((ReadingAirPressure > 950) || (ReadingAirPressure < 750)) SearchAirPressureOffset();
}
 
AdNeutralNick= AdValueGyrNick;
AdNeutralPitch= AdValueGyrPitch;
AdNeutralRoll= AdValueGyrRoll;
AdNeutralGier= AdValueGyrGier;
AdNeutralYaw= AdValueGyrYaw;
StartNeutralRoll = AdNeutralRoll;
StartNeutralNick = AdNeutralNick;
if(GetParamByte(PID_ACC_NICK) > 4)
StartNeutralPitch = AdNeutralPitch;
if(GetParamByte(PID_ACC_PITCH) > 4)
{
NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
NeutralAccY = abs(Mean_AccRoll) / ACC_AMPLIFY;
NeutralAccX = abs(Mean_AccPitch) / ACC_AMPLIFY;
NeutralAccZ = Current_AccZ;
}
else
{
NeutralAccX = (int)GetParamByte(PID_ACC_NICK) * 256 + (int)GetParamByte(PID_ACC_NICK+1);
{ // why not GetParamWord()?
NeutralAccX = (int)GetParamByte(PID_ACC_PITCH) * 256 + (int)GetParamByte(PID_ACC_PITCH+1);
NeutralAccY = (int)GetParamByte(PID_ACC_ROLL) * 256 + (int)GetParamByte(PID_ACC_ROLL+1);
NeutralAccZ = (int)GetParamByte(PID_ACC_Z) * 256 + (int)GetParamByte(PID_ACC_Z+1);
}
 
Mess_IntegralNick = 0;
Mess_IntegralNick2 = 0;
Mess_IntegralRoll = 0;
Mess_IntegralRoll2 = 0;
Mess_Integral_Gier = 0;
MesswertNick = 0;
MesswertRoll = 0;
MesswertGier = 0;
StartLuftdruck = Luftdruck;
Reading_IntegralPitch = 0;
Reading_IntegralPitch2 = 0;
Reading_IntegralRoll = 0;
Reading_IntegralRoll2 = 0;
Reading_Integral_Yaw = 0;
ReadingPitch = 0;
ReadingRoll = 0;
ReadingYaw = 0;
StartAirPressure = AirPressure;
HoeheD = 0;
Mess_Integral_Hoch = 0;
KompassStartwert = KompassValue;
Reading_Integral_Top = 0;
CompassCourse = CompassHeading;
GPS_Neutral();
BeepTime = 50;
Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L;
Umschlag180Roll = (long) ParamSet.WinkelUmschlagRoll * 2500L;
ExternHoehenValue = 0;
TurnOver180Pitch = (long) ParamSet.AngleTurnOverPitch * 2500L;
TurnOver180Roll = (long) ParamSet.AngleTurnOverRoll * 2500L;
ExternHightValue = 0;
}
 
//############################################################################
// Bearbeitet die Messwerte
void Mittelwert(void)
void Mean(void)
//############################################################################
{
static signed long tmpl,tmpl2;
MesswertGier = (signed int) AdNeutralGier - AdValueGyrGier;
MesswertRoll = (signed int) AdValueGyrRoll - AdNeutralRoll;
MesswertNick = (signed int) AdValueGyrNick - AdNeutralNick;
static int32_t tmpl,tmpl2;
ReadingYaw = (int16_t) AdNeutralYaw - AdValueGyrYaw;
ReadingRoll = (int16_t) AdValueGyrRoll - AdNeutralRoll;
ReadingPitch = (int16_t) AdValueGyrPitch - AdNeutralPitch;
 
//DebugOut.Analog[26] = MesswertNick;
DebugOut.Analog[28] = MesswertRoll;
//DebugOut.Analog[26] = ReadingPitch;
DebugOut.Analog[28] = ReadingRoll;
 
// Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++
Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdValueAccNick))) / 2L;
Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdValueAccRoll))) / 2L;
Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdValueAccTop)) / 2L;
IntegralAccNick += ACC_AMPLIFY * AdValueAccNick;
Mean_AccPitch = ((long)Mean_AccPitch * 1 + ((ACC_AMPLIFY * (long)AdValueAccPitch))) / 2L;
Mean_AccRoll = ((long)Mean_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdValueAccRoll))) / 2L;
Mean_AccTop = ((long)Mean_AccTop * 1 + ((long)AdValueAccTop)) / 2L;
IntegralAccPitch += ACC_AMPLIFY * AdValueAccPitch;
IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll;
IntegralAccZ += Current_AccZ - NeutralAccZ;
// Gier ++++++++++++++++++++++++++++++++++++++++++++++++
Mess_Integral_Gier += MesswertGier;
Mess_Integral_Gier2 += MesswertGier;
// Yaw ++++++++++++++++++++++++++++++++++++++++++++++++
Reading_Integral_Yaw += ReadingYaw;
Reading_Integral_Yaw2 += ReadingYaw;
// Kopplungsanteil +++++++++++++++++++++++++++++++++++++
if(!Looping_Nick && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE))
if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE))
{
tmpl = Mess_IntegralNick / 4096L;
tmpl *= MesswertGier;
tmpl = Reading_IntegralPitch / 4096L;
tmpl *= ReadingYaw;
tmpl *= Parameter_AchsKopplung1; //125
tmpl /= 2048L;
tmpl2 = Mess_IntegralRoll / 4096L;
tmpl2 *= MesswertGier;
tmpl2 = Reading_IntegralRoll / 4096L;
tmpl2 *= ReadingYaw;
tmpl2 *= Parameter_AchsKopplung1;
tmpl2 /= 2048L;
}
else tmpl = tmpl2 = 0;
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
MesswertRoll += tmpl;
MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
Mess_IntegralRoll2 += MesswertRoll;
Mess_IntegralRoll += MesswertRoll - LageKorrekturRoll;
if(Mess_IntegralRoll > Umschlag180Roll)
ReadingRoll += tmpl;
ReadingRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
Reading_IntegralRoll2 += ReadingRoll;
Reading_IntegralRoll += ReadingRoll - AttitudeCorrectionRoll;
if(Reading_IntegralRoll > TurnOver180Roll)
{
Mess_IntegralRoll = -(Umschlag180Roll - 10000L);
Mess_IntegralRoll2 = Mess_IntegralRoll;
Reading_IntegralRoll = -(TurnOver180Roll - 10000L);
Reading_IntegralRoll2 = Reading_IntegralRoll;
}
if(Mess_IntegralRoll <-Umschlag180Roll)
if(Reading_IntegralRoll <-TurnOver180Roll)
{
Mess_IntegralRoll = (Umschlag180Roll - 10000L);
Mess_IntegralRoll2 = Mess_IntegralRoll;
Reading_IntegralRoll = (TurnOver180Roll - 10000L);
Reading_IntegralRoll2 = Reading_IntegralRoll;
}
if(AdValueGyrRoll < 15) MesswertRoll = -1000;
if(AdValueGyrRoll < 7) MesswertRoll = -2000;
if(AdValueGyrRoll < 15) ReadingRoll = -1000;
if(AdValueGyrRoll < 7) ReadingRoll = -2000;
if(BoardRelease == 10)
{
if(AdValueGyrRoll > 1010) MesswertRoll = +1000;
if(AdValueGyrRoll > 1017) MesswertRoll = +2000;
if(AdValueGyrRoll > 1010) ReadingRoll = +1000;
if(AdValueGyrRoll > 1017) ReadingRoll = +2000;
}
else
{
if(AdValueGyrRoll > 2020) MesswertRoll = +1000;
if(AdValueGyrRoll > 2034) MesswertRoll = +2000;
if(AdValueGyrRoll > 2020) ReadingRoll = +1000;
if(AdValueGyrRoll > 2034) ReadingRoll = +2000;
}
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
MesswertNick -= tmpl2;
MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
Mess_IntegralNick2 += MesswertNick;
Mess_IntegralNick += MesswertNick - LageKorrekturNick;
if(Mess_IntegralNick > Umschlag180Nick)
// Pitch ++++++++++++++++++++++++++++++++++++++++++++++++
ReadingPitch -= tmpl2;
ReadingPitch -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
Reading_IntegralPitch2 += ReadingPitch;
Reading_IntegralPitch += ReadingPitch - AttitudeCorrectionPitch;
if(Reading_IntegralPitch > TurnOver180Pitch)
{
Mess_IntegralNick = -(Umschlag180Nick - 10000L);
Mess_IntegralNick2 = Mess_IntegralNick;
Reading_IntegralPitch = -(TurnOver180Pitch - 10000L);
Reading_IntegralPitch2 = Reading_IntegralPitch;
}
if(Mess_IntegralNick <-Umschlag180Nick)
if(Reading_IntegralPitch <-TurnOver180Pitch)
{
Mess_IntegralNick = (Umschlag180Nick - 10000L);
Mess_IntegralNick2 = Mess_IntegralNick;
Reading_IntegralPitch = (TurnOver180Pitch - 10000L);
Reading_IntegralPitch2 = Reading_IntegralPitch;
}
if(AdValueGyrNick < 15) MesswertNick = -1000;
if(AdValueGyrNick < 7) MesswertNick = -2000;
if(AdValueGyrPitch < 15) ReadingPitch = -1000;
if(AdValueGyrPitch < 7) ReadingPitch = -2000;
if(BoardRelease == 10)
{
if(AdValueGyrNick > 1010) MesswertNick = +1000;
if(AdValueGyrNick > 1017) MesswertNick = +2000;
if(AdValueGyrPitch > 1010) ReadingPitch = +1000;
if(AdValueGyrPitch > 1017) ReadingPitch = +2000;
}
else
{
if(AdValueGyrNick > 2020) MesswertNick = +1000;
if(AdValueGyrNick > 2034) MesswertNick = +2000;
if(AdValueGyrPitch > 2020) ReadingPitch = +1000;
if(AdValueGyrPitch > 2034) ReadingPitch = +2000;
}
//++++++++++++++++++++++++++++++++++++++++++++++++
// ADC einschalten
293,18 → 293,18
ADC_Enable();
//++++++++++++++++++++++++++++++++++++++++++++++++
 
Integral_Gier = Mess_Integral_Gier;
IntegralNick = Mess_IntegralNick;
IntegralRoll = Mess_IntegralRoll;
IntegralNick2 = Mess_IntegralNick2;
IntegralRoll2 = Mess_IntegralRoll2;
Integral_Yaw = Reading_Integral_Yaw;
IntegralPitch = Reading_IntegralPitch;
IntegralRoll = Reading_IntegralRoll;
IntegralPitch2 = Reading_IntegralPitch2;
IntegralRoll2 = Reading_IntegralRoll2;
 
if(ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER && !Looping_Nick && !Looping_Roll)
if(ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER && !Looping_Pitch && !Looping_Roll)
{
if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200);
else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200);
else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
if(ReadingPitch > 200) ReadingPitch += 4 * (ReadingPitch - 200);
else if(ReadingPitch < -200) ReadingPitch += 4 * (ReadingPitch + 200);
if(ReadingRoll > 200) ReadingRoll += 4 * (ReadingRoll - 200);
else if(ReadingRoll < -200) ReadingRoll += 4 * (ReadingRoll + 200);
}
if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--;
if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--;
318,17 → 318,17
 
//############################################################################
// Messwerte beim Ermitteln der Nullage
void CalibrierMittelwert(void)
void CalibMean(void)
//############################################################################
{
// ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
ADC_Disable();
MesswertNick = AdValueGyrNick;
MesswertRoll = AdValueGyrRoll;
MesswertGier = AdValueGyrGier;
Mittelwert_AccNick = ACC_AMPLIFY * (long)AdValueAccNick;
Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdValueAccRoll;
Mittelwert_AccHoch = (long)AdValueAccTop;
ReadingPitch = AdValueGyrPitch;
ReadingRoll = AdValueGyrRoll;
ReadingYaw = AdValueGyrYaw;
Mean_AccPitch = ACC_AMPLIFY * (long)AdValueAccPitch;
Mean_AccRoll = ACC_AMPLIFY * (long)AdValueAccRoll;
Mean_AccTop = (long)AdValueAccTop;
// ADC einschalten
ADC_Enable();
if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--;
340,8 → 340,8
if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
 
Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L;
Umschlag180Roll = (long) ParamSet.WinkelUmschlagNick * 2500L;
TurnOver180Pitch = (long) ParamSet.AngleTurnOverPitch * 2500L;
TurnOver180Roll = (long) ParamSet.AngleTurnOverRoll * 2500L;
}
 
//############################################################################
349,22 → 349,22
void SendMotorData(void)
//############################################################################
{
if(MOTOR_OFF || !MotorenEin)
if(MOTOR_OFF || !MotorsOn)
{
Motor_Hinten = 0;
Motor_Vorne = 0;
Motor_Rechts = 0;
Motor_Links = 0;
if(MotorTest[0]) Motor_Vorne = MotorTest[0];
if(MotorTest[1]) Motor_Hinten = MotorTest[1];
if(MotorTest[2]) Motor_Links = MotorTest[2];
if(MotorTest[3]) Motor_Rechts = MotorTest[3];
Motor_Rear = 0;
Motor_Front = 0;
Motor_Right = 0;
Motor_Left = 0;
if(MotorTest[0]) Motor_Front = MotorTest[0];
if(MotorTest[1]) Motor_Rear = MotorTest[1];
if(MotorTest[2]) Motor_Left = MotorTest[2];
if(MotorTest[3]) Motor_Right = MotorTest[3];
}
 
DebugOut.Analog[12] = Motor_Vorne;
DebugOut.Analog[13] = Motor_Hinten;
DebugOut.Analog[14] = Motor_Links;
DebugOut.Analog[15] = Motor_Rechts;
DebugOut.Analog[12] = Motor_Front;
DebugOut.Analog[13] = Motor_Rear;
DebugOut.Analog[14] = Motor_Left;
DebugOut.Analog[15] = Motor_Right;
 
//Start I2C Interrupt Mode
twi_state = 0;
381,11 → 381,11
{
 
#define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;}
CHK_POTI(Parameter_MaxHoehe,ParamSet.MaxHoehe,0,255);
CHK_POTI(Parameter_Luftdruck_D,ParamSet.Luftdruck_D,0,100);
CHK_POTI(Parameter_Hoehe_P,ParamSet.Hoehe_P,0,100);
CHK_POTI(Parameter_Hoehe_ACC_Wirkung,ParamSet.Hoehe_ACC_Wirkung,0,255);
CHK_POTI(Parameter_KompassWirkung,ParamSet.KompassWirkung,0,255);
CHK_POTI(Parameter_MaxHoehe,ParamSet.MaxHight,0,255);
CHK_POTI(Parameter_Luftdruck_D,ParamSet.AirPressure_D,0,100);
CHK_POTI(Parameter_Hoehe_P,ParamSet.Hight_P,0,100);
CHK_POTI(Parameter_Hoehe_ACC_Wirkung,ParamSet.Hight_ACC_Effect,0,255);
CHK_POTI(Parameter_CompassYawEffect,ParamSet.CompassYawEffect,0,255);
CHK_POTI(Parameter_Gyro_P,ParamSet.Gyro_P,10,255);
CHK_POTI(Parameter_Gyro_I,ParamSet.Gyro_I,0,255);
CHK_POTI(Parameter_I_Factor,ParamSet.I_Factor,0,255);
397,7 → 397,7
CHK_POTI(Parameter_UserParam6,ParamSet.UserParam6,0,255);
CHK_POTI(Parameter_UserParam7,ParamSet.UserParam7,0,255);
CHK_POTI(Parameter_UserParam8,ParamSet.UserParam8,0,255);
CHK_POTI(Parameter_ServoNickControl,ParamSet.ServoNickControl,0,255);
CHK_POTI(Parameter_ServoPitchControl,ParamSet.ServoPitchControl,0,255);
CHK_POTI(Parameter_LoopGasLimit,ParamSet.LoopGasLimit,0,255);
CHK_POTI(Parameter_AchsKopplung1, ParamSet.AchsKopplung1,0,255);
CHK_POTI(Parameter_AchsGegenKopplung1,ParamSet.AchsGegenKopplung1,0,255);
414,29 → 414,29
void MotorRegler(void)
//############################################################################
{
int motorwert,pd_ergebnis,h,tmp_int;
int GierMischanteil,GasMischanteil;
static long SummeNick=0,SummeRoll=0;
static long sollGier = 0,tmp_long,tmp_long2;
static long IntegralFehlerNick = 0;
static long IntegralFehlerRoll = 0;
int MotorValue, pd_ergebnis, h, tmp_int;
int YawMixingFraction, GasMixingFraction;
static long SumPitch = 0, SumRoll = 0;
static long SetPointYaw = 0, tmp_long, tmp_long2;
static long IntegralErrorPitch = 0;
static long IntegralErrorRoll = 0;
static unsigned int RcLostTimer;
static unsigned char delay_neutral = 0;
static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
static unsigned int modell_fliegt = 0;
static int hoehenregler = 0;
static char TimerWerteausgabe = 0;
static char NeueKompassRichtungMerken = 0;
static long ausgleichNick, ausgleichRoll;
static char TimerDebugOut = 0;
static char StoreNewCompassCourse = 0;
static long CorrectionPitch, CorrectionRoll;
 
Mittelwert();
Mean();
 
GRN_ON;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Gaswert ermitteln
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
GasMischanteil = StickGas;
if(GasMischanteil < 0) GasMischanteil = 0;
GasMixingFraction = StickGas;
if(GasMixingFraction < 0) GasMixingFraction = 0;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Emfang schlecht
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
453,19 → 453,19
if(RcLostTimer) RcLostTimer--;
else
{
MotorenEin = 0;
Notlandung = 0;
MotorsOn = 0;
EmergencyLanding = 0;
}
ROT_ON;
if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken
{
GasMischanteil = ParamSet.EmergencyGas;
Notlandung = 1;
PPM_in[ParamSet.ChannelAssignment[CH_NICK]] = 0;
GasMixingFraction = ParamSet.EmergencyGas;
EmergencyLanding = 1;
PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] = 0;
PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0;
PPM_in[ParamSet.ChannelAssignment[CH_GIER]] = 0;
PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0;
}
else MotorenEin = 0;
else MotorsOn = 0;
}
else
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
473,45 → 473,45
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(SenderOkay > 140)
{
Notlandung = 0;
EmergencyLanding = 0;
RcLostTimer = ParamSet.EmergencyGasDuration * 50;
if(GasMischanteil > 40)
if(GasMixingFraction > 40)
{
if(modell_fliegt < 0xffff) modell_fliegt++;
}
if((modell_fliegt < 200) || (GasMischanteil < 40))
if((modell_fliegt < 200) || (GasMixingFraction < 40))
{
SummeNick = 0;
SummeRoll = 0;
Mess_Integral_Gier = 0;
Mess_Integral_Gier2 = 0;
SumPitch = 0;
SumRoll = 0;
Reading_Integral_Yaw = 0;
Reading_Integral_Yaw2 = 0;
}
if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && MotorenEin == 0)
if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && MotorsOn == 0)
{
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// auf Nullwerte kalibrieren
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] > 75) // Neutralwerte
if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) // Neutralwerte
{
if(++delay_neutral > 200) // nicht sofort
{
GRN_OFF;
MotorenEin = 0;
MotorsOn = 0;
delay_neutral = 0;
modell_fliegt = 0;
if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70 || abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > 70)
if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70 || abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > 70)
{
unsigned char setting=1;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 1;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 2;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 3;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 4;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 5;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < 70) setting = 1;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 2;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 3;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 4;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < 70) setting = 5;
SetActiveParamSet(setting); // aktiven Datensatz merken
}
if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung aktiviert?
{
if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
if((ReadingAirPressure > 950) || (ReadingAirPressure < 750)) SearchAirPressureOffset();
}
ParamSet_ReadFromEEProm(GetActiveParamSet());
SetNeutral();
519,18 → 519,18
}
}
else
if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] < -75) // ACC Neutralwerte speichern
if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) // ACC Neutralwerte speichern
{
if(++delay_neutral > 200) // nicht sofort
{
GRN_OFF;
SetParamByte(PID_ACC_NICK,0xFF); // Werte löschen
MotorenEin = 0;
SetParamByte(PID_ACC_PITCH,0xFF); // Werte löschen
MotorsOn = 0;
delay_neutral = 0;
modell_fliegt = 0;
SetNeutral();
SetParamByte(PID_ACC_NICK, NeutralAccX / 256); // ACC-NeutralWerte speichern
SetParamByte(PID_ACC_NICK+1,NeutralAccX % 256); // ACC-NeutralWerte speichern
SetParamByte(PID_ACC_PITCH, NeutralAccX / 256); // ACC-NeutralWerte speichern
SetParamByte(PID_ACC_PITCH+1,NeutralAccX % 256); // ACC-NeutralWerte speichern
SetParamByte(PID_ACC_ROLL,NeutralAccY / 256);
SetParamByte(PID_ACC_ROLL+1,NeutralAccY % 256);
SetParamByte(PID_ACC_Z,(int)NeutralAccZ / 256);
546,7 → 546,7
if(PPM_in[ParamSet.ChannelAssignment[CH_GAS]] < 35-120)
{
// Starten
if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] < -75)
if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75)
{
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Einschalten
555,16 → 555,16
{
delay_einschalten = 200;
modell_fliegt = 1;
MotorenEin = 1;
sollGier = 0;
Mess_Integral_Gier = 0;
Mess_Integral_Gier2 = 0;
Mess_IntegralNick = 0;
Mess_IntegralRoll = 0;
Mess_IntegralNick2 = IntegralNick;
Mess_IntegralRoll2 = IntegralRoll;
SummeNick = 0;
SummeRoll = 0;
MotorsOn = 1;
SetPointYaw = 0;
Reading_Integral_Yaw = 0;
Reading_Integral_Yaw2 = 0;
Reading_IntegralPitch = 0;
Reading_IntegralRoll = 0;
Reading_IntegralPitch2 = IntegralPitch;
Reading_IntegralRoll2 = IntegralRoll;
SumPitch = 0;
SumRoll = 0;
}
}
else delay_einschalten = 0;
572,11 → 572,11
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Auschalten
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] > 75)
if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75)
{
if(++delay_ausschalten > 200) // nicht sofort
{
MotorenEin = 0;
MotorsOn = 0;
delay_ausschalten = 200;
modell_fliegt = 0;
}
588,27 → 588,26
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// neue Werte von der Funke
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(!NewPpmData-- || Notlandung)
if(!NewPpmData-- || EmergencyLanding)
{
int tmp_int;
static int stick_nick,stick_roll;
ParameterZuordnung();
StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4;
StickNick += PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_D;
StickPitch = (StickPitch * 3 + PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_P) / 4;
StickPitch += PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_D;
StickRoll = (StickRoll * 3 + PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_P) / 4;
StickRoll += PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_D;
 
StickGier = -PPM_in[ParamSet.ChannelAssignment[CH_GIER]];
StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]];
StickGas = PPM_in[ParamSet.ChannelAssignment[CH_GAS]] + 120;
 
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]) > MaxStickNick)
MaxStickNick = abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]); else MaxStickNick--;
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]) > MaxStickPitch)
MaxStickPitch = abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]); else MaxStickPitch--;
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll)
MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); else MaxStickRoll--;
if(Notlandung) {MaxStickNick = 0; MaxStickRoll = 0;}
if(EmergencyLanding) {MaxStickPitch = 0; MaxStickRoll = 0;}
 
GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0;
IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
GyroFactor = ((float)Parameter_Gyro_P + 10.0) / 256.0;
IntegralFactor = ((float) Parameter_Gyro_I) / 44000;
 
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+ Digitale Steuerung per DubWise
617,78 → 616,78
if(DubWiseKeys[1]) BeepTime = 10;
if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; else
if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; else tmp_int = 0;
ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
ExternStickPitch= (ExternStickPitch* 7 + tmp_int) / 8;
if(DubWiseKeys[1] & DUB_KEY_LEFT) tmp_int = KEY_VALUE; else
if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
 
if(DubWiseKeys[0] & 8) ExternStickGier = 50;else
if(DubWiseKeys[0] & 4) ExternStickGier =-50;else ExternStickGier = 0;
if(DubWiseKeys[0] & 2) ExternHoehenValue++;
if(DubWiseKeys[0] & 16) ExternHoehenValue--;
if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else
if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0;
if(DubWiseKeys[0] & 2) ExternHightValue++;
if(DubWiseKeys[0] & 16) ExternHightValue--;
 
StickNick += ExternStickNick / 8;
StickPitch += ExternStickPitch/ 8;
StickRoll += ExternStickRoll / 8;
StickGier += ExternStickGier;
StickYaw += ExternStickYaw;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+ Analoge Steuerung per Seriell
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(ExternControl.Config & 0x01 && Parameter_UserParam1 > 128)
{
StickNick += (int) ExternControl.Nick * (int) ParamSet.Stick_P;
StickPitch += (int) ExternControl.Pitch * (int) ParamSet.Stick_P;
StickRoll += (int) ExternControl.Roll * (int) ParamSet.Stick_P;
StickGier += ExternControl.Gier;
ExternHoehenValue = (int) ExternControl.Hight * (int)ParamSet.Hoehe_Verstaerkung;
StickYaw += ExternControl.Yaw;
ExternHightValue = (int) ExternControl.Hight * (int)ParamSet.Hight_Gain;
if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
}
 
if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0;
if(GyroFaktor < 0) GyroFaktor = 0;
if(IntegralFaktor < 0) IntegralFaktor = 0;
if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) IntegralFactor = 0;
if(GyroFactor < 0) GyroFactor = 0;
if(IntegralFactor < 0) IntegralFactor = 0;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Looping?
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT) Looping_Links = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT) Looping_Left = 1;
else
{
{
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Links = 0;
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Left = 0;
}
}
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Rechts = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Right = 1;
else
{
if(Looping_Rechts) // Hysterese
if(Looping_Right) // Hysterese
{
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Rechts = 0;
if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Right = 0;
}
}
 
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Oben = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Top = 1;
else
{
if(Looping_Oben) // Hysterese
if(Looping_Top) // Hysterese
{
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Oben = 0;
if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0;
}
}
if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Unten = 1;
if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Down = 1;
else
{
if(Looping_Unten) // Hysterese
if(Looping_Down) // Hysterese
{
if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Unten = 0;
if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Down = 0;
}
}
 
if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0;
if(Looping_Oben || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
if(Looping_Left || Looping_Right) Looping_Roll = 1; else Looping_Roll = 0;
if(Looping_Top || Looping_Down) {Looping_Pitch = 1; Looping_Roll = 0; Looping_Left = 0; Looping_Right = 0;} else Looping_Pitch = 0;
} // Ende neue Funken-Werte
 
if(Looping_Roll) BeepTime = 100;
if(Looping_Roll || Looping_Nick)
if(Looping_Roll || Looping_Pitch)
{
if(GasMischanteil > ParamSet.LoopGasLimit) GasMischanteil = ParamSet.LoopGasLimit;
if(GasMixingFraction > ParamSet.LoopGasLimit) GasMixingFraction = ParamSet.LoopGasLimit;
}
 
 
695,15 → 694,15
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Bei Empfangsausfall im Flug
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(Notlandung)
if(EmergencyLanding)
{
StickGier = 0;
StickNick = 0;
StickYaw = 0;
StickPitch = 0;
StickRoll = 0;
GyroFaktor = 0.5;//Originalwert von Holger 0.1;
IntegralFaktor = 0.003; //Originalwert von Holger 0.005;
GyroFactor = 0.5;//Originalwert von Holger 0.1;
IntegralFactor = 0.003; //Originalwert von Holger 0.005;
Looping_Roll = 0;
Looping_Nick = 0;
Looping_Pitch = 0;
}
 
 
712,40 → 711,40
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define ABGLEICH_ANZAHL 256L
 
MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren
MittelIntegralRoll += IntegralRoll;
MittelIntegralNick2 += IntegralNick2;
MittelIntegralRoll2 += IntegralRoll2;
MeanIntegralPitch += IntegralPitch; // Für die Mittelwertbildung aufsummieren
MeanIntegralRoll += IntegralRoll;
MeanIntegralPitch2 += IntegralPitch2;
MeanIntegralRoll2 += IntegralRoll2;
 
if(Looping_Nick || Looping_Roll)
if(Looping_Pitch || Looping_Roll)
{
IntegralAccNick = 0;
IntegralAccPitch = 0;
IntegralAccRoll = 0;
MittelIntegralNick = 0;
MittelIntegralRoll = 0;
MittelIntegralNick2 = 0;
MittelIntegralRoll2 = 0;
Mess_IntegralNick2 = Mess_IntegralNick;
Mess_IntegralRoll2 = Mess_IntegralRoll;
MeanIntegralPitch = 0;
MeanIntegralRoll = 0;
MeanIntegralPitch2 = 0;
MeanIntegralRoll2 = 0;
Reading_IntegralPitch2 = Reading_IntegralPitch;
Reading_IntegralRoll2 = Reading_IntegralRoll;
ZaehlMessungen = 0;
LageKorrekturNick = 0;
LageKorrekturRoll = 0;
AttitudeCorrectionPitch = 0;
AttitudeCorrectionRoll = 0;
}
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(!Looping_Nick && !Looping_Roll)
if(!Looping_Pitch && !Looping_Roll)
{
long tmp_long, tmp_long2;
tmp_long = (long)(IntegralNick / ParamSet.GyroAccFaktor - (long)Mittelwert_AccNick);
tmp_long2 = (long)(IntegralRoll / ParamSet.GyroAccFaktor - (long)Mittelwert_AccRoll);
tmp_long = (long)(IntegralPitch / ParamSet.GyroAccFaktor - (long)Mean_AccPitch);
tmp_long2 = (long)(IntegralRoll / ParamSet.GyroAccFaktor - (long)Mean_AccRoll);
tmp_long /= 16;
tmp_long2 /= 16;
if((MaxStickNick > 15) || (MaxStickRoll > 15))
if((MaxStickPitch > 15) || (MaxStickRoll > 15))
{
tmp_long /= 3;
tmp_long2 /= 3;
}
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_GIER]]) > 25)
if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)
{
tmp_long /= 3;
tmp_long2 /= 3;
757,8 → 756,8
if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH;
if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH;
 
Mess_IntegralNick -= tmp_long;
Mess_IntegralRoll -= tmp_long2;
Reading_IntegralPitch -= tmp_long;
Reading_IntegralRoll -= tmp_long2;
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
766,118 → 765,118
{
static int cnt = 0;
static char last_n_p,last_n_n,last_r_p,last_r_n;
static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
if(!Looping_Nick && !Looping_Roll)
static long MeanIntegralPitch_old,MeanIntegralRoll_old;
if(!Looping_Pitch && !Looping_Roll)
{
MittelIntegralNick /= ABGLEICH_ANZAHL;
MittelIntegralRoll /= ABGLEICH_ANZAHL;
IntegralAccNick = (ParamSet.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
MeanIntegralPitch /= ABGLEICH_ANZAHL;
MeanIntegralRoll /= ABGLEICH_ANZAHL;
IntegralAccPitch = (ParamSet.GyroAccFaktor * IntegralAccPitch) / ABGLEICH_ANZAHL;
IntegralAccRoll = (ParamSet.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL;
#define MAX_I 0//(Poti2/10)
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
ausgleichNick = IntegralFehlerNick / ParamSet.GyroAccAbgleich;
// Pitch ++++++++++++++++++++++++++++++++++++++++++++++++
IntegralErrorPitch = (long)(MeanIntegralPitch - (long)IntegralAccPitch);
CorrectionPitch = IntegralErrorPitch / ParamSet.GyroAccTrim;
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
ausgleichRoll = IntegralFehlerRoll / ParamSet.GyroAccAbgleich;
IntegralErrorRoll = (long)(MeanIntegralRoll - (long)IntegralAccRoll);
CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim;
 
LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
AttitudeCorrectionPitch = CorrectionPitch / ABGLEICH_ANZAHL;
AttitudeCorrectionRoll = CorrectionRoll / ABGLEICH_ANZAHL;
 
if((MaxStickNick > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_GIER]]) > 25))
if((MaxStickPitch > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25))
{
LageKorrekturNick /= 2;
LageKorrekturNick /= 2;
AttitudeCorrectionPitch /= 2;
AttitudeCorrectionPitch /= 2;
}
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Gyro-Drift ermitteln
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MittelIntegralNick2 /= ABGLEICH_ANZAHL;
MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
tmp_long = IntegralNick2 - IntegralNick;
MeanIntegralPitch2 /= ABGLEICH_ANZAHL;
MeanIntegralRoll2 /= ABGLEICH_ANZAHL;
tmp_long = IntegralPitch2 - IntegralPitch;
tmp_long2 = IntegralRoll2 - IntegralRoll;
//DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
//DebugOut.Analog[25] = MeanIntegralRoll2 / 26;
 
IntegralFehlerNick = tmp_long;
IntegralFehlerRoll = tmp_long2;
Mess_IntegralNick2 -= IntegralFehlerNick;
Mess_IntegralRoll2 -= IntegralFehlerRoll;
IntegralErrorPitch = tmp_long;
IntegralErrorRoll = tmp_long2;
Reading_IntegralPitch2 -= IntegralErrorPitch;
Reading_IntegralRoll2 -= IntegralErrorRoll;
 
// IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
// IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
// IntegralErrorPitch = (IntegralErrorPitch * 1 + tmp_long) / 2;
// IntegralErrorRoll = (IntegralErrorRoll * 1 + tmp_long2) / 2;
 
 
DebugOut.Analog[17] = IntegralAccNick / 26;
DebugOut.Analog[17] = IntegralAccPitch / 26;
DebugOut.Analog[18] = IntegralAccRoll / 26;
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
DebugOut.Analog[21] = MittelIntegralNick / 26;
DebugOut.Analog[22] = MittelIntegralRoll / 26;
//DebugOut.Analog[28] = ausgleichNick;
DebugOut.Analog[29] = ausgleichRoll;
DebugOut.Analog[30] = LageKorrekturRoll * 10;
DebugOut.Analog[19] = IntegralErrorPitch;// / 26;
DebugOut.Analog[20] = IntegralErrorRoll;// / 26;
DebugOut.Analog[21] = MeanIntegralPitch / 26;
DebugOut.Analog[22] = MeanIntegralRoll / 26;
//DebugOut.Analog[28] = CorrectionPitch;
DebugOut.Analog[29] = CorrectionRoll;
DebugOut.Analog[30] = AttitudeCorrectionRoll * 10;
 
#define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4)
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
#define BEWEGUNGS_LIMIT 20000
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
cnt = 1;// + labs(IntegralFehlerNick) / 4096;
if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
// Pitch +++++++++++++++++++++++++++++++++++++++++++++++++
cnt = 1;// + labs(IntegralErrorPitch) / 4096;
if(labs(MeanIntegralPitch_old - MeanIntegralPitch) < BEWEGUNGS_LIMIT)
{
if(IntegralFehlerNick > FEHLER_LIMIT2)
if(IntegralErrorPitch > FEHLER_LIMIT2)
{
if(last_n_p)
{
cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
ausgleichNick = IntegralFehlerNick / 8;
if(ausgleichNick > 5000) ausgleichNick = 5000;
LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
cnt += labs(IntegralErrorPitch) / FEHLER_LIMIT2;
CorrectionPitch = IntegralErrorPitch / 8;
if(CorrectionPitch > 5000) CorrectionPitch = 5000;
AttitudeCorrectionPitch += CorrectionPitch / ABGLEICH_ANZAHL;
}
else last_n_p = 1;
} else last_n_p = 0;
if(IntegralFehlerNick < -FEHLER_LIMIT2)
if(IntegralErrorPitch < -FEHLER_LIMIT2)
{
if(last_n_n)
{
cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
ausgleichNick = IntegralFehlerNick / 8;
if(ausgleichNick < -5000) ausgleichNick = -5000;
LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
cnt += labs(IntegralErrorPitch) / FEHLER_LIMIT2;
CorrectionPitch = IntegralErrorPitch / 8;
if(CorrectionPitch < -5000) CorrectionPitch = -5000;
AttitudeCorrectionPitch += CorrectionPitch / ABGLEICH_ANZAHL;
}
else last_n_n = 1;
} else last_n_n = 0;
} else cnt = 0;
if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp;
if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt;
if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt;
if(IntegralErrorPitch > FEHLER_LIMIT) AdNeutralPitch += cnt;
if(IntegralErrorPitch < -FEHLER_LIMIT) AdNeutralPitch -= cnt;
 
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
cnt = 1;// + labs(IntegralFehlerNick) / 4096;
cnt = 1;// + labs(IntegralErrorPitch) / 4096;
 
ausgleichRoll = 0;
if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
CorrectionRoll = 0;
if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < BEWEGUNGS_LIMIT)
{
if(IntegralFehlerRoll > FEHLER_LIMIT2)
if(IntegralErrorRoll > FEHLER_LIMIT2)
{
if(last_r_p)
{
cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
ausgleichRoll = IntegralFehlerRoll / 8;
if(ausgleichRoll > 5000) ausgleichRoll = 5000;
LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
cnt += labs(IntegralErrorRoll) / FEHLER_LIMIT2;
CorrectionRoll = IntegralErrorRoll / 8;
if(CorrectionRoll > 5000) CorrectionRoll = 5000;
AttitudeCorrectionRoll += CorrectionRoll / ABGLEICH_ANZAHL;
}
else last_r_p = 1;
} else last_r_p = 0;
if(IntegralFehlerRoll < -FEHLER_LIMIT2)
if(IntegralErrorRoll < -FEHLER_LIMIT2)
{
if(last_r_n)
{
cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
ausgleichRoll = IntegralFehlerRoll / 8;
if(ausgleichRoll < -5000) ausgleichRoll = -5000;
LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
cnt += labs(IntegralErrorRoll) / FEHLER_LIMIT2;
CorrectionRoll = IntegralErrorRoll / 8;
if(CorrectionRoll < -5000) CorrectionRoll = -5000;
AttitudeCorrectionRoll += CorrectionRoll / ABGLEICH_ANZAHL;
}
else last_r_n = 1;
} else last_r_n = 0;
887,47 → 886,47
}
 
if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp;
if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt;
if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt;
DebugOut.Analog[27] = ausgleichRoll;
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
if(IntegralErrorRoll > FEHLER_LIMIT) AdNeutralRoll += cnt;
if(IntegralErrorRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt;
DebugOut.Analog[27] = CorrectionRoll;
DebugOut.Analog[23] = AdNeutralPitch;//10*(AdNeutralPitch - StartNeutralPitch);
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
}
else
{
LageKorrekturRoll = 0;
LageKorrekturNick = 0;
AttitudeCorrectionRoll = 0;
AttitudeCorrectionPitch = 0;
}
 
if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
if(!IntegralFactor) { AttitudeCorrectionRoll = 0; AttitudeCorrectionPitch = 0;} // z.B. bei HH
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
MittelIntegralNick_Alt = MittelIntegralNick;
MittelIntegralRoll_Alt = MittelIntegralRoll;
MeanIntegralPitch_old = MeanIntegralPitch;
MeanIntegralRoll_old = MeanIntegralRoll;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
IntegralAccNick = 0;
IntegralAccPitch = 0;
IntegralAccRoll = 0;
IntegralAccZ = 0;
MittelIntegralNick = 0;
MittelIntegralRoll = 0;
MittelIntegralNick2 = 0;
MittelIntegralRoll2 = 0;
MeanIntegralPitch = 0;
MeanIntegralRoll = 0;
MeanIntegralPitch2 = 0;
MeanIntegralRoll2 = 0;
ZaehlMessungen = 0;
}
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
//DebugOut.Analog[31] = StickRoll / (26*IntegralFactor);
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Gieren
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(abs(StickGier) > 20) // war 35
if(abs(StickYaw) > 20) // war 35
{
if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) NeueKompassRichtungMerken = 1;
if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) StoreNewCompassCourse = 1;
}
tmp_int = (long) ParamSet.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx²
tmp_int += (ParamSet.Gier_P * StickGier) / 4;
sollGier = tmp_int;
Mess_Integral_Gier -= tmp_int;
if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen
if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
tmp_int = (long) ParamSet.Yaw_P * ((long)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx²
tmp_int += (ParamSet.Yaw_P * StickYaw) / 4;
SetPointYaw = tmp_int;
Reading_Integral_Yaw -= tmp_int;
if(Reading_Integral_Yaw > 50000) Reading_Integral_Yaw = 50000; // begrenzen
if(Reading_Integral_Yaw <-50000) Reading_Integral_Yaw =-50000;
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Kompass
935,28 → 934,28
if(ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE)
{
int w,v;
static uint8_t updKompass = 0;
static uint8_t updCompass = 0;
 
if (!updKompass--) // Aufruf mit ~10 Hz
if (!updCompass--) // Aufruf mit ~10 Hz
{
KompassValue = MM3_heading(); // get current compass reading
KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
updKompass = 50;
CompassHeading = MM3_heading(); // get current compass reading
CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180;
updCompass = 50;
}
 
w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
w = abs(IntegralPitch /512); // mit zunehmender Neigung den Einfluss drosseln
v = abs(IntegralRoll /512);
if(v > w) w = v; // grösste Neigung ermitteln
if(w < 35 && NeueKompassRichtungMerken)
if(w < 35 && StoreNewCompassCourse)
{
KompassStartwert = KompassValue;
NeueKompassRichtungMerken = 0;
CompassCourse = CompassHeading;
StoreNewCompassCourse = 0;
}
w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren
w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln
w = (w * Parameter_CompassYawEffect) / 64; // auf die Wirkung normieren
w = Parameter_CompassYawEffect - w; // Wirkung ggf drosseln
if(w > 0)
{
Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten
Reading_Integral_Yaw -= (CompassOffCourse * w) / 32; // nach Kompass ausrichten
}
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
964,20 → 963,20
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Debugwerte zuordnen
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
if(!TimerWerteausgabe--)
if(!TimerDebugOut--)
{
TimerWerteausgabe = 24;
DebugOut.Analog[0] = IntegralNick / ParamSet.GyroAccFaktor;
TimerDebugOut = 24;
DebugOut.Analog[0] = IntegralPitch / ParamSet.GyroAccFaktor;
DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFaktor;
DebugOut.Analog[2] = Mittelwert_AccNick;
DebugOut.Analog[3] = Mittelwert_AccRoll;
DebugOut.Analog[4] = MesswertGier;
DebugOut.Analog[5] = HoehenWert;
DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
DebugOut.Analog[8] = KompassValue;
DebugOut.Analog[2] = Mean_AccPitch;
DebugOut.Analog[3] = Mean_AccRoll;
DebugOut.Analog[4] = ReadingYaw;
DebugOut.Analog[5] = ReadingHight;
DebugOut.Analog[6] = (Reading_Integral_Top / 512);
DebugOut.Analog[8] = CompassHeading;
DebugOut.Analog[9] = UBat;
DebugOut.Analog[10] = SenderOkay;
DebugOut.Analog[16] = Mittelwert_AccHoch;
DebugOut.Analog[16] = Mean_AccTop;
 
/* DebugOut.Analog[16] = motor_rx[0];
DebugOut.Analog[17] = motor_rx[1];
991,14 → 990,14
DebugOut.Analog[24] = motor_rx[7];
DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
*/
// DebugOut.Analog[9] = MesswertNick;
// DebugOut.Analog[9] = SollHoehe;
// DebugOut.Analog[10] = Mess_Integral_Gier / 128;
// DebugOut.Analog[11] = KompassStartwert;
// DebugOut.Analog[9] = ReadingPitch;
// DebugOut.Analog[9] = SetPointHight;
// DebugOut.Analog[10] = Reading_Integral_Yaw / 128;
// DebugOut.Analog[11] = CompassCourse;
// DebugOut.Analog[10] = Parameter_Gyro_I;
// DebugOut.Analog[10] = ParamSet.Gyro_I;
// DebugOut.Analog[9] = KompassRichtung;
// DebugOut.Analog[10] = GasMischanteil;
// DebugOut.Analog[9] = CompassOffCourse;
// DebugOut.Analog[10] = GasMixingFraction;
// DebugOut.Analog[3] = HoeheD * 32;
// DebugOut.Analog[4] = hoehenregler;
}
1006,27 → 1005,27
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//DebugOut.Analog[26] = MesswertNick;
//DebugOut.Analog[28] = MesswertRoll;
//DebugOut.Analog[26] = ReadingPitch;
//DebugOut.Analog[28] = ReadingRoll;
 
if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
if(Looping_Pitch) ReadingPitch = ReadingPitch * GyroFactor;
else ReadingPitch = IntegralPitch * IntegralFactor + ReadingPitch * GyroFactor;
if(Looping_Roll) ReadingRoll = ReadingRoll * GyroFactor;
else ReadingRoll = IntegralRoll * IntegralFactor + ReadingRoll * GyroFactor;
ReadingYaw = ReadingYaw * (2 * GyroFactor) + Integral_Yaw * IntegralFactor / 2;
 
DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
DebugOut.Analog[28] = MesswertRoll;
DebugOut.Analog[25] = IntegralRoll * IntegralFactor;
DebugOut.Analog[31] = StickRoll;// / (26*IntegralFactor);
DebugOut.Analog[28] = ReadingRoll;
 
// Maximalwerte abfangen
#define MAX_SENSOR 2048
if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR;
if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR;
if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR;
if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
if(ReadingPitch > MAX_SENSOR) ReadingPitch = MAX_SENSOR;
if(ReadingPitch < -MAX_SENSOR) ReadingPitch = -MAX_SENSOR;
if(ReadingRoll > MAX_SENSOR) ReadingRoll = MAX_SENSOR;
if(ReadingRoll < -MAX_SENSOR) ReadingRoll = -MAX_SENSOR;
if(ReadingYaw > MAX_SENSOR) ReadingYaw = MAX_SENSOR;
if(ReadingYaw < -MAX_SENSOR) ReadingYaw = -MAX_SENSOR;
 
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Höhenregelung
1041,108 → 1040,108
{
if(Parameter_MaxHoehe < 50)
{
SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters
HoehenReglerAktiv = 0;
SetPointHight = ReadingHight - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters
HightControlActive = 0;
}
else
HoehenReglerAktiv = 1;
HightControlActive = 1;
}
else
{
SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)ParamSet.Hoehe_Verstaerkung - 20;
HoehenReglerAktiv = 1;
SetPointHight = ((int) ExternHightValue + (int) Parameter_MaxHoehe) * (int)ParamSet.Hight_Gain - 20;
HightControlActive = 1;
}
 
if(Notlandung) SollHoehe = 0;
h = HoehenWert;
if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln
{ h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
h = GasMischanteil - h; // vom Gas abziehen
if(EmergencyLanding) SetPointHight = 0;
h = ReadingHight;
if((h > SetPointHight) && HightControlActive) // zu hoch --> drosseln
{ h = ((h - SetPointHight) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
h = GasMixingFraction - h; // vom Gas abziehen
h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil
tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
tmp_int = ((Reading_Integral_Top / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
if(tmp_int > 50) tmp_int = 50;
else if(tmp_int < -50) tmp_int = -50;
h -= tmp_int;
hoehenregler = (hoehenregler*15 + h) / 16;
if(hoehenregler < ParamSet.Hoehe_MinGas) // nicht unter MIN
if(hoehenregler < ParamSet.Hight_MinGas) // nicht unter MIN
{
if(GasMischanteil >= ParamSet.Hoehe_MinGas) hoehenregler = ParamSet.Hoehe_MinGas;
if(GasMischanteil < ParamSet.Hoehe_MinGas) hoehenregler = GasMischanteil;
if(GasMixingFraction >= ParamSet.Hight_MinGas) hoehenregler = ParamSet.Hight_MinGas;
if(GasMixingFraction < ParamSet.Hight_MinGas) hoehenregler = GasMixingFraction;
}
if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
GasMischanteil = hoehenregler;
if(hoehenregler > GasMixingFraction) hoehenregler = GasMixingFraction; // nicht mehr als Gas
GasMixingFraction = hoehenregler;
}
}
if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20;
if(GasMixingFraction > MAX_GAS - 20) GasMixingFraction = MAX_GAS - 20;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Mischer und PI-Regler
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DebugOut.Analog[7] = GasMischanteil;
DebugOut.Analog[7] = GasMixingFraction;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Gier-Anteil
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define MUL_G 1.0
GierMischanteil = MesswertGier - sollGier; // Regler für Gier
// GierMischanteil = 0;
YawMixingFraction = ReadingYaw - SetPointYaw; // Regler für Gier
// YawMixingFraction = 0;
 
if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil));
if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil));
if(YawMixingFraction > (GasMixingFraction / 2)) YawMixingFraction = GasMixingFraction / 2;
if(YawMixingFraction < -(GasMixingFraction / 2)) YawMixingFraction = -(GasMixingFraction / 2);
if(YawMixingFraction > ((MAX_GAS - GasMixingFraction))) YawMixingFraction = ((MAX_GAS - GasMixingFraction));
if(YawMixingFraction < -((MAX_GAS - GasMixingFraction))) YawMixingFraction = -((MAX_GAS - GasMixingFraction));
 
if(GasMischanteil < 20) GierMischanteil = 0;
if(GasMixingFraction < 20) YawMixingFraction = 0;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Nick-Achse
// Pitch-Achse
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DiffNick = MesswertNick - (StickNick - GPS_Nick); // Differenz bestimmen
if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
else SummeNick += DiffNick; // I-Anteil bei HH
if(SummeNick > 16000) SummeNick = 16000;
if(SummeNick < -16000) SummeNick = -16000;
pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick
DiffPitch = ReadingPitch - (StickPitch - GPS_Pitch); // Differenz bestimmen
if(IntegralFactor) SumPitch += IntegralPitch * IntegralFactor - (StickPitch - GPS_Pitch); // I-Anteil bei Winkelregelung
else SumPitch += DiffPitch; // I-Anteil bei HH
if(SumPitch > 16000) SumPitch = 16000;
if(SumPitch < -16000) SumPitch = -16000;
pd_ergebnis = DiffPitch + Ki * SumPitch; // PI-Regler für Pitch
// Motor Vorn
tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMixingFraction + abs(YawMixingFraction)/2)) / 64;
if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int;
if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
 
motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer
if ((motorwert < 0)) motorwert = 0;
else if(motorwert > MAX_GAS) motorwert = MAX_GAS;
if (motorwert < MIN_GAS) motorwert = MIN_GAS;
Motor_Vorne = motorwert;
MotorValue = GasMixingFraction + pd_ergebnis + YawMixingFraction; // Mischer
if ((MotorValue < 0)) MotorValue = 0;
else if(MotorValue > MAX_GAS) MotorValue = MAX_GAS;
if (MotorValue < MIN_GAS) MotorValue = MIN_GAS;
Motor_Front = MotorValue;
// Motor Heck
motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
if ((motorwert < 0)) motorwert = 0;
else if(motorwert > MAX_GAS) motorwert = MAX_GAS;
if (motorwert < MIN_GAS) motorwert = MIN_GAS;
Motor_Hinten = motorwert;
MotorValue = GasMixingFraction - pd_ergebnis + YawMixingFraction;
if ((MotorValue < 0)) MotorValue = 0;
else if(MotorValue > MAX_GAS) MotorValue = MAX_GAS;
if (MotorValue < MIN_GAS) MotorValue = MIN_GAS;
Motor_Rear = MotorValue;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Roll-Achse
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DiffRoll = MesswertRoll - (StickRoll - GPS_Roll); // Differenz bestimmen
if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll - GPS_Roll);// I-Anteil bei Winkelregelung
else SummeRoll += DiffRoll; // I-Anteil bei HH
if(SummeRoll > 16000) SummeRoll = 16000;
if(SummeRoll < -16000) SummeRoll = -16000;
pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll
tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
DiffRoll = ReadingRoll - (StickRoll - GPS_Roll); // Differenz bestimmen
if(IntegralFactor) SumRoll += IntegralRoll * IntegralFactor - (StickRoll - GPS_Roll);// I-Anteil bei Winkelregelung
else SumRoll += DiffRoll; // I-Anteil bei HH
if(SumRoll > 16000) SumRoll = 16000;
if(SumRoll < -16000) SumRoll = -16000;
pd_ergebnis = DiffRoll + Ki * SumRoll; // PI-Regler für Roll
tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMixingFraction + abs(YawMixingFraction)/2)) / 64;
if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int;
if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
// Motor Links
motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
MotorValue = GasMixingFraction + pd_ergebnis - YawMixingFraction;
#define GRENZE Poti1
 
if ((motorwert < 0)) motorwert = 0;
else if(motorwert > MAX_GAS) motorwert = MAX_GAS;
if (motorwert < MIN_GAS) motorwert = MIN_GAS;
Motor_Links = motorwert;
if ((MotorValue < 0)) MotorValue = 0;
else if(MotorValue > MAX_GAS) MotorValue = MAX_GAS;
if (MotorValue < MIN_GAS) MotorValue = MIN_GAS;
Motor_Left = MotorValue;
// Motor Rechts
motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
MotorValue = GasMixingFraction - pd_ergebnis - YawMixingFraction;
 
if ((motorwert < 0)) motorwert = 0;
else if(motorwert > MAX_GAS) motorwert = MAX_GAS;
if (motorwert < MIN_GAS) motorwert = MIN_GAS;
Motor_Rechts = motorwert;
if ((MotorValue < 0)) MotorValue = 0;
else if(MotorValue > MAX_GAS) MotorValue = MAX_GAS;
if (MotorValue < MIN_GAS) MotorValue = MIN_GAS;
Motor_Right = MotorValue;
// +++++++++++++++++++++++++++++++++++++++++++++++
}
 
/branches/V0.68d Code Redesign killagreg/fc.h
6,47 → 6,47
#define _FC_H
 
extern volatile unsigned int I2CTimeout;
extern volatile long IntegralNick,IntegralNick2;
extern volatile long IntegralPitch,IntegralPitch2;
extern volatile long IntegralRoll,IntegralRoll2;
extern volatile long Mess_IntegralNick,Mess_IntegralNick2;
extern volatile long Mess_IntegralRoll,Mess_IntegralRoll2;
extern volatile long IntegralAccNick,IntegralAccRoll;
extern volatile long Mess_Integral_Hoch;
extern volatile long Integral_Gier,Mess_Integral_Gier,Mess_Integral_Gier2;
extern volatile int KompassValue;
extern volatile int KompassStartwert;
extern volatile int KompassRichtung;
extern int HoehenWert;
extern int SollHoehe;
extern volatile int MesswertNick,MesswertRoll,MesswertGier;
extern volatile int AdNeutralNick,AdNeutralRoll,AdNeutralGier, Mittelwert_AccNick, Mittelwert_AccRoll;
extern volatile int NeutralAccX, NeutralAccY,Mittelwert_AccHoch;
extern volatile long Reading_IntegralPitch,Reading_IntegralPitch2;
extern volatile long Reading_IntegralRoll,Reading_IntegralRoll2;
extern volatile long IntegralAccPitch,IntegralAccRoll;
extern volatile long Reading_Integral_Top;
extern volatile long Integral_Yaw,Reading_Integral_Yaw,Reading_Integral_Yaw2;
extern volatile int CompassHeading;
extern volatile int CompassCourse;
extern volatile int CompassOffCourse;
extern int ReadingHight;
extern int SetPointHight;
extern volatile int16_t ReadingPitch,ReadingRoll,ReadingYaw;
extern volatile int AdNeutralPitch,AdNeutralRoll,AdNeutralYaw, Mean_AccPitch, Mean_AccRoll;
extern volatile int NeutralAccX, NeutralAccY,Mean_AccTop;
extern volatile float NeutralAccZ;
extern long Umschlag180Nick, Umschlag180Roll;
extern signed int ExternStickNick,ExternStickRoll,ExternStickGier;
extern long TurnOver180Pitch, TurnOver180Roll;
extern signed int ExternStickPitch,ExternStickRoll,ExternStickYaw;
extern unsigned char Parameter_UserParam1,Parameter_UserParam2,Parameter_UserParam3,Parameter_UserParam4,Parameter_UserParam5,Parameter_UserParam6,Parameter_UserParam7,Parameter_UserParam8;
 
void MotorRegler(void);
void SendMotorData(void);
void CalibrierMittelwert(void);
void Mittelwert(void);
void CalibMean(void);
void Mean(void);
void SetNeutral(void);
void Piep(unsigned char Anzahl);
 
extern unsigned char h,m,s;
extern volatile unsigned char Timeout;
extern volatile long IntegralNick,IntegralNick2;
extern volatile long IntegralPitch,IntegralPitch2;
extern volatile long IntegralRoll,IntegralRoll2;
extern volatile long Integral_Gier;
extern volatile long Mess_IntegralNick,Mess_IntegralNick2;
extern volatile long Mess_IntegralRoll,Mess_IntegralRoll2;
extern volatile long Mess_Integral_Gier;
extern volatile int DiffNick,DiffRoll;
extern volatile long Integral_Yaw;
extern volatile long Reading_IntegralPitch,Reading_IntegralPitch2;
extern volatile long Reading_IntegralRoll,Reading_IntegralRoll2;
extern volatile long Reading_Integral_Yaw;
extern volatile int DiffPitch,DiffRoll;
extern int Poti1, Poti2, Poti3, Poti4;
extern volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
extern unsigned char MotorWert[5];
extern int StickNick,StickRoll,StickGier;
extern char MotorenEin;
extern volatile unsigned char Motor_Front,Motor_Rear,Motor_Right,Motor_Left, Count;
extern unsigned char MotorValue[5];
extern int StickPitch,StickRoll,StickYaw;
extern char MotorsOn;
 
 
 
54,11 → 54,11
extern unsigned char Parameter_MaxHoehe;
extern unsigned char Parameter_Hoehe_P;
extern unsigned char Parameter_Hoehe_ACC_Wirkung;
extern unsigned char Parameter_KompassWirkung;
extern unsigned char Parameter_CompassYawEffect;
extern unsigned char Parameter_Gyro_P;
extern unsigned char Parameter_Gyro_I;
extern unsigned char Parameter_Gier_P;
extern unsigned char Parameter_ServoNickControl;
extern unsigned char Parameter_ServoPitchControl;
extern unsigned char Parameter_AchsKopplung1;
extern unsigned char Parameter_AchsGegenKopplung1;
 
/branches/V0.68d Code Redesign killagreg/gps.h
1,14 → 1,11
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
extern signed int GPS_Nick;
#ifndef _GPS_H
#define _GPS_H
 
extern signed int GPS_Pitch;
extern signed int GPS_Roll;
 
void GPS_Neutral(void);
void GPS_BerechneZielrichtung(void);
void GPS_CalcTargetDirection(void);
 
#endif //_GPS_H
 
/branches/V0.68d Code Redesign killagreg/main.c
110,9 → 110,9
BeepTime = 2000;
 
PPM_in[CH_GAS] = 0;
StickGier = 0;
StickYaw = 0;
StickRoll = 0;
StickNick = 0;
StickPitch = 0;
 
ROT_OFF;
 
119,7 → 119,7
TIMER0_Init();
TIMER2_Init();
USART0_Init();
USART1_Init();
//USART1_Init();
rc_sum_init();
ADC_Init();
i2c_init();
140,7 → 140,7
// Parameter set handling
ParamSet_Init();
 
if(GetParamByte(PID_ACC_NICK) > 4)
if(GetParamByte(PID_ACC_PITCH) > 4)
{
printf("\n\rACC nicht abgeglichen!");
}
150,7 → 150,7
while(!CheckDelay(timer));
 
//Compass calibration?
if(PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 100 && PPM_in[ParamSet.ChannelAssignment[CH_GIER]] > 100)
if(PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 100 && PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 100)
{
printf("\n\rCalibrating Compass");
MM3_calibrate();
161,7 → 161,7
{
printf("\n\rAbgleich Luftdrucksensor..");
timer = SetDelay(1000);
SucheLuftruckOffset();
SearchAirPressureOffset();
while (!CheckDelay(timer));
printf("OK\n\r");
}
200,9 → 200,9
DubWiseKeys[0] = 0;
DubWiseKeys[1] = 0;
ExternControl.Config = 0;
ExternStickNick = 0;
ExternStickPitch= 0;
ExternStickRoll = 0;
ExternStickGier = 0;
ExternStickYaw = 0;
}
if(SenderOkay) SenderOkay--;
if(!I2CTimeout)
209,7 → 209,7
{
I2CTimeout = 5;
i2c_reset();
if((BeepModulation == 0xFFFF) && MotorenEin)
if((BeepModulation == 0xFFFF) && MotorsOn)
{
BeepTime = 10000; // 1 second
BeepModulation = 0x0080;
/branches/V0.68d Code Redesign killagreg/menu.c
90,9 → 90,9
case 1:// Hight Control Menu Item
if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)
{
LCD_printfxy(0,0,"Hight: %5i",HoehenWert);
LCD_printfxy(0,1,"Set Point: %5i",SollHoehe);
LCD_printfxy(0,2,"Air Press.: %5i",MessLuftdruck);
LCD_printfxy(0,0,"Hight: %5i",ReadingHight);
LCD_printfxy(0,1,"Set Point: %5i",SetPointHight);
LCD_printfxy(0,2,"Air Press.: %5i",ReadingAirPressure);
LCD_printfxy(0,3,"Offset : %5i",DruckOffsetSetting);
}
else
104,9 → 104,9
break;
case 2:// Attitude Menu Item
LCD_printfxy(0,0,"Attitude");
LCD_printfxy(0,1,"Nick: %5i",IntegralNick/1024);
LCD_printfxy(0,1,"Pitch: %5i",IntegralPitch/1024);
LCD_printfxy(0,2,"Roll: %5i",IntegralRoll/1024);
LCD_printfxy(0,3,"Compass: %5i",KompassValue);
LCD_printfxy(0,3,"Compass: %5i",CompassHeading);
break;
case 3:// Remote Control Channel Menu Item
LCD_printfxy(0,0,"C1:%4i C2:%4i ",PPM_in[1],PPM_in[2]);
115,8 → 115,8
LCD_printfxy(0,3,"C7:%4i C8:%4i ",PPM_in[7],PPM_in[8]);
break;
case 4:// Remote Control Mapping Menu Item
LCD_printfxy(0,0,"Ni:%4i Ro:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_NICK]],PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]);
LCD_printfxy(0,1,"Gs:%4i Gi:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_GAS]],PPM_in[ParamSet.ChannelAssignment[CH_GIER]]);
LCD_printfxy(0,0,"Pi:%4i Ro:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_PITCH]],PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]);
LCD_printfxy(0,1,"Gs:%4i Ya:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_GAS]],PPM_in[ParamSet.ChannelAssignment[CH_YAW]]);
LCD_printfxy(0,2,"P1:%4i P2:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_POTI1]],PPM_in[ParamSet.ChannelAssignment[CH_POTI2]]);
LCD_printfxy(0,3,"P3:%4i P4:%4i ",PPM_in[ParamSet.ChannelAssignment[CH_POTI3]],PPM_in[ParamSet.ChannelAssignment[CH_POTI4]]);
break;
124,22 → 124,22
LCD_printfxy(0,0,"Gyro - Sensor");
if(BoardRelease == 10)
{
LCD_printfxy(0,1,"Nick %4i (%3i)",AdValueGyrNick - AdNeutralNick, AdNeutralNick);
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueGyrRoll - AdNeutralRoll, AdNeutralRoll);
LCD_printfxy(0,3,"Yaw %4i (%3i)",MesswertGier, AdNeutralGier);
LCD_printfxy(0,1,"Pitch %4i (%3i)",AdValueGyrPitch - AdNeutralPitch, AdNeutralPitch);
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueGyrRoll - AdNeutralRoll, AdNeutralRoll);
LCD_printfxy(0,3,"Yaw %4i (%3i)",ReadingYaw, AdNeutralYaw);
}
else
{
LCD_printfxy(0,1,"Nick %4i (%3i)",AdValueGyrNick - AdNeutralNick, AdNeutralNick/2);
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueGyrRoll - AdNeutralRoll, AdNeutralRoll/2);
LCD_printfxy(0,3,"Yaw %4i (%3i)",MesswertGier, AdNeutralGier/2);
LCD_printfxy(0,1,"Pitch %4i (%3i)",AdValueGyrPitch - AdNeutralPitch, AdNeutralPitch/2);
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueGyrRoll - AdNeutralRoll, AdNeutralRoll/2);
LCD_printfxy(0,3,"Yaw %4i (%3i)",ReadingYaw, AdNeutralYaw/2);
}
break;
case 6:// Acceleration Sensor Menu Item
LCD_printfxy(0,0,"ACC - Sensor");
LCD_printfxy(0,1,"Nick %4i (%3i)",AdValueAccNick,NeutralAccX);
LCD_printfxy(0,1,"Pitch %4i (%3i)",AdValueAccPitch,NeutralAccX);
LCD_printfxy(0,2,"Roll %4i (%3i)",AdValueAccRoll,NeutralAccY);
LCD_printfxy(0,3,"Hight %4i (%3i)",Mittelwert_AccHoch/*accumulate_AccHoch / messanzahl_AccHoch*/,(int)NeutralAccZ);
LCD_printfxy(0,3,"Hight %4i (%3i)",Mean_AccTop/*accumulate_AccHoch / messanzahl_AccHoch*/,(int)NeutralAccZ);
break;
case 7:// Accumulator Voltage / Remote Control Level
LCD_printfxy(0,1,"Voltage: %5i",UBat);
147,9 → 147,9
break;
case 8:// Compass Menu Item
LCD_printfxy(0,0,"Compass ");
LCD_printfxy(0,1,"Direction: %5i",KompassRichtung);
LCD_printfxy(0,2,"Reading: %5i",KompassValue);
LCD_printfxy(0,3,"Start: %5i",KompassStartwert);
LCD_printfxy(0,1,"Course: %5i",CompassCourse);
LCD_printfxy(0,2,"Heading: %5i",CompassHeading);
LCD_printfxy(0,3,"OffCourse: %5i",CompassOffCourse);
break;
case 9:// Poti Menu Item
LCD_printfxy(0,0,"Poti1: %3i",Poti1);
159,14 → 159,14
break;
case 10:// Servo Menu Item
LCD_printfxy(0,0,"Servo " );
LCD_printfxy(0,1,"Setpoint %3i",Parameter_ServoNickControl);
LCD_printfxy(0,1,"Setpoint %3i",Parameter_ServoPitchControl);
LCD_printfxy(0,2,"Position: %3i",ServoValue);
LCD_printfxy(0,3,"Range:%3i-%3i",ParamSet.ServoNickMin,ParamSet.ServoNickMax);
LCD_printfxy(0,3,"Range:%3i-%3i",ParamSet.ServoPitchMin,ParamSet.ServoPitchMax);
break;
case 11://Extern Control
LCD_printfxy(0,0,"ExternControl " );
LCD_printfxy(0,1,"Ni:%4i Ro:%4i ",ExternControl.Nick,ExternControl.Roll);
LCD_printfxy(0,2,"Gs:%4i Gi:%4i ",ExternControl.Gas,ExternControl.Gier);
LCD_printfxy(0,1,"Pi:%4i Ro:%4i ",ExternControl.Pitch,ExternControl.Roll);
LCD_printfxy(0,2,"Gs:%4i Ya:%4i ",ExternControl.Gas,ExternControl.Yaw);
LCD_printfxy(0,3,"Hi:%4i Cf:%4i ",ExternControl.Hight,ExternControl.Config);
break;
case 12:// MM3 Kompass
/branches/V0.68d Code Redesign killagreg/mm3.c
265,7 → 265,7
/*********************************************/
int16_t MM3_heading(void)
{
int32_t sin_nick, cos_nick, sin_roll, cos_roll, sin_yaw, cos_yaw;
int32_t sin_pitch, cos_pitch, sin_roll, cos_roll, sin_yaw, cos_yaw;
int32_t Hx, Hy, Hz, Hx_corr, Hy_corr;
int16_t angle;
uint16_t div_factor;
305,17 → 305,17
// calibration factor for transforming Gyro Integrals to angular degrees
div_factor = (uint16_t)ParamSet.UserParam3 * 8;
 
// calculate sinus cosinus of nick and tilt angle
angle = (IntegralNick/div_factor);
sin_nick = (int32_t)(c_sin_8192(angle));
cos_nick = (int32_t)(c_cos_8192(angle));
// calculate sinus cosinus of pitch and tilt angle
angle = (IntegralPitch/div_factor);
sin_pitch = (int32_t)(c_sin_8192(angle));
cos_pitch = (int32_t)(c_cos_8192(angle));
 
angle = (IntegralRoll/div_factor);
sin_roll = (int32_t)(c_sin_8192(angle));
cos_roll = (int32_t)(c_cos_8192(angle));
 
Hx_corr = Hx * cos_nick;
Hx_corr -= Hz * sin_nick;
Hx_corr = Hx * cos_pitch;
Hx_corr -= Hz * sin_pitch;
Hx_corr /= 8192;
 
Hy_corr = Hy * cos_roll;
/branches/V0.68d Code Redesign killagreg/spi.c
25,11 → 25,11
ToNaviCtrl.Sync2 = 0x55;
 
ToNaviCtrl.Comp = 12;
ToNaviCtrl.IntegralNick = 12345;
ToNaviCtrl.IntegralPitch = 12345;
ToNaviCtrl.IntegralRoll = 56789;
ToNaviCtrl.StickNick = 100;
ToNaviCtrl.StickPitch = 100;
ToNaviCtrl.StickRoll = 150;//(char) StickRoll;
ToNaviCtrl.StickGier = 200;//(char) StickGier;
ToNaviCtrl.StickYaw = 200;//(char) StickYaw;
 
}
 
47,9 → 47,9
DebugOut.Analog[16]++;
// -- Debug-Output ---
/* DebugOut.Analog[20] = FromNaviCtrl.Comp;
DebugOut.Analog[21] = FromNaviCtrl.GPS_Nick;
DebugOut.Analog[21] = FromNaviCtrl.GPS_Pitch;
DebugOut.Analog[22] = FromNaviCtrl.GPS_Roll;
DebugOut.Analog[23] = FromNaviCtrl.CompassValue;
DebugOut.Analog[23] = FromNaviCtrl.CompassHeading;
*/
//----
SPDR = ToNaviCtrl.Sync1; // Start transmission
100,11 → 100,11
/*static unsigned char i =0;
cli();
ToNaviCtrl.Comp = SPI_PROTOCOL_COMP;
ToNaviCtrl.IntegralNick = (int) (IntegralNick >> 4);
ToNaviCtrl.IntegralPitch = (int) (IntegralPitch >> 4);
ToNaviCtrl.IntegralRoll = (int) (IntegralRoll >> 4);
ToNaviCtrl.StickNick = 4;
ToNaviCtrl.StickPitch = 4;
ToNaviCtrl.StickRoll = 5;//(char) StickRoll;
ToNaviCtrl.StickGier = 6;//(char) StickGier;
ToNaviCtrl.StickYaw = 6;//(char) StickYaw;
sei();
*/
}
/branches/V0.68d Code Redesign killagreg/spi.h
2,7 → 2,7
#ifndef _SPI_H
#define _SPI_H
 
//#define USE_SPI_COMMUNICATION
//#define USE_SPI_COMMUNICATION
 
#define SPI_PROTOCOL_COMP 1
 
11,36 → 11,36
#define DD_SS PB4
#define DD_SCK PB7
#define DD_MOSI PB5
#define DD_MISO PB6
#define DD_MISO PB6
 
// for compatibility reasons gcc3.x <-> gcc4.x
#ifndef SPCR
// for compatibility reasons gcc3.x <-> gcc4.x
#ifndef SPCR
#define SPCR SPCR0
#endif
#ifndef SPE
#endif
#ifndef SPE
#define SPE SPE0
#endif
#ifndef MSTR
#endif
#ifndef MSTR
#define MSTR MSTR0
#endif
#ifndef SPR1
#endif
#ifndef SPR1
#define SPR1 SPR01
#endif
#ifndef SPR0
#endif
#ifndef SPR0
#define SPR0 SPR00
#endif
#ifndef SPIE
#endif
#ifndef SPIE
#define SPIE SPIE0
#endif
#ifndef SPDR
#endif
#ifndef SPDR
#define SPDR SPDR0
#endif
#ifndef SPIF
#endif
#ifndef SPIF
#define SPIF SPIF0
#endif
#ifndef SPSR
#endif
#ifndef SPSR
#define SPSR SPSR0
#endif
#endif
// -------------------------
 
#define SLAVE_SELECT_DDR_PORT DDRC
51,20 → 51,20
{
unsigned char Sync1, Sync2;
unsigned char Comp;
int IntegralNick;
int IntegralPitch;
int IntegralRoll;
char StickNick,StickRoll,StickGier;
char StickPitch,StickRoll,StickYaw;
unsigned char ChkSum;
};
};
 
struct str_FromNaviCtrl
{
unsigned int Dummy;
unsigned char Comp;
int GPS_Nick;
int GPS_Pitch;
int GPS_Roll;
int CompassValue;
};
int CompassHeading;
};
 
#ifdef USE_SPI_COMMUNICATION
extern struct str_ToNaviCtrl ToNaviCtrl;
79,7 → 79,7
 
 
// -------------------------------- Dummy -----------------------------------------
#define SPI_MasterInit() ;
#define SPI_MasterInit() ;
#define SPI_StartTransmitPacket() ;
#define UpdateSPI_Buffer() ;
#define SPI_TransmitByte() ;
/branches/V0.68d Code Redesign killagreg/timer2.c
68,30 → 68,30
// enable PWM on PD7 in non inverting mode
TCCR2A = (TCCR2A & 0x3F)|(1<<COM2A1)|(0<<COM2A0);
 
ServoValue = Parameter_ServoNickControl;
ServoValue = Parameter_ServoPitchControl;
// inverting movment of servo
if(ParamSet.ServoNickCompInvert & 0x01)
if(ParamSet.ServoPitchCompInvert & 0x01)
{
ServoValue += ((int32_t) ParamSet.ServoNickComp * (IntegralNick / 128)) / 512;
ServoValue += ((int32_t) ParamSet.ServoPitchComp * (IntegralPitch / 128)) / 512;
}
else // non inverting movement of servo
{
ServoValue -= ((int32_t) ParamSet.ServoNickComp * (IntegralNick / 128)) / 512;
ServoValue -= ((int32_t) ParamSet.ServoPitchComp * (IntegralPitch / 128)) / 512;
}
 
// limit servo value to its parameter range definition
if(ServoValue < ParamSet.ServoNickMin)
if(ServoValue < ParamSet.ServoPitchMin)
{
ServoValue = ParamSet.ServoNickMin;
ServoValue = ParamSet.ServoPitchMin;
}
else if(ServoValue > ParamSet.ServoNickMax)
else if(ServoValue > ParamSet.ServoPitchMax)
{
ServoValue = ParamSet.ServoNickMax;
ServoValue = ParamSet.ServoPitchMax;
}
 
// update PWM
OCR2A = ServoValue;
timer = ParamSet.ServoNickRefresh;
timer = ParamSet.ServoPitchRefresh;
}
else
{
/branches/V0.68d Code Redesign killagreg/twimaster.c
139,16 → 139,16
switch(motor++)
{
case 0:
i2c_write_byte(Motor_Vorne);
i2c_write_byte(Motor_Front);
break;
case 1:
i2c_write_byte(Motor_Hinten);
i2c_write_byte(Motor_Rear);
break;
case 2:
i2c_write_byte(Motor_Rechts);
i2c_write_byte(Motor_Right);
break;
case 3:
i2c_write_byte(Motor_Links);
i2c_write_byte(Motor_Left);
break;
}
break;
/branches/V0.68d Code Redesign killagreg/uart.c
46,37 → 46,37
const unsigned char ANALOG_TEXT[32][16] =
{
//1234567890123456
"IntegralNick ", //0
"IntegralPitch ", //0
"IntegralRoll ",
"AccNick ",
"AccPitch ",
"AccRoll ",
"GyroGier ",
"HoehenWert ", //5
"GyroYaw ",
"ReadingHight ", //5
"AccZ ",
"Gas ",
"KompassValue ",
"Spannung ",
"Empfang ", //10
"CompassHeading ",
"Voltage ",
"Receiver Level ", //10
"Analog11 ",
"Motor_Vorne ",
"Motor_Hinten ",
"Motor_Links ",
"Motor_Rechts ", //15
"Motor_Front ",
"Motor_Rear ",
"Motor_Left ",
"Motor_Right ", //15
"Acc_Z ",
"MittelAccNick ",
"MittelAccRoll ",
"IntegralErrNick ",
"MeanAccPitch ",
"MeanAccRoll ",
"IntegralErrPitch",
"IntegralErrRoll ", //20
"MittelIntNick ",
"MittelIntRoll ",
"NeutralNick ",
"MeanIntPitch ",
"MMeanIntRoll ",
"NeutralPitch ",
"RollOffset ",
"IntRoll*Faktor ", //25
"IntRoll*Factor ", //25
"Analog26 ",
"DirektAusglRoll ",
"MesswertRoll ",
"AusgleichRoll ",
"I-LageRoll ", //30
"DirectCorrRoll ",
"ReadingRoll ",
"CorrectionRoll ",
"I-AttRoll ", //30
"StickRoll "
};
 
357,8 → 357,8
Decode64((uint8_t *) &ParamSet.ChannelAssignment[0],PARAMSET_STRUCT_LEN,3,AnzahlEmpfangsBytes);
ParamSet_WriteToEEProm(rxd_buffer[2] - 'l' + 1);
//SetActiveParamSet(rxd_buffer[2] - 'l' + 1); // is alredy done in ParamSet_WriteToEEProm()
Umschlag180Nick = (int32_t) ParamSet.WinkelUmschlagNick * 2500L;
Umschlag180Roll = (int32_t) ParamSet.WinkelUmschlagRoll * 2500L;
TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L;
TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L;
Piep(GetActiveParamSet());
break;
 
/branches/V0.68d Code Redesign killagreg/uart.h
50,16 → 50,16
 
struct str_ExternControl
{
unsigned char Digital[2];
unsigned char RemoteButtons;
signed char Nick;
signed char Roll;
signed char Gier;
unsigned char Gas;
signed char Hight;
unsigned char free;
unsigned char Frame;
unsigned char Config;
uint8_t Digital[2];
uint8_t RemoteButtons;
int8_t Pitch;
int8_t Roll;
int8_t Yaw;
uint8_t Gas;
int8_t Hight;
uint8_t free;
uint8_t Frame;
uint8_t Config;
};
extern struct str_ExternControl ExternControl;
 
/branches/V0.68d Code Redesign killagreg/uart1.c
43,11 → 43,12
 
// set direction of RXD1 and TXD1 pins
// set RXD1 (PD2) as an input pin
DDRD &= ~(1 << DDD2);
PORTD |= (1 << PORTD2);
DDRD &= ~(1 << DDD2);
 
// set TXD1 (PD3) as an output pin
DDRD |= (1 << DDD3);
PORTD |= (1 << PORTD3);
DDRD |= (1 << DDD3);
 
// USART0 Baud Rate Register
// set clock divider