Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
889 Nick666 1
/*#######################################################################################
2
Flight Control
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + this list of conditions and the following disclaimer.
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +     from this software without specific prior written permission.
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +     clearly linked as origin 
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  POSSIBILITY OF SUCH DAMAGE. 
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
 
55
#include "main.h"
56
#include "eeprom.c"
57
 
58
unsigned char h,m,s;
59
volatile unsigned int I2CTimeout = 100;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch;
63
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
64
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;
185
    CalibrierMittelwert();     
186
    Delay_ms_Mess(100);
187
        CalibrierMittelwert();
188
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
189
     {    
190
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
191
     }
192
 
193
     AdNeutralNick= AdWertNick;
194
         AdNeutralRoll= AdWertRoll;    
195
         AdNeutralGier= AdWertGier;
196
     StartNeutralRoll = AdNeutralRoll;
197
     StartNeutralNick = AdNeutralNick;
198
 
199
        eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
200
 
201
        Mess_IntegralNick = 0; 
202
    Mess_IntegralNick2 = 0;
203
    Mess_IntegralRoll = 0;     
204
    Mess_IntegralRoll2 = 0;
205
    Mess_Integral_Gier = 0;    
206
    MesswertNick = 0;
207
    MesswertRoll = 0;
208
    MesswertGier = 0;
209
    StartLuftdruck = Luftdruck;
210
    HoeheD = 0;
211
    Mess_Integral_Hoch = 0;
212
    KompassStartwert = KompassValue;
213
    GPS_Neutral();
214
    beeptime = 50;  
215
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
216
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
217
    ExternHoehenValue = 0;
218
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
219
    GierGyroFehler = 0;
220
    SendVersionToNavi = 1;
221
}
222
 
223
//############################################################################
224
// Bearbeitet die Messwerte
225
void Mittelwert(void)
226
//############################################################################
227
{      
890 Nick666 228
    static signed long tmpl,tmpl2;
229
 
889 Nick666 230
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
231
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
232
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
233
 
234
//DebugOut.Analog[26] = MesswertNick;
235
DebugOut.Analog[28] = MesswertRoll;
236
 
237
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
238
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
239
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
240
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
241
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
242
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
243
    NaviAccNick    += AdWertAccNick;
244
    NaviAccRoll    += AdWertAccRoll;
245
    NaviCntAcc++;
246
    IntegralAccZ    += Aktuell_az - acc_neutral.Z;
247
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
248
            ErsatzKompass +=  MesswertGier;
249
            Mess_Integral_Gier +=  MesswertGier;
250
            Mess_Integral_Gier2 += MesswertGier;
251
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
252
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
253
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
254
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
255
         {
256
            tmpl = (MesswertGier * Mess_IntegralNick) / 2048L;
257
            tmpl *= Parameter_AchsKopplung1;  //125
258
            tmpl /= 4096L;
259
            tmpl2 = (MesswertGier * Mess_IntegralRoll) / 2048L;
260
            tmpl2 *= Parameter_AchsKopplung1;
261
            tmpl2 /= 4096L;
262
            if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
263
         }
264
      else  tmpl = tmpl2 = 0;
265
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
266
            MesswertRoll += tmpl;
267
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
268
            Mess_IntegralRoll2 += MesswertRoll;
269
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
270
            if(Mess_IntegralRoll > Umschlag180Roll)
271
            {
272
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
273
             Mess_IntegralRoll2 = Mess_IntegralRoll;
274
            }
275
            if(Mess_IntegralRoll <-Umschlag180Roll)
276
            {
277
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
278
             Mess_IntegralRoll2 = Mess_IntegralRoll;
279
            }  
280
            if(AdWertRoll < 15)   MesswertRoll = -1000;
281
            if(AdWertRoll <  7)   MesswertRoll = -2000;
282
            if(PlatinenVersion == 10)
283
                         {
284
              if(AdWertRoll > 1010) MesswertRoll = +1000;
285
              if(AdWertRoll > 1017) MesswertRoll = +2000;
286
                         }
287
                         else
288
                         {
289
              if(AdWertRoll > 2020) MesswertRoll = +1000;
290
              if(AdWertRoll > 2034) MesswertRoll = +2000;
291
                         }
292
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
293
            MesswertNick -= tmpl2;
294
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
295
            Mess_IntegralNick2 += MesswertNick;
296
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
297
 
298
            if(Mess_IntegralNick > Umschlag180Nick)
299
             {
300
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
301
              Mess_IntegralNick2 = Mess_IntegralNick;
302
             }
303
            if(Mess_IntegralNick <-Umschlag180Nick)
304
            {
305
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
306
             Mess_IntegralNick2 = Mess_IntegralNick;
307
            }
308
            if(AdWertNick < 15)   MesswertNick = -1000;
309
            if(AdWertNick <  7)   MesswertNick = -2000;
310
            if(PlatinenVersion == 10)
311
                         {
312
              if(AdWertNick > 1010) MesswertNick = +1000;
313
              if(AdWertNick > 1017) MesswertNick = +2000;
314
                         }
315
                         else
316
                         {
317
              if(AdWertNick > 2020) MesswertNick = +1000;
318
              if(AdWertNick > 2034) MesswertNick = +2000;
319
                         }
320
//++++++++++++++++++++++++++++++++++++++++++++++++
890 Nick666 321
// Neue ADC-Runde starten
902 Nick666 322
    ADC_START; 
889 Nick666 323
//++++++++++++++++++++++++++++++++++++++++++++++++
324
 
325
    Integral_Gier  = Mess_Integral_Gier;
326
    IntegralNick = Mess_IntegralNick;
327
    IntegralRoll = Mess_IntegralRoll;
328
    IntegralNick2 = Mess_IntegralNick2;
329
    IntegralRoll2 = Mess_IntegralRoll2;
330
 
331
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
332
  {
333
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
334
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
335
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
336
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
337
  }
890 Nick666 338
 
339
    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--;
340
    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--;
341
    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--;
342
    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 343
}
344
 
345
//############################################################################
346
// Messwerte beim Ermitteln der Nullage
347
void CalibrierMittelwert(void)
348
//############################################################################
349
{                
902 Nick666 350
    // IRQ auschalten, damit die Werte sich nicht während der Berechnung ändern
351
        uint8_t tmp_sreg = SREG;
352
    cli();
889 Nick666 353
         MesswertNick = AdWertNick;
354
         MesswertRoll = AdWertRoll;
355
         MesswertGier = AdWertGier;
356
         Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
357
         Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
358
         Mittelwert_AccHoch = (long)AdWertAccHoch;
902 Nick666 359
    // IRQ einschalten
360
    SREG = tmp_sreg;
889 Nick666 361
 
890 Nick666 362
    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--;
363
    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--;
364
    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--;
365
    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--;
366
 
889 Nick666 367
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
368
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
369
}
370
 
371
//############################################################################
372
// Senden der Motorwerte per I2C-Bus
373
void SendMotorData(void)
374
//############################################################################
375
{
376
    if(MOTOR_OFF || !MotorenEin)
377
        {
378
        Motor_Hinten = 0;
379
        Motor_Vorne = 0;
380
        Motor_Rechts = 0;
381
        Motor_Links = 0;
382
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
383
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
384
        if(MotorTest[2]) Motor_Links = MotorTest[2];
385
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
386
        }
387
 
388
    DebugOut.Analog[12] = Motor_Vorne;
389
    DebugOut.Analog[13] = Motor_Hinten;
390
    DebugOut.Analog[14] = Motor_Links;
391
    DebugOut.Analog[15] = Motor_Rechts;  
392
 
393
    //Start I2C Interrupt Mode
394
    twi_state = 0;
395
    motor = 0;
396
    i2c_start();
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
void MotorRegler(void)
437
//############################################################################
438
{
439
         int motorwert,pd_ergebnis,h,tmp_int;
440
         int GierMischanteil,GasMischanteil;
441
     static long SummeNick=0,SummeRoll=0;
442
     static long sollGier = 0,tmp_long,tmp_long2;
443
     static long IntegralFehlerNick = 0;
444
     static long IntegralFehlerRoll = 0;
445
         static unsigned int RcLostTimer;
446
         static unsigned char delay_neutral = 0;
447
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
448
     static int hoehenregler = 0;
449
     static char TimerWerteausgabe = 0;
450
     static char NeueKompassRichtungMerken = 0;
451
     static long ausgleichNick, ausgleichRoll;
452
 
453
        Mittelwert();
454
 
455
    GRN_ON;
456
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
457
// Gaswert ermitteln
458
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
459
        GasMischanteil = StickGas;
460
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
890 Nick666 461
 
462
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++               
463
// Datenübernahme von RC
464
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
465
        int16_t PPM_in_nick, PPM_in_roll, PPM_in_gier, PPM_diff_nick, PPM_diff_roll, PPM_in_gas;
466
 
467
        uint8_t tmp_sreg = SREG;
468
    cli();  
469
     PPM_in_nick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]];
470
     PPM_diff_nick = PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]];
471
     PPM_in_roll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]];
472
     PPM_diff_roll = PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]];
473
     PPM_in_gier = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
474
     PPM_in_gas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];
475
    SREG = tmp_sreg;
476
 
889 Nick666 477
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
478
// Empfang schlecht
479
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
480
   if(SenderOkay < 100)
481
        {
482
        if(!PcZugriff)
483
         {
484
           if(BeepMuster == 0xffff)
485
            {
486
             beeptime = 15000;
487
             BeepMuster = 0x0c00;
488
            }
489
         }
490
        if(RcLostTimer) RcLostTimer--;
491
        else
492
         {
493
          MotorenEin = 0;
494
          Notlandung = 0;
495
         }
496
        ROT_ON;
497
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
498
            {
499
            GasMischanteil = EE_Parameter.NotGas;
500
            Notlandung = 1;
890 Nick666 501
            PPM_diff_nick = 0;
502
            PPM_diff_roll = 0;            
503
            PPM_in_nick = 0;
504
            PPM_in_roll = 0;
505
            PPM_in_gier = 0;
889 Nick666 506
            }
507
         else MotorenEin = 0;
508
        }
509
        else
510
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
511
// Emfang gut
512
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
513
        if(SenderOkay > 140)
514
            {
515
            Notlandung = 0;
516
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
517
            if(GasMischanteil > 40)
518
                {
519
                if(modell_fliegt < 0xffff) modell_fliegt++;
520
                }
521
            if((modell_fliegt < 256))
522
                {
523
                SummeNick = 0;
524
                SummeRoll = 0;
525
                if(modell_fliegt == 250) NeueKompassRichtungMerken = 1;
526
                }
890 Nick666 527
            if((PPM_in_gas > 80) && MotorenEin == 0)
889 Nick666 528
                {
529
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
530
// auf Nullwerte kalibrieren
531
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 532
                if(PPM_in_gier > 75)  // Neutralwerte
889 Nick666 533
                    {
534
                    if(++delay_neutral > 200)  // nicht sofort
535
                        {
536
                        GRN_OFF;
537
                        MotorenEin = 0;
538
                        delay_neutral = 0;
539
                        modell_fliegt = 0;
890 Nick666 540
                        if(PPM_in_nick > 70 || abs(PPM_in_roll) > 70)
889 Nick666 541
                        {
542
                         unsigned char setting=1;
890 Nick666 543
                         if(PPM_in_roll > 70 && PPM_in_nick < 70) setting = 1;
544
                         if(PPM_in_roll > 70 && PPM_in_nick > 70) setting = 2;
545
                         if(PPM_in_roll < 70 && PPM_in_nick > 70) setting = 3;
546
                         if(PPM_in_roll <-70 && PPM_in_nick > 70) setting = 4;
547
                         if(PPM_in_roll <-70 && PPM_in_nick < 70) setting = 5;
889 Nick666 548
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
549
                        }
550
//                        else
890 Nick666 551
                         if(abs(PPM_in_roll) < 20 && PPM_in_nick < -70)
889 Nick666 552
                          {
553
                           WinkelOut.CalcState = 1;
554
                           beeptime = 1000;
555
                          }
556
                          else
557
                          {
902 Nick666 558
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], sizeof(struct mk_param_struct));
889 Nick666 559
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
560
                            {
561
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
562
                            }  
563
                           SetNeutral();
564
                           Piep(GetActiveParamSetNumber());
565
                         }
566
                        }
567
                    }
568
                 else delay_neutral = 0;
569
                }
570
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
571
// Gas ist unten
572
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 573
            if(PPM_in_gas < 35-120)
889 Nick666 574
                {
575
                // Starten
890 Nick666 576
                if(PPM_in_gier < -75)
889 Nick666 577
                    {
578
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
579
// Einschalten
580
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
581
                    if(++delay_einschalten > 200)
582
                        {
583
                        delay_einschalten = 200;
584
                        modell_fliegt = 1;
585
                        MotorenEin = 1;
586
                        sollGier = 0;
587
                        Mess_Integral_Gier = 0;
588
                        Mess_Integral_Gier2 = 0;
589
                        Mess_IntegralNick = 0;
590
                        Mess_IntegralRoll = 0;
591
                        Mess_IntegralNick2 = IntegralNick;
592
                        Mess_IntegralRoll2 = IntegralRoll;
593
                        SummeNick = 0;
594
                        SummeRoll = 0;
595
                        }          
596
                    }  
597
                    else delay_einschalten = 0;
598
                //Auf Neutralwerte setzen
599
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
600
// Auschalten
601
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 602
                if(PPM_in_gier > 75)
889 Nick666 603
                    {
604
                    if(++delay_ausschalten > 200)  // nicht sofort
605
                        {
606
                        MotorenEin = 0;
607
                        delay_ausschalten = 200;
608
                        modell_fliegt = 0;
609
                        }
610
                    }
611
                else delay_ausschalten = 0;
612
                }
613
            }
614
 
615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
616
// neue Werte von der Funke
617
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
618
 if(!NewPpmData-- || Notlandung)  
619
  {
620
    int tmp_int;
621
        static int stick_nick,stick_roll;
622
    ParameterZuordnung();
890 Nick666 623
    stick_nick = (stick_nick * 3 + PPM_in_nick * EE_Parameter.Stick_P) / 4;
624
    stick_nick += PPM_diff_nick * EE_Parameter.Stick_D;
889 Nick666 625
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
890 Nick666 626
//    StickNick  = (StickNick  * 3 + PPM_in_nick * EE_Parameter.Stick_P) / 4; 
889 Nick666 627
 
890 Nick666 628
    stick_roll = (stick_roll * 3 + PPM_in_roll * EE_Parameter.Stick_P) / 4;
629
    stick_roll += PPM_diff_roll * EE_Parameter.Stick_D;
889 Nick666 630
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
631
 
890 Nick666 632
//    StickRoll = (StickRoll * 3 + PPM_in_roll * EE_Parameter.Stick_P) / 4;
889 Nick666 633
 
890 Nick666 634
    StickGier = -PPM_in_gier;
635
        StickGas  = PPM_in_gas + 120;
889 Nick666 636
 
890 Nick666 637
/*   if(abs(PPM_in_nick) > MaxStickNick)
638
     MaxStickNick = abs(PPM_in_nick); else MaxStickNick--;
639
   if(abs(PPM_in_roll) > MaxStickRoll)
640
     MaxStickRoll = abs(PPM_in_roll); else MaxStickRoll--;
889 Nick666 641
*/
642
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN);
643
    IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN);
