Subversion Repositories FlightCtrl

Rev

Rev 890 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
889 Nick666 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// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  POSSIBILITY OF SUCH DAMAGE. 
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
 
55
#include "main.h"
56
#include "eeprom.c"
57
 
58
unsigned char h,m,s;
59
volatile unsigned int I2CTimeout = 100;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch;
63
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
64
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
65
long IntegralNick = 0,IntegralNick2 = 0;
66
long IntegralRoll = 0,IntegralRoll2 = 0;
67
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
68
long Integral_Gier = 0;
69
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
70
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
71
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
72
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
73
volatile long Mess_Integral_Hoch = 0;
891 Nick666 74
 
75
int  KompassValue = 0;
76
int  KompassStartwert = 0;
77
int  KompassRichtung = 0;
78
uint8_t updKompass;
79
 
889 Nick666 80
unsigned int  KompassSignalSchlecht = 500;
81
unsigned char  MAX_GAS,MIN_GAS;
82
unsigned char Notlandung = 0;
83
unsigned char HoehenReglerAktiv = 0;
84
unsigned char TrichterFlug = 0;
85
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
86
long  ErsatzKompass;
87
int   ErsatzKompassInGrad; // Kompasswert in Grad
88
int   GierGyroFehler = 0;
89
float GyroFaktor;
90
float IntegralFaktor;
91
volatile int  DiffNick,DiffRoll;
890 Nick666 92
uint8_t  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
889 Nick666 93
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
94
volatile unsigned char SenderOkay = 0;
95
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
96
char MotorenEin = 0;
97
int HoehenWert = 0;
98
int SollHoehe = 0;
99
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
100
float Ki =  FAKTOR_I;
101
unsigned char Looping_Nick = 0,Looping_Roll = 0;
102
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
103
 
104
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
105
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
106
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
107
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
108
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
109
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
110
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
111
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
112
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
113
unsigned char Parameter_UserParam1 = 0;
114
unsigned char Parameter_UserParam2 = 0;
115
unsigned char Parameter_UserParam3 = 0;
116
unsigned char Parameter_UserParam4 = 0;
117
unsigned char Parameter_UserParam5 = 0;
118
unsigned char Parameter_UserParam6 = 0;
119
unsigned char Parameter_UserParam7 = 0;
120
unsigned char Parameter_UserParam8 = 0;
121
unsigned char Parameter_ServoNickControl = 100;
122
unsigned char Parameter_LoopGasLimit = 70;
123
unsigned char Parameter_AchsKopplung1 = 0;
124
unsigned char Parameter_AchsGegenKopplung1 = 0;
125
unsigned char Parameter_DynamicStability = 100;
126
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
127
int MaxStickNick = 0,MaxStickRoll = 0;
128
unsigned int  modell_fliegt = 0;
129
 
130
struct mk_param_struct EE_Parameter;
131
struct acc_neutral_struct ee_acc_neutral EEMEM;         // Reservierung im EEPROM
132
struct acc_neutral_struct acc_neutral;
133
 
134
void Piep(unsigned char Anzahl)
135
{
136
 while(Anzahl--)
137
 {
138
  if(MotorenEin) return; //auf keinen Fall im Flug!
139
  beeptime = 100;
140
  Delay_ms(250);
141
 }
142
}
143
 
144
//############################################################################
145
//  Neutrallage kalibrieren und fest im EEPROM abspeichern
146
void calib_acc(void)
147
//############################################################################
148
{
149
        acc_neutral.X = 0;
150
        acc_neutral.Y = 0;
151
        acc_neutral.Z = 0;
152
 
153
        Piep(1);
154
        while (PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100)       //Warten, bis Benutzer den Kopter neu ausgerichtet hat
155
 
156
    CalibrierMittelwert();     
157
    Delay_ms_Mess(100);
158
        CalibrierMittelwert();
159
 
160
        acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
161
        acc_neutral.Y = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
162
        acc_neutral.Z = Aktuell_az;
163
 
891 Nick666 164
        Piep(2);
165
        while (PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100)       //Warten, bis Benutzer den Kopter neu ausgerichtet hat
166
 
167
        Delay_ms_Mess(100);
168
        acc_neutral.compass = Aktuell_az;
169
 
889 Nick666 170
        eeprom_write_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
171
}
172
 
