Subversion Repositories FlightCtrl

Rev

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