Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################
2
Flight Control
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + this list of conditions and the following disclaimer.
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +     from this software without specific prior written permission.
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
446 salvo 55
// Aenderungen von Peter Muehlenbrock ("Salvo") Stand 6.10.2007
56
/*
57
Driftkompensation fuer Gyros verbessert
58
Linearsensor mit fixem Neutralwert
59
Ersatzkompass abgeleitet aus Magnetkompass und Giergyro fuer nahezu neigungsunabhaengige Kompassfunktion
60
*/
1 ingob 61
 
62
#include "main.h"
395 hbuss 63
#include "eeprom.c"
1 ingob 64
 
65
unsigned char h,m,s;
173 holgerb 66
volatile unsigned int I2CTimeout = 100;
1 ingob 67
volatile int MesswertNick,MesswertRoll,MesswertGier;
401 hbuss 68
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
1 ingob 69
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
70
volatile float NeutralAccZ = 0;
71
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
72
volatile long IntegralNick = 0,IntegralNick2 = 0;
73
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
395 hbuss 74
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
1 ingob 75
volatile long Integral_Gier = 0;
76
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
77
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
78
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
395 hbuss 79
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
1 ingob 80
volatile long Mess_Integral_Hoch = 0;
81
volatile int  KompassValue = 0;
82
volatile int  KompassStartwert = 0;
83
volatile int  KompassRichtung = 0;
84
unsigned char MAX_GAS,MIN_GAS;
85
unsigned char Notlandung = 0;
86
unsigned char HoehenReglerAktiv = 0;
395 hbuss 87
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
1 ingob 88
 
446 salvo 89
//Salvo 12.10.2007
90
uint8_t magkompass_ok=0;
91
uint8_t gps_cmd = GPS_CMD_STOP;
92
static int       ubat_cnt =0;
93
static int gas_actual,gas_mittel; //Parameter fuer Gasreduzierung bei unterspannung
94
int w,v;
95
//Salvo End
96
 
97
 //Salvo 2.9.2007 Ersatzkompass
98
volatile long GyroKomp_Int;
99
volatile int GyroKomp_Value; //  Der ermittelte Kompasswert aus Gyro und Magnetkompass
100
// Salvo End
101
 
1 ingob 102
float GyroFaktor;
103
float IntegralFaktor;
104
 
105
volatile int  DiffNick,DiffRoll;
106
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
107
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
108
unsigned char MotorWert[5];
109
volatile unsigned char SenderOkay = 0;
110
int StickNick = 0,StickRoll = 0,StickGier = 0;
111
char MotorenEin = 0;
112
int HoehenWert = 0;
113
int SollHoehe = 0;
395 hbuss 114
int I_LageRoll = 0,I_LageNick = 0;
1 ingob 115
float Kp =  FAKTOR_P;
116
float Ki =  FAKTOR_I;
395 hbuss 117
unsigned char Looping_Nick = 0,Looping_Roll = 0;
118
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
1 ingob 119
 
120
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
121
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
122
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
123
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
124
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
446 salvo 125
unsigned char Parameter_Gyro_P = 50;           // Wert : 10-250
1 ingob 126
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
127
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
128
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
129
unsigned char Parameter_UserParam1 = 0;
130
unsigned char Parameter_UserParam2 = 0;
131
unsigned char Parameter_UserParam3 = 0;
132
unsigned char Parameter_UserParam4 = 0;
133
unsigned char Parameter_ServoNickControl = 100;
173 holgerb 134
unsigned char Parameter_LoopGasLimit = 70;
395 hbuss 135
unsigned char Parameter_AchsKopplung1 = 0;
136
unsigned char Parameter_AchsGegenKopplung1 = 0;
1 ingob 137
struct mk_param_struct EE_Parameter;
138
 
139
void Piep(unsigned char Anzahl)
140
{
141
 while(Anzahl--)
142
 {
143
  if(MotorenEin) return; //auf keinen Fall im Flug!
144
  beeptime = 100;
145
  Delay_ms(250);
146
 }
147
}
148
 