644
 
645
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
646
//+ Digitale Steuerung per DubWise
647
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
648
#define KEY_VALUE (Parameter_UserParam8 * 4)  //(Poti3 * 8)
649
if(DubWiseKeys[1]) beeptime = 10;
650
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
651
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
652
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
653
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
654
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
655
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
656
 
657
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
658
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
659
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
660
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
661
 
662
    StickNick += (STICK_GAIN * ExternStickNick) / 8;
663
    StickRoll += (STICK_GAIN * ExternStickRoll) / 8;
664
    StickGier += STICK_GAIN * ExternStickGier;
665
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
666
//+ Analoge Steuerung per Seriell
667
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
668
   if(ExternControl.Config & 0x01 && Parameter_UserParam8 > 128)
669
    {
670
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
671
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
672
         StickGier += ExternControl.Gier;
673
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
674
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
675
    }
676
    if(StickGas < 0) StickGas = 0;
677
 
678
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
679
    if(GyroFaktor < 0) GyroFaktor = 0;
680
    if(IntegralFaktor < 0) IntegralFaktor = 0;
681
 
682
    if(abs(StickNick/STICK_GAIN) > MaxStickNick) MaxStickNick = abs(StickNick)/STICK_GAIN; else MaxStickNick--;
683
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) MaxStickRoll = abs(StickRoll)/STICK_GAIN; else MaxStickRoll--;
684
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
685
 