173
//############################################################################
174
//  Nullwerte ermitteln
175
void SetNeutral(void)
176
//############################################################################
177
{
178
        acc_neutral.X = 0;
179
        acc_neutral.Y = 0;
180
        acc_neutral.Z = 0;
181
    AdNeutralNick = 0; 
182
        AdNeutralRoll = 0;     
183
        AdNeutralGier = 0;
184
    Parameter_AchsKopplung1 = 0;
185
    Parameter_AchsGegenKopplung1 = 0;
186
    CalibrierMittelwert();     
187
    Delay_ms_Mess(100);
188
        CalibrierMittelwert();
189
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
190
     {    
191
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
192
     }
193
 
194
     AdNeutralNick= AdWertNick;
195
         AdNeutralRoll= AdWertRoll;    
196
         AdNeutralGier= AdWertGier;
197
     StartNeutralRoll = AdNeutralRoll;
198
     StartNeutralNick = AdNeutralNick;
199
 
200
        eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
201
 
202
        Mess_IntegralNick = 0; 
203
    Mess_IntegralNick2 = 0;
204
    Mess_IntegralRoll = 0;     
205
    Mess_IntegralRoll2 = 0;
206
    Mess_Integral_Gier = 0;    
207
    MesswertNick = 0;
208
    MesswertRoll = 0;
209
    MesswertGier = 0;
210
    StartLuftdruck = Luftdruck;
211
    HoeheD = 0;
212
    Mess_Integral_Hoch = 0;
213
    KompassStartwert = KompassValue;
214
    GPS_Neutral();
215
    beeptime = 50;  
216
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
217
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
218
    ExternHoehenValue = 0;
219
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
220
    GierGyroFehler = 0;
221
    SendVersionToNavi = 1;
222
}
223
 
224
//############################################################################
225
// Bearbeitet die Messwerte
226
void Mittelwert(void)
227
//############################################################################
228
{      
890 Nick666 229
    static signed long tmpl,tmpl2;
230
 
889 Nick666 231
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
232
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
233
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
234
 
235
//DebugOut.Analog[26] = MesswertNick;
236
DebugOut.Analog[28] = MesswertRoll;
237
 
238
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
239
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
240
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
241
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
242
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
243
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
244
    NaviAccNick    += AdWertAccNick;
245
    NaviAccRoll    += AdWertAccRoll;
246
    NaviCntAcc++;
247
    IntegralAccZ    += Aktuell_az - acc_neutral.Z;
248
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
249
            ErsatzKompass +=  MesswertGier;
250
            Mess_Integral_Gier +=  MesswertGier;
251
            Mess_Integral_Gier2 += MesswertGier;
252
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
253
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
254
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
255
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
256
         {
257
            tmpl = (MesswertGier * Mess_IntegralNick) / 2048L;
258
            tmpl *= Parameter_AchsKopplung1;  //125
259
            tmpl /= 4096L;
260
            tmpl2 = (MesswertGier * Mess_IntegralRoll) / 2048L;
261
            tmpl2 *= Parameter_AchsKopplung1;
262
            tmpl2 /= 4096L;
263
            if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
264
         }
265
      else  tmpl = tmpl2 = 0;
266
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
267
            MesswertRoll += tmpl;
268
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
269
            Mess_IntegralRoll2 += MesswertRoll;
270
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
271
            if(Mess_IntegralRoll > Umschlag180Roll)
272
            {
273
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
274
             Mess_IntegralRoll2 = Mess_IntegralRoll;
275
            }
276
            if(Mess_IntegralRoll <-Umschlag180Roll)
277
            {
278
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
279
             Mess_IntegralRoll2 = Mess_IntegralRoll;
280
            }  
281
            if(AdWertRoll < 15)   MesswertRoll = -1000;
282
            if(AdWertRoll <  7)   MesswertRoll = -2000;
283
            if(PlatinenVersion == 10)
284
                         {
285
              if(AdWertRoll > 1010) MesswertRoll = +1000;
286
              if(AdWertRoll > 1017) MesswertRoll = +2000;
287
                         }
288
                         else
289
                         {
290
              if(AdWertRoll > 2020) MesswertRoll = +1000;
291
              if(AdWertRoll > 2034) MesswertRoll = +2000;
292
                         }
293
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
294
            MesswertNick -= tmpl2;
295
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
296
            Mess_IntegralNick2 += MesswertNick;
297
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
298
 
299
            if(Mess_IntegralNick > Umschlag180Nick)
300
             {
301
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
302
              Mess_IntegralNick2 = Mess_IntegralNick;
303
             }
304
            if(Mess_IntegralNick <-Umschlag180Nick)
305
            {
306
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
307
             Mess_IntegralNick2 = Mess_IntegralNick;
308
            }
309
            if(AdWertNick < 15)   MesswertNick = -1000;
310
            if(AdWertNick <  7)   MesswertNick = -2000;
311
            if(PlatinenVersion == 10)
312
                         {
313
              if(AdWertNick > 1010) MesswertNick = +1000;
314
              if(AdWertNick > 1017) MesswertNick = +2000;
315
                         }
316
                         else
317
                         {
318
              if(AdWertNick > 2020) MesswertNick = +1000;
319
              if(AdWertNick > 2034) MesswertNick = +2000;
320
                         }
321
//++++++++++++++++++++++++++++++++++++++++++++++++
890 Nick666 322
// Neue ADC-Runde starten
889 Nick666 323
    ANALOG_ON; 
324
//++++++++++++++++++++++++++++++++++++++++++++++++
325
 
326
    Integral_Gier  = Mess_Integral_Gier;
327
    IntegralNick = Mess_IntegralNick;
328
    IntegralRoll = Mess_IntegralRoll;
329
    IntegralNick2 = Mess_IntegralNick2;
330
    IntegralRoll2 = Mess_IntegralRoll2;
331
 
332
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
333
  {
334
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
335
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
336
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
337
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
338
  }
890 Nick666 339
 
340
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 128 && Poti1 < 255) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 128 && Poti1 > 0) Poti1--;
341
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 128 && Poti2 < 255) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 128 && Poti2 > 0) Poti2--;
342
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 128 && Poti3 < 255) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 128 && Poti3 > 0) Poti3--;
343
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 128 && Poti4 < 255) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 128 && Poti4 > 0) Poti4--;
889 Nick666 344
}
345
 