149
//############################################################################
150
//  Nullwerte ermitteln
151
void SetNeutral(void)
152
//############################################################################
153
{
154
        NeutralAccX = 0;
155
        NeutralAccY = 0;
156
        NeutralAccZ = 0;
157
    AdNeutralNick = 0; 
158
        AdNeutralRoll = 0;     
159
        AdNeutralGier = 0;
395 hbuss 160
    Parameter_AchsKopplung1 = 0;
161
    Parameter_AchsGegenKopplung1 = 0;
446 salvo 162
 
1 ingob 163
    CalibrierMittelwert();     
395 hbuss 164
    Delay_ms_Mess(100);
1 ingob 165
        CalibrierMittelwert();
166
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
167
     {    
168
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
169
     }
173 holgerb 170
 
395 hbuss 171
     AdNeutralNick= AdWertNick;
172
         AdNeutralRoll= AdWertRoll;    
173
         AdNeutralGier= AdWertGier;
401 hbuss 174
     StartNeutralRoll = AdNeutralRoll;
175
     StartNeutralNick = AdNeutralNick;
446 salvo 176
 
177
// Salvo 1.9.2007 ACC mit festen neutralwerten *****
178
        if (ACC_NEUTRAL_FIXED > 0)
179
        {
180
                NeutralAccX     = ACC_NICK_NEUTRAL;
181
                NeutralAccY     = ACC_ROLL_NEUTRAL;
182
        }
183
        else
184
        { // Automatisch bei Offsetabgleich ermitteln
185
                NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
186
                NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
187
        }
188
 // Salvo End   
1 ingob 189
        NeutralAccZ = Aktuell_az;
190
 
191
        Mess_IntegralNick = 0; 
192
    Mess_IntegralNick2 = 0;
193
    Mess_IntegralRoll = 0;     
194
    Mess_IntegralRoll2 = 0;
195
    Mess_Integral_Gier = 0;    
196
    MesswertNick = 0;
197
    MesswertRoll = 0;
198
    MesswertGier = 0;
199
    StartLuftdruck = Luftdruck;
200
    HoeheD = 0;
201
    Mess_Integral_Hoch = 0;
202
    KompassStartwert = KompassValue;
203
    GPS_Neutral();
204
    beeptime = 50;  
395 hbuss 205
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
206
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
446 salvo 207
 
208
//Salvo 13.10.2007 Ersatzkompass und Gas
209
        GyroKomp_Int =  KompassValue * GYROKOMP_INC_GRAD_DEFAULT; //Neu ab 3.1.2007
210
        gas_mittel      =       30;
211
        gas_actual      =       gas_mittel;
212
// Salvo End
1 ingob 213
}
214
 
215
//############################################################################
395 hbuss 216
// Bearbeitet die Messwerte
1 ingob 217
void Mittelwert(void)
218
//############################################################################
219
{      
395 hbuss 220
    static signed long tmpl,tmpl2;     
221
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
222
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
223
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
401 hbuss 224
 
395 hbuss 225
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
226
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
227
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
228
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
229
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
230
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
231
    IntegralAccZ    += Aktuell_az - 704;//NeutralAccZ;
232
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
446 salvo 233
//Salvo 12.11.2007
234
                        GyroKomp_Int  += MesswertGier;
235
//Salvo End
395 hbuss 236
            Mess_Integral_Gier +=  MesswertGier;
237
            Mess_Integral_Gier2 += MesswertGier;
238
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
239
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
240
         {
241
            tmpl = Mess_IntegralNick / 4096L;
242
            tmpl *= MesswertGier;
243
            tmpl *= Parameter_AchsKopplung1;  //125
244
            tmpl /= 2048L;
245
            tmpl2 = Mess_IntegralRoll / 4096L;
246
            tmpl2 *= MesswertGier;
247
            tmpl2 *= Parameter_AchsKopplung1;
248
            tmpl2 /= 2048L;
249
         }
250
      else  tmpl = tmpl2 = 0;
251
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
252
            MesswertRoll += tmpl;
253
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
254
            Mess_IntegralRoll2 += MesswertRoll;
255
            Mess_IntegralRoll +=  MesswertRoll - I_LageRoll;
256
            if(Mess_IntegralRoll > Umschlag180Roll)
257
            {
258
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
259
             Mess_IntegralRoll2 = Mess_IntegralRoll;
260
            }
261
            if(Mess_IntegralRoll <-Umschlag180Roll)
262
            {
263
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
264
             Mess_IntegralRoll2 = Mess_IntegralRoll;
265
            }  
266
            if(AdWertRoll < 15)   MesswertRoll = -1000;
267
            if(AdWertRoll <  7)   MesswertRoll = -2000;
401 hbuss 268
            if(PlatinenVersion == 10)
269
                         {
270
              if(AdWertRoll > 1010) MesswertRoll = +1000;
271
              if(AdWertRoll > 1017) MesswertRoll = +2000;
272
                         }
273
                         else
274
                         {
275
              if(AdWertRoll > 2020) MesswertRoll = +1000;
276
              if(AdWertRoll > 2034) MesswertRoll = +2000;
277
                         }
395 hbuss 278
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
279
            MesswertNick -= tmpl2;
280
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
281
            Mess_IntegralNick2 += MesswertNick;
282
            Mess_IntegralNick  += MesswertNick - I_LageNick;
283
            if(Mess_IntegralNick > Umschlag180Nick)
284
            {
285
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
286
             Mess_IntegralNick2 = Mess_IntegralNick;
287
            }
288
            if(Mess_IntegralNick <-Umschlag180Nick)
289
            {
290
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
291
             Mess_IntegralNick2 = Mess_IntegralNick;
292
            }
293
            if(AdWertNick < 15)   MesswertNick = -1000;
294
            if(AdWertNick <  7)   MesswertNick = -2000;
401 hbuss 295
            if(PlatinenVersion == 10)
296
                         {
297
              if(AdWertNick > 1010) MesswertNick = +1000;
298
              if(AdWertNick > 1017) MesswertNick = +2000;
299
                         }
300
                         else
301
                         {
302
              if(AdWertNick > 2020) MesswertNick = +1000;
303
              if(AdWertNick > 2034) MesswertNick = +2000;
304
                         }
395 hbuss 305
//++++++++++++++++++++++++++++++++++++++++++++++++
306
// ADC einschalten
307
    ANALOG_ON; 
308
//++++++++++++++++++++++++++++++++++++++++++++++++
401 hbuss 309
DebugOut.Analog[11] = MesswertRoll;
395 hbuss 310
 
1 ingob 311
    Integral_Gier  = Mess_Integral_Gier;
312
    IntegralNick = Mess_IntegralNick;
313
    IntegralRoll = Mess_IntegralRoll;
314
    IntegralNick2 = Mess_IntegralNick2;
315
    IntegralRoll2 = Mess_IntegralRoll2;
316
 
395 hbuss 317
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
318
  {
319
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
320
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
321
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
322
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
323
  }
1 ingob 324
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
325
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
326
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
327
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
328
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
329
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
330
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
331
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
332
}
333
 