686
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
687
// Looping?
688
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
890 Nick666 689
  if((PPM_in_roll > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
889 Nick666 690
  else
691
   {
692
     {
890 Nick666 693
      if((PPM_in_roll < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
889 Nick666 694
     }  
695
   }
890 Nick666 696
  if((PPM_in_roll < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
889 Nick666 697
   else
698
   {
699
   if(Looping_Rechts) // Hysterese
700
     {
890 Nick666 701
      if(PPM_in_roll > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
889 Nick666 702
     }
703
   }
704
 
890 Nick666 705
  if((PPM_in_nick > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
889 Nick666 706
  else
707
   {
708
    if(Looping_Oben)  // Hysterese
709
     {
890 Nick666 710
      if((PPM_in_nick < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
889 Nick666 711
     }  
712
   }
890 Nick666 713
  if((PPM_in_nick < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
889 Nick666 714
   else
715
   {
716
    if(Looping_Unten) // Hysterese
717
     {
890 Nick666 718
      if(PPM_in_nick > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
889 Nick666 719
     }
720
   }
721
 
722
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
723
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
724
  } // Ende neue Funken-Werte
725
 
726
  if(Looping_Roll) beeptime = 100;
727
  if(Looping_Roll || Looping_Nick)
728
   {
729
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
730
   }
731
 
732
 
733
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
734
// Bei Empfangsausfall im Flug 
735
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
736
   if(Notlandung)
737
    {
738
     StickGier = 0;
739
     StickNick = 0;
740
     StickRoll = 0;
741
     GyroFaktor     = (float) 100 / (256.0 / STICK_GAIN);
742
     IntegralFaktor = (float) 120 / (44000 / STICK_GAIN);
743
     Looping_Roll = 0;
744
     Looping_Nick = 0;
745
    }  
746
 
747
 
748
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
749
// Integrale auf ACC-Signal abgleichen
750
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
751
#define ABGLEICH_ANZAHL 256L
752
 
753
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
754
 MittelIntegralRoll  += IntegralRoll;
755
 MittelIntegralNick2 += IntegralNick2;
756
 MittelIntegralRoll2 += IntegralRoll2;
757
 
758
 if(Looping_Nick || Looping_Roll)
759
  {
760
    IntegralAccNick = 0;
761
    IntegralAccRoll = 0;
762
    MittelIntegralNick = 0;
763
    MittelIntegralRoll = 0;
764
    MittelIntegralNick2 = 0;
765
    MittelIntegralRoll2 = 0;
766
    Mess_IntegralNick2 = Mess_IntegralNick;
767
    Mess_IntegralRoll2 = Mess_IntegralRoll;
768
    ZaehlMessungen = 0;
769
    LageKorrekturNick = 0;
770
    LageKorrekturRoll = 0;
771
  }
772
 
773
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
774
  if(!Looping_Nick && !Looping_Roll)
775
  {
776
   long tmp_long, tmp_long2;
777
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
778
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
779
    tmp_long /= 16;
780
    tmp_long2 /= 16;
781
   if((MaxStickNick > 32) || (MaxStickRoll > 32))
782
    {
783
    tmp_long  /= 3;
784
    tmp_long2 /= 3;
785
    }
890 Nick666 786
   if(abs(PPM_in_gier) > 25)
889 Nick666 787
    {
788
    tmp_long  /= 3;
789
    tmp_long2 /= 3;
790
    }
791
 
792
 #define AUSGLEICH 32
793
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
794
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
795
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
796
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
797
 
798
    Mess_IntegralNick -= tmp_long;
799
    Mess_IntegralRoll -= tmp_long2;
800
  }
801
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
802
 
803
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
804
 {
805
  static int cnt = 0;
806
  static char last_n_p,last_n_n,last_r_p,last_r_n;
807
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
808
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug)
809
  {
810
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
811
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
812
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
813
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
814
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
815
#define MAX_I 0//(Poti2/10)
816
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
817
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
818
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
819
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
820
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
821
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
822
 
823
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
824
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
825
 
890 Nick666 826
   if((MaxStickNick > 32) || (MaxStickRoll > 32) || (abs(PPM_in_gier) > 25))
889 Nick666 827
    {
828
     LageKorrekturNick /= 2;
829
     LageKorrekturRoll /= 2;
830
    }
831
 
832
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
833
// Gyro-Drift ermitteln
834
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
835
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
836
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
837
    tmp_long  = IntegralNick2 - IntegralNick;
838
    tmp_long2 = IntegralRoll2 - IntegralRoll;
839
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
840
 
841
    IntegralFehlerNick = tmp_long;
842
    IntegralFehlerRoll = tmp_long2;
843
    Mess_IntegralNick2 -= IntegralFehlerNick;
844
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
845
 
846
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
847
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
848
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) AdNeutralGier++;
849
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) AdNeutralGier--;
850
 
851
DebugOut.Analog[22] = MittelIntegralRoll / 26;
852
 
853
    GierGyroFehler = 0;
854
 
855
 
856
/*DebugOut.Analog[17] = IntegralAccNick / 26;
857
DebugOut.Analog[18] = IntegralAccRoll / 26;
858
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
859
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
860
*/
861
//DebugOut.Analog[21] = MittelIntegralNick / 26;
862
//MittelIntegralRoll = MittelIntegralRoll;
863
//DebugOut.Analog[28] = ausgleichNick;
864
/*
865
DebugOut.Analog[29] = ausgleichRoll;
866
DebugOut.Analog[30] = LageKorrekturRoll * 10;
867
*/
868
 
869
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
870
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
871
#define BEWEGUNGS_LIMIT 20000
872
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
873
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
874
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
875
        {
876
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
877
         {
878
           if(last_n_p)
879
           {
880
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
881
            ausgleichNick = IntegralFehlerNick / 8;
882
            if(ausgleichNick > 5000) ausgleichNick = 5000;
883
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
884
           }
885
           else last_n_p = 1;
886
         } else  last_n_p = 0;
887
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
888
         {
889
           if(last_n_n)
890
            {
891
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
892
             ausgleichNick = IntegralFehlerNick / 8;
893
             if(ausgleichNick < -5000) ausgleichNick = -5000;
894
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
895
            }
896
           else last_n_n = 1;
897
         } else  last_n_n = 0;
898
        }
899
        else
900
        {
901
         cnt = 0;
902
         KompassSignalSchlecht = 500;
903
        }
904
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
905
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
906
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
907
 
908
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
909
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
910
 
911
        ausgleichRoll = 0;
912
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
913
        {
914
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
915
         {
916
           if(last_r_p)
917
           {
918
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
919
            ausgleichRoll = IntegralFehlerRoll / 8;
920
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
921
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
922
           }
923
           else last_r_p = 1;
924
         } else  last_r_p = 0;
925
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
926
         {
927
           if(last_r_n)
928
           {
929
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
930
            ausgleichRoll = IntegralFehlerRoll / 8;
931
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
932
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
933
           }
934
           else last_r_n = 1;
935
         } else  last_r_n = 0;
936
        } else
937
        {
938
         cnt = 0;
939
         KompassSignalSchlecht = 500;
940
        }
941
 
942
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
943
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
944
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
945
/*DebugOut.Analog[27] = ausgleichRoll;
946
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
947
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
948
*/
949
  }
950
  else
951
  {
952
   LageKorrekturRoll = 0;
953
   LageKorrekturNick = 0;
954
   TrichterFlug = 0;
955
  }
956
 
957
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
958
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
959
   MittelIntegralNick_Alt = MittelIntegralNick;      
960
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
961
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
962
    IntegralAccNick = 0;
963
    IntegralAccRoll = 0;
964
    IntegralAccZ = 0;
965
    MittelIntegralNick = 0;
966
    MittelIntegralRoll = 0;
967
    MittelIntegralNick2 = 0;
968
    MittelIntegralRoll2 = 0;
969
    ZaehlMessungen = 0;
970
 }
971
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
972
 
973
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
974
//  Gieren
975
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
976
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
977
    if(abs(StickGier) > 15) // war 35 
978
     {
979
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
980
       {
981
         NeueKompassRichtungMerken = 1;
982
         KompassStartwert = ErsatzKompass;
983
         KompassSignalSchlecht = 250;
984
        };
985
     }
986
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
987
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
988
    sollGier = tmp_int;
989
    Mess_Integral_Gier -= tmp_int;  
990
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
991
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
992
 
993
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
994
//  Kompass
995
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
996
//DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll);
997
 
891 Nick666 998
        if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
999
        {
1000
                int w,v,r,fehler,korrektur;
1001
 
1002
                if (!updKompass--)              // Aufruf mit ~20 Hz
1003
                {
1004
                        updKompass = 25;
1005
                        KompassValue = heading_MM3();
1006
                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
1007
                }
1008
                        w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1009
                        v = abs(IntegralRoll /512);
1010
                        if(v > w) w = v; // grösste Neigung ermitteln
1011
                        korrektur = w / 8 + 1;
1012
                        if(w < 25 && NeueKompassRichtungMerken && !KompassSignalSchlecht)    
1013
                        {
1014
                                beeptime = 200;
1015
                                //KompassStartwert = KompassValue;
1016
                                KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1017
                                NeueKompassRichtungMerken = 0;
1018
                        }
1019
                        fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1020
                        ErsatzKompass += (fehler * 8) / korrektur;
1021
                        w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1022
                        w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1023
                        if(w > 0)
1024
                        {
1025
                                if(!KompassSignalSchlecht)
1026
                                {
1027
                                        GierGyroFehler += fehler;
1028
                                        v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;  
1029
                                        r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1030
                                        //r = KompassRichtung;
1031
                                        v = (r * w) / v;  // nach Kompass ausrichten
1032
                                        w = 3 * Parameter_KompassWirkung;
1033
                                        if(v > w) v = w; // Begrenzen
1034
                                        else if(v < -w) v = -w;
1035
                                        Mess_Integral_Gier += v;
1036
                                }
1037
                        if(KompassSignalSchlecht) KompassSignalSchlecht--;
1038
                        }  
889 Nick666 1039
        else KompassSignalSchlecht = 250; // so lange das Signal taub stellen --> ca. 0,5 sek
891 Nick666 1040
        }
1041
 
889 Nick666 1042
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1043
 
1044
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1045
//  Debugwerte zuordnen
1046
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1047
  if(!TimerWerteausgabe--)
1048
   {
1049
    TimerWerteausgabe = 24;
1050
 
1051
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
1052
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
893 Nick666 1053
    DebugOut.Analog[2] = Mittelwert_AccNick;   
889 Nick666 1054
    DebugOut.Analog[3] = Mittelwert_AccRoll;
1055
    DebugOut.Analog[4] = MesswertGier;
1056
    DebugOut.Analog[5] = HoehenWert;
1057
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
1058
    DebugOut.Analog[8] = KompassValue;
1059
    DebugOut.Analog[9] = UBat;
1060
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;  
1061
    DebugOut.Analog[10] = SenderOkay;
1062
    DebugOut.Analog[16] = Mittelwert_AccHoch;
1063
 
1064
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1065
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1066
    DebugOut.Analog[19] = WinkelOut.CalcState;
1067
    DebugOut.Analog[20] = ServoValue;
1068
 
1069
    DebugOut.Analog[30] = GPS_Nick;
1070
    DebugOut.Analog[31] = GPS_Roll;
1071
 
1072
 
1073
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1074
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1075
 
1076
/*    DebugOut.Analog[16] = motor_rx[0];
1077
    DebugOut.Analog[17] = motor_rx[1];
1078
    DebugOut.Analog[18] = motor_rx[2];
1079
    DebugOut.Analog[19] = motor_rx[3];
1080
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1081
    DebugOut.Analog[20] /= 14;
1082
    DebugOut.Analog[21] = motor_rx[4];
1083
    DebugOut.Analog[22] = motor_rx[5];
1084
    DebugOut.Analog[23] = motor_rx[6];
1085
    DebugOut.Analog[24] = motor_rx[7];
1086
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1087
*/
1088
//    DebugOut.Analog[9] = MesswertNick;
1089
//    DebugOut.Analog[9] = SollHoehe;
1090
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1091
//    DebugOut.Analog[11] = KompassStartwert;
1092
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
1093
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
1094
//    DebugOut.Analog[9] = KompassRichtung;    
1095
//    DebugOut.Analog[10] = GasMischanteil;
1096
//    DebugOut.Analog[3] = HoeheD * 32;
1097
//    DebugOut.Analog[4] = hoehenregler;
1098
  }
1099
 
1100
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1101
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1102
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1103
 
1104
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1105
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1106
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1107
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1108
    MesswertGier =   MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
1109
 
1110
    DebugOut.Analog[21] = MesswertNick;
1111
    DebugOut.Analog[22] = MesswertRoll;
1112
 
1113
    // Maximalwerte abfangen
1114
    #define MAX_SENSOR  (4096*STICK_GAIN)
1115
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1116
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1117
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1118
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1119
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1120
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1121
 
1122
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1123
// Höhenregelung
1124
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1125
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1126
//OCR0B = 180 - (Poti1 + 120) / 4;
1127
//DruckOffsetSetting = OCR0B;
1128
  GasMischanteil *= STICK_GAIN;
1129
 
1130
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1131
  {
1132
    int tmp_int;
1133
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1134
    {
1135
     if(Parameter_MaxHoehe < 50)
1136
      {
1137
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1138
       HoehenReglerAktiv = 0;
1139
      }
1140
      else  
1141
        HoehenReglerAktiv = 1;
1142
    }
1143
    else
1144
    {
1145
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1146
     HoehenReglerAktiv = 1;
1147
    }
1148
 
1149
    if(Notlandung) SollHoehe = 0;
1150
    h = HoehenWert;
1151
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1152
     {      
1153
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1154
      h = GasMischanteil - h;         // vom Gas abziehen
1155
//      h -= (HoeheD * Parameter_Luftdruck_D)/(8/STICK_GAIN);    // D-Anteil
1156
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1157
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1158
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1159
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1160
      h -= tmp_int;
1161
      hoehenregler = (hoehenregler*15 + h) / 16;      
1162
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1163
       {
1164
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1165
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1166
       }  
1167
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1168
      GasMischanteil = hoehenregler;
1169
     }
1170
  }
1171
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1172
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1173
// + Mischer und PI-Regler
1174
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1175
  DebugOut.Analog[7] = GasMischanteil;
1176
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1177
// Gier-Anteil
1178
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1179
#define MUL_G  1.0
1180
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1181
// GierMischanteil = 0;
1182
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1183
   if(GasMischanteil > MIN_GIERGAS)
1184
    {
1185
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1186
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1187
    }
1188
    else
1189
    {
1190
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1191
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1192
    }
1193
    tmp_int = MAX_GAS*STICK_GAIN;
1194
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1195
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1196
 
1197
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1198
// Nick-Achse
1199
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1200
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1201
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung
1202
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1203
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1204
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1205
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1206
    // Motor Vorn
1207
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1208
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1209
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1210
 
1211
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1212
    motorwert /= STICK_GAIN;
1213
        if ((motorwert < 0)) motorwert = 0;
1214
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1215
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1216
        Motor_Vorne = motorwert;           
1217
    // Motor Heck
1218
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1219
    motorwert /= STICK_GAIN;
1220
        if ((motorwert < 0)) motorwert = 0;
1221
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1222
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1223
        Motor_Hinten = motorwert;              
1224
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1225
// Roll-Achse
1226
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1227
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1228
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll;// I-Anteil bei Winkelregelung
1229
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
902 Nick666 1230
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L);
1231
    if(SummeRoll < -(STICK_GAIN * 16000L)) SummeRoll = -(STICK_GAIN * 16000L);
889 Nick666 1232
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1233
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1234
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1235
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1236
    // Motor Links
1237
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1238
    motorwert /= STICK_GAIN;
1239
        if ((motorwert < 0)) motorwert = 0;
1240
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1241
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1242
    Motor_Links = motorwert;           
1243
    // Motor Rechts
1244
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1245
    motorwert /= STICK_GAIN;
1246
        if ((motorwert < 0)) motorwert = 0;
1247
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1248
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1249
    Motor_Rechts = motorwert;          
1250
   // +++++++++++++++++++++++++++++++++++++++++++++++
1251
}
1252