346
//############################################################################
347
// Messwerte beim Ermitteln der Nullage
348
void CalibrierMittelwert(void)
349
//############################################################################
350
{                
351
    // IRQ auschalten, damit die Werte sich nicht während der Berechnung ändern
352
        uint8_t temp_sreg = SREG;
353
        cli();
354
         MesswertNick = AdWertNick;
355
         MesswertRoll = AdWertRoll;
356
         MesswertGier = AdWertGier;
357
         Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
358
         Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
359
         Mittelwert_AccHoch = (long)AdWertAccHoch;
360
    // IRQ einschalten
361
    SREG = temp_sreg;
362
 
890 Nick666 363
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 128 && Poti1 < 255) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 128 && Poti1 > 0) Poti1--;
364
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 128 && Poti2 < 255) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 128 && Poti2 > 0) Poti2--;
365
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 128 && Poti3 < 255) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 128 && Poti3 > 0) Poti3--;
366
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 128 && Poti4 < 255) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 128 && Poti4 > 0) Poti4--;
367
 
889 Nick666 368
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
369
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 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
// Trägt ggf. das Poti als Parameter ein
402
void ParameterZuordnung(void)
403
//############################################################################
404
{
405
 
406
 #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;}
407
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
408
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
409
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
410
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
411
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
412
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
413
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
414
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
415
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
416
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
417
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
418
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
419
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
420
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
421
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
422
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
423
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
424
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
425
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
426
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
427
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
428
 
429
 Ki = (float) Parameter_I_Faktor * 0.0001;
430
 MAX_GAS = EE_Parameter.Gas_Max;
431
 MIN_GAS = EE_Parameter.Gas_Min;
432
}
433
 
434
 
435
//############################################################################
436
//
437
void MotorRegler(void)
438
//############################################################################
439
{
440
         int motorwert,pd_ergebnis,h,tmp_int;
441
         int GierMischanteil,GasMischanteil;
442
     static long SummeNick=0,SummeRoll=0;
443
     static long sollGier = 0,tmp_long,tmp_long2;
444
     static long IntegralFehlerNick = 0;
445
     static long IntegralFehlerRoll = 0;
446
         static unsigned int RcLostTimer;
447
         static unsigned char delay_neutral = 0;
448
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
449
     static int hoehenregler = 0;
450
     static char TimerWerteausgabe = 0;
451
     static char NeueKompassRichtungMerken = 0;
452
     static long ausgleichNick, ausgleichRoll;
453
 
454
        Mittelwert();
455
 
456
    GRN_ON;
457
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
458
// Gaswert ermitteln
459
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
460
        GasMischanteil = StickGas;
461
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
890 Nick666 462
 
463
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++               
464
// Datenübernahme von RC
465
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
466
        int16_t PPM_in_nick, PPM_in_roll, PPM_in_gier, PPM_diff_nick, PPM_diff_roll, PPM_in_gas;
467
 
468
        uint8_t tmp_sreg = SREG;
469
    cli();  
470
     PPM_in_nick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]];
471
     PPM_diff_nick = PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]];
472
     PPM_in_roll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]];
473
     PPM_diff_roll = PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]];
474
     PPM_in_gier = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
475
     PPM_in_gas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];
476
    SREG = tmp_sreg;
477
 
889 Nick666 478
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
479
// Empfang schlecht
480
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
481
   if(SenderOkay < 100)
