Subversion Repositories FlightCtrl

Rev

Rev 528 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 528 Rev 529
1
/*#######################################################################################
1
/*#######################################################################################
2
Flight Control
2
Flight Control
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + mit unserer Zustimmung zulässig
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + this list of conditions and the following disclaimer.
33
// + this list of conditions and the following disclaimer.
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +     from this software without specific prior written permission.
35
// +     from this software without specific prior written permission.
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
37
// +     for non-commercial use (directly or indirectly)
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     with our written permission
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +     clearly linked as origin 
41
// +     clearly linked as origin 
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-
 
51
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53
// +  POSSIBILITY OF SUCH DAMAGE. 
52
// +  POSSIBILITY OF SUCH DAMAGE. 
54
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// Aenderungen von Peter Muehlenbrock ("Salvo") Stand 6.10.2007
54
// Aenderungen von Peter Muehlenbrock ("Salvo") Stand 6.10.2007
56
/*
55
/*
57
Driftkompensation fuer Gyros verbessert
56
Driftkompensation fuer Gyros verbessert
58
Linearsensor mit fixem Neutralwert
57
Linearsensor mit fixem Neutralwert
59
Ersatzkompass abgeleitet aus Magnetkompass und Giergyro fuer nahezu neigungsunabhaengige Kompassfunktion
58
Ersatzkompass abgeleitet aus Magnetkompass und Giergyro fuer nahezu neigungsunabhaengige Kompassfunktion
60
*/
59
*/
61
 
60
 
62
#include "main.h"
61
#include "main.h"
-
 
62
#include "eeprom.c"
63
 
63
 
64
unsigned char h,m,s;
64
unsigned char h,m,s;
65
volatile unsigned int I2CTimeout = 100;
65
volatile unsigned int I2CTimeout = 100;
66
volatile int MesswertNick,MesswertRoll,MesswertGier;
66
volatile int MesswertNick,MesswertRoll,MesswertGier;
67
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0;
67
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
68
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
68
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
69
volatile float NeutralAccZ = 0;
69
volatile float NeutralAccZ = 0;
70
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
70
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
71
volatile long IntegralNick = 0,IntegralNick2 = 0;
71
volatile long IntegralNick = 0,IntegralNick2 = 0;
72
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
72
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
-
 
73
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
73
volatile long Integral_Gier = 0;
74
volatile long Integral_Gier = 0;
74
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
75
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
75
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
76
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
76
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
77
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
-
 
78
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
77
volatile long Mess_Integral_Hoch = 0;
79
volatile long Mess_Integral_Hoch = 0;
78
volatile int  KompassValue = 0;
80
volatile int  KompassValue = 0;
79
volatile int  KompassStartwert = 0;
81
volatile int  KompassStartwert = 0;
80
volatile int  KompassRichtung = 0;
82
volatile int  KompassRichtung = 0;
81
unsigned char MAX_GAS,MIN_GAS;
83
unsigned char MAX_GAS,MIN_GAS;
82
unsigned char Notlandung = 0;
84
unsigned char Notlandung = 0;
83
unsigned char HoehenReglerAktiv = 0;
85
unsigned char HoehenReglerAktiv = 0;
-
 
86
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
-
 
87
 
-
 
88
 
84
//Salvo 12.10.2007
89
//Salvo 12.10.2007
85
uint8_t magkompass_ok=0;
90
uint8_t magkompass_ok=0;
86
uint8_t gps_cmd = GPS_CMD_STOP;
91
uint8_t gps_cmd = GPS_CMD_STOP;
87
static int       ubat_cnt =0;
92
static int       ubat_cnt =0;
88
static int gas_actual,gas_mittel; //Parameter fuer Gasreduzierung bei unterspannung
93
static int gas_actual,gas_mittel; //Parameter fuer Gasreduzierung bei unterspannung
-
 
94
int w,v;
89
//Salvo End
95
//Salvo End
90
 
96
 
91
 //Salvo 2.9.2007 Ersatzkompass
97
 //Salvo 2.9.2007 Ersatzkompass
92
volatile long GyroKomp_Int,GyroKomp_Int2;
98
volatile long GyroKomp_Int;
93
volatile int GyroKomp_Value; //  Der ermittelte Kompasswert aus Gyro und Magnetkompass
99
volatile int GyroKomp_Value; //  Der ermittelte Kompasswert aus Gyro und Magnetkompass
94
// Salvo End
100
// Salvo End
-
 
101
 
95
float GyroFaktor;
102
float GyroFaktor;
96
float IntegralFaktor;
103
float IntegralFaktor;
97
 
-
 
98
volatile int  DiffNick,DiffRoll;
104
volatile int  DiffNick,DiffRoll;
99
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
105
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
100
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
106
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
101
unsigned char MotorWert[5];
107
unsigned char MotorWert[5];
102
volatile unsigned char SenderOkay = 0;
108
volatile unsigned char SenderOkay = 0;
103
int StickNick = 0,StickRoll = 0,StickGier = 0;
109
int StickNick = 0,StickRoll = 0,StickGier = 0;
104
char MotorenEin = 0;
110
char MotorenEin = 0;
105
int HoehenWert = 0;
111
int HoehenWert = 0;
106
int SollHoehe = 0;
112
int SollHoehe = 0;
107
unsigned char Looping_Nick = 0,Looping_Roll = 0;
113
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
108
 
-
 
109
 
-
 
110
int w,v;
-
 
111
 
-
 
112
float Kp =  FAKTOR_P;
-
 
113
float Ki =  FAKTOR_I;
114
float Ki =  FAKTOR_I;
-
 
115
unsigned char Looping_Nick = 0,Looping_Roll = 0;
-
 
116
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
114
 
117
 
115
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
118
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
116
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
119
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
117
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
120
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
118
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
121
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
119
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
122
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
120
unsigned char Parameter_Gyro_P = 50;           // Wert : 10-250
123
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
121
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
124
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
122
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
125
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
123
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
126
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
124
unsigned char Parameter_UserParam1 = 0;
127
unsigned char Parameter_UserParam1 = 0;
125
unsigned char Parameter_UserParam2 = 0;
128
unsigned char Parameter_UserParam2 = 0;
126
unsigned char Parameter_UserParam3 = 0;
129
unsigned char Parameter_UserParam3 = 0;
127
unsigned char Parameter_UserParam4 = 0;
130
unsigned char Parameter_UserParam4 = 0;
-
 
131
unsigned char Parameter_UserParam5 = 0;
-
 
132
unsigned char Parameter_UserParam6 = 0;
-
 
133
unsigned char Parameter_UserParam7 = 0;
-
 
134
unsigned char Parameter_UserParam8 = 0;
128
unsigned char Parameter_ServoNickControl = 100;
135
unsigned char Parameter_ServoNickControl = 100;
129
unsigned char Parameter_LoopGasLimit = 70;
136
unsigned char Parameter_LoopGasLimit = 70;
-
 
137
unsigned char Parameter_AchsKopplung1 = 0;
-
 
138
unsigned char Parameter_AchsGegenKopplung1 = 0;
-
 
139
unsigned char Parameter_DynamicStability = 100;
130
struct mk_param_struct EE_Parameter;
140
struct mk_param_struct EE_Parameter;
-
 
141
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
131
 
142
 
132
void Piep(unsigned char Anzahl)
143
void Piep(unsigned char Anzahl)
133
{
144
{
134
 while(Anzahl--)
145
 while(Anzahl--)
135
 {
146
 {
136
  if(MotorenEin) return; //auf keinen Fall im Flug!
147
  if(MotorenEin) return; //auf keinen Fall im Flug!
137
  beeptime = 100;
148
  beeptime = 100;
138
  Delay_ms(250);
149
  Delay_ms(250);
139
 }
150
 }
140
}
151
}
141
 
152
 