334
//############################################################################
335
// Messwerte beim Ermitteln der Nullage
336
void CalibrierMittelwert(void)
337
//############################################################################
338
{                
339
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
340
        ANALOG_OFF;
395 hbuss 341
        MesswertNick = AdWertNick;
342
        MesswertRoll = AdWertRoll;
343
        MesswertGier = AdWertGier;
344
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
345
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
346
        Mittelwert_AccHoch = (long)AdWertAccHoch;
347
   // ADC einschalten
1 ingob 348
    ANALOG_ON; 
349
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
350
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
351
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
352
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
353
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
354
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
355
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
356
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
395 hbuss 357
 
358
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
359
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
1 ingob 360
}
361
 
362
//############################################################################
363
// Senden der Motorwerte per I2C-Bus
364
void SendMotorData(void)
365
//############################################################################
366
{
367
    if(MOTOR_OFF || !MotorenEin)
368
        {
369
        Motor_Hinten = 0;
370
        Motor_Vorne = 0;
371
        Motor_Rechts = 0;
372
        Motor_Links = 0;
373
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
374
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
375
        if(MotorTest[2]) Motor_Links = MotorTest[2];
376
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
377
        }
378
 
379
    DebugOut.Analog[12] = Motor_Vorne;
380
    DebugOut.Analog[13] = Motor_Hinten;
381
    DebugOut.Analog[14] = Motor_Links;
382
    DebugOut.Analog[15] = Motor_Rechts;  
383
 
384
    //Start I2C Interrupt Mode
385
    twi_state = 0;
386
    motor = 0;
387
    i2c_start();
388
}
389
 
390
 
391
 
392
//############################################################################
393
// Trägt ggf. das Poti als Parameter ein
394
void ParameterZuordnung(void)
395
//############################################################################
396
{
397
 
398
 #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;}
399
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
400
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
401
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
402
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
403
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
404
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
405
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
406
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
407
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
408
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
409
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
410
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
411
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
173 holgerb 412
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
395 hbuss 413
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
414
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
1 ingob 415
 
416
 Ki = (float) Parameter_I_Faktor * 0.0001;
417
 MAX_GAS = EE_Parameter.Gas_Max;
418
 MIN_GAS = EE_Parameter.Gas_Min;
419
}
420
 
421
 
