Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
573 joko 1
/*#######################################################################################
2
Flight Control
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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. 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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"
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
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
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 
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +     clearly linked as origin 
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"
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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)
52
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53
// +  POSSIBILITY OF SUCH DAMAGE. 
54
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
 
56
#include "main.h"
57
#include "eeprom.c"
58
 
59
unsigned char h,m,s;
60
volatile unsigned int I2CTimeout = 100;
61
volatile int MesswertNick,MesswertRoll,MesswertGier;
62
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
63
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
64
volatile float NeutralAccZ = 0;
65
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
66
volatile long IntegralNick = 0,IntegralNick2 = 0;
67
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
68
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
69
volatile long Integral_Gier = 0;
70
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
71
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
72
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
73
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
74
volatile long Mess_Integral_Hoch = 0;
75
 
76
int  KompassValue = 0;
77
int  KompassStartwert = 0;
78
int  KompassRichtung = 0;
79
uint8_t updKompass = 0;
80
 
81
unsigned char MAX_GAS,MIN_GAS;
82
unsigned char Notlandung = 0;
83
unsigned char HoehenReglerAktiv = 0;
84
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
85
 
86
unsigned char blinkcount_LED1 = 0;//Hilfszähler für die blinkende LED (310807Kr)
87
unsigned char LED1_TOTALTIME = 0;//Parameter für Blinkverhalten von LED1 (091207Kr)
88
unsigned char LED1_ONTIME = 0;//Parameter für Blinkverhalten von LED1 (091207Kr)
89
unsigned int modell_fliegt_gps = 0;//(030907Kr)
90
 
91
 
92
float GyroFaktor;
93
float IntegralFaktor;
94
volatile int  DiffNick,DiffRoll;
95
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; //PPM24-Erweiterung (121007Kr)
96
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
97
unsigned char MotorWert[5];
98
volatile unsigned char SenderOkay = 0;
99
int StickNick = 0,StickRoll = 0,StickGier = 0;
100
char MotorenEin = 0;
101
int HoehenWert = 0;
102
int SollHoehe = 0;
103
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
104
float Ki =  FAKTOR_I;
105
unsigned char Looping_Nick = 0,Looping_Roll = 0;
106
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
107
 
108
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
109
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
110
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
111
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
112
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
113
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
114
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
115
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
116
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
117
unsigned char Parameter_UserParam1 = 0;
118
unsigned char Parameter_UserParam2 = 0;
119
unsigned char Parameter_UserParam3 = 0;
120
unsigned char Parameter_UserParam4 = 0;
121
unsigned char Parameter_UserParam5 = 0;
122
unsigned char Parameter_UserParam6 = 0;
123
unsigned char Parameter_UserParam7 = 0;
124
unsigned char Parameter_UserParam8 = 0;
125
unsigned char Parameter_ServoNickControl = 100;
126
unsigned char Parameter_LoopGasLimit = 70;
127
unsigned char Parameter_AchsKopplung1 = 0;
128
unsigned char Parameter_AchsGegenKopplung1 = 0;
129
unsigned char Parameter_DynamicStability = 100;
130
struct mk_param_struct EE_Parameter;
131
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
132
 
133
void Piep(unsigned char Anzahl)
134
{
135
 while(Anzahl--)
136
 {
137
  if(MotorenEin) return; //auf keinen Fall im Flug!
138
  beeptime = 100;
139
  Delay_ms(250);
140
 }
141
}
142
 
143
//############################################################################
144
//  Nullwerte ermitteln
145
void SetNeutral(void)
146
//############################################################################
147
{
148
        NeutralAccX = 0;
149
        NeutralAccY = 0;
150
        NeutralAccZ = 0;
151
    AdNeutralNick = 0; 
152
        AdNeutralRoll = 0;     
153
        AdNeutralGier = 0;
154
    Parameter_AchsKopplung1 = 0;
155
    Parameter_AchsGegenKopplung1 = 0;
156
    CalibrierMittelwert();     
157
    Delay_ms_Mess(100);
158
        CalibrierMittelwert();
159
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
160
     {    
161
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
162
     }
163
 
164
     AdNeutralNick= AdWertNick;
165
         AdNeutralRoll= AdWertRoll;    
166
         AdNeutralGier= AdWertGier;
167
     StartNeutralRoll = AdNeutralRoll;
168
     StartNeutralNick = AdNeutralNick;
169
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
170
    {
171
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
172
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
173
          NeutralAccZ = Aktuell_az;
174
    }
175
    else
176
    {
177
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
178
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
179
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
180
    }
181
 
182
        Mess_IntegralNick = 0; 
183
    Mess_IntegralNick2 = 0;
184
    Mess_IntegralRoll = 0;     
185
    Mess_IntegralRoll2 = 0;
186
    Mess_Integral_Gier = 0;    
187
    MesswertNick = 0;
188
    MesswertRoll = 0;
189
    MesswertGier = 0;
190
    StartLuftdruck = Luftdruck;
191
    HoeheD = 0;
192
    Mess_Integral_Hoch = 0;
193
    KompassStartwert = KompassValue;
194
    beeptime = 50;  
195
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
196
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
197
    ExternHoehenValue = 0;
198
}
199
 
200
//############################################################################
201
// Bearbeitet die Messwerte
202
void Mittelwert(void)
203
//############################################################################
204
{      
205
    static signed long tmpl,tmpl2;     
206
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
207
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
208
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
209
 
210
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
211
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
212
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
213
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
214
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
215
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
216
    IntegralAccZ    += Aktuell_az - NeutralAccZ;
217
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
218
            Mess_Integral_Gier +=  MesswertGier;
219
            Mess_Integral_Gier2 += MesswertGier;
220
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
221
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
222
         {
223
            tmpl = Mess_IntegralNick / 4096L;
224
            tmpl *= MesswertGier;
225
            tmpl *= Parameter_AchsKopplung1;  //125
226
            tmpl /= 2048L;
227
            tmpl2 = Mess_IntegralRoll / 4096L;
228
            tmpl2 *= MesswertGier;
229
            tmpl2 *= Parameter_AchsKopplung1;
230
            tmpl2 /= 2048L;
231
         }
232
      else  tmpl = tmpl2 = 0;
233
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
234
            MesswertRoll += tmpl;
235
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
236
            Mess_IntegralRoll2 += MesswertRoll;
237
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
238
            if(Mess_IntegralRoll > Umschlag180Roll)
239
            {
240
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
241
             Mess_IntegralRoll2 = Mess_IntegralRoll;
242
            }
243
            if(Mess_IntegralRoll <-Umschlag180Roll)
244
            {
245
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
246
             Mess_IntegralRoll2 = Mess_IntegralRoll;
247
            }  
248
            if(AdWertRoll < 15)   MesswertRoll = -1000;
249
            if(AdWertRoll <  7)   MesswertRoll = -2000;
250
            if(PlatinenVersion == 10)
251
                         {
252
              if(AdWertRoll > 1010) MesswertRoll = +1000;
253
              if(AdWertRoll > 1017) MesswertRoll = +2000;
254
                         }
255
                         else
256
                         {
257
              if(AdWertRoll > 2020) MesswertRoll = +1000;
258
              if(AdWertRoll > 2034) MesswertRoll = +2000;
259
                         }
260
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
261
            MesswertNick -= tmpl2;
262
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
263
            Mess_IntegralNick2 += MesswertNick;
264
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
265
            if(Mess_IntegralNick > Umschlag180Nick)
266
            {
267
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
268
             Mess_IntegralNick2 = Mess_IntegralNick;
269
            }
270
            if(Mess_IntegralNick <-Umschlag180Nick)
271
            {
272
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
273
             Mess_IntegralNick2 = Mess_IntegralNick;
274
            }
275
            if(AdWertNick < 15)   MesswertNick = -1000;
276
            if(AdWertNick <  7)   MesswertNick = -2000;
277
            if(PlatinenVersion == 10)
278
                         {
279
              if(AdWertNick > 1010) MesswertNick = +1000;
280
              if(AdWertNick > 1017) MesswertNick = +2000;
281
                         }
282
                         else
283
                         {
284
              if(AdWertNick > 2020) MesswertNick = +1000;
285
              if(AdWertNick > 2034) MesswertNick = +2000;
286
                         }
287
//++++++++++++++++++++++++++++++++++++++++++++++++
288
// ADC einschalten
289
    ANALOG_ON; 
290
//++++++++++++++++++++++++++++++++++++++++++++++++
291
 
292
    Integral_Gier  = Mess_Integral_Gier;
293
    IntegralNick = Mess_IntegralNick;
294
    IntegralRoll = Mess_IntegralRoll;
295
    IntegralNick2 = Mess_IntegralNick2;
296
    IntegralRoll2 = Mess_IntegralRoll2;
297
 
298
//------------------------------------------------------------------------------
299
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll && !(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD))  //um Heading_Hold erweitert //(071107Kr)
300
  {
301
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
302
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
303
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
304
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
305
         }
306
//------------------------------------------------------------------------------
307
 
308
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
309
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
310
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
311
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
312
    //PPM24-Erweiterung (121007Kr)
313
        if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 >  PPM_in[9] + 110 && Poti5) Poti5--;
314
    if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--;
315
    if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--;
316
    if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--;
317
 
318
 
319
        if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
320
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
321
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
322
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
323
        //PPM24-Erweiterung (121007Kr)
324
        if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255;
325
        if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255;
326
        if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255;
327
    if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255;
328
}
329
 
330
//############################################################################
331
// Messwerte beim Ermitteln der Nullage
332
void CalibrierMittelwert(void)
333
//############################################################################
334
{                
335
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
336
        ANALOG_OFF;
337
        MesswertNick = AdWertNick;
338
        MesswertRoll = AdWertRoll;
339
        MesswertGier = AdWertGier;
340
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
341
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
342
        Mittelwert_AccHoch = (long)AdWertAccHoch;
343
   // ADC einschalten
344
    ANALOG_ON; 
345
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
346
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
347
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
348
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
349
    //PPM24-Erweiterung (121007Kr)
350
        if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 >  PPM_in[9] + 110 && Poti5) Poti5--;
351
    if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--;
352
    if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--;
353
    if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--;
354
 
355
 
356
 
357
 
358
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
359
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
360
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
361
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
362
        //PPM24-Erweiterung (121007Kr)
363
        if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255;
364
        if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255;
365
        if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255;
366
    if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255;
367
 
368
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
369
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
370
}
371
 
372
//############################################################################
373
// Senden der Motorwerte per I2C-Bus
374
void SendMotorData(void)
375
//############################################################################
376
{
377
    if(MOTOR_OFF || !MotorenEin)
378
        {
379
        Motor_Hinten = 0;
380
        Motor_Vorne = 0;
381
        Motor_Rechts = 0;
382
        Motor_Links = 0;
383
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
384
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
385
        if(MotorTest[2]) Motor_Links = MotorTest[2];
386
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
387
        }
388
 
389
   // DebugOut.Analog[12] = Motor_Vorne;
390
   // DebugOut.Analog[13] = Motor_Hinten;
391
   // DebugOut.Analog[14] = Motor_Links;
392
   // DebugOut.Analog[15] = Motor_Rechts;   
393
 
394
    //Start I2C Interrupt Mode
395
    twi_state = 0;
396
    motor = 0;
397
    i2c_start();
398
}
399
 
400
 
401
 
402
//############################################################################
403
// Trägt ggf. das Poti als Parameter ein
404
void ParameterZuordnung(void)
405
//############################################################################
406
{
407
 
408
 #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;}
409
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
410
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
411
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
412
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
413
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
414
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
415
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
416
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
417
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
418
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
419
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
420
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
421
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
422
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
423
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
424
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
425
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
426
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
427
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
428
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
429
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
430
 
431
 Ki = (float) Parameter_I_Faktor * 0.0001;
432
 MAX_GAS = EE_Parameter.Gas_Max;
433
 MIN_GAS = EE_Parameter.Gas_Min;
434
}
435
 
436
 
437
//############################################################################
438
//
439
void MotorRegler(void)
440
//############################################################################
441
{
442
         int motorwert,pd_ergebnis,h,tmp_int;
443
         int GierMischanteil,GasMischanteil;
444
     static long SummeNick=0,SummeRoll=0;
445
     static long sollGier = 0,tmp_long,tmp_long2;
446
     static long IntegralFehlerNick = 0;
447
     static long IntegralFehlerRoll = 0;
448
         static unsigned int RcLostTimer;
449
         static unsigned char delay_neutral = 0;
450
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
451
         static unsigned int  modell_fliegt = 0;
452
     static int hoehenregler = 0;
453
     static char TimerWerteausgabe = 0;
454
     static char NeueKompassRichtungMerken = 0;
455
     static long ausgleichNick, ausgleichRoll;
456
 
457
        Mittelwert();
458
 
459
    GRN_ON;
460
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
461
// Gaswert ermitteln
462
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
463
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
464
    if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20;
465
    if(GasMischanteil < 0) GasMischanteil = 0;
466
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
467
// Emfang schlecht
468
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
469
   if(SenderOkay < 100)
470
        {
471
        if(!PcZugriff)
472
         {
473
           if(BeepMuster == 0xffff)
474
            {
475
             beeptime = 15000;
476
             BeepMuster = 0x0c00;
477
            }
478
         }
479
        if(RcLostTimer) RcLostTimer--;
480
        else
481
         {
482
          MotorenEin = 0;
483
          Notlandung = 0;
484
         }
485
        ROT_ON;
486
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
487
            {
488
            GasMischanteil = EE_Parameter.NotGas;
489
            Notlandung = 1;
490
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
491
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
492
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
493
            }
494
         else MotorenEin = 0;
495
        }
496
        else
497
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
498
// Emfang gut
499
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
500
        if(SenderOkay > 140)
501
            {
502
            Notlandung = 0;
503
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
504
            if(GasMischanteil > 40)
505
                {
506
                if(modell_fliegt < 0xffff) modell_fliegt++;
507
                                modell_fliegt_gps = modell_fliegt;// (030907Kr)
508
                }
509
            if((modell_fliegt < 200) || (GasMischanteil < 40))
510
                {
511
                SummeNick = 0;
512
                SummeRoll = 0;
513
                Mess_Integral_Gier = 0;
514
                Mess_Integral_Gier2 = 0;
515
                }
516
            if((GasMischanteil > 200) && MotorenEin == 0)
517
                {
518
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
519
// auf Nullwerte kalibrieren
520
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
521
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
522
                    {
523
                    if(++delay_neutral > 200)  // nicht sofort
524
                        {
525
                        GRN_OFF;
526
                        MotorenEin = 0;
527
                        delay_neutral = 0;
528
                        modell_fliegt = 0;
529
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
530
                        {
531
                         unsigned char setting=1;
532
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
533
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
534
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
535
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
536
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
537
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
538
                        }
539
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
540
                          {
541
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
542
                          }  
543
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
544
                        SetNeutral();
545
                        Piep(GetActiveParamSetNumber());
546
                        }
547
                    }
548
                 else
549
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
550
                    {
551
                    if(++delay_neutral > 200)  // nicht sofort
552
                        {
553
                        GRN_OFF;
554
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
555
                        MotorenEin = 0;
556
                        delay_neutral = 0;
557
                        modell_fliegt = 0;
558
                        SetNeutral();
559
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
560
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
561
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
562
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
563
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
564
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
565
                        Piep(GetActiveParamSetNumber());
566
                        }
567
                    }
568
                 else delay_neutral = 0;
569
                }
570
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
571
// Gas ist unten
572
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
573
            if(GasMischanteil < 35)
574
                {
575
                // Starten
576
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
577
                    {
578
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
579
// Einschalten
580
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
581
                    if(++delay_einschalten > 200)
582
                        {
583
                        delay_einschalten = 200;
584
                        modell_fliegt = 1;
585
                        MotorenEin = 1;
586
                        sollGier = 0;
587
                        Mess_Integral_Gier = 0;
588
                        Mess_Integral_Gier2 = 0;
589
                        Mess_IntegralNick = 0;
590
                        Mess_IntegralRoll = 0;
591
                        Mess_IntegralNick2 = IntegralNick;
592
                        Mess_IntegralRoll2 = IntegralRoll;
593
                        SummeNick = 0;
594
                        SummeRoll = 0;
595
                        }          
596
                    }  
597
                    else delay_einschalten = 0;
598
                //Auf Neutralwerte setzen
599
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
600
// Auschalten
601
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
602
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
603
                    {
604
                    if(++delay_ausschalten > 200)  // nicht sofort
605
                        {
606
                        MotorenEin = 0;
607
                        delay_ausschalten = 200;
608
                        modell_fliegt = 0;
609
                        }
610
                    }
611
                else delay_ausschalten = 0;
612
                }
613
            }
614
 
615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
616
// neue Werte von der Funke
617
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
618
 if(!NewPpmData-- || Notlandung)  
619
  {
620
    int tmp_int;
621
    ParameterZuordnung();
622
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
623
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
624
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
625
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
626
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
627
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
628
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
629
 
630
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
631
if(DubWiseKeys[1]) beeptime = 10;
632
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
633
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
634
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
635
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
636
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
637
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
638
 
639
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
640
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
641
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
642
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
643
 
644
    StickNick += ExternStickNick / 8;
645
    StickRoll += ExternStickRoll / 8;
646
    StickGier += ExternStickGier;
647
 
648
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
649
    if(GyroFaktor < 0) GyroFaktor = 0;
650
    if(IntegralFaktor < 0) IntegralFaktor = 0;
651
    // greift in den Stick ein, um ungewolltes überschlagen zu verhindern
652
        //bei aktiviertem GPS dürfen die Stickwerte nicht beeinflusst werden, da ansonsten ein Neulernen der Sollposition stattfinden könnte //(051107Kr)
653
    if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) && !(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) && !(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD)) //(051107Kr)
654
     {
655
      if(IntegralNick >  60000)  
656
      {
657
       StickNick -=  8 * EE_Parameter.Stick_P;      
658
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
659
      }
660
      else
661
      if(IntegralNick < -60000)  
662
      {
663
       StickNick += 8 * EE_Parameter.Stick_P;
664
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
665
      }
666
      if(IntegralRoll >  60000)  
667
      {
668
       StickRoll -=  8 * EE_Parameter.Stick_P;      
669
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
670
      }
671
      else
672
      if(IntegralRoll < -60000)  
673
      {
674
       StickRoll += 8 * EE_Parameter.Stick_P;
675
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
676
      }
677
     }
678
 
679
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
680
// LED Stuff
681
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
682
 
683
        LED1_TOTALTIME = Parameter_UserParam7;
684
        LED1_ONTIME = Parameter_UserParam8;
685
 
686
        LED1_OFF;
687
 
688
        if(LED1_TOTALTIME >= 200)
689
        {
690
        LED1_ON;
691
        blinkcount_LED1 = 0;
692
        }
693
 
694
        else if(blinkcount_LED1 >= LED1_TOTALTIME && LED1_TOTALTIME > 0 && MotorenEin == 1)
695
        {
696
        LED1_ON;
697
 
698
                if(blinkcount_LED1 >= LED1_ONTIME + LED1_TOTALTIME)
699
                {
700
                LED1_OFF;
701
                blinkcount_LED1 = 0;
702
                }
703
        }
704
 
705
        blinkcount_LED1++;
706
 
707
        //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] > 75) LED1_ON; else LED1_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr)
708
        //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 75) LED2_ON; else LED2_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr)
709
 
710
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
711
// Looping?
712
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
713
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
714
  else
715
   {
716
     {
717
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
718
     }  
719
   }
720
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
721
   else
722
   {
723
   if(Looping_Rechts) // Hysterese
724
     {
725
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
726
     }
727
   }
728
 
729
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
730
  else
731
   {
732
    if(Looping_Oben)  // Hysterese
733
     {
734
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
735
     }  
736
   }
737
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
738
   else
739
   {
740
    if(Looping_Unten) // Hysterese
741
     {
742
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
743
     }
744
   }
745
 
746
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
747
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
748
  } // Ende neue Funken-Werte
749
 
750
  if(Looping_Roll) beeptime = 100;
751
  if(Looping_Roll || Looping_Nick)
752
   {
753
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
754
   }
755
 
756
 
757
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
758
// Bei Empfangsausfall im Flug 
759
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
760
   if(Notlandung)
761
    {
762
     StickGier = 0;
763
     StickNick = 0;
764
     StickRoll = 0;
765
     GyroFaktor  = 0.1;
766
     IntegralFaktor = 0.005;
767
     Looping_Roll = 0;
768
     Looping_Nick = 0;
769
    }  
770
 
771
 
772
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
773
// Integrale auf ACC-Signal abgleichen
774
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
775
#define ABGLEICH_ANZAHL 256L
776
 
777
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
778
 MittelIntegralRoll  += IntegralRoll;
779
 MittelIntegralNick2 += IntegralNick2;
780
 MittelIntegralRoll2 += IntegralRoll2;
781
 
782
 if(Looping_Nick || Looping_Roll)
783
  {
784
    IntegralAccNick = 0;
785
    IntegralAccRoll = 0;
786
    MittelIntegralNick = 0;
787
    MittelIntegralRoll = 0;
788
    MittelIntegralNick2 = 0;
789
    MittelIntegralRoll2 = 0;
790
    Mess_IntegralNick2 = Mess_IntegralNick;
791
    Mess_IntegralRoll2 = Mess_IntegralRoll;
792
    ZaehlMessungen = 0;
793
    LageKorrekturNick = 0;
794
    LageKorrekturRoll = 0;
795
  }
796
 
797
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
798
  if(!Looping_Nick && !Looping_Roll)
799
  {
800
   long tmp_long, tmp_long2;
801
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
802
    tmp_long /= 16;
803
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
804
    tmp_long2 /= 16;
805
 #define AUSGLEICH 32 //(Parameter_UserParam1 / 2)
806
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
807
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
808
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
809
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
810
    Mess_IntegralNick -= tmp_long;
811
    Mess_IntegralRoll -= tmp_long2;
812
  }
813
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
814
 
815
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
816
 {
817
  static int cnt = 0;
818
  static char last_n_p,last_n_n,last_r_p,last_r_n;
819
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
820
  if(!Looping_Nick && !Looping_Roll)
821
  {
822
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
823
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
824
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
825
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
826
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
827
#define MAX_I 0//(Poti2/10)
828
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
829
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
830
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
831
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
832
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
833
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
834
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
835
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
836
 
837
//    Mess_IntegralNick -= ausgleichNick;
838
//    Mess_IntegralRoll -= ausgleichRoll;
839
 
840
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
841
// Gyro-Drift ermitteln
842
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
843
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
844
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
845
//    tmp_long  = (long)(MittelIntegralNick2 - (long)IntegralAccNick); 
846
//    tmp_long2 = (long)(MittelIntegralRoll2 - (long)IntegralAccRoll); 
847
    tmp_long  = IntegralNick2 - IntegralNick;
848
    tmp_long2 = IntegralRoll2 - IntegralRoll;
849
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
850
 
851
    IntegralFehlerNick = tmp_long;
852
    IntegralFehlerRoll = tmp_long2;
853
    Mess_IntegralNick2 -= IntegralFehlerNick;
854
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
855
 
856
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
857
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
858
 
859
 
860
//DebugOut.Analog[17] = IntegralAccNick / 26;
861
//DebugOut.Analog[18] = IntegralAccRoll / 26;
862
//DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
863
//DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
864
//DebugOut.Analog[21] = MittelIntegralNick / 26;
865
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
866
//DebugOut.Analog[28] = ausgleichNick;
867
//DebugOut.Analog[29] = ausgleichRoll;
868
//DebugOut.Analog[30] = LageKorrekturRoll * 10;
869
 
870
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
871
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
872
#define BEWEGUNGS_LIMIT 20000
873
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
874
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
875
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
876
        {
877
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
878
         {
879
           if(last_n_p)
880
           {
881
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
882
            ausgleichNick = IntegralFehlerNick / 8;
883
            if(ausgleichNick > 5000) ausgleichNick = 5000;
884
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
885
           }
886
           else last_n_p = 1;
887
         } else  last_n_p = 0;
888
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
889
         {
890
           if(last_n_n)
891
            {
892
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
893
             ausgleichNick = IntegralFehlerNick / 8;
894
             if(ausgleichNick < -5000) ausgleichNick = -5000;
895
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
896
            }
897
           else last_n_n = 1;
898
         } else  last_n_n = 0;
899
        } else cnt = 0;
900
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
901
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
902
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
903
 
904
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
905
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
906
 
907
        ausgleichRoll = 0;
908
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
909
        {
910
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
911
         {
912
           if(last_r_p)
913
           {
914
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
915
            ausgleichRoll = IntegralFehlerRoll / 8;
916
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
917
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
918
           }
919
           else last_r_p = 1;
920
         } else  last_r_p = 0;
921
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
922
         {
923
           if(last_r_n)
924
           {
925
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
926
            ausgleichRoll = IntegralFehlerRoll / 8;
927
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
928
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
929
           }
930
           else last_r_n = 1;
931
         } else  last_r_n = 0;
932
        } else
933
        {
934
         cnt = 0;
935
        }
936
//DebugOut.Analog[27] = ausgleichRoll;
937
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
938
//if(cnt > 1) beeptime = 50;
939
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
940
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
941
//DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
942
//DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
943
  }
944
  else
945
  {
946
   LageKorrekturRoll = 0;
947
   LageKorrekturNick = 0;
948
  }
949
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
950
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
951
   MittelIntegralNick_Alt = MittelIntegralNick;      
952
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
953
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
954
    IntegralAccNick = 0;
955
    IntegralAccRoll = 0;
956
    IntegralAccZ = 0;
957
    MittelIntegralNick = 0;
958
    MittelIntegralRoll = 0;
959
    MittelIntegralNick2 = 0;
960
    MittelIntegralRoll2 = 0;
961
    ZaehlMessungen = 0;
962
 }
963
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
964
 
965
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
966
//  Gieren
967
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
968
    if(abs(StickGier) > 20) // war 35 
969
     {
970
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
971
     }
972
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
973
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
974
    sollGier = tmp_int;
975
    Mess_Integral_Gier -= tmp_int;  
976
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
977
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
978
 
979
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
980
//  Kompass
981
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
982
    if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
983
     {
984
       int w,v;
985
 
986
                if (!updKompass--)              // Aufruf mit ~10 Hz
987
                {
988
                        KompassValue = heading_MM3();
989
                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
990
                        updKompass = 50;
991
                }
992
 
993
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
994
       v = abs(IntegralRoll /512);
995
       if(v > w) w = v; // grösste Neigung ermitteln
996
       if(w < 35 && NeueKompassRichtungMerken)    
997
        {
998
         KompassStartwert = KompassValue;
999
         NeueKompassRichtungMerken = 0;
1000
        }
1001
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1002
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1003
       if(w > 0)
1004
       {
1005
                        ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
1006
                        Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
1007
                        ANALOG_ON;  // ADC einschalten
1008
           }  
1009
     }
1010
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1011
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1012
 
1013
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++        
1014
// GPS  
1015
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++        
1016
        if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)
1017
        {
1018
          P_GPS_Verstaerkung = Parameter_UserParam5;
1019
          D_GPS_Verstaerkung = Parameter_UserParam6;
1020
 
1021
          //if(newData_navPosUtm == 1)
1022
                //{
1023
                gps_main();
1024
                //}
1025
        }
1026
        else
1027
        {
1028
          GPS_Nick = 0;
1029
          GPS_Roll = 0;
1030
        }
1031
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1032
//  Debugwerte zuordnen
1033
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1034
  if(!TimerWerteausgabe--)
1035
   {
1036
    TimerWerteausgabe = 24;
1037
 
1038
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
1039
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
1040
    DebugOut.Analog[2] = Mittelwert_AccNick;
1041
    DebugOut.Analog[3] = Mittelwert_AccRoll;
1042
        DebugOut.Analog[4] = P_GPS_Verstaerkung;
1043
    DebugOut.Analog[5] = D_GPS_Verstaerkung;
1044
        DebugOut.Analog[6] = Soll_Position_North;
1045
    DebugOut.Analog[7] = Soll_Position_East;
1046
        DebugOut.Analog[8] = KompassValue;
1047
        DebugOut.Analog[9] = UBat;
1048
        DebugOut.Analog[10] = SenderOkay;
1049
        DebugOut.Analog[11] = actualPos.GPSFix;
1050
        DebugOut.Analog[12] = (motor_rx[0]+motor_rx[1]+motor_rx[2]+motor_rx[3]); //Gesamtstrom
1051
        DebugOut.Analog[13] = actualPos.GSpeed; //Geschwindigkeit über Grund
1052
        DebugOut.Analog[14] = actualPos.northing;
1053
        DebugOut.Analog[15] = actualPos.easting;
1054
        DebugOut.Analog[16] = Poti3;
1055
        DebugOut.Analog[17] = actualPos.altitude;
1056
        DebugOut.Analog[18] = GPS_Home_North;
1057
        DebugOut.Analog[19] = GPS_Home_East;   
1058
        DebugOut.Analog[20] = GPS_Positionsabweichung_North;
1059
        DebugOut.Analog[21] = GPS_Positionsabweichung_East;    
1060
        DebugOut.Analog[22] = P_Einfluss_North;
1061
        DebugOut.Analog[23] = P_Einfluss_East;
1062
        DebugOut.Analog[24] = D_Einfluss_North;
1063
        DebugOut.Analog[25] = D_Einfluss_East;
1064
        DebugOut.Analog[26] = NORTH_MITTEL;
1065
        DebugOut.Analog[27] = EAST_MITTEL;
1066
        DebugOut.Analog[28] = GPS_Nick;
1067
        DebugOut.Analog[29] = GPS_Roll;
1068
        DebugOut.Analog[30] = StickNick;
1069
        DebugOut.Analog[31] = StickRoll;
1070
 
1071
        //DebugOut.Analog[xx] = motor_rx[0];    //Motorstrom vorne
1072
        //DebugOut.Analog[xx] = motor_rx[1];    //Motorstrom hinten
1073
        //DebugOut.Analog[xx] = motor_rx[2];    //Motorstrom links
1074
        //DebugOut.Analog[xx] = motor_rx[3];    //Motorstrom rechts
1075
        //DebugOut.Analog[xx] = actualPos.velNorth;
1076
        //DebugOut.Analog[xx] = actualPos.velEast;
1077
        //DebugOut.Analog[xx] = Parameter_UserParam3;
1078
    //DebugOut.Analog[xx] = Parameter_UserParam4;
1079
        //DebugOut.Analog[xx] = StickGier;
1080
        //DebugOut.Analog[xx] = GPS_North;
1081
        //DebugOut.Analog[xx] = GPS_East;
1082
 
1083
  }
1084
 
1085
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1086
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1087
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1088
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1089
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1090
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1091
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1092
//    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
1093
    MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2;
1094
 
1095
//DebugOut.Analog[28] = MesswertRoll;
1096
//DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
1097
//DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
1098
 
1099
    // Maximalwerte abfangen
1100
    #define MAX_SENSOR  2048
1101
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1102
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1103
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1104
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1105
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1106
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1107
 
1108
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1109
// Höhenregelung
1110
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1111
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1112
//OCR0B = 180 - (Poti1 + 120) / 4;
1113
//DruckOffsetSetting = OCR0B;
1114
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1115
  {
1116
    int tmp_int;
1117
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1118
    {
1119
     if(Parameter_MaxHoehe < 50)
1120
      {
1121
       SollHoehe = HoehenWert - 40;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1122
       HoehenReglerAktiv = 0;
1123
      }
1124
      else  
1125
        HoehenReglerAktiv = 1;
1126
    }
1127
    else
1128
    {
1129
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 40;
1130
     HoehenReglerAktiv = 1;
1131
    }
1132
 
1133
    if(Notlandung) SollHoehe = 0;
1134
    h = HoehenWert;
1135
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1136
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1137
      h = GasMischanteil - h;         // vom Gas abziehen
1138
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1139
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1140
      if(tmp_int > 50) tmp_int = 50;
1141
      else if(tmp_int < -50) tmp_int = -50;
1142
      h -= tmp_int;
1143
      hoehenregler = (hoehenregler*15 + h) / 16;      
1144
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1145
       {
1146
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1147
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1148
       }  
1149
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1150
      GasMischanteil = hoehenregler;
1151
     }
1152
  }
1153
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1154
// + Mischer und PI-Regler
1155
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1156
  // DebugOut.Analog[7] = GasMischanteil;
1157
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1158
// Gier-Anteil
1159
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1160
#define MUL_G  1.0
1161
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1162
//GierMischanteil = 0;
1163
 
1164
    if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1165
    if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1166
    if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil));
1167
    if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil));
1168
 
1169
    if(GasMischanteil < 20) GierMischanteil = 0;
1170
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1171
// Nick-Achse
1172
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1173
    DiffNick = MesswertNick - (StickNick - GPS_Nick);   // Differenz bestimmen
1174
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
1175
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1176
    if(SummeNick > 0) SummeNick-= 2 ; else SummeNick += 2 ;
1177
    if(SummeNick >  16000) SummeNick =  16000;
1178
    if(SummeNick < -16000) SummeNick = -16000;
1179
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1180
    // Motor Vorn
1181
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1182
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1183
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1184
 
1185
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1186
        if ((motorwert < 0)) motorwert = 0;
1187
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1188
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1189
        Motor_Vorne = motorwert;           
1190
    // Motor Heck
1191
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1192
        if ((motorwert < 0)) motorwert = 0;
1193
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1194
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1195
        Motor_Hinten = motorwert;              
1196
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1197
// Roll-Achse
1198
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1199
        DiffRoll = MesswertRoll - (StickRoll  - GPS_Roll);      // Differenz bestimmen
1200
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll  - GPS_Roll);// I-Anteil bei Winkelregelung
1201
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1202
    if(SummeRoll > 0) SummeRoll-= 2 ; else SummeRoll += 2 ;
1203
    if(SummeRoll >  16000) SummeRoll =  16000;
1204
    if(SummeRoll < -16000) SummeRoll = -16000;
1205
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1206
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1207
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1208
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1209
    // Motor Links
1210
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1211
        if ((motorwert < 0)) motorwert = 0;
1212
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1213
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1214
        Motor_Links = motorwert;               
1215
    // Motor Rechts
1216
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1217
        if ((motorwert < 0)) motorwert = 0;
1218
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1219
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1220
        Motor_Rechts = motorwert;
1221
   // +++++++++++++++++++++++++++++++++++++++++++++++
1222
}
1223