Subversion Repositories FlightCtrl

Rev

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