422
//############################################################################
423
//
424
void MotorRegler(void)
425
//############################################################################
426
{
427
         int motorwert,pd_ergebnis,h,tmp_int;
428
         int GierMischanteil,GasMischanteil;
429
     static long SummeNick=0,SummeRoll=0;
430
     static long sollGier = 0,tmp_long,tmp_long2;
395 hbuss 431
     static long IntegralFehlerNick = 0;
432
     static long IntegralFehlerRoll = 0;
1 ingob 433
         static unsigned int RcLostTimer;
434
         static unsigned char delay_neutral = 0;
435
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
436
         static unsigned int  modell_fliegt = 0;
437
     static int hoehenregler = 0;
438
     static char TimerWerteausgabe = 0;
439
     static char NeueKompassRichtungMerken = 0;
395 hbuss 440
     static long ausgleichNick, ausgleichRoll;
441
 
1 ingob 442
        Mittelwert();
446 salvo 443
//****** GPS Daten holen ***************
444
        short int n;
445
        if (gps_alive_cnt > 0) gps_alive_cnt--; //Dekrementieren. Wenn 0 kommen keine ausreichenden GPS Meldungen (Timeout)
446
        n = Get_Rel_Position();
447
        if (n == 0)    
448
        {
449
                ROT_ON; //led blitzen lassen
450
        }
451
//******PROVISORISCH***************
452
    GRN_ON;
1 ingob 453
 
454
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
455
// Gaswert ermitteln
446 salvo 456
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
457
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
458
//Salvo 13.10.2007 langsame Gasreduktion bei Unterspannung. Als Ausgangswert wird der bei UBAT=k gemessen Mittelwert genommen
459
// und dieser dann langsam zwangsweise reduziert
460
        if (UBat <= EE_Parameter.UnterspannungsWarnung - 2)     //Unterhalb der Piepser Schwelle aktivieren
461
        {
462
                if (ubat_cnt > 700)
463
                {
464
                        ubat_cnt = 0;
465
                        if (gas_actual > ((gas_mittel*12)/15)) gas_actual--;
466
                }
467
                else ubat_cnt++;
468
                if (GasMischanteil > gas_actual) GasMischanteil = gas_actual;
469
        }
470
        else   //Falls UBAT wieder ok ist
471
        {
472
                if (ubat_cnt > 1000)
473
                {
474
                        gas_mittel = ((gas_mittel*9) + GasMischanteil)/10; //Filtern
475
                        gas_actual = GasMischanteil;
476
                }
477
                else
478
                {
479
                        ubat_cnt++;
480
                        if ((ubat_cnt % 10) == 0)
481
                        {
482
                                if (gas_actual < GasMischanteil) gas_actual++;
483
                                else gas_actual = GasMischanteil;
484
                }
485
                }
486
                GasMischanteil = gas_actual;
487
        }      
488
// Salvo End
1 ingob 489
    if(GasMischanteil < 0) GasMischanteil = 0;
490
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
446 salvo 491
// Empfang schlecht
1 ingob 492
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
493
   if(SenderOkay < 100)
494
        {
173 holgerb 495
        if(!PcZugriff)
496
         {
497
           if(BeepMuster == 0xffff)
498
            {
499
             beeptime = 15000;
500
             BeepMuster = 0x0c00;
501
            }
502
         }
1 ingob 503
        if(RcLostTimer) RcLostTimer--;
504
        else
505
         {
506
          MotorenEin = 0;
507
          Notlandung = 0;
508
         }
509
        ROT_ON;
510
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
511
            {
512
            GasMischanteil = EE_Parameter.NotGas;
513
            Notlandung = 1;
514
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
515
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
516
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
173 holgerb 517
            }
1 ingob 518
         else MotorenEin = 0;
519
        }
520
        else
521
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
522
// Emfang gut
523
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
524
        if(SenderOkay > 140)
525
            {
526
            Notlandung = 0;
527
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
528
            if(GasMischanteil > 40)
529
                {
530
                if(modell_fliegt < 0xffff) modell_fliegt++;
531
                }
532
            if((modell_fliegt < 200) || (GasMischanteil < 40))
533
                {
534
                SummeNick = 0;
535
                SummeRoll = 0;
536
                Mess_Integral_Gier = 0;
537
                Mess_Integral_Gier2 = 0;
538
                }
539
            if((GasMischanteil > 200) && MotorenEin == 0)
540
                {
541
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
542
// auf Nullwerte kalibrieren
543
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
544
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
545
                    {
395 hbuss 546
                    unsigned char setting = 2;
1 ingob 547
                    if(++delay_neutral > 200)  // nicht sofort
548
                        {
549
                        GRN_OFF;
446 salvo 550
                        SetNeutral();
1 ingob 551
                        MotorenEin = 0;
552
                        delay_neutral = 0;
553
                        modell_fliegt = 0;
554
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
555
                        {
304 ingob 556
                         unsigned char setting=1;
1 ingob 557
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
558
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
559
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
560
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
561
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
562
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
563
                        }
446 salvo 564
 
565
 
566
 
567
 
173 holgerb 568
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
446 salvo 569
 
173 holgerb 570
                        Piep(GetActiveParamSetNumber());
446 salvo 571
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
572
                        {
573
                          if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
574
                        }  
575
                                                GPS_Save_Home(); //Daten sind jetzt hoffentlich verfuegbar
576
                                                if (gps_home_position.status > 0 )
577
                                                {
578
                                                        Delay_ms(1000);  //akustisch verkuenden dass GPS Home Daten da sind
579
                                                        beeptime = 2000;
580
                                                        Delay_ms(500);
581
                                                }
582
                       }
1 ingob 583
                    }
584
                 else delay_neutral = 0;
585
                }
586
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
587
// Gas ist unten
588
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
589
            if(GasMischanteil < 35)
590
                {
591
                // Starten
592
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
593
                    {
594
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
595
// Einschalten
596
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
597
                    if(++delay_einschalten > 200)
598
                        {
599
                        delay_einschalten = 200;
600
                        modell_fliegt = 1;
601
                        MotorenEin = 1;
602
                        sollGier = 0;
603
                        Mess_Integral_Gier = 0;
604
                        Mess_Integral_Gier2 = 0;
605
                        Mess_IntegralNick = 0;
606
                        Mess_IntegralRoll = 0;
607
                        Mess_IntegralNick2 = IntegralNick;
608
                        Mess_IntegralRoll2 = IntegralRoll;
609
                        SummeNick = 0;
610
                        SummeRoll = 0;
611
                        }          
612
                    }  
613
                    else delay_einschalten = 0;
614
                //Auf Neutralwerte setzen
615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
616
// Auschalten
617
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
618
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
619
                    {
620
                    if(++delay_ausschalten > 200)  // nicht sofort
621
                        {
622
                        MotorenEin = 0;
623
                        delay_ausschalten = 200;
624
                        modell_fliegt = 0;
625
                        }
626
                    }
627
                else delay_ausschalten = 0;
628
                }
629
            }
630
 
631
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
632
// neue Werte von der Funke
633
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
634
 if(!NewPpmData-- || Notlandung)  
635
  {
636
    ParameterZuordnung();
637
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
638
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
639
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
640
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
641
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
642
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
643
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
644
 
645
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
646
    if(GyroFaktor < 0) GyroFaktor = 0;
647
    if(IntegralFaktor < 0) IntegralFaktor = 0;
173 holgerb 648
    // greift in den Stick ein, um ungewolltes überschlagen zu verhindern
649
    if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
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
     }
1 ingob 674
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 675
// Looping?
676
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
395 hbuss 677
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
678
  else
173 holgerb 679
   {
395 hbuss 680
     {
681
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
682
     }  
683
   }
684
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
685
   else
686
   {
687
   if(Looping_Rechts) // Hysterese
688
     {
689
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
690
     }
691
   }
173 holgerb 692
 
395 hbuss 693
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
694
  else
173 holgerb 695
   {
395 hbuss 696
    if(Looping_Oben)  // Hysterese
697
     {
698
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
699
     }  
700
   }
701
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
702
   else
703
   {
704
    if(Looping_Unten) // Hysterese
705
     {
706
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
707
     }
708
   }
709
 
710
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
711
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
712
  } // Ende neue Funken-Werte