142
//############################################################################
153
//############################################################################
143
//  Nullwerte ermitteln
154
//  Nullwerte ermitteln
144
void SetNeutral(void)
155
void SetNeutral(void)
145
//############################################################################
156
//############################################################################
146
{
157
{
147
    unsigned int timer;
-
 
148
        NeutralAccX = 0;
158
        NeutralAccX = 0;
149
        NeutralAccY = 0;
159
        NeutralAccY = 0;
150
        NeutralAccZ = 0;
160
        NeutralAccZ = 0;
151
    AdNeutralNick = 0; 
161
    AdNeutralNick = 0; 
152
        AdNeutralRoll = 0;     
162
        AdNeutralRoll = 0;     
153
        AdNeutralGier = 0;
163
        AdNeutralGier = 0;
154
        GPS_Neutral();
164
    Parameter_AchsKopplung1 = 0;
-
 
165
    Parameter_AchsGegenKopplung1 = 0;
155
    CalibrierMittelwert();     
166
    CalibrierMittelwert();     
156
    timer = SetDelay(5);    
167
    Delay_ms_Mess(100);
157
        while (!CheckDelay(timer));
-
 
158
        CalibrierMittelwert();
168
        CalibrierMittelwert();
159
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
169
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
160
     {    
170
     {    
161
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
171
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
162
     }
172
     }
163
 
173
 
-
 
174
     AdNeutralNick= AdWertNick;
-
 
175
         AdNeutralRoll= AdWertRoll;    
-
 
176
         AdNeutralGier= AdWertGier;
-
 
177
     StartNeutralRoll = AdNeutralRoll;
-
 
178
     StartNeutralNick = AdNeutralNick;
164
    if(PlatinenVersion == 10)
179
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
165
    {
180
    {
166
     AdNeutralNick= abs(MesswertNick); 
181
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
167
         AdNeutralRoll= abs(MesswertRoll);     
182
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
168
         AdNeutralGier= abs(MesswertGier);
183
          NeutralAccZ = Aktuell_az;
169
    }
184
    }
170
    else
185
    else
171
    {
186
    {
172
     AdNeutralNick= abs(MesswertNick) / 2;     
187
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
173
         AdNeutralRoll= abs(MesswertRoll) / 2; 
188
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
174
         AdNeutralGier= abs(MesswertGier) / 2;
189
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
175
    }
-
 
176
// Salvo 1.9.2007 ACC mit festen neutralwerten *****
-
 
177
        if (ACC_NEUTRAL_FIXED > 0)
-
 
178
        {
-
 
179
                NeutralAccX     = ACC_NICK_NEUTRAL;
-
 
180
                NeutralAccY     = ACC_ROLL_NEUTRAL;
-
 
181
        }
-
 
182
        else
-
 
183
        { // Automatisch bei Offsetabgleich ermitteln
-
 
184
                NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
-
 
185
                NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
-
 
186
        }
-
 
187
 // Salvo End   
-
 
188
        NeutralAccZ = Aktuell_az;
190
    }
189
   
191
   
190
        Mess_IntegralNick = 0; 
192
        Mess_IntegralNick = 0; 
191
    Mess_IntegralNick2 = 0;
193
    Mess_IntegralNick2 = 0;
192
    Mess_IntegralRoll = 0;     
194
    Mess_IntegralRoll = 0;     
193
    Mess_IntegralRoll2 = 0;
195
    Mess_IntegralRoll2 = 0;
194
    Mess_Integral_Gier = 0;    
196
    Mess_Integral_Gier = 0;    
195
    MesswertNick = 0;
197
    MesswertNick = 0;
196
    MesswertRoll = 0;
198
    MesswertRoll = 0;
197
    MesswertGier = 0;
199
    MesswertGier = 0;
198
    StartLuftdruck = Luftdruck;
200
    StartLuftdruck = Luftdruck;
199
    HoeheD = 0;
201
    HoeheD = 0;
200
    Mess_Integral_Hoch = 0;
202
    Mess_Integral_Hoch = 0;
201
    KompassStartwert = KompassValue;
203
    KompassStartwert = KompassValue;
202
 
-
 
-
 
204
    GPS_Neutral();
203
    beeptime = 50;  
205
    beeptime = 50;  
-
 
206
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
-
 
207
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
-
 
208
    ExternHoehenValue = 0;
-
 
209
 
-
 
210
 
204
//Salvo 13.10.2007 Ersatzkompass und Gas
211
//Salvo 13.10.2007 Ersatzkompass und Gas
205
        GyroKomp_Int =  KompassValue * GYROKOMP_INC_GRAD_DEFAULT; //Neu ab 3.1.2007
212
        GyroKomp_Int =  KompassValue * GYROKOMP_INC_GRAD_DEFAULT; //Neu ab 3.1.2007
206
        gas_mittel      =       30;
213
        gas_mittel      =       30;
207
        gas_actual      =       gas_mittel;
214
        gas_actual      =       gas_mittel;
208
// Salvo End
215
// Salvo End
209
}
216
}
210
 
217
 
211
//############################################################################
218
//############################################################################
212
// Bildet den Mittelwert aus den Messwerten
219
// Bearbeitet die Messwerte
213
void Mittelwert(void)
220
void Mittelwert(void)
214
//############################################################################
221
//############################################################################
215
{      
222
{      
216
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
223
    static signed long tmpl,tmpl2;     
217
    ANALOG_OFF;
-
 
218
        if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
224
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
219
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
225
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
220
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
226
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
-
 
227
 
-
 
228
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
221
        if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L;
229
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
222
        if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L;
230
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
223
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L;
231
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
-
 
232
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
-
 
233
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
-
 
234
    IntegralAccZ    += Aktuell_az - NeutralAccZ;
-
 
235
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
-
 
236
//Salvo 12.11.2007
-
 
237
                        GyroKomp_Int  += MesswertGier;
-
 
238
//Salvo End
-
 
239
            Mess_Integral_Gier +=  MesswertGier;
-
 
240
            Mess_Integral_Gier2 += MesswertGier;
-
 
241
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
-
 
242
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
-
 
243
         {
224
    AccumulateNick = 0;   MessanzahlNick = 0;
244
            tmpl = Mess_IntegralNick / 4096L;
-
 
245
            tmpl *= MesswertGier;
-
 
246
            tmpl *= Parameter_AchsKopplung1;  //125
-
 
247
            tmpl /= 2048L;
225
    AccumulateRoll = 0;   MessanzahlRoll = 0;
248
            tmpl2 = Mess_IntegralRoll / 4096L;
226
    AccumulateGier = 0;   MessanzahlGier = 0;
249
            tmpl2 *= MesswertGier;
-
 
250
            tmpl2 *= Parameter_AchsKopplung1;
-
 
251
            tmpl2 /= 2048L;
-
 
252
         }
-
 
253
      else  tmpl = tmpl2 = 0;
-
 
254
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
-
 
255
            MesswertRoll += tmpl;
-
 
256
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
-
 
257
            Mess_IntegralRoll2 += MesswertRoll;
-
 
258
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
-
 
259
            if(Mess_IntegralRoll > Umschlag180Roll)
-
 
260
            {
-
 
261
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
-
 
262
             Mess_IntegralRoll2 = Mess_IntegralRoll;
-
 
263
            }
-
 
264
            if(Mess_IntegralRoll <-Umschlag180Roll)
-
 
265
            {
-
 
266
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
-
 
267
             Mess_IntegralRoll2 = Mess_IntegralRoll;
-
 
268
            }  
-
 
269
            if(AdWertRoll < 15)   MesswertRoll = -1000;
227
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
270
            if(AdWertRoll <  7)   MesswertRoll = -2000;
-
 
271
            if(PlatinenVersion == 10)
-
 
272
                         {
-
 
273
              if(AdWertRoll > 1010) MesswertRoll = +1000;
-
 
274
              if(AdWertRoll > 1017) MesswertRoll = +2000;
-
 
275
                         }
-
 
276
                         else
-
 
277
                         {
-
 
278
              if(AdWertRoll > 2020) MesswertRoll = +1000;
-
 
279
              if(AdWertRoll > 2034) MesswertRoll = +2000;
-
 
280
                         }
-
 
281
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
-
 
282
            MesswertNick -= tmpl2;
-
 
283
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
-
 
284
            Mess_IntegralNick2 += MesswertNick;
-
 
285
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
-
 
286
            if(Mess_IntegralNick > Umschlag180Nick)
-
 
287
            {
-
 
288
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
-
 
289
             Mess_IntegralNick2 = Mess_IntegralNick;
-
 
290
            }
-
 
291
            if(Mess_IntegralNick <-Umschlag180Nick)
-
 
292
            {
-
 
293
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
-
 
294
             Mess_IntegralNick2 = Mess_IntegralNick;
-
 
295
            }
228
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
296
            if(AdWertNick < 15)   MesswertNick = -1000;
229
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
297
            if(AdWertNick <  7)   MesswertNick = -2000;
-
 
298
            if(PlatinenVersion == 10)
-
 
299
                         {
-
 
300
              if(AdWertNick > 1010) MesswertNick = +1000;
-
 
301
              if(AdWertNick > 1017) MesswertNick = +2000;
-
 
302
                         }
-
 
303
                         else
-
 
304
                         {
-
 
305
              if(AdWertNick > 2020) MesswertNick = +1000;
-
 
306
              if(AdWertNick > 2034) MesswertNick = +2000;
-
 
307
                         }
-
 
308
//++++++++++++++++++++++++++++++++++++++++++++++++
-
 
309
// ADC einschalten
-
 
310
    ANALOG_ON; 
-
 
311
//++++++++++++++++++++++++++++++++++++++++++++++++
-
 
312
 
230
    Integral_Gier  = Mess_Integral_Gier;
313
    Integral_Gier  = Mess_Integral_Gier;
231
//    Integral_Gier2 = Mess_Integral_Gier2;
-
 
232
    IntegralNick = Mess_IntegralNick;
314
    IntegralNick = Mess_IntegralNick;
233
    IntegralRoll = Mess_IntegralRoll;
315
    IntegralRoll = Mess_IntegralRoll;
234
    IntegralNick2 = Mess_IntegralNick2;
316
    IntegralNick2 = Mess_IntegralNick2;
235
    IntegralRoll2 = Mess_IntegralRoll2;
317
    IntegralRoll2 = Mess_IntegralRoll2;
236
    // ADC einschalten
-
 
237
    ANALOG_ON; 
-
 
-
 
318
 
238
 
319
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
239
/*
-
 
240
//------------------------------------------------------------------------------
320
  {
241
    if(MesswertNick > 200)  MesswertNick += 4 * (MesswertNick - 200);
-
 
242
    else                                         
321
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
243
    if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
322
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
244
    if(MesswertRoll > 200)  MesswertRoll += 4 * (MesswertRoll - 200);
-
 
245
    else                                         
323
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
246
    if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
-
 
247
//------------------------------------------------------------------------------
324
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
248
*/
325
  }
249
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
326
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
250
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
327
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
251
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
328
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
252
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
329
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
253
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
330
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
254
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
331
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
255
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
332
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
256
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
333
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
257
}
334
}
258
 
335
 
259
//############################################################################
336
//############################################################################
260
// Messwerte beim Ermitteln der Nullage
337
// Messwerte beim Ermitteln der Nullage
261
void CalibrierMittelwert(void)
338
void CalibrierMittelwert(void)
262
//############################################################################
339
//############################################################################
263
{                
340
{                
264
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
341
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
265
        ANALOG_OFF;
342
        ANALOG_OFF;
266
    if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
-
 
267
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
-
 
268
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
-
 
269
        if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick);
-
 
270
        if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll;
-
 
271
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch;
-
 
272
    AccumulateNick = 0;   MessanzahlNick = 0;
343
        MesswertNick = AdWertNick;
273
    AccumulateRoll = 0;   MessanzahlRoll = 0;
344
        MesswertRoll = AdWertRoll;
274
    AccumulateGier = 0;   MessanzahlGier = 0;
345
        MesswertGier = AdWertGier;
275
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
346
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
276
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
347
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
277
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
348
        Mittelwert_AccHoch = (long)AdWertAccHoch;
278
    // ADC einschalten
349
   // ADC einschalten
279
    ANALOG_ON; 
350
    ANALOG_ON; 
280
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
351
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
281
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
352
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
282
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
353
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
283
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
354
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
284
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
355
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
285
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
356
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
286
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
357
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
287
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
358
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
-
 
359
 
-
 
360
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
-
 
361
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
288
}
362
}
289
 
363
 