482
        {
483
        if(!PcZugriff)
484
         {
485
           if(BeepMuster == 0xffff)
486
            {
487
             beeptime = 15000;
488
             BeepMuster = 0x0c00;
489
            }
490
         }
491
        if(RcLostTimer) RcLostTimer--;
492
        else
493
         {
494
          MotorenEin = 0;
495
          Notlandung = 0;
496
         }
497
        ROT_ON;
498
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
499
            {
500
            GasMischanteil = EE_Parameter.NotGas;
501
            Notlandung = 1;
890 Nick666 502
            PPM_diff_nick = 0;
503
            PPM_diff_roll = 0;            
504
            PPM_in_nick = 0;
505
            PPM_in_roll = 0;
506
            PPM_in_gier = 0;
889 Nick666 507
            }
508
         else MotorenEin = 0;
509
        }
510
        else
511
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
512
// Emfang gut
513
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
514
        if(SenderOkay > 140)
515
            {
516
            Notlandung = 0;
517
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
518
            if(GasMischanteil > 40)
519
                {
520
                if(modell_fliegt < 0xffff) modell_fliegt++;
521
                }
522
            if((modell_fliegt < 256))
523
                {
524
                SummeNick = 0;
525
                SummeRoll = 0;
526
                if(modell_fliegt == 250) NeueKompassRichtungMerken = 1;
527
                }
890 Nick666 528
            if((PPM_in_gas > 80) && MotorenEin == 0)
889 Nick666 529
                {
530
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
531
// auf Nullwerte kalibrieren
532
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 533
                if(PPM_in_gier > 75)  // Neutralwerte
889 Nick666 534
                    {
535
                    if(++delay_neutral > 200)  // nicht sofort
536
                        {
537
                        GRN_OFF;
538
                        MotorenEin = 0;
539
                        delay_neutral = 0;
540
                        modell_fliegt = 0;
890 Nick666 541
                        if(PPM_in_nick > 70 || abs(PPM_in_roll) > 70)
889 Nick666 542
                        {
543
                         unsigned char setting=1;
890 Nick666 544
                         if(PPM_in_roll > 70 && PPM_in_nick < 70) setting = 1;
545
                         if(PPM_in_roll > 70 && PPM_in_nick > 70) setting = 2;
546
                         if(PPM_in_roll < 70 && PPM_in_nick > 70) setting = 3;
547
                         if(PPM_in_roll <-70 && PPM_in_nick > 70) setting = 4;
548
                         if(PPM_in_roll <-70 && PPM_in_nick < 70) setting = 5;
889 Nick666 549
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
550
                        }
551
//                        else
890 Nick666 552
                         if(abs(PPM_in_roll) < 20 && PPM_in_nick < -70)
889 Nick666 553
                          {
554
                           WinkelOut.CalcState = 1;
555
                           beeptime = 1000;
556
                          }
557
                          else
558
                          {
559
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
560
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
561
                            {
562
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
563
                            }  
564
                           SetNeutral();
565
                           Piep(GetActiveParamSetNumber());
566
                         }
567
                        }
568
                    }
569
                 else delay_neutral = 0;
570
                }
571
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
572
// Gas ist unten
573
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 574
            if(PPM_in_gas < 35-120)
889 Nick666 575
                {
576
                // Starten
890 Nick666 577
                if(PPM_in_gier < -75)
889 Nick666 578
                    {
579
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
580
// Einschalten
581
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
582
                    if(++delay_einschalten > 200)
583
                        {
584
                        delay_einschalten = 200;
585
                        modell_fliegt = 1;
586
                        MotorenEin = 1;
587
                        sollGier = 0;
588
                        Mess_Integral_Gier = 0;
589
                        Mess_Integral_Gier2 = 0;
590
                        Mess_IntegralNick = 0;
591
                        Mess_IntegralRoll = 0;
592
                        Mess_IntegralNick2 = IntegralNick;
593
                        Mess_IntegralRoll2 = IntegralRoll;
594
                        SummeNick = 0;
595
                        SummeRoll = 0;
596
                        }          
597
                    }  
598
                    else delay_einschalten = 0;
599
                //Auf Neutralwerte setzen
600
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
601
// Auschalten
602
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 603
                if(PPM_in_gier > 75)
889 Nick666 604
                    {
605
                    if(++delay_ausschalten > 200)  // nicht sofort
606
                        {
607
                        MotorenEin = 0;
608
                        delay_ausschalten = 200;
609
                        modell_fliegt = 0;
610
                        }
611
                    }
612
                else delay_ausschalten = 0;
613
                }
614
            }
615
 
616
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
617
// neue Werte von der Funke
618
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
619
 if(!NewPpmData-- || Notlandung)  