713
 
714
  if(Looping_Roll) beeptime = 100;
715
  if(Looping_Roll || Looping_Nick)
716
   {
173 holgerb 717
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
718
   }
719
 
720
 
721
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1 ingob 722
// Bei Empfangsausfall im Flug 
723
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
724
   if(Notlandung)
725
    {
726
     StickGier = 0;
727
     StickNick = 0;
728
     StickRoll = 0;
729
     GyroFaktor  = 0.1;
730
     IntegralFaktor = 0.005;
173 holgerb 731
     Looping_Roll = 0;
732
     Looping_Nick = 0;
1 ingob 733
    }  
395 hbuss 734
 
735
 
446 salvo 736
 
1 ingob 737
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
738
// Integrale auf ACC-Signal abgleichen
739
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
395 hbuss 740
#define ABGLEICH_ANZAHL 256L
741
 
742
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
743
 MittelIntegralRoll  += IntegralRoll;
744
 MittelIntegralNick2 += IntegralNick2;
745
 MittelIntegralRoll2 += IntegralRoll2;
746
 
747
 if(Looping_Nick || Looping_Roll)
748
  {
749
    IntegralAccNick = 0;
750
    IntegralAccRoll = 0;
751
    MittelIntegralNick = 0;
752
    MittelIntegralRoll = 0;
753
    MittelIntegralNick2 = 0;
754
    MittelIntegralRoll2 = 0;
755
    Mess_IntegralNick2 = Mess_IntegralNick;
756
    Mess_IntegralRoll2 = Mess_IntegralRoll;
757
    ZaehlMessungen = 0;
758
    I_LageNick = 0;
759
    I_LageRoll = 0;
760
  }
761
 
762
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
763
 {
764
  static int cnt = 0;
765
  static char last_n_p,last_n_n,last_r_p,last_r_n;
766
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
297 holgerb 767
  if(!Looping_Nick && !Looping_Roll)
173 holgerb 768
  {
395 hbuss 769
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
770
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
771
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
772
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
773
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
401 hbuss 774
#define MAX_I 32
395 hbuss 775
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
776
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
777
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
778
    if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < 5000)
779
     {
780
       tmp_long = IntegralFehlerNick / 700L;
401 hbuss 781
       if(tmp_long > MAX_I) tmp_long = MAX_I;
782
       if(tmp_long <-MAX_I) tmp_long =-MAX_I;
395 hbuss 783
       I_LageNick = tmp_long;    
784
     }
785
     else
786
     {
787
      I_LageNick /= 2;
788
     }
789
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
790
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
791
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
792
    if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < 5000)
