Subversion Repositories FlightCtrl

Rev

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