290
//############################################################################
364
//############################################################################
291
// Senden der Motorwerte per I2C-Bus
365
// Senden der Motorwerte per I2C-Bus
292
void SendMotorData(void)
366
void SendMotorData(void)
293
//############################################################################
367
//############################################################################
294
{
368
{
295
    if(MOTOR_OFF || !MotorenEin)
369
    if(MOTOR_OFF || !MotorenEin)
296
        {
370
        {
297
        Motor_Hinten = 0;
371
        Motor_Hinten = 0;
298
        Motor_Vorne = 0;
372
        Motor_Vorne = 0;
299
        Motor_Rechts = 0;
373
        Motor_Rechts = 0;
300
        Motor_Links = 0;
374
        Motor_Links = 0;
301
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
375
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
302
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
376
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
303
        if(MotorTest[2]) Motor_Links = MotorTest[2];
377
        if(MotorTest[2]) Motor_Links = MotorTest[2];
304
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
378
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
305
        }
379
        }
306
 
380
 
307
    DebugOut.Analog[12] = Motor_Vorne;
381
    DebugOut.Analog[12] = Motor_Vorne;
308
    DebugOut.Analog[13] = Motor_Hinten;
382
    DebugOut.Analog[13] = Motor_Hinten;
309
    DebugOut.Analog[14] = Motor_Links;
383
    DebugOut.Analog[14] = Motor_Links;
310
    DebugOut.Analog[15] = Motor_Rechts;  
384
    DebugOut.Analog[15] = Motor_Rechts;  
311
 
385
 
312
    //Start I2C Interrupt Mode
386
    //Start I2C Interrupt Mode
313
    twi_state = 0;
387
    twi_state = 0;
314
    motor = 0;
388
    motor = 0;
315
    i2c_start();
389
    i2c_start();
316
}
390
}
317
 
-
 
318
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
319
// + Konstanten 
-
 
320
// + 0-250 -> normale Werte
-
 
321
// + 251 -> Poti1
-
 
322
// + 252 -> Poti2
-
 
323
// + 253 -> Poti3
-
 
324
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
325
void DefaultKonstanten1(void)
-
 
326
{
-
 
327
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
-
 
328
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
-
 
329
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
-
 
330
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
-
 
331
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
-
 
332
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
-
 
333
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
-
 
334
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
-
 
335
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01;    
-
 
336
 EE_Parameter.Hoehe_MinGas = 30;
-
 
337
 EE_Parameter.MaxHoehe     = 251;      // Wert : 0-32   251 -> Poti1
-
 
338
 EE_Parameter.Hoehe_P      = 10;       // Wert : 0-32
-
 
339
 EE_Parameter.Luftdruck_D  = 50;       // Wert : 0-250
-
 
340
 EE_Parameter.Hoehe_ACC_Wirkung = 50;  // Wert : 0-250
-
 
341
 EE_Parameter.Hoehe_Verstaerkung = 4;  // Wert : 0-50
-
 
342
 EE_Parameter.Stick_P = 2; //2         // Wert : 1-6
-
 
343
 EE_Parameter.Stick_D = 4; //8         // Wert : 0-64
-
 
344
 EE_Parameter.Gier_P = 16;             // Wert : 1-20
-
 
345
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
-
 
346
 EE_Parameter.Gas_Max = 250;           // Wert : 33-250
-
 
347
 EE_Parameter.GyroAccFaktor = 26;      // Wert : 1-64
-
 
348
 EE_Parameter.KompassWirkung = 128;    // Wert : 0-250
-
 
349
 EE_Parameter.Gyro_P = 120; //80          // Wert : 0-250
-
 
350
 EE_Parameter.Gyro_I = 150;               // Wert : 0-250
-
 
351
 EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250
-
 
352
 EE_Parameter.NotGas = 100;                // Wert : 0-250     // Gaswert bei Empangsverlust
-
 
353
 EE_Parameter.NotGasZeit = 60;            // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
-
 
354
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
-
 
355
 EE_Parameter.I_Faktor = 0;
-
 
356
 EE_Parameter.UserParam1 = 8;             //zur freien Verwendung
-
 
357
 EE_Parameter.UserParam2 = 2;             //zur freien Verwendung
-
 
358
 EE_Parameter.UserParam3 = 12;             //zur freien Verwendung
-
 
359
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
-
 
360
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
-
 
361
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
-
 
362
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
-
 
363
 EE_Parameter.ServoNickMin = 50;          // Wert : 0-250     // Anschlag
-
 
364
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
-
 
365
 EE_Parameter.ServoNickRefresh = 5;
-
 
366
 EE_Parameter.LoopGasLimit = 50;
-
 
367
 EE_Parameter.LoopThreshold = 90;         // Wert: 0-250  Schwelle für Stickausschlag
-
 
368
 EE_Parameter.LoopConfig = 0;             // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt
-
 
369
 memcpy(EE_Parameter.Name, "Sport\0", 12);  
-
 
370
}
-
 
371
 
-
 
372
void DefaultKonstanten2(void)
-
 
373
{
-
 
374
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
-
 
375
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
-
 
376
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
-
 
377
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
-
 
378
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
-
 
379
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
-
 
380
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
-
 
381
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
-
 
382
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01;    
-
 
383
 EE_Parameter.Hoehe_MinGas = 30;
-
 
384
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
-
 
385
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
-
 
386
 EE_Parameter.Luftdruck_D  = 50;      // Wert : 0-250
-
 
387
 EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250
-
 
388
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
-
 
389
 EE_Parameter.Stick_P = 2; //2           // Wert : 1-6
-
 
390
 EE_Parameter.Stick_D = 0; //8           // Wert : 0-64
-
 
391
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
-
 
392
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
-
 
393
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
-
 
394
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
-
 
395
 EE_Parameter.KompassWirkung = 64;    // Wert : 0-250
-
 
396
 EE_Parameter.Gyro_P = 175; //80           // Wert : 0-250
-
 
397
 EE_Parameter.Gyro_I = 175;           // Wert : 0-250
-
 
398
 EE_Parameter.UnterspannungsWarnung = 100;  // Wert : 0-250
-
 
399
 EE_Parameter.NotGas = 100;                 // Wert : 0-250     // Gaswert bei Empangsverlust
-
 
400
 EE_Parameter.NotGasZeit = 60;             // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
-
 
401
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
-
 
402
 EE_Parameter.I_Faktor = 5;
-
 
403
 EE_Parameter.UserParam1 = 12;   //zur freien Verwendung
-
 
404
 EE_Parameter.UserParam2 = 2;   //zur freien Verwendung
-
 
405
 EE_Parameter.UserParam3 = 16;   //zur freien Verwendung
-
 
406
 EE_Parameter.UserParam4 = 0;   //zur freien Verwendung
-
 
407
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
-
 
408
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
-
 
409
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
-
 
410
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
-
 
411
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
-
 
412
 EE_Parameter.ServoNickRefresh = 5;
-
 
413
 EE_Parameter.LoopGasLimit = 50;
-
 
414
 EE_Parameter.LoopThreshold = 90;         // Wert: 0-250  Schwelle für Stickausschlag
-
 
415
 EE_Parameter.LoopConfig = 0;              // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts 
-
 
416
 memcpy(EE_Parameter.Name, "Kamera\0", 12);  
-
 
417
}
391
 
418
 
392
 
419
 
393
 
420
//############################################################################
394
//############################################################################
421
// Trägt ggf. das Poti als Parameter ein
395
// Trägt ggf. das Poti als Parameter ein
422
void ParameterZuordnung(void)
396
void ParameterZuordnung(void)
423
//############################################################################
397
//############################################################################
424
{
398
{
425
 
399
 
426
 #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;}
400
 #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;}
427
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
401
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
428
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
402
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
429
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
403
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
430
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
404
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
431
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
405
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
432
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
406
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
433
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
407
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
434
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
408
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
435
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
409
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
436
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
410
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
437
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
411
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
438
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
412
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
439
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
413
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
440
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
414
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
-
 
415
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
-
 
416
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
441
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
417
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
442
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
418
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
-
 
419
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
-
 
420
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
-
 
421
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
443
 
422
 
444
 Ki = (float) Parameter_I_Faktor * 0.0001;
423
 Ki = (float) Parameter_I_Faktor * 0.0001;
445
 MAX_GAS = EE_Parameter.Gas_Max;
424
 MAX_GAS = EE_Parameter.Gas_Max;
446
 MIN_GAS = EE_Parameter.Gas_Min;
425
 MIN_GAS = EE_Parameter.Gas_Min;
447
}
426
}
448
 
427
 
449
 
428
 