620
  {
621
    int tmp_int;
622
        static int stick_nick,stick_roll;
623
    ParameterZuordnung();
890 Nick666 624
    stick_nick = (stick_nick * 3 + PPM_in_nick * EE_Parameter.Stick_P) / 4;
625
    stick_nick += PPM_diff_nick * EE_Parameter.Stick_D;
889 Nick666 626
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
890 Nick666 627
//    StickNick  = (StickNick  * 3 + PPM_in_nick * EE_Parameter.Stick_P) / 4; 
889 Nick666 628
 
890 Nick666 629
    stick_roll = (stick_roll * 3 + PPM_in_roll * EE_Parameter.Stick_P) / 4;
630
    stick_roll += PPM_diff_roll * EE_Parameter.Stick_D;
889 Nick666 631
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
632
 
890 Nick666 633
//    StickRoll = (StickRoll * 3 + PPM_in_roll * EE_Parameter.Stick_P) / 4;
889 Nick666 634
 
890 Nick666 635
    StickGier = -PPM_in_gier;
636
        StickGas  = PPM_in_gas + 120;
889 Nick666 637
 
890 Nick666 638
/*   if(abs(PPM_in_nick) > MaxStickNick)
639
     MaxStickNick = abs(PPM_in_nick); else MaxStickNick--;
640
   if(abs(PPM_in_roll) > MaxStickRoll)
641
     MaxStickRoll = abs(PPM_in_roll); else MaxStickRoll--;
889 Nick666 642
*/
643
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN);
644
    IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN);
645
 
646
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
647
//+ Digitale Steuerung per DubWise
648
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
649
#define KEY_VALUE (Parameter_UserParam8 * 4)  //(Poti3 * 8)
650
if(DubWiseKeys[1]) beeptime = 10;
651
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
652
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
653
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
654
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
655
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
656
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
657
 
658
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
659
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
660
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
661
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
662
 
663
    StickNick += (STICK_GAIN * ExternStickNick) / 8;
664
    StickRoll += (STICK_GAIN * ExternStickRoll) / 8;
665
    StickGier += STICK_GAIN * ExternStickGier;
666
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
667
//+ Analoge Steuerung per Seriell
668
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
669
   if(ExternControl.Config & 0x01 && Parameter_UserParam8 > 128)
670
    {
671
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
672
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
673
         StickGier += ExternControl.Gier;
674
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
675
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
676
    }
677
    if(StickGas < 0) StickGas = 0;
678
 
679
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
680
    if(GyroFaktor < 0) GyroFaktor = 0;
681
    if(IntegralFaktor < 0) IntegralFaktor = 0;
682
 
683
    if(abs(StickNick/STICK_GAIN) > MaxStickNick) MaxStickNick = abs(StickNick)/STICK_GAIN; else MaxStickNick--;
684
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) MaxStickRoll = abs(StickRoll)/STICK_GAIN; else MaxStickRoll--;
685
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
686
 