793
     {
794
      tmp_long2 = IntegralFehlerRoll / 700L;
401 hbuss 795
      if(tmp_long2 > MAX_I) tmp_long2 = MAX_I;
796
      if(tmp_long2 <-MAX_I) tmp_long2 =-MAX_I;
395 hbuss 797
      I_LageRoll = tmp_long2;    
798
     }
799
     else
800
     {
801
      I_LageRoll /=2;
802
     }
803
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
804
   MittelIntegralNick_Alt = MittelIntegralNick;      
805
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
806
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
807
    Mess_IntegralNick -= ausgleichNick;
808
    Mess_IntegralRoll -= ausgleichRoll;
809
 
810
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
811
// Gyro-Drift ermitteln
812
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
813
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
814
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
815
    tmp_long  = (long)(MittelIntegralNick2 - (long)IntegralAccNick);
816
    tmp_long2 = (long)(MittelIntegralRoll2 - (long)IntegralAccRoll);
817
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
818
 
819
    IntegralFehlerNick = tmp_long;
820
    IntegralFehlerRoll = tmp_long2;
821
    Mess_IntegralNick2 -= IntegralFehlerNick;
822
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
823
 
824
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
825
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
826
 
446 salvo 827
//Salvo Ersatzkompass Ueberlauf korrigieren
828
                if (GyroKomp_Int >= ((long)360 * GYROKOMP_INC_GRAD_DEFAULT)) GyroKomp_Int = GyroKomp_Int - (GYROKOMP_INC_GRAD_DEFAULT *(long)360); //neu ab 3.11.2007
829
                if (GyroKomp_Int < 0) GyroKomp_Int = GyroKomp_Int + (GYROKOMP_INC_GRAD_DEFAULT *(long)360); //neu ab 3.11.2007
830
                ROT_OFF;
831
// Salvo End
395 hbuss 832
 
446 salvo 833
/*
401 hbuss 834
DebugOut.Analog[30] = I_LageRoll * 10;
395 hbuss 835
DebugOut.Analog[17] = IntegralAccNick / 26;
836
DebugOut.Analog[18] = IntegralAccRoll / 26;
837
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
838
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
839
DebugOut.Analog[21] = MittelIntegralNick / 26;
840
DebugOut.Analog[22] = MittelIntegralRoll / 26;
841
DebugOut.Analog[28] = ausgleichNick;
842
DebugOut.Analog[29] = ausgleichRoll;
446 salvo 843
*/
395 hbuss 844
 
845
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL/2)
401 hbuss 846
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL*4)
395 hbuss 847
 
848
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
849
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
850
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
851
         {
852
           if(last_n_p)
853
           {
854
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
419 hbuss 855
            ausgleichNick = IntegralFehlerNick / 8;
401 hbuss 856
            if(ausgleichNick > 5000) ausgleichNick = 5000;
857
            Mess_IntegralNick -= ausgleichNick;
395 hbuss 858
           }
859
           else last_n_p = 1;
860
         } else  last_n_p = 0;
861
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
862
         {
863
           if(last_n_n)
864
            {
865
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
419 hbuss 866
             ausgleichNick = IntegralFehlerNick / 8;
401 hbuss 867
             if(ausgleichNick < -5000) ausgleichNick = -5000;
868
             Mess_IntegralNick -= ausgleichNick;
395 hbuss 869
            }
870
           else last_n_n = 1;
871
         } else  last_n_n = 0;
872
 
401 hbuss 873
        if(cnt > 3) cnt = 3;
395 hbuss 874
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
875
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
401 hbuss 876
 
395 hbuss 877
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
878
        cnt = 1;// + labs(IntegralFehlerRoll) / 4096;
446 salvo 879
                ausgleichRoll = 0;
395 hbuss 880
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
881
         {
882
           if(last_r_p)
883
           {
884
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
401 hbuss 885
            ausgleichRoll = IntegralFehlerRoll / 4;
886
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
887
            Mess_IntegralRoll -= ausgleichRoll;
395 hbuss 888
           }
889
           else last_r_p = 1;
890
         } else  last_r_p = 0;
891
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
892
         {
893
           if(last_r_n)
894
           {
895
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
401 hbuss 896
            ausgleichRoll = IntegralFehlerRoll / 4;
897
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
898
            Mess_IntegralRoll -= ausgleichRoll;
395 hbuss 899
           }
900
           else last_r_n = 1;
901
         } else  last_r_n = 0;
902
 
401 hbuss 903
DebugOut.Analog[27] = ausgleichRoll;
904
        if(cnt > 3) cnt = 3;
395 hbuss 905
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
906
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
401 hbuss 907
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
173 holgerb 908
  }
395 hbuss 909
    IntegralAccNick = 0;
910
    IntegralAccRoll = 0;
911
    IntegralAccZ = 0;
912
    MittelIntegralNick = 0;