450
//############################################################################
429
//############################################################################
451
//
430
//
452
void MotorRegler(void)
431
void MotorRegler(void)
453
//############################################################################
432
//############################################################################
454
{
433
{
455
         int motorwert,pd_ergebnis,h,tmp_int;
434
         int motorwert,pd_ergebnis,h,tmp_int;
456
         int GierMischanteil,GasMischanteil;
435
         int GierMischanteil,GasMischanteil;
457
     static long SummeNick=0,SummeRoll=0;
436
     static long SummeNick=0,SummeRoll=0;
458
     static long sollGier = 0,tmp_long,tmp_long2;
437
     static long sollGier = 0,tmp_long,tmp_long2;
459
     long IntegralFehlerNick = 0;
438
     static long IntegralFehlerNick = 0;
460
     long IntegralFehlerRoll = 0;
439
     static long IntegralFehlerRoll = 0;
461
         static unsigned int RcLostTimer;
440
         static unsigned int RcLostTimer;
462
         static unsigned char delay_neutral = 0;
441
         static unsigned char delay_neutral = 0;
463
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
442
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
464
         static unsigned int  modell_fliegt = 0;
443
         static unsigned int  modell_fliegt = 0;
465
     static int hoehenregler = 0;
444
     static int hoehenregler = 0;
466
     static char TimerWerteausgabe = 0;
445
     static char TimerWerteausgabe = 0;
467
     static char NeueKompassRichtungMerken = 0;
446
     static char NeueKompassRichtungMerken = 0;
-
 
447
     static long ausgleichNick, ausgleichRoll;
-
 
448
     
468
        Mittelwert();
449
        Mittelwert();
469
//****** GPS Daten holen ***************
450
//****** GPS Daten holen ***************
470
        short int n;
451
        short int n;
471
        if (gps_alive_cnt > 0) gps_alive_cnt--; //Dekrementieren. Wenn 0 kommen keine ausreichenden GPS Meldungen (Timeout)
452
        if (gps_alive_cnt > 0) gps_alive_cnt--; //Dekrementieren. Wenn 0 kommen keine ausreichenden GPS Meldungen (Timeout)
472
        n = Get_Rel_Position();
453
        n = Get_Rel_Position();
473
        if (n == 0)    
454
        if (n == 0)    
474
        {
455
        {
475
                ROT_ON; //led blitzen lassen
456
                ROT_ON; //led blitzen lassen
476
        }
457
        }
477
//******PROVISORISCH***************
458
//******PROVISORISCH***************
478
    GRN_ON;
459
    GRN_ON;
-
 
460
 
479
 
461
    GRN_ON;
480
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
462
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
481
// Gaswert ermitteln
463
// Gaswert ermitteln
482
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
464
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
465
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
483
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
466
    if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20;
484
//Salvo 13.10.2007 langsame Gasreduktion bei Unterspannung. Als Ausgangswert wird der bei UBAT=k gemessen Mittelwert genommen
467
//Salvo 13.10.2007 langsame Gasreduktion bei Unterspannung. Als Ausgangswert wird der bei UBAT=k gemessen Mittelwert genommen
485
// und dieser dann langsam zwangsweise reduziert
-
 
486
        ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern 
468
// und dieser dann langsam zwangsweise reduziert
487
        if (UBat <= EE_Parameter.UnterspannungsWarnung - 2)     //Unterhalb der Piepser Schwelle aktivieren
469
        if (UBat <= EE_Parameter.UnterspannungsWarnung - 2)     //Unterhalb der Piepser Schwelle aktivieren
488
        {
470
        {
489
                if (ubat_cnt > 700)
471
                if (ubat_cnt > 700)
490
                {
472
                {
491
                        ubat_cnt = 0;
473
                        ubat_cnt = 0;
492
                        if (gas_actual > ((gas_mittel*12)/15)) gas_actual--;
474
                        if (gas_actual > ((gas_mittel*12)/15)) gas_actual--;
493
                }
475
                }
494
                else ubat_cnt++;
476
                else ubat_cnt++;
495
                if (GasMischanteil > gas_actual) GasMischanteil = gas_actual;
477
                if (GasMischanteil > gas_actual) GasMischanteil = gas_actual;
496
        }
478
        }
497
        else   //Falls UBAT wieder ok ist
479
        else   //Falls UBAT wieder ok ist
498
        {
480
        {
499
                if (ubat_cnt > 1000)
481
                if (ubat_cnt > 1000)
500
                {
482
                {
501
                        gas_mittel = ((gas_mittel*9) + GasMischanteil)/10; //Filtern
483
                        gas_mittel = ((gas_mittel*9) + GasMischanteil)/10; //Filtern
502
                        gas_actual = GasMischanteil;
484
                        gas_actual = GasMischanteil;
503
                }
485
                }
504
                else
486
                else
505
                {
487
                {
506
                        ubat_cnt++;
488
                        ubat_cnt++;
507
                        if ((ubat_cnt % 10) == 0)
489
                        if ((ubat_cnt % 10) == 0)
508
                        {
490
                        {
509
                                if (gas_actual < GasMischanteil) gas_actual++;
491
                                if (gas_actual < GasMischanteil) gas_actual++;
510
                                else gas_actual = GasMischanteil;
492
                                else gas_actual = GasMischanteil;
511
                }
493
                }
512
                }
494
                }
513
                GasMischanteil = gas_actual;
495
                GasMischanteil = gas_actual;
514
        }      
496
        }      
515
        ANALOG_ON;      // ADC einschalten
-
 
516
// Salvo End
497
// Salvo End
517
    if(GasMischanteil < 0) GasMischanteil = 0;
498
    if(GasMischanteil < 0) GasMischanteil = 0;
-
 
499
 
-
 
500
 
518
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
501
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
519
// Empfang schlecht
502
// Empfang schlecht
520
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
503
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
521
   if(SenderOkay < 100)
504
   if(SenderOkay < 100)
522
        {
505
        {
523
        if(!PcZugriff)
506
        if(!PcZugriff)
524
         {
507
         {
525
           if(BeepMuster == 0xffff)
508
           if(BeepMuster == 0xffff)
526
            {
509
            {
527
             beeptime = 15000;
510
             beeptime = 15000;
528
             BeepMuster = 0x0c00;
511
             BeepMuster = 0x0c00;
529
            }
512
            }
530
         }
513
         }
531
        if(RcLostTimer) RcLostTimer--;
514
        if(RcLostTimer) RcLostTimer--;
532
        else
515
        else
533
         {
516
         {
534
          MotorenEin = 0;
517
          MotorenEin = 0;
535
          Notlandung = 0;
518
          Notlandung = 0;
536
         }
519
         }
537
        ROT_ON;
520
        ROT_ON;
538
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
521
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
539
            {
522
            {
540
            GasMischanteil = EE_Parameter.NotGas;
523
            GasMischanteil = EE_Parameter.NotGas;
541
            Notlandung = 1;
524
            Notlandung = 1;
542
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
525
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
543
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
526
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
544
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
527
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
545
            }
528
            }
546
         else MotorenEin = 0;
529
         else MotorenEin = 0;
547
        }
530
        }
548
        else
531
        else
549
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
532
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
550
// Emfang gut
533
// Emfang gut
551
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
534
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
552
        if(SenderOkay > 140)
535
        if(SenderOkay > 140)
553
            {
536
            {
554
            Notlandung = 0;
537
            Notlandung = 0;
555
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
538
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
556
            if(GasMischanteil > 40)
539
            if(GasMischanteil > 40)
557
                {
540
                {
558
                if(modell_fliegt < 0xffff) modell_fliegt++;
541
                if(modell_fliegt < 0xffff) modell_fliegt++;
559
                }
542
                }
560
            if((modell_fliegt < 200) || (GasMischanteil < 40))
543
            if((modell_fliegt < 200) || (GasMischanteil < 40))
561
                {
544
                {
562
                SummeNick = 0;
545
                SummeNick = 0;
563
                SummeRoll = 0;
546
                SummeRoll = 0;
564
                Mess_Integral_Gier = 0;
547
                Mess_Integral_Gier = 0;
565
                Mess_Integral_Gier2 = 0;
548
                Mess_Integral_Gier2 = 0;
566
                }
549
                }
567
            if((GasMischanteil > 200) && MotorenEin == 0)
550
            if((GasMischanteil > 200) && MotorenEin == 0)
568
                {
551
                {
569
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
552
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
570
// auf Nullwerte kalibrieren
553
// auf Nullwerte kalibrieren
571
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
554
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
572
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
555
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
573
                    {
556
                    {
574
                    unsigned char setting;
-
 
575
                    if(++delay_neutral > 200)  // nicht sofort
557
                    if(++delay_neutral > 200)  // nicht sofort
576
                        {
558
                        {
577
                        GRN_OFF;
559
                        GRN_OFF;
578
                        SetNeutral();
560
                        SetNeutral();
579
                        MotorenEin = 0;
561
                        MotorenEin = 0;
580
                        delay_neutral = 0;
562
                        delay_neutral = 0;
581
                        modell_fliegt = 0;
563
                        modell_fliegt = 0;
582
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
564
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
583
                        {
565
                        {
-
 
566
                         unsigned char setting=1;
584
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
567
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
585
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
568
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
586
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
569
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
587
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
570
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
588
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
571
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
589
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
572
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
590
                        }
573
                        }
591
 
574
 
592
 
-
 
593
 
-
 
594
 
575
 
595
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
576
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
596
 
577
 
597
                        Piep(GetActiveParamSetNumber());
578
                        Piep(GetActiveParamSetNumber());
598
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
579
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
599
                        {
580
                        {
600
                          if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
581
                          if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
601
                        }  
582
                        }  
602
                                                GPS_Save_Home(); //Daten sind jetzt hoffentlich verfuegbar
583
                                                GPS_Save_Home(); //Daten sind jetzt hoffentlich verfuegbar
603
                                                if (gps_home_position.status > 0 )
584
                                                if (gps_home_position.status > 0 )
604
                                                {
585
                                                {
605
                                                        Delay_ms(1000);  //akustisch verkuenden dass GPS Home Daten da sind
586
                                                        Delay_ms(1000);  //akustisch verkuenden dass GPS Home Daten da sind
606
                                                        beeptime = 2000;
587
                                                        beeptime = 2000;
607
                                                        Delay_ms(500);
588
                                                        Delay_ms(500);
608
                                                }
589
                                                }
609
                       }
590
                       }
610
                    }
591
                    }
-
 
592
                 else
-
 
593
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
-
 
594
                    {
-
 
595
                    if(++delay_neutral > 200)  // nicht sofort
-
 
596
                        {
-
 
597
                        GRN_OFF;
-
 
598
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
-
 
599
                        MotorenEin = 0;
-
 
600
                        delay_neutral = 0;
-
 
601
                        modell_fliegt = 0;
-
 
602
                        SetNeutral();
-
 
603
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
-
 
604
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
-
 
605
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
-
 
606
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
-
 
607
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
-
 
608
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
-
 
609
                        Piep(GetActiveParamSetNumber());
-
 
610
                        }
-
 
611
                    }
-
 
612
 
611
                 else delay_neutral = 0;
613
                 else delay_neutral = 0;
612
                }
614
                }
613
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
614
// Gas ist unten
616
// Gas ist unten
615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
617
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
616
            if(GasMischanteil < 35)
618
            if(GasMischanteil < 35)
617
                {
619
                {
618
                // Starten
620
                // Starten
619
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
621
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
620
                    {
622
                    {
621
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
623
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
622
// Einschalten
624
// Einschalten
623
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
625
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
624
                    if(++delay_einschalten > 200)
626
                    if(++delay_einschalten > 200)
625
                        {
627
                        {
626
                        delay_einschalten = 200;
628
                        delay_einschalten = 200;
627
                        modell_fliegt = 1;
629
                        modell_fliegt = 1;
628
                        MotorenEin = 1;
630
                        MotorenEin = 1;
629
                        sollGier = 0;
631
                        sollGier = 0;
630
                        Mess_Integral_Gier = 0;
632
                        Mess_Integral_Gier = 0;
631
                        Mess_Integral_Gier2 = 0;
633
                        Mess_Integral_Gier2 = 0;
632
                        Mess_IntegralNick = 0;
634
                        Mess_IntegralNick = 0;
633
                        Mess_IntegralRoll = 0;
635
                        Mess_IntegralRoll = 0;
634
                        Mess_IntegralNick2 = IntegralNick;
636
                        Mess_IntegralNick2 = IntegralNick;
635
                        Mess_IntegralRoll2 = IntegralRoll;
637
                        Mess_IntegralRoll2 = IntegralRoll;
636
                        SummeNick = 0;
638
                        SummeNick = 0;
637
                        SummeRoll = 0;
639
                        SummeRoll = 0;
638
                        }          
640
                        }          
639
                    }  
641
                    }  
640
                    else delay_einschalten = 0;
642
                    else delay_einschalten = 0;
641
                //Auf Neutralwerte setzen
643
                //Auf Neutralwerte setzen
642
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
644
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
643
// Auschalten
645
// Auschalten
644
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
646
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
645
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
647
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
646
                    {
648
                    {
647
                    if(++delay_ausschalten > 200)  // nicht sofort
649
                    if(++delay_ausschalten > 200)  // nicht sofort
648
                        {
650
                        {
649
                        MotorenEin = 0;
651
                        MotorenEin = 0;
650
                        delay_ausschalten = 200;
652
                        delay_ausschalten = 200;
651
                        modell_fliegt = 0;
653
                        modell_fliegt = 0;
652
                        }
654
                        }
653
                    }
655
                    }
654
                else delay_ausschalten = 0;
656
                else delay_ausschalten = 0;
655
                }
657
                }
656
            }
658
            }
657
 
659
 
658
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
660
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
659
// neue Werte von der Funke
661
// neue Werte von der Funke
660
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
662
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
661
 if(!NewPpmData-- || Notlandung)  
663
 if(!NewPpmData-- || Notlandung)  
662
  {
664
  {
-
 
665
    int tmp_int;
663
    ParameterZuordnung();
666
    ParameterZuordnung();
664
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
667
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
665
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
668
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
666
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
669
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
667
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
670
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
668
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
671
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
669
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
672
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
670
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
673
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
-
 
674
 
-
 
675
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
-
 
676
if(DubWiseKeys[1]) beeptime = 10;
-
 
677
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
-
 
678
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
-
 
679
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
-
 
680
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
-
 
681
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
-
 
682
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
-
 
683
 
-
 
684
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
-
 
685
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
-
 
686
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
-
 
687
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
-
 
688
 
-
 
689
    StickNick += ExternStickNick / 8;
-
 
690
    StickRoll += ExternStickRoll / 8;
-
 
691
    StickGier += ExternStickGier;
671
 
692
 
672
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
693
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
673
    if(GyroFaktor < 0) GyroFaktor = 0;
694
    if(GyroFaktor < 0) GyroFaktor = 0;
674
    if(IntegralFaktor < 0) IntegralFaktor = 0;
695
    if(IntegralFaktor < 0) IntegralFaktor = 0;
675
    // greift in den Stick ein, um ungewolltes überschlagen zu verhindern
696
    // greift in den Stick ein, um ungewolltes überschlagen zu verhindern
676
    if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
697
    if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
677
     {
698
     {
678
      if(IntegralNick >  60000)  
699
      if(IntegralNick >  60000)  
679
      {
700
      {
680
       StickNick -=  8 * EE_Parameter.Stick_P;      
701
       StickNick -=  8 * EE_Parameter.Stick_P;      
681
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
702
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
682
      }
703
      }
683
      else
704
      else
684
      if(IntegralNick < -60000)  
705
      if(IntegralNick < -60000)  
685
      {
706
      {
686
       StickNick += 8 * EE_Parameter.Stick_P;
707
       StickNick += 8 * EE_Parameter.Stick_P;
687
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
708
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
688
      }
709
      }
689
      if(IntegralRoll >  60000)  
710
      if(IntegralRoll >  60000)  
690
      {
711
      {
691
       StickRoll -=  8 * EE_Parameter.Stick_P;      
712
       StickRoll -=  8 * EE_Parameter.Stick_P;      
692
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
713
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
693
      }
714
      }
694
      else
715
      else
695
      if(IntegralRoll < -60000)  
716
      if(IntegralRoll < -60000)  
696
      {
717
      {
697
       StickRoll += 8 * EE_Parameter.Stick_P;
718
       StickRoll += 8 * EE_Parameter.Stick_P;
698
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
719
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
699
      }
720
      }
700
     }
721
     }
701
 
-
 
702
  }
-
 
703
 
-
 
704
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
722
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
705
// Looping?
723
// Looping?
706
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
724
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
707
  if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) ||
725
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
708
     ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
-
 
-
 
726
  else
709
   {
727
   {
710
    Looping_Roll = 1;
728
     {
711
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
729
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
-
 
730
     }  
712
   }
731
   }
-
 
732
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
-
 
733
   else
-
 
734
   {
713
   else Looping_Roll = 0;  
735
   if(Looping_Rechts) // Hysterese
-
 
736
     {
-
 
737
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
-
 
738
     }
-
 
739
   }
714
 
740
 
715
  if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) ||
-
 
-
 
741
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
716
     ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN))