687
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
688
// Looping?
689
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 690
  if((PPM_in_roll > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
889 Nick666 691
  else
692
   {
693
     {
890 Nick666 694
      if((PPM_in_roll < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
889 Nick666 695
     }  
696
   }
890 Nick666 697
  if((PPM_in_roll < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
889 Nick666 698
   else
699
   {
700
   if(Looping_Rechts) // Hysterese
701
     {
890 Nick666 702
      if(PPM_in_roll > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
889 Nick666 703
     }
704
   }
705
 
890 Nick666 706
  if((PPM_in_nick > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
889 Nick666 707
  else
708
   {
709
    if(Looping_Oben)  // Hysterese
710
     {
890 Nick666 711
      if((PPM_in_nick < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
889 Nick666 712
     }  
713
   }
890 Nick666 714
  if((PPM_in_nick < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
889 Nick666 715
   else
716
   {
717
    if(Looping_Unten) // Hysterese
718
     {
890 Nick666 719
      if(PPM_in_nick > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
889 Nick666 720
     }
721
   }
722
 
723
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
724
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
725
  } // Ende neue Funken-Werte
726
 
727
  if(Looping_Roll) beeptime = 100;
728
  if(Looping_Roll || Looping_Nick)
729
   {
730
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
731
   }
732
 
733
 
734
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
735
// Bei Empfangsausfall im Flug 
736
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
737
   if(Notlandung)
738
    {
739
     StickGier = 0;
740
     StickNick = 0;
741
     StickRoll = 0;
742
     GyroFaktor     = (float) 100 / (256.0 / STICK_GAIN);
743
     IntegralFaktor = (float) 120 / (44000 / STICK_GAIN);
744
     Looping_Roll = 0;
745
     Looping_Nick = 0;
746
    }  
747
 
748
 
749
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
750
// Integrale auf ACC-Signal abgleichen
751
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
752
#define ABGLEICH_ANZAHL 256L
753
 
754
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
755
 MittelIntegralRoll  += IntegralRoll;
756
 MittelIntegralNick2 += IntegralNick2;
757
 MittelIntegralRoll2 += IntegralRoll2;
758
 
759
 if(Looping_Nick || Looping_Roll)
760
  {
761
    IntegralAccNick = 0;
762
    IntegralAccRoll = 0;
763
    MittelIntegralNick = 0;
764
    MittelIntegralRoll = 0;
765
    MittelIntegralNick2 = 0;
766
    MittelIntegralRoll2 = 0;
767
    Mess_IntegralNick2 = Mess_IntegralNick;
768
    Mess_IntegralRoll2 = Mess_IntegralRoll;
769
    ZaehlMessungen = 0;
770
    LageKorrekturNick = 0;
771
    LageKorrekturRoll = 0;
772
  }
773
 
774
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
775
  if(!Looping_Nick && !Looping_Roll)
776
  {
777
   long tmp_long, tmp_long2;
778
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
779
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
780
    tmp_long /= 16;
781
    tmp_long2 /= 16;
782
   if((MaxStickNick > 32) || (MaxStickRoll > 32))
783
    {
784
    tmp_long  /= 3;
785
    tmp_long2 /= 3;
786
    }
890 Nick666 787
   if(abs(PPM_in_gier) > 25)
889 Nick666 788
    {
789
    tmp_long  /= 3;
790
    tmp_long2 /= 3;
791
    }
792
 
793
 #define AUSGLEICH 32
794
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
795
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
796
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
797
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
798
 
799
    Mess_IntegralNick -= tmp_long;
800
    Mess_IntegralRoll -= tmp_long2;
801
  }
802
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
803
 
804
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
805
 {
806
  static int cnt = 0;
807
  static char last_n_p,last_n_n,last_r_p,last_r_n;
808
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
809
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug)
810
  {
811
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
812
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
813
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
814
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
815
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
816
#define MAX_I 0//(Poti2/10)
817
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
818
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
819
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
820
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
821
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
822
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
823
 
824
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
825
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
826
 
890 Nick666 827
   if((MaxStickNick > 32) || (MaxStickRoll > 32) || (abs(PPM_in_gier) > 25))
889 Nick666 828
    {
829
     LageKorrekturNick /= 2;
830
     LageKorrekturRoll /= 2;
831
    }
832
 
833
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
834
// Gyro-Drift ermitteln
835
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
836
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
837
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
838
    tmp_long  = IntegralNick2 - IntegralNick;
839
    tmp_long2 = IntegralRoll2 - IntegralRoll;
840
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
841
 
842
    IntegralFehlerNick = tmp_long;
843
    IntegralFehlerRoll = tmp_long2;
844
    Mess_IntegralNick2 -= IntegralFehlerNick;
845
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
846
 
847
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
848
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
849
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) AdNeutralGier++;
850
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) AdNeutralGier--;
851
 
852
DebugOut.Analog[22] = MittelIntegralRoll / 26;
853
 
854
    GierGyroFehler = 0;
855
 
856
 
857
/*DebugOut.Analog[17] = IntegralAccNick / 26;
858
DebugOut.Analog[18] = IntegralAccRoll / 26;
859
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
860
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
861
*/
862
//DebugOut.Analog[21] = MittelIntegralNick / 26;
863
//MittelIntegralRoll = MittelIntegralRoll;
864
//DebugOut.Analog[28] = ausgleichNick;
865
/*
866
DebugOut.Analog[29] = ausgleichRoll;
867
DebugOut.Analog[30] = LageKorrekturRoll * 10;
868
*/
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
        }
900
        else
901
        {
902
         cnt = 0;
903
         KompassSignalSchlecht = 500;
904
        }
905
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
906
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
907
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
908
 
909
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
910
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
911
 
912
        ausgleichRoll = 0;
913
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
914
        {
915
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
916
         {
917
           if(last_r_p)
918
           {
919
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
920
            ausgleichRoll = IntegralFehlerRoll / 8;
921
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
922
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
923
           }
924
           else last_r_p = 1;
925
         } else  last_r_p = 0;
926
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
927
         {
928
           if(last_r_n)
929
           {
930
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
931
            ausgleichRoll = IntegralFehlerRoll / 8;
932
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
933
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
934
           }
935
           else last_r_n = 1;
936
         } else  last_r_n = 0;
937
        } else
938
        {
939
         cnt = 0;
940
         KompassSignalSchlecht = 500;
941
        }
942
 
943
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
944
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
945
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
946
/*DebugOut.Analog[27] = ausgleichRoll;
947
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
948
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
949
*/
950
  }
951
  else
952
  {
953
   LageKorrekturRoll = 0;
954
   LageKorrekturNick = 0;
955
   TrichterFlug = 0;
956
  }
957
 
958
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
959
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
960
   MittelIntegralNick_Alt = MittelIntegralNick;      
961
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
962
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
963
    IntegralAccNick = 0;
964
    IntegralAccRoll = 0;
965
    IntegralAccZ = 0;
966
    MittelIntegralNick = 0;
967
    MittelIntegralRoll = 0;
968
    MittelIntegralNick2 = 0;
969
    MittelIntegralRoll2 = 0;
970
    ZaehlMessungen = 0;
971
 }
972
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
973
 
974
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
975
//  Gieren
976
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
977
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
978
    if(abs(StickGier) > 15) // war 35 
979
     {
980
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
981
       {
982
         NeueKompassRichtungMerken = 1;
983
         KompassStartwert = ErsatzKompass;
984
         KompassSignalSchlecht = 250;
985
        };
986
     }
987
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
988
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
989
    sollGier = tmp_int;
990
    Mess_Integral_Gier -= tmp_int;  
991
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
992
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
993
 
994
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
995
//  Kompass
996
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
997
//DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll);
998
 
891 Nick666 999
        if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
1000
        {
1001
                int w,v,r,fehler,korrektur;
1002
 
1003
                if (!updKompass--)              // Aufruf mit ~20 Hz
1004
                {
1005
                        updKompass = 25;
1006
                        KompassValue = heading_MM3();
1007
                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
1008
                }
1009
                        w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1010
                        v = abs(IntegralRoll /512);
1011
                        if(v > w) w = v; // grösste Neigung ermitteln
1012
                        korrektur = w / 8 + 1;
1013
                        if(w < 25 && NeueKompassRichtungMerken && !KompassSignalSchlecht)    
1014
                        {
1015
                                beeptime = 200;
1016
                                //KompassStartwert = KompassValue;
1017
                                KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1018
                                NeueKompassRichtungMerken = 0;
1019
                        }
1020
                        fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1021
                        ErsatzKompass += (fehler * 8) / korrektur;
1022
                        w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1023
                        w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1024
                        if(w > 0)
1025
                        {
1026
                                if(!KompassSignalSchlecht)
1027
                                {
1028
                                        GierGyroFehler += fehler;
1029
                                        v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;  
1030
                                        r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1031
                                        //r = KompassRichtung;
1032
                                        v = (r * w) / v;  // nach Kompass ausrichten
1033
                                        w = 3 * Parameter_KompassWirkung;
1034
                                        if(v > w) v = w; // Begrenzen
1035
                                        else if(v < -w) v = -w;
1036
                                        Mess_Integral_Gier += v;
1037
                                }
1038
                        if(KompassSignalSchlecht) KompassSignalSchlecht--;
1039
                        }  
889 Nick666 1040
        else KompassSignalSchlecht = 250; // so lange das Signal taub stellen --> ca. 0,5 sek
891 Nick666 1041
        }
1042
 
889 Nick666 1043
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1044
 
1045
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1046
//  Debugwerte zuordnen
1047
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1048
  if(!TimerWerteausgabe--)
1049
   {
1050
    TimerWerteausgabe = 24;
1051
 
1052
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
1053
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
1054
    DebugOut.Analog[2] = Mittelwert_AccNick;
1055
    DebugOut.Analog[3] = Mittelwert_AccRoll;
1056
    DebugOut.Analog[4] = MesswertGier;
1057
    DebugOut.Analog[5] = HoehenWert;
1058
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
1059
    DebugOut.Analog[8] = KompassValue;
1060
    DebugOut.Analog[9] = UBat;
1061
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;  
1062
    DebugOut.Analog[10] = SenderOkay;
1063
    DebugOut.Analog[16] = Mittelwert_AccHoch;
1064
 
1065
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1066
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1067
    DebugOut.Analog[19] = WinkelOut.CalcState;
1068
    DebugOut.Analog[20] = ServoValue;
1069
 
1070
    DebugOut.Analog[30] = GPS_Nick;
1071
    DebugOut.Analog[31] = GPS_Roll;
1072
 
1073
 
1074
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1075
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1076
 
1077
/*    DebugOut.Analog[16] = motor_rx[0];
1078
    DebugOut.Analog[17] = motor_rx[1];
1079
    DebugOut.Analog[18] = motor_rx[2];
1080
    DebugOut.Analog[19] = motor_rx[3];
1081
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1082
    DebugOut.Analog[20] /= 14;
1083
    DebugOut.Analog[21] = motor_rx[4];
1084
    DebugOut.Analog[22] = motor_rx[5];
1085
    DebugOut.Analog[23] = motor_rx[6];
1086
    DebugOut.Analog[24] = motor_rx[7];
1087
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1088
*/
1089
//    DebugOut.Analog[9] = MesswertNick;
1090
//    DebugOut.Analog[9] = SollHoehe;
1091
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1092
//    DebugOut.Analog[11] = KompassStartwert;
1093
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
1094
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
1095
//    DebugOut.Analog[9] = KompassRichtung;    
1096
//    DebugOut.Analog[10] = GasMischanteil;
1097
//    DebugOut.Analog[3] = HoeheD * 32;
1098
//    DebugOut.Analog[4] = hoehenregler;
1099
  }
1100
 
1101
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1102
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1103
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1104
 
1105
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1106
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1107
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1108
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1109
    MesswertGier =   MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
1110
 
1111
    DebugOut.Analog[21] = MesswertNick;
1112
    DebugOut.Analog[22] = MesswertRoll;
1113
 
1114
    // Maximalwerte abfangen
1115
    #define MAX_SENSOR  (4096*STICK_GAIN)
1116
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1117
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1118
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1119
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1120
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1121
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1122
 
1123
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1124
// Höhenregelung
1125
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1126
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1127
//OCR0B = 180 - (Poti1 + 120) / 4;
1128
//DruckOffsetSetting = OCR0B;
1129
  GasMischanteil *= STICK_GAIN;
1130
 
1131
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1132
  {
1133
    int tmp_int;
1134
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1135
    {
1136
     if(Parameter_MaxHoehe < 50)
1137
      {
1138
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1139
       HoehenReglerAktiv = 0;
1140
      }
1141
      else  
1142
        HoehenReglerAktiv = 1;
1143
    }
1144
    else
1145
    {
1146
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1147
     HoehenReglerAktiv = 1;
1148
    }
1149
 
1150
    if(Notlandung) SollHoehe = 0;
1151
    h = HoehenWert;
1152
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1153
     {      
1154
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1155
      h = GasMischanteil - h;         // vom Gas abziehen
1156
//      h -= (HoeheD * Parameter_Luftdruck_D)/(8/STICK_GAIN);    // D-Anteil
1157
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1158
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1159
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1160
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1161
      h -= tmp_int;
1162
      hoehenregler = (hoehenregler*15 + h) / 16;      
1163
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1164
       {
1165
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1166
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1167
       }  
1168
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1169
      GasMischanteil = hoehenregler;
1170
     }
1171
  }
1172
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1173
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1174
// + Mischer und PI-Regler
1175
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1176
  DebugOut.Analog[7] = GasMischanteil;
1177
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1178
// Gier-Anteil
1179
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1180
#define MUL_G  1.0
1181
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1182
// GierMischanteil = 0;
1183
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1184
   if(GasMischanteil > MIN_GIERGAS)
1185
    {
1186
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1187
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1188
    }
1189
    else
1190
    {
1191
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1192
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1193
    }
1194
    tmp_int = MAX_GAS*STICK_GAIN;
1195
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1196
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1197
 
1198
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1199
// Nick-Achse
1200
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1201
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1202
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung
1203
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1204
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1205
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1206
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1207
    // Motor Vorn
1208
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1209
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1210
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1211
 
1212
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1213
    motorwert /= STICK_GAIN;
1214
        if ((motorwert < 0)) motorwert = 0;
1215
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1216
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1217
        Motor_Vorne = motorwert;           
1218
    // Motor Heck
1219
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1220
    motorwert /= STICK_GAIN;
1221
        if ((motorwert < 0)) motorwert = 0;
1222
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1223
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1224
        Motor_Hinten = motorwert;              
1225
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1226
// Roll-Achse
1227
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1228
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1229
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll;// I-Anteil bei Winkelregelung
1230
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1231
    if(SummeRoll >  16000) SummeRoll =  16000;
1232
    if(SummeRoll < -16000) SummeRoll = -16000;
1233
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1234
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1235
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1236
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1237
    // Motor Links
1238
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1239
    motorwert /= STICK_GAIN;
1240
        if ((motorwert < 0)) motorwert = 0;
1241
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1242
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1243
    Motor_Links = motorwert;           
1244
    // Motor Rechts
1245
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1246
    motorwert /= STICK_GAIN;
1247
        if ((motorwert < 0)) motorwert = 0;
1248
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1249
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1250
    Motor_Rechts = motorwert;          
1251
   // +++++++++++++++++++++++++++++++++++++++++++++++
1252
}
1253