Subversion Repositories FlightCtrl

Rev

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

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