742
  else
717
   {
743
   {
-
 
744
    if(Looping_Oben)  // Hysterese
-
 
745
     {
-
 
746
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
-
 
747
     }  
-
 
748
   }
-
 
749
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
-
 
750
   else
-
 
751
   {
-
 
752
    if(Looping_Unten) // Hysterese
-
 
753
     {
-
 
754
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
-
 
755
     }
-
 
756
   }
-
 
757
 
-
 
758
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
-
 
759
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
-
 
760
  } // Ende neue Funken-Werte
718
    Looping_Nick = 1;
761
 
-
 
762
  if(Looping_Roll) beeptime = 100;
-
 
763
  if(Looping_Roll || Looping_Nick)
719
    Looping_Roll = 0;
764
   {
720
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
765
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
721
   }
-
 
722
   else Looping_Nick = 0;  
766
   }
723
   
767
   
724
 
768
 
725
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
769
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
726
// Bei Empfangsausfall im Flug 
770
// Bei Empfangsausfall im Flug 
727
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
771
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
728
   if(Notlandung)
772
   if(Notlandung)
729
    {
773
    {
730
     StickGier = 0;
774
     StickGier = 0;
731
     StickNick = 0;
775
     StickNick = 0;
732
     StickRoll = 0;
776
     StickRoll = 0;
733
     GyroFaktor  = 0.1;
777
     GyroFaktor  = 0.1;
734
     IntegralFaktor = 0.005;
778
     IntegralFaktor = 0.005;
735
     Looping_Roll = 0;
779
     Looping_Roll = 0;
736
     Looping_Nick = 0;
780
     Looping_Nick = 0;
737
    }  
781
    }  
-
 
782
 
-
 
783
 
738
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
784
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
739
// Gyro-Drift kompensieren
785
// Integrale auf ACC-Signal abgleichen
740
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
786
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
741
#define DRIFT_FAKTOR 3
787
#define ABGLEICH_ANZAHL 256L
742
    if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR)
-
 
743
        {
-
 
744
        IntegralFehlerNick = IntegralNick2 - IntegralNick;
-
 
745
        IntegralFehlerRoll = IntegralRoll2 - IntegralRoll;
-
 
746
        ZaehlMessungen = 0;
-
 
747
        if(IntegralFehlerNick > 500/DRIFT_FAKTOR)   AdNeutralNick++;
-
 
748
        if(IntegralFehlerNick < -500/DRIFT_FAKTOR)  AdNeutralNick--;
-
 
749
        if(IntegralFehlerRoll > 500/DRIFT_FAKTOR)   AdNeutralRoll++;
-
 
750
        if(IntegralFehlerRoll < -500/DRIFT_FAKTOR)  AdNeutralRoll--;
-
 
-
 
788
 
-
 
789
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
-
 
790
 MittelIntegralRoll  += IntegralRoll;
-
 
791
 MittelIntegralNick2 += IntegralNick2;
751
 
792
 MittelIntegralRoll2 += IntegralRoll2;
-
 
793
 
-
 
794
 if(Looping_Nick || Looping_Roll)
-
 
795
  {
752
 
796
    IntegralAccNick = 0;
753
        ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
797
    IntegralAccRoll = 0;
754
        Mess_IntegralNick2 = IntegralNick;
798
    MittelIntegralNick = 0;
755
        Mess_IntegralRoll2 = IntegralRoll;
-
 
756
        Mess_Integral_Gier2 = Integral_Gier;
799
    MittelIntegralRoll = 0;
757
       
800
    MittelIntegralNick2 = 0;
758
//Salvo Ersatzkompass Ueberlauf korrigieren
801
    MittelIntegralRoll2 = 0;
-
 
802
    Mess_IntegralNick2 = Mess_IntegralNick;
759
                if (GyroKomp_Int >= ((long)360 * GYROKOMP_INC_GRAD_DEFAULT)) GyroKomp_Int = GyroKomp_Int - (GYROKOMP_INC_GRAD_DEFAULT *(long)360); //neu ab 3.11.2007
803
    Mess_IntegralRoll2 = Mess_IntegralRoll;
760
                if (GyroKomp_Int < 0) GyroKomp_Int = GyroKomp_Int + (GYROKOMP_INC_GRAD_DEFAULT *(long)360); //neu ab 3.11.2007
804
    ZaehlMessungen = 0;
761
                ANALOG_ON;      // ADC einschalten
805
    LageKorrekturNick = 0;
762
                ROT_OFF;
-
 
763
// Salvo End
-
 
764
 
-
 
765
        }
806
    LageKorrekturRoll = 0;
766
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
807
  }
767
// Integrale auf ACC-Signal abgleichen
808
 
-
 
809
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
768
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
810
  if(!Looping_Nick && !Looping_Roll)
769
  if(IntegralFaktor && !Looping_Nick && !Looping_Roll)
