Subversion Repositories FlightCtrl

Rev

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