913
    MittelIntegralRoll = 0;
914
    MittelIntegralNick2 = 0;
915
    MittelIntegralRoll2 = 0;
916
    ZaehlMessungen = 0;
917
 }
918
 
1 ingob 919
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
920
//  Gieren
921
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
188 holgerb 922
    if(abs(StickGier) > 20) // war 35 
1 ingob 923
     {
924
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
925
     }
395 hbuss 926
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
173 holgerb 927
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
928
    sollGier = tmp_int;
1 ingob 929
    Mess_Integral_Gier -= tmp_int;  
395 hbuss 930
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
931
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
932
 
446 salvo 933
// Salvo Ersatzkompass  26.9.2007 **********************
934
        if ((Kompass_Neuer_Wert > 0))
935
        {
936
           Kompass_Neuer_Wert = 0;
937
           w = (abs(Mittelwert_AccNick));
938
           v = (abs(Mittelwert_AccRoll));
939
           if  ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) //Ersatzkompass nur mit Magnetkompass aktualisieren wenn alles ok
940
           {
941
                if  ((abs(KompassValue - Kompass_Value_Old)) <= 5) // Aufeinanderfolgende Werte duerfen nur minimal abweichen
942
                 {
943
                  magkompass_ok = 1; // Flag dass Magnetkompass stabil arbeitet 
944
                  GyroKomp_Int = (GyroKomp_Int )/GYROKOMP_INC_GRAD_DEFAULT;
945
                  w = KompassValue - GyroKomp_Int;
946
                  if ((w > 0) && (w < 180))
947
                  {
948
                   ++GyroKomp_Int;
949
                  }
950
                  else if ((w > 0) && (w >= 180))
951
                  {
952
                   --GyroKomp_Int;
953
                  }
954
                  else if ((w < 0) && (w >= -180))
955
                  {
956
                   --GyroKomp_Int;
957
                  }
958
                  else if ((w < 0) && (w < -180))
959
                  {
960
                   ++GyroKomp_Int;
961
                  }
962
                  if (GyroKomp_Int < 0)  GyroKomp_Int = GyroKomp_Int + 360;
963
                  GyroKomp_Int = (GyroKomp_Int%360) * GYROKOMP_INC_GRAD_DEFAULT; // An Magnetkompasswert annaehern
964
                 }
965
           }
966
           else magkompass_ok = 0;
967
        }
968
// Salvo End *************************
969
 
970
// Salvo 6.10.2007 
971
        // GPS Home aktivieren wenn Knueppel in Ruhelage und Hoehenschalter aktiviert ist
972
        //GPS Hold Aktiveren wenn Knueppel in Ruhelage sind
973
        if ((EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) && (abs(StickRoll) < GPS_STICK_HOLDOFF) && (abs(StickNick) < GPS_STICK_HOLDOFF) && (gps_alive_cnt > 0))
974
        {
975
                if (Parameter_MaxHoehe > 200)  
976
                {      
977
                        if ( gps_cmd == GPS_CMD_REQ_HOLD) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
978
                        else gps_cmd = GPS_CMD_REQ_HOME;
979
                        n = GPS_CRTL(gps_cmd);
980
                }
981
                else
982
                {
983
                        if ( gps_cmd == GPS_CMD_REQ_HOME) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
984
                        else gps_cmd = GPS_CMD_REQ_HOLD;
985
                        n= GPS_CRTL(gps_cmd);
986
                }
987
        }
988
        else (n= GPS_CRTL(GPS_CMD_STOP)); //GPS Lageregelung beenden
1 ingob 989
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
990
//  Kompass
991
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
446 salvo 992
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (Kompass_present > 0))
1 ingob 993
     {
446 salvo 994
           if(v > w) w = v; // grösste Neigung ermitteln
995
 
996
// Salvo 13.9.2007 Nur wenn Magnetkompass ordentliche Werte liefert
997
                if ((magkompass_ok > 0)  &&  NeueKompassRichtungMerken)  
1 ingob 998
        {
446 salvo 999
                 KompassStartwert = KompassValue;
1 ingob 1000
         NeueKompassRichtungMerken = 0;
1001
        }
446 salvo 1002
// Salvo 13.9.2007
1003
       w=0;
1004
// Salvo End
1 ingob 1005
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1006
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1007
       if(w > 0)
1008
        {
446 salvo 1009
// Salvo Kompasssteuerung **********************        
1010
                 if (magkompass_ok > 0) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
1011
// Salvo End
1 ingob 1012
        }  
446 salvo 1013
 
1 ingob 1014
     }
1015
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1016
 
1017
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1018
//  Debugwerte zuordnen
1019
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1020
  if(!TimerWerteausgabe--)