-
 
770
  {
811
  {
771
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
812
   long tmp_long, tmp_long2;
772
    if(labs(Mittelwert_AccNick) < 200) tmp_long /= 8;
-
 
773
    else tmp_long /= 16;
813
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
774
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
-
 
775
    if(labs(Mittelwert_AccRoll) < 200) tmp_long2 /= 8;
814
    tmp_long /= 16;
776
    else tmp_long2 /= 16;
815
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
777
 
816
    tmp_long2 /= 16;
778
 #define AUSGLEICH 500
817
 #define AUSGLEICH 32 //(Parameter_UserParam1 / 2)
779
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
818
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
780
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
819
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
781
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
820
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
782
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
821
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
-
 
822
    Mess_IntegralNick -= tmp_long;
-
 
823
    Mess_IntegralRoll -= tmp_long2;
-
 
824
  }
-
 
825
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
826
 
-
 
827
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
-
 
828
 {
-
 
829
  static int cnt = 0;
-
 
830
  static char last_n_p,last_n_n,last_r_p,last_r_n;
-
 
831
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
-
 
832
  if(!Looping_Nick && !Looping_Roll)
-
 
833
  {
-
 
834
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
-
 
835
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
-
 
836
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
-
 
837
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
-
 
838
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
-
 
839
#define MAX_I 0//(Poti2/10)
-
 
840
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
-
 
841
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
-
 
842
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
-
 
843
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
-
 
844
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
-
 
845
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
-
 
846
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
-
 
847
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
-
 
848
 
-
 
849
//    Mess_IntegralNick -= ausgleichNick;
-
 
850
//    Mess_IntegralRoll -= ausgleichRoll;
-
 
851
 
-
 
852
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
853
// Gyro-Drift ermitteln
-
 
854
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
-
 
855
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
-
 
856
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
-
 
857
//    tmp_long  = (long)(MittelIntegralNick2 - (long)IntegralAccNick); 
-
 
858
//    tmp_long2 = (long)(MittelIntegralRoll2 - (long)IntegralAccRoll); 
-
 
859
    tmp_long  = IntegralNick2 - IntegralNick;
-
 
860
    tmp_long2 = IntegralRoll2 - IntegralRoll;
-
 
861
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
-
 
862
 
-
 
863
    IntegralFehlerNick = tmp_long;
-
 
864
    IntegralFehlerRoll = tmp_long2;
-
 
865
    Mess_IntegralNick2 -= IntegralFehlerNick;
-
 
866
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
-
 
867
 
-
 
868
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
-
 
869
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
-
 
870
 
-
 
871
//Salvo Ersatzkompass Ueberlauf korrigieren
-
 
872
                if (GyroKomp_Int >= ((long)360 * GYROKOMP_INC_GRAD_DEFAULT)) GyroKomp_Int = GyroKomp_Int - (GYROKOMP_INC_GRAD_DEFAULT *(long)360); //neu ab 3.11.2007
-
 
873
                if (GyroKomp_Int < 0) GyroKomp_Int = GyroKomp_Int + (GYROKOMP_INC_GRAD_DEFAULT *(long)360); //neu ab 3.11.2007
-
 
874
                ROT_OFF;
-
 
875
// Salvo End
-
 
876
 
-
 
877
/*DebugOut.Analog[17] = IntegralAccNick / 26;
-
 
878
DebugOut.Analog[18] = IntegralAccRoll / 26;
-
 
879
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
-
 
880
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
-
 
881
DebugOut.Analog[21] = MittelIntegralNick / 26;
-
 
882
DebugOut.Analog[22] = MittelIntegralRoll / 26;
-
 
883
DebugOut.Analog[28] = ausgleichNick;
-
 
884
DebugOut.Analog[29] = ausgleichRoll;
-
 
885
DebugOut.Analog[30] = LageKorrekturRoll * 10;
-
 
886
*/
-
 
887
 
-
 
888
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
-
 
889
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
-
 
890
#define BEWEGUNGS_LIMIT 20000
-
 
891
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
-
 
892
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
-
 
893
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
-
 
894
        {
-
 
895
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
-
 
896
         {
-
 
897
           if(last_n_p)
-
 
898
           {
-
 
899
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
-
 
900
            ausgleichNick = IntegralFehlerNick / 8;
-
 
901
            if(ausgleichNick > 5000) ausgleichNick = 5000;
-
 
902
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
-
 
903
           }
-
 
904
           else last_n_p = 1;
-
 
905
         } else  last_n_p = 0;
-
 
906
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
-
 
907
         {
-
 
908
           if(last_n_n)
-
 
909
            {
-
 
910
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
-
 
911
             ausgleichNick = IntegralFehlerNick / 8;
-
 
912
             if(ausgleichNick < -5000) ausgleichNick = -5000;
-
 
913
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
-
 
914
            }
-
 
915
           else last_n_n = 1;
-
 
916
         } else  last_n_n = 0;
-
 
917
        } else cnt = 0;
-
 
918
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
-
 
919
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
-
 
920
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
-
 
921
 
-
 
922
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
-
 
923
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
-
 
924
 
-
 
925
        ausgleichRoll = 0;
-
 
926
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
-
 
927
        {
-
 
928
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
-
 
929
         {
-
 
930
           if(last_r_p)
-
 
931
           {
-
 
932
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
-
 
933
            ausgleichRoll = IntegralFehlerRoll / 8;
-
 
934
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
-
 
935
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
-
 
936
           }
-
 
937
           else last_r_p = 1;
-
 
938
         } else  last_r_p = 0;
-
 
939
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
-
 
940
         {
-
 
941
           if(last_r_n)
-
 
942
           {
-
 
943
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
-
 
944
            ausgleichRoll = IntegralFehlerRoll / 8;
-
 
945
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
-
 
946
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
-
 
947
           }
-
 
948
           else last_r_n = 1;
-
 
949
         } else  last_r_n = 0;
-
 
950
        } else
-
 
951
        {
-
 
952
         cnt = 0;
-
 
953
        }
-
 
954
//DebugOut.Analog[27] = ausgleichRoll;
-
 
955
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
-
 
956
//if(cnt > 1) beeptime = 50;
-
 
957
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
-
 
958
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
-
 
959
//DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
-
 
960
//DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
783
  }
961
  }
784
  else
962
  else
785
  {
963
  {
786
   tmp_long = 0;
964
   LageKorrekturRoll = 0;
787
   tmp_long2 = 0;
965
   LageKorrekturNick = 0;
788
  }
966
  }
789
 ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
967
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
-
 
968
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
-
 
969
   MittelIntegralNick_Alt = MittelIntegralNick;      
790
 // Salvo 1.9.2007 Volle Korrektur nur wenn waagrechte Lage, sonst abgeschawecht *****************
970
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
-
 
971
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
-
 
972
    IntegralAccNick = 0;
-
 
973
    IntegralAccRoll = 0;
-
 
974
    IntegralAccZ = 0;
-
 
975
    MittelIntegralNick = 0;
-
 
976
    MittelIntegralRoll = 0;
-
 
977
    MittelIntegralNick2 = 0;
-
 
978
    MittelIntegralRoll2 = 0;
-
 
979
    ZaehlMessungen = 0;
-
 
980
 }
791
 
-
 
792
        w = (abs(Mittelwert_AccNick));
-
 
793
        v = (abs(Mittelwert_AccRoll));
-
 
794
        if ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT))
-
 
795
        {
-
 
796
        Mess_IntegralNick -= tmp_long;
-
 
797
        Mess_IntegralRoll -= tmp_long2;
-
 
798
        }
-
 
799
        else if ((w  < 2 * ACC_WAAGRECHT_LIMIT) && (v < 2 * ACC_WAAGRECHT_LIMIT))
-
 
800
        {
-
 
801
        Mess_IntegralNick -= tmp_long/2; //Vorher 8
-
 
802
        Mess_IntegralRoll -= tmp_long2/2;
-
 
803
        }
-
 
804
        else if ((w  < 4 * ACC_WAAGRECHT_LIMIT) && (v < 4 * ACC_WAAGRECHT_LIMIT))
-
 
805
        {
-
 
806
        Mess_IntegralNick -= tmp_long/4;
-
 
807
        Mess_IntegralRoll -= tmp_long2/4;
-
 
808
        }
-
 
809
        else
-
 
810
        {
-
 
811
        Mess_IntegralNick -= tmp_long/8;
-
 
812
        Mess_IntegralRoll -= tmp_long2/8;              
-
 
813
        }
-
 
814
// Salvo End ***********************
981
 
815
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
982
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
816
//  Gieren
983
//  Gieren
817
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
984
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
818
    if(abs(StickGier) > 20) // war 35 
985
    if(abs(StickGier) > 20) // war 35 
819
     {
986
     {
820
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
987
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
821
     }
988
     }
822
    tmp_int  = EE_Parameter.Gier_P * (StickGier * abs(StickGier)) / 512; // expo  y = ax + bx²
989
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
823
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
990
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
824
    sollGier = tmp_int;
991
    sollGier = tmp_int;
825
    Mess_Integral_Gier -= tmp_int;  
992
    Mess_Integral_Gier -= tmp_int;  
826
    if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000;  // begrenzen
993
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
827
    if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000;
994
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
828
   
-
 
829
 // Salvo Gewolltes Gieren ignorieren 30.8.2007 **********************
-
 
830
    Mess_Integral_Gier2  -= tmp_int;  
-
 
831
// Salvo End *************************
-
 
832
 ANALOG_ON;     // ADC einschalten
-
 
833
 
995
 
834
// Salvo Ersatzkompass  26.9.2007 **********************
996
// Salvo Ersatzkompass  26.9.2007 **********************
835
        if ((Kompass_Neuer_Wert > 0))
997
        if ((Kompass_Neuer_Wert > 0))
836
        {
998
        {
837
           Kompass_Neuer_Wert = 0;
999
           Kompass_Neuer_Wert = 0;
838
           w = (abs(Mittelwert_AccNick));
1000
           w = (abs(Mittelwert_AccNick));
839
           v = (abs(Mittelwert_AccRoll));
1001
           v = (abs(Mittelwert_AccRoll));
840
           if  ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) //Ersatzkompass nur mit Magnetkompass aktualisieren wenn alles ok
1002
           if  ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) //Ersatzkompass nur mit Magnetkompass aktualisieren wenn alles ok
