Subversion Repositories FlightCtrl

Rev

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