1021
   {
395 hbuss 1022
    TimerWerteausgabe = 24;
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;
1027
    DebugOut.Analog[4] = MesswertGier;
1028
    DebugOut.Analog[5] = HoehenWert;
395 hbuss 1029
    DebugOut.Analog[6] =(Mess_Integral_Hoch / 512);
1 ingob 1030
    DebugOut.Analog[8] = KompassValue;
446 salvo 1031
        DebugOut.Analog[9] = GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT;
173 holgerb 1032
 
446 salvo 1033
// Diverse parameter Debugging
1034
        DebugOut.Analog[16] =  dataset_cnt;
1035
        DebugOut.Analog[17] =  UBat;
1036
        DebugOut.Analog[18] =  MesswertNick;
1037
        DebugOut.Analog[19] =  MesswertRoll;
1038
        DebugOut.Analog[20] =  MesswertGier;
1039
        DebugOut.Analog[21] =  StickNick;
1040
        DebugOut.Analog[22] =  StickRoll;
1041
        DebugOut.Analog[23] =  StickGier;
1042
 
1043
 
1044
// GPS Debugging
1045
        DebugOut.Analog[26] =  gps_rel_act_position.utm_east;
1046
        DebugOut.Analog[27] =  gps_rel_act_position.utm_north;
1047
        DebugOut.Analog[28] =  gps_rel_act_position.utm_alt;
1048
        DebugOut.Analog[29] =  gps_sub_state+(20*gps_cmd);
1049
 
173 holgerb 1050
/*    DebugOut.Analog[16] = motor_rx[0];
1051
    DebugOut.Analog[17] = motor_rx[1];
1052
    DebugOut.Analog[18] = motor_rx[2];
1053
    DebugOut.Analog[19] = motor_rx[3];
1054
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1055
    DebugOut.Analog[20] /= 14;
1056
    DebugOut.Analog[21] = motor_rx[4];
1057
    DebugOut.Analog[22] = motor_rx[5];
1058
    DebugOut.Analog[23] = motor_rx[6];
1059
    DebugOut.Analog[24] = motor_rx[7];
1060
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1061
*/
1062
//    DebugOut.Analog[9] = MesswertNick;
1 ingob 1063
//    DebugOut.Analog[9] = SollHoehe;
1064
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1065
//    DebugOut.Analog[11] = KompassStartwert;
1066
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
1067
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
1068
//    DebugOut.Analog[9] = KompassRichtung;    
1069
//    DebugOut.Analog[10] = GasMischanteil;
1070
//    DebugOut.Analog[3] = HoeheD * 32;
1071
//    DebugOut.Analog[4] = hoehenregler;
1072
  }
1073
 
1074
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1075
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1076
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 1077
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1078
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1079
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1080
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1081
//    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
1082
    MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2;
1 ingob 1083
 
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
    {
1114
     SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20;
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
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 1141
  DebugOut.Analog[7] = GasMischanteil;
1 ingob 1142
 
1143
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1144
// Gier-Anteil
1145
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
188 holgerb 1146
#define MUL_G  1.0
173 holgerb 1147
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1148
//GierMischanteil = 0;
1149
    if(GierMischanteil > (MUL_G * GasMischanteil))  GierMischanteil = MUL_G * GasMischanteil;
1150
    if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil);
188 holgerb 1151
    if(GierMischanteil > 100)  GierMischanteil = 100;
1152
    if(GierMischanteil < -100) GierMischanteil = -100;
173 holgerb 1153
 
188 holgerb 1154
    if(GasMischanteil < 20) GierMischanteil = 0;
1 ingob 1155
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1156
// Nick-Achse
1157
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1158
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
1159
    SummeNick += DiffNick;                                   // I-Anteil
1160
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
1161
    if(SummeNick >  16000) SummeNick =  16000;
1162
    if(SummeNick < -16000) SummeNick = -16000;
297 holgerb 1163
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1 ingob 1164
    // Motor Vorn
173 holgerb 1165
#define MUL  2
188 holgerb 1166
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1167
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
173 holgerb 1168
 
1 ingob 1169
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
173 holgerb 1170
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1171
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1172
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1173
        Motor_Vorne = motorwert;           
1174
    // Motor Heck
1175
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
173 holgerb 1176
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1177
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1178
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1179
        Motor_Hinten = motorwert;              
1180
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1181
// Roll-Achse
1182
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1183
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
1184
        SummeRoll += DiffRoll;                                                              // I-Anteil
1185
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
1186
    if(SummeRoll >  16000) SummeRoll =  16000;
1187
    if(SummeRoll < -16000) SummeRoll = -16000;
297 holgerb 1188
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
188 holgerb 1189
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1190
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1 ingob 1191
    // Motor Links
1192
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
173 holgerb 1193
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1194
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1195
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1196
        Motor_Links = motorwert;               
1197
    // Motor Rechts
1198
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
173 holgerb 1199
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1200
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1201
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1202
        Motor_Rechts = motorwert;
1203
   // +++++++++++++++++++++++++++++++++++++++++++++++
1204
}
1205