Subversion Repositories FlightCtrl

Rev

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