Subversion Repositories FlightCtrl

Rev

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

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