841
           {
1003
           {
842
                if  ((abs(KompassValue - Kompass_Value_Old)) <= 5) // Aufeinanderfolgende Werte duerfen nur minimal abweichen
1004
                if  ((abs(KompassValue - Kompass_Value_Old)) <= 5) // Aufeinanderfolgende Werte duerfen nur minimal abweichen
843
                 {
1005
                 {
844
                  ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
-
 
845
                  magkompass_ok = 1; // Flag dass Magnetkompass stabil arbeitet 
1006
                  magkompass_ok = 1; // Flag dass Magnetkompass stabil arbeitet 
846
                  GyroKomp_Int = (GyroKomp_Int )/GYROKOMP_INC_GRAD_DEFAULT;
1007
                  GyroKomp_Int = (GyroKomp_Int )/GYROKOMP_INC_GRAD_DEFAULT;
847
                  w = KompassValue - GyroKomp_Int;
1008
                  w = KompassValue - GyroKomp_Int;
848
                  if ((w > 0) && (w < 180))
1009
                  if ((w > 0) && (w < 180))
849
                  {
1010
                  {
850
                   ++GyroKomp_Int;
1011
                   ++GyroKomp_Int;
851
                  }
1012
                  }
852
                  else if ((w > 0) && (w >= 180))
1013
                  else if ((w > 0) && (w >= 180))
853
                  {
1014
                  {
854
                   --GyroKomp_Int;
1015
                   --GyroKomp_Int;
855
                  }
1016
                  }
856
                  else if ((w < 0) && (w >= -180))
1017
                  else if ((w < 0) && (w >= -180))
857
                  {
1018
                  {
858
                   --GyroKomp_Int;
1019
                   --GyroKomp_Int;
859
                  }
1020
                  }
860
                  else if ((w < 0) && (w < -180))
1021
                  else if ((w < 0) && (w < -180))
861
                  {
1022
                  {
862
                   ++GyroKomp_Int;
1023
                   ++GyroKomp_Int;
863
                  }
1024
                  }
864
                  if (GyroKomp_Int < 0)  GyroKomp_Int = GyroKomp_Int + 360;
1025
                  if (GyroKomp_Int < 0)  GyroKomp_Int = GyroKomp_Int + 360;
865
                  GyroKomp_Int = (GyroKomp_Int%360) * GYROKOMP_INC_GRAD_DEFAULT; // An Magnetkompasswert annaehern
1026
                  GyroKomp_Int = (GyroKomp_Int%360) * GYROKOMP_INC_GRAD_DEFAULT; // An Magnetkompasswert annaehern
866
                  ANALOG_ON;    // ADC einschalten
-
 
867
                 }
1027
                 }
868
           }
1028
           }
869
           else magkompass_ok = 0;
1029
           else magkompass_ok = 0;
870
        }
1030
        }
871
// Salvo End *************************
1031
// Salvo End *************************
872
 
1032
 
873
// Salvo 6.10.2007 
1033
// Salvo 6.10.2007 
874
        // GPS Home aktivieren wenn Knueppel in Ruhelage und Hoehenschalter aktiviert ist
1034
        // GPS Home aktivieren wenn Knueppel in Ruhelage und Hoehenschalter aktiviert ist
875
        //GPS Hold Aktiveren wenn Knueppel in Ruhelage sind
1035
        //GPS Hold Aktiveren wenn Knueppel in Ruhelage sind
876
        if ((EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) && (abs(StickRoll) < GPS_STICK_HOLDOFF) && (abs(StickNick) < GPS_STICK_HOLDOFF) && (gps_alive_cnt > 0))
1036
        if ((EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) && (abs(StickRoll) < GPS_STICK_HOLDOFF) && (abs(StickNick) < GPS_STICK_HOLDOFF) && (gps_alive_cnt > 0))
877
        {
1037
        {
878
                if (Parameter_MaxHoehe > 200)  
1038
                if (Parameter_MaxHoehe > 200)  
879
                {      
1039
                {      
880
                        if ( gps_cmd == GPS_CMD_REQ_HOLD) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
1040
                        if ( gps_cmd == GPS_CMD_REQ_HOLD) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
881
                        else gps_cmd = GPS_CMD_REQ_HOME;
1041
                        else gps_cmd = GPS_CMD_REQ_HOME;
882
                        n = GPS_CRTL(gps_cmd);
1042
                        n = GPS_CRTL(gps_cmd);
883
                }
1043
                }
884
                else
1044
                else
885
                {
1045
                {
886
                        if ( gps_cmd == GPS_CMD_REQ_HOME) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
1046
                        if ( gps_cmd == GPS_CMD_REQ_HOME) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
887
                        else gps_cmd = GPS_CMD_REQ_HOLD;
1047
                        else gps_cmd = GPS_CMD_REQ_HOLD;
888
                        n= GPS_CRTL(gps_cmd);
1048
                        n= GPS_CRTL(gps_cmd);
889
                }
1049
                }
890
        }
1050
        }
-
 
1051
        else
-
 
1052
        {
-
 
1053
                if (gps_cmd != GPS_CMD_STOP)
-
 
1054
                {
-
 
1055
                        gps_cmd = GPS_CMD_STOP;
891
        else (n= GPS_CRTL(GPS_CMD_STOP)); //GPS Lageregelung beenden
1056
                        n= GPS_CRTL(gps_cmd); //GPS Lageregelung beenden
-
 
1057
                }
-
 
1058
        }
892
 
1059
 
893
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1060
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
894
//  Kompass
1061
//  Kompass
895
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1062
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
896
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (Kompass_present > 0))
1063
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (Kompass_present > 0))
897
     {
1064
     {
898
           if(v > w) w = v; // grösste Neigung ermitteln
1065
           if(v > w) w = v; // grösste Neigung ermitteln
899
 
1066
 
900
// Salvo 13.9.2007 Nur wenn Magnetkompass ordentliche Werte liefert
1067
// Salvo 13.9.2007 Nur wenn Magnetkompass ordentliche Werte liefert
901
                if ((magkompass_ok > 0)  &&  NeueKompassRichtungMerken)  
1068
                if ((magkompass_ok > 0)  &&  NeueKompassRichtungMerken)  
902
        {
1069
        {
903
                 KompassStartwert = KompassValue;
1070
                 KompassStartwert = KompassValue;
904
         NeueKompassRichtungMerken = 0;
1071
         NeueKompassRichtungMerken = 0;
905
        }
1072
        }
906
// Salvo 13.9.2007
1073
// Salvo 13.9.2007
907
       w=0;
1074
       w=0;
908
// Salvo End
1075
// Salvo End
909
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1076
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
910
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1077
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
911
       if(w > 0)
1078
       if(w > 0)
912
        {
1079
        {
913
          ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
-
 
914
 
-
 
915
// Salvo Kompasssteuerung **********************        
1080
// Salvo Kompasssteuerung **********************        
916
                 if (magkompass_ok > 0) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
1081
                 if (magkompass_ok > 0) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
917
// Salvo End
1082
// Salvo End
918
          ANALOG_ON;  // ADC einschalten
-
 
919
        }  
1083
        }  
920
 
1084
 
921
     }
1085
     }
922
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1086
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
923
 
1087
 
924
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1088
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
925
//  Debugwerte zuordnen
1089
//  Debugwerte zuordnen
926
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1090
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
927
  if(!TimerWerteausgabe--)
1091
  if(!TimerWerteausgabe--)
928
   {
1092
   {
929
    TimerWerteausgabe = 49;
1093
    TimerWerteausgabe = 24;
930
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
1094
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
931
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
1095
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
932
    DebugOut.Analog[2] = Mittelwert_AccNick;
1096
    DebugOut.Analog[2] = Mittelwert_AccNick;
933
    DebugOut.Analog[3] = Mittelwert_AccRoll;
1097
    DebugOut.Analog[3] = Mittelwert_AccRoll;
934
    DebugOut.Analog[4] = MesswertGier;
1098
    DebugOut.Analog[4] = MesswertGier;
935
    DebugOut.Analog[5] = HoehenWert;
1099
    DebugOut.Analog[5] = HoehenWert;
936
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
1100
    DebugOut.Analog[6] =(Mess_Integral_Hoch / 512);
937
    DebugOut.Analog[8] = KompassValue;
1101
    DebugOut.Analog[8] = KompassValue;
938
        DebugOut.Analog[9] = GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT;
1102
        DebugOut.Analog[9] = GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT;
939
 
1103
 
940
// Diverse parameter Debugging
1104
// Diverse parameter Debugging
941
        DebugOut.Analog[16] =  dataset_cnt;
1105
        DebugOut.Analog[16] =  dataset_cnt;
942
        DebugOut.Analog[17] =  UBat;
1106
        DebugOut.Analog[17] =  UBat;
943
        DebugOut.Analog[18] =  MesswertNick;
1107
        DebugOut.Analog[18] =  MesswertNick;
944
        DebugOut.Analog[19] =  MesswertRoll;
1108
        DebugOut.Analog[19] =  MesswertRoll;
945
        DebugOut.Analog[20] =  MesswertGier;
1109
        DebugOut.Analog[20] =  MesswertGier;
946
        DebugOut.Analog[21] =  StickNick;
1110
        DebugOut.Analog[21] =  StickNick;
947
        DebugOut.Analog[22] =  StickRoll;
1111
        DebugOut.Analog[22] =  StickRoll;
948
        DebugOut.Analog[23] =  StickGier;
1112
        DebugOut.Analog[23] =  StickGier;
949
 
1113
 
950
 
1114
 
951
// GPS Debugging
1115
// GPS Debugging
952
        DebugOut.Analog[26] =  gps_rel_act_position.utm_east;
1116
        DebugOut.Analog[26] =  gps_rel_act_position.utm_east;
953
        DebugOut.Analog[27] =  gps_rel_act_position.utm_north;
1117
        DebugOut.Analog[27] =  gps_rel_act_position.utm_north;
954
        DebugOut.Analog[28] =  gps_rel_act_position.utm_alt;
1118
        DebugOut.Analog[28] =  gps_rel_act_position.utm_alt;
955
        DebugOut.Analog[29] =  gps_sub_state+(20*gps_cmd);
1119
        DebugOut.Analog[29] =  gps_sub_state+(20*gps_cmd);
956
 
1120
 
957
/*    DebugOut.Analog[16] = motor_rx[0];
1121
/*    DebugOut.Analog[16] = motor_rx[0];
958
    DebugOut.Analog[17] = motor_rx[1];
1122
    DebugOut.Analog[17] = motor_rx[1];
959
    DebugOut.Analog[18] = motor_rx[2];
1123
    DebugOut.Analog[18] = motor_rx[2];
960
    DebugOut.Analog[19] = motor_rx[3];
1124
    DebugOut.Analog[19] = motor_rx[3];
961
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1125
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
962
    DebugOut.Analog[20] /= 14;
1126
    DebugOut.Analog[20] /= 14;
963
    DebugOut.Analog[21] = motor_rx[4];
1127
    DebugOut.Analog[21] = motor_rx[4];
964
    DebugOut.Analog[22] = motor_rx[5];
1128
    DebugOut.Analog[22] = motor_rx[5];
965
    DebugOut.Analog[23] = motor_rx[6];
1129
    DebugOut.Analog[23] = motor_rx[6];
966
    DebugOut.Analog[24] = motor_rx[7];
1130
    DebugOut.Analog[24] = motor_rx[7];
967
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1131
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
968
*/
1132
*/
969
//    DebugOut.Analog[9] = MesswertNick;
1133
//    DebugOut.Analog[9] = MesswertNick;
970
//    DebugOut.Analog[9] = SollHoehe;
1134
//    DebugOut.Analog[9] = SollHoehe;
971
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1135
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
972
//    DebugOut.Analog[11] = KompassStartwert;
1136
//    DebugOut.Analog[11] = KompassStartwert;
973
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
1137
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
974
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
1138
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
975
//    DebugOut.Analog[9] = KompassRichtung;    
1139
//    DebugOut.Analog[9] = KompassRichtung;    
976
//    DebugOut.Analog[10] = GasMischanteil;
1140
//    DebugOut.Analog[10] = GasMischanteil;
977
//    DebugOut.Analog[3] = HoeheD * 32;
1141
//    DebugOut.Analog[3] = HoeheD * 32;
978
//    DebugOut.Analog[4] = hoehenregler;
1142
//    DebugOut.Analog[4] = hoehenregler;
979
  }
1143
  }
980
 
1144
 
981
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1145
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
982
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1146
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
983
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1147
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
984
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1148
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
985
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1149
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
986
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1150
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
987
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1151
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
988
//    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
1152
//    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
989
    MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2;
1153
    MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2;
-
 
1154
 
-
 
1155
//DebugOut.Analog[28] = MesswertRoll;
-
 
1156
DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
-
 
1157
DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
990
 
1158
 
991
    // Maximalwerte abfangen
1159
    // Maximalwerte abfangen
992
    #define MAX_SENSOR  2048
1160
    #define MAX_SENSOR  2048
993
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1161
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
994
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1162
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
995
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1163
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
996
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1164
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
997
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1165
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
998
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1166
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
999
 
1167
 
1000
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1168
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1001
// Höhenregelung
1169
// Höhenregelung
1002
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1170
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1003
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1171
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1004
//OCR0B = 180 - (Poti1 + 120) / 4;
1172
//OCR0B = 180 - (Poti1 + 120) / 4;
1005
//DruckOffsetSetting = OCR0B;
1173
//DruckOffsetSetting = OCR0B;
1006
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1174
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1007
  {
1175
  {
1008
    int tmp_int;
1176
    int tmp_int;
1009
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1177
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1010
    {
1178
    {
1011
     if(Parameter_MaxHoehe < 50)
1179
     if(Parameter_MaxHoehe < 50)
1012
      {
1180
      {
1013
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1181
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1014
       HoehenReglerAktiv = 0;
1182
       HoehenReglerAktiv = 0;
1015
      }
1183
      }
1016
      else  
1184
      else  
1017
        HoehenReglerAktiv = 1;
1185
        HoehenReglerAktiv = 1;
1018
    }
1186
    }
1019
    else
1187
    else
1020
    {
1188
    {
1021
     SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20;
1189
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1022
     HoehenReglerAktiv = 1;
1190
     HoehenReglerAktiv = 1;
1023
    }
1191
    }
1024
 
1192
 
1025
    if(Notlandung) SollHoehe = 0;
1193
    if(Notlandung) SollHoehe = 0;
1026
    h = HoehenWert;
1194
    h = HoehenWert;
1027
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1195
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1028
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1196
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1029
      h = GasMischanteil - h;         // vom Gas abziehen
1197
      h = GasMischanteil - h;         // vom Gas abziehen
1030
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1198
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1031
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1199
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1032
      if(tmp_int > 50) tmp_int = 50;
1200
      if(tmp_int > 50) tmp_int = 50;
1033
      else if(tmp_int < -50) tmp_int = -50;
1201
      else if(tmp_int < -50) tmp_int = -50;
1034
      h -= tmp_int;
1202
      h -= tmp_int;
1035
      hoehenregler = (hoehenregler*15 + h) / 16;      
1203
      hoehenregler = (hoehenregler*15 + h) / 16;      
1036
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1204
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1037
       {
1205
       {
1038
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1206
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1039
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1207
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1040
       }  
1208
       }  
1041
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1209
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1042
      GasMischanteil = hoehenregler;
1210
      GasMischanteil = hoehenregler;
1043
     }
1211
     }
1044
  }
1212
  }
1045
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1213
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1046
// + Mischer und PI-Regler
1214
// + Mischer und PI-Regler
1047
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1215
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1048
  DebugOut.Analog[7] = GasMischanteil;
1216
  DebugOut.Analog[7] = GasMischanteil;
1049
 
-
 
1050
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1217
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1051
// Gier-Anteil
1218
// Gier-Anteil
1052
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1219
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1053
#define MUL_G  1.0
1220
#define MUL_G  1.0
1054
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1221
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1055
//GierMischanteil = 0;
1222
//GierMischanteil = 0;
-
 
1223
 
1056
    if(GierMischanteil > (MUL_G * GasMischanteil))  GierMischanteil = MUL_G * GasMischanteil;
1224
    if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1057
    if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil);
1225
    if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1058
    if(GierMischanteil > 100)  GierMischanteil = 100;
1226
    if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil));
1059
    if(GierMischanteil < -100) GierMischanteil = -100;
1227
    if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil));
1060
 
1228
 
1061
    if(GasMischanteil < 20) GierMischanteil = 0;
1229
    if(GasMischanteil < 20) GierMischanteil = 0;
1062
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1230
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1063
// Nick-Achse
1231
// Nick-Achse
1064
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1232
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1065
 
-
 
1066
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
1233
    DiffNick = MesswertNick - (StickNick - GPS_Nick);   // Differenz bestimmen
-
 
1234
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
1067
    SummeNick += DiffNick;                                   // I-Anteil
1235
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1068
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
1236
    if(SummeNick > 0) SummeNick-= 2 ; else SummeNick += 2 ;
1069
    if(SummeNick >  16000) SummeNick =  16000;
1237
    if(SummeNick >  16000) SummeNick =  16000;
1070
    if(SummeNick < -16000) SummeNick = -16000;
1238
    if(SummeNick < -16000) SummeNick = -16000;
1071
    pd_ergebnis = DiffNick;// + Ki * SummeNick; // PI-Regler für Nick                                   
1239
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1072
    // Motor Vorn
1240
    // Motor Vorn
1073
#define MUL  2
-
 
1074
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1241
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
-
 
1242
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1075
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1243
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1076
 
1244
 
1077
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1245
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1078
        if ((motorwert < 0)) motorwert = 0;
1246
        if ((motorwert < 0)) motorwert = 0;
1079
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1247
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1080
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1248
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1081
        Motor_Vorne = motorwert;           
1249
        Motor_Vorne = motorwert;           
1082
    // Motor Heck
1250
    // Motor Heck
1083
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1251
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1084
        if ((motorwert < 0)) motorwert = 0;
1252
        if ((motorwert < 0)) motorwert = 0;
1085
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1253
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1086
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1254
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1087
        Motor_Hinten = motorwert;              
1255
        Motor_Hinten = motorwert;              
1088
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1256
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1089
// Roll-Achse
1257
// Roll-Achse
1090
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1258
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1091
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
1259
        DiffRoll = MesswertRoll - (StickRoll  - GPS_Roll);      // Differenz bestimmen
-
 
1260
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll  - GPS_Roll);// I-Anteil bei Winkelregelung
1092
        SummeRoll += DiffRoll;                                                              // I-Anteil
1261
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1093
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
1262
    if(SummeRoll > 0) SummeRoll-= 2 ; else SummeRoll += 2 ;
1094
    if(SummeRoll >  16000) SummeRoll =  16000;
1263
    if(SummeRoll >  16000) SummeRoll =  16000;
1095
    if(SummeRoll < -16000) SummeRoll = -16000;
1264
    if(SummeRoll < -16000) SummeRoll = -16000;
1096
    pd_ergebnis = DiffRoll;// + Ki * SummeRoll; // PI-Regler für Roll
1265
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1097
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1266
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
-
 
1267
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1098
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1268
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1099
    // Motor Links
1269
    // Motor Links
1100
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1270
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1101
        if ((motorwert < 0)) motorwert = 0;
1271
        if ((motorwert < 0)) motorwert = 0;
1102
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1272
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1103
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1273
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1104
        Motor_Links = motorwert;               
1274
        Motor_Links = motorwert;               
1105
    // Motor Rechts
1275
    // Motor Rechts
1106
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1276
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1107
        if ((motorwert < 0)) motorwert = 0;
1277
        if ((motorwert < 0)) motorwert = 0;
1108
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1278
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1109
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1279
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1110
        Motor_Rechts = motorwert;
1280
        Motor_Rechts = motorwert;
1111
   // +++++++++++++++++++++++++++++++++++++++++++++++
1281
   // +++++++++++++++++++++++++++++++++++++++++++++++
1112
}
1282
}
1113
 
1283
 
1114
 
1284