Subversion Repositories FlightCtrl

Rev

Rev 189 | 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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
330 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"
63
 
64
unsigned char h,m,s;
173 holgerb 65
volatile unsigned int I2CTimeout = 100;
1 ingob 66
volatile int MesswertNick,MesswertRoll,MesswertGier;
67
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0;
68
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
69
volatile float NeutralAccZ = 0;
70
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
71
volatile long IntegralNick = 0,IntegralNick2 = 0;
72
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
73
volatile long Integral_Gier = 0;
74
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
75
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
76
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
77
volatile long Mess_Integral_Hoch = 0;
78
volatile int  KompassValue = 0;
79
volatile int  KompassStartwert = 0;
80
volatile int  KompassRichtung = 0;
81
unsigned char MAX_GAS,MIN_GAS;
82
unsigned char Notlandung = 0;
83
unsigned char HoehenReglerAktiv = 0;
330 salvo 84
//Salvo 12.10.2007
85
uint8_t magkompass_ok=0;
86
uint8_t gps_cmd = GPS_CMD_STOP;
87
static int       ubat_cnt =0;
88
static int gas_actual,gas_mittel; //Parameter fuer Gasreduzierung bei unterspannung
89
//Salvo End
1 ingob 90
 
330 salvo 91
 //Salvo 2.9.2007 Ersatzkompass
92
volatile long GyroKomp_Int,GyroKomp_Int2;
93
volatile int GyroKomp_Value; //  Der ermittelte Kompasswert aus Gyro und Magnetkompass
94
// Salvo End
1 ingob 95
float GyroFaktor;
96
float IntegralFaktor;
97
 
98
volatile int  DiffNick,DiffRoll;
99
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
100
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
101
unsigned char MotorWert[5];
102
volatile unsigned char SenderOkay = 0;
103
int StickNick = 0,StickRoll = 0,StickGier = 0;
104
char MotorenEin = 0;
105
int HoehenWert = 0;
106
int SollHoehe = 0;
173 holgerb 107
unsigned char Looping_Nick = 0,Looping_Roll = 0;
1 ingob 108
 
330 salvo 109
 
110
int w,v;
111
 
1 ingob 112
float Kp =  FAKTOR_P;
113
float Ki =  FAKTOR_I;
114
 
115
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
116
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
117
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
118
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
119
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
173 holgerb 120
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
1 ingob 121
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
122
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
123
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
124
unsigned char Parameter_UserParam1 = 0;
125
unsigned char Parameter_UserParam2 = 0;
126
unsigned char Parameter_UserParam3 = 0;
127
unsigned char Parameter_UserParam4 = 0;
128
unsigned char Parameter_ServoNickControl = 100;
173 holgerb 129
unsigned char Parameter_LoopGasLimit = 70;
1 ingob 130
struct mk_param_struct EE_Parameter;
131
 
132
void Piep(unsigned char Anzahl)
133
{
134
 while(Anzahl--)
135
 {
136
  if(MotorenEin) return; //auf keinen Fall im Flug!
137
  beeptime = 100;
138
  Delay_ms(250);
139
 }
140
}
141
 
142
//############################################################################
143
//  Nullwerte ermitteln
144
void SetNeutral(void)
145
//############################################################################
146
{
147
    unsigned int timer;
148
        NeutralAccX = 0;
149
        NeutralAccY = 0;
150
        NeutralAccZ = 0;
151
    AdNeutralNick = 0; 
152
        AdNeutralRoll = 0;     
153
        AdNeutralGier = 0;
330 salvo 154
        GPS_Neutral();
1 ingob 155
    CalibrierMittelwert();     
156
    timer = SetDelay(5);    
157
        while (!CheckDelay(timer));
158
        CalibrierMittelwert();
159
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
160
     {    
161
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
162
     }
173 holgerb 163
 
164
    if(PlatinenVersion == 10)
165
    {
166
     AdNeutralNick= abs(MesswertNick); 
167
         AdNeutralRoll= abs(MesswertRoll);     
168
         AdNeutralGier= abs(MesswertGier);
169
    }
170
    else
171
    {
172
     AdNeutralNick= abs(MesswertNick) / 2;     
173
         AdNeutralRoll= abs(MesswertRoll) / 2; 
174
         AdNeutralGier= abs(MesswertGier) / 2;
175
    }
330 salvo 176
// Salvo 1.9.2007 ACC mit festen neutralwerten *****
177
        if (ACC_NEUTRAL_FIXED > 0)
178
        {
179
                NeutralAccX     = ACC_NICK_NEUTRAL;
180
                NeutralAccY     = ACC_ROLL_NEUTRAL;
181
        }
182
        else
183
        { // Automatisch bei Offsetabgleich ermitteln
184
                NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
185
                NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
186
        }
187
 // Salvo End   
1 ingob 188
        NeutralAccZ = Aktuell_az;
189
 
190
        Mess_IntegralNick = 0; 
191
    Mess_IntegralNick2 = 0;
192
    Mess_IntegralRoll = 0;     
193
    Mess_IntegralRoll2 = 0;
194
    Mess_Integral_Gier = 0;    
195
    MesswertNick = 0;
196
    MesswertRoll = 0;
197
    MesswertGier = 0;
198
    StartLuftdruck = Luftdruck;
199
    HoeheD = 0;
200
    Mess_Integral_Hoch = 0;
201
    KompassStartwert = KompassValue;
330 salvo 202
 
1 ingob 203
    beeptime = 50;  
330 salvo 204
//Salvo 13.10.2007 Ersatzkompass 
205
        GyroKomp_Int = 0;
206
        gas_mittel      =       30;
207
        gas_actual      =       gas_mittel;
208
// Salvo End
1 ingob 209
}
210
 
211
//############################################################################
212
// Bildet den Mittelwert aus den Messwerten
213
void Mittelwert(void)
214
//############################################################################
215
{      
216
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
217
    ANALOG_OFF;
218
        if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
219
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
220
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
221
        if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L;
222
        if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L;
223
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L;
224
    AccumulateNick = 0;   MessanzahlNick = 0;
225
    AccumulateRoll = 0;   MessanzahlRoll = 0;
226
    AccumulateGier = 0;   MessanzahlGier = 0;
227
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
228
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
229
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
230
    Integral_Gier  = Mess_Integral_Gier;
231
//    Integral_Gier2 = Mess_Integral_Gier2;
232
    IntegralNick = Mess_IntegralNick;
233
    IntegralRoll = Mess_IntegralRoll;
234
    IntegralNick2 = Mess_IntegralNick2;
235
    IntegralRoll2 = Mess_IntegralRoll2;
236
    // ADC einschalten
237
    ANALOG_ON; 
238
 
173 holgerb 239
/*
1 ingob 240
//------------------------------------------------------------------------------
241
    if(MesswertNick > 200)  MesswertNick += 4 * (MesswertNick - 200);
242
    else                                         
243
    if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
244
    if(MesswertRoll > 200)  MesswertRoll += 4 * (MesswertRoll - 200);
245
    else                                         
246
    if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
247
//------------------------------------------------------------------------------
173 holgerb 248
*/
1 ingob 249
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
250
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
251
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
252
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
253
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
254
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
255
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
256
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
257
}
258
 
259
//############################################################################
260
// Messwerte beim Ermitteln der Nullage
261
void CalibrierMittelwert(void)
262
//############################################################################
263
{                
264
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
265
        ANALOG_OFF;
266
    if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
267
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
268
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
269
        if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick);
270
        if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll;
271
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch;
272
    AccumulateNick = 0;   MessanzahlNick = 0;
273
    AccumulateRoll = 0;   MessanzahlRoll = 0;
274
    AccumulateGier = 0;   MessanzahlGier = 0;
275
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
276
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
277
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
278
    // ADC einschalten
279
    ANALOG_ON; 
280
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
281
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
282
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
283
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
284
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
285
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
286
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
287
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
288
}
289
 
290
//############################################################################
291
// Senden der Motorwerte per I2C-Bus
292
void SendMotorData(void)
293
//############################################################################
294
{
295
    if(MOTOR_OFF || !MotorenEin)
296
        {
297
        Motor_Hinten = 0;
298
        Motor_Vorne = 0;
299
        Motor_Rechts = 0;
300
        Motor_Links = 0;
301
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
302
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
303
        if(MotorTest[2]) Motor_Links = MotorTest[2];
304
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
305
        }
306
 
307
    DebugOut.Analog[12] = Motor_Vorne;
308
    DebugOut.Analog[13] = Motor_Hinten;
309
    DebugOut.Analog[14] = Motor_Links;
310
    DebugOut.Analog[15] = Motor_Rechts;  
311
 
312
    //Start I2C Interrupt Mode
313
    twi_state = 0;
314
    motor = 0;
315
    i2c_start();
316
}
317
 
318
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
319
// + Konstanten 
320
// + 0-250 -> normale Werte
321
// + 251 -> Poti1
322
// + 252 -> Poti2
323
// + 253 -> Poti3
324
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
325
void DefaultKonstanten1(void)
326
{
327
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
328
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
329
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
330
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
331
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
332
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
333
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
334
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
335
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01;    
336
 EE_Parameter.Hoehe_MinGas = 30;
173 holgerb 337
 EE_Parameter.MaxHoehe     = 251;      // Wert : 0-32   251 -> Poti1
338
 EE_Parameter.Hoehe_P      = 10;       // Wert : 0-32
339
 EE_Parameter.Luftdruck_D  = 50;       // Wert : 0-250
340
 EE_Parameter.Hoehe_ACC_Wirkung = 50;  // Wert : 0-250
341
 EE_Parameter.Hoehe_Verstaerkung = 4;  // Wert : 0-50
330 salvo 342
 EE_Parameter.Stick_P = 2; //2         // Wert : 1-6
343
 EE_Parameter.Stick_D = 4; //8         // Wert : 0-64
173 holgerb 344
 EE_Parameter.Gier_P = 16;             // Wert : 1-20
1 ingob 345
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
173 holgerb 346
 EE_Parameter.Gas_Max = 250;           // Wert : 33-250
347
 EE_Parameter.GyroAccFaktor = 26;      // Wert : 1-64
1 ingob 348
 EE_Parameter.KompassWirkung = 128;    // Wert : 0-250
349
 EE_Parameter.Gyro_P = 120; //80          // Wert : 0-250
350
 EE_Parameter.Gyro_I = 150;               // Wert : 0-250
330 salvo 351
 EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250
352
 EE_Parameter.NotGas = 100;                // Wert : 0-250     // Gaswert bei Empangsverlust
353
 EE_Parameter.NotGasZeit = 60;            // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
1 ingob 354
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
173 holgerb 355
 EE_Parameter.I_Faktor = 0;
330 salvo 356
 EE_Parameter.UserParam1 = 8;             //zur freien Verwendung
357
 EE_Parameter.UserParam2 = 2;             //zur freien Verwendung
358
 EE_Parameter.UserParam3 = 12;             //zur freien Verwendung
1 ingob 359
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
360
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
361
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
362
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
173 holgerb 363
 EE_Parameter.ServoNickMin = 50;          // Wert : 0-250     // Anschlag
1 ingob 364
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
365
 EE_Parameter.ServoNickRefresh = 5;
173 holgerb 366
 EE_Parameter.LoopGasLimit = 50;
367
 EE_Parameter.LoopThreshold = 90;         // Wert: 0-250  Schwelle für Stickausschlag
368
 EE_Parameter.LoopConfig = 0;             // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt
369
 memcpy(EE_Parameter.Name, "Sport\0", 12);  
1 ingob 370
}
371
 
372
void DefaultKonstanten2(void)
373
{
374
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
375
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
376
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
377
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
378
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
379
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
380
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
55 ingob 381
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
1 ingob 382
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01;    
383
 EE_Parameter.Hoehe_MinGas = 30;
384
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
385
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
386
 EE_Parameter.Luftdruck_D  = 50;      // Wert : 0-250
387
 EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250
388
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
330 salvo 389
 EE_Parameter.Stick_P = 2; //2           // Wert : 1-6
1 ingob 390
 EE_Parameter.Stick_D = 0; //8           // Wert : 0-64
391
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
392
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
393
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
394
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
330 salvo 395
 EE_Parameter.KompassWirkung = 64;    // Wert : 0-250
1 ingob 396
 EE_Parameter.Gyro_P = 175; //80           // Wert : 0-250
397
 EE_Parameter.Gyro_I = 175;           // Wert : 0-250
330 salvo 398
 EE_Parameter.UnterspannungsWarnung = 100;  // Wert : 0-250
399
 EE_Parameter.NotGas = 100;                 // Wert : 0-250     // Gaswert bei Empangsverlust
400
 EE_Parameter.NotGasZeit = 60;             // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
1 ingob 401
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
330 salvo 402
 EE_Parameter.I_Faktor = 5;
403
 EE_Parameter.UserParam1 = 12;   //zur freien Verwendung
404
 EE_Parameter.UserParam2 = 2;   //zur freien Verwendung
405
 EE_Parameter.UserParam3 = 16;   //zur freien Verwendung
1 ingob 406
 EE_Parameter.UserParam4 = 0;   //zur freien Verwendung
407
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
408
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
409
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
410
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
411
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
412
 EE_Parameter.ServoNickRefresh = 5;
173 holgerb 413
 EE_Parameter.LoopGasLimit = 50;
414
 EE_Parameter.LoopThreshold = 90;         // Wert: 0-250  Schwelle für Stickausschlag
415
 EE_Parameter.LoopConfig = 0;              // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts 
1 ingob 416
 memcpy(EE_Parameter.Name, "Kamera\0", 12);  
417
}
418
 
419
 
420
//############################################################################
421
// Trägt ggf. das Poti als Parameter ein
422
void ParameterZuordnung(void)
423
//############################################################################
424
{
425
 
426
 #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;}
427
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
428
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
429
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
430
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
431
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
432
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
433
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
434
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
435
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
436
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
437
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
438
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
439
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
440
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
441
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
173 holgerb 442
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
1 ingob 443
 
444
 Ki = (float) Parameter_I_Faktor * 0.0001;
445
 MAX_GAS = EE_Parameter.Gas_Max;
446
 MIN_GAS = EE_Parameter.Gas_Min;
447
}
448
 
449
 
450
//############################################################################
451
//
452
void MotorRegler(void)
453
//############################################################################
454
{
455
         int motorwert,pd_ergebnis,h,tmp_int;
456
         int GierMischanteil,GasMischanteil;
457
     static long SummeNick=0,SummeRoll=0;
458
     static long sollGier = 0,tmp_long,tmp_long2;
173 holgerb 459
     long IntegralFehlerNick = 0;
460
     long IntegralFehlerRoll = 0;
1 ingob 461
         static unsigned int RcLostTimer;
462
         static unsigned char delay_neutral = 0;
463
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
464
         static unsigned int  modell_fliegt = 0;
465
     static int hoehenregler = 0;
466
     static char TimerWerteausgabe = 0;
467
     static char NeueKompassRichtungMerken = 0;
468
        Mittelwert();
330 salvo 469
//****** GPS Daten holen ***************
470
        short int n;
471
        if (gps_alive_cnt > 0) gps_alive_cnt--; //Dekrementieren. Wenn 0 kommen keine ausreichenden GPS Meldungen (Timeout)
472
        n = Get_Rel_Position();
473
        if (n == 0)    
474
        {
475
                ROT_ON; //led blitzen lassen
476
        }
477
//******PROVISORISCH***************
1 ingob 478
    GRN_ON;
479
 
480
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
481
// Gaswert ermitteln
330 salvo 482
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
483
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
484
//Salvo 13.10.2007 langsame Gasreduktion bei Unterspannung. Als Ausgangswert wird der bei UBAT=k gemessen Mittelwert genommen
485
// und dieser dann langsam zwangsweise reduziert
486
        ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern 
487
        if (UBat <= EE_Parameter.UnterspannungsWarnung - 2)     //Unterhalb der Piepser Schwelle aktivieren
488
        {
489
                if (ubat_cnt > 700)
490
                {
491
                        ubat_cnt = 0;
492
                        if (gas_actual > ((gas_mittel*12)/15)) gas_actual--;
493
                }
494
                else ubat_cnt++;
495
                if (GasMischanteil > gas_actual) GasMischanteil = gas_actual;
496
        }
497
        else   //Falls UBAT wieder ok ist
498
        {
499
                if (ubat_cnt > 1000)
500
                {
501
                        gas_mittel = ((gas_mittel*9) + GasMischanteil)/10; //Filtern
502
                        gas_actual = GasMischanteil;
503
                }
504
                else
505
                {
506
                        ubat_cnt++;
507
                        if ((ubat_cnt % 10) == 0)
508
                        {
509
                                if (gas_actual < GasMischanteil) gas_actual++;
510
                                else gas_actual = GasMischanteil;
511
                }
512
                }
513
                GasMischanteil = gas_actual;
514
        }      
515
        ANALOG_ON;      // ADC einschalten
516
// Salvo End
1 ingob 517
    if(GasMischanteil < 0) GasMischanteil = 0;
518
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
330 salvo 519
// Empfang schlecht
1 ingob 520
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
521
   if(SenderOkay < 100)
522
        {
173 holgerb 523
        if(!PcZugriff)
524
         {
525
           if(BeepMuster == 0xffff)
526
            {
527
             beeptime = 15000;
528
             BeepMuster = 0x0c00;
529
            }
530
         }
1 ingob 531
        if(RcLostTimer) RcLostTimer--;
532
        else
533
         {
534
          MotorenEin = 0;
535
          Notlandung = 0;
536
         }
537
        ROT_ON;
538
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
539
            {
540
            GasMischanteil = EE_Parameter.NotGas;
541
            Notlandung = 1;
542
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
543
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
544
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
173 holgerb 545
            }
1 ingob 546
         else MotorenEin = 0;
547
        }
548
        else
549
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
550
// Emfang gut
551
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
552
        if(SenderOkay > 140)
553
            {
554
            Notlandung = 0;
555
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
556
            if(GasMischanteil > 40)
557
                {
558
                if(modell_fliegt < 0xffff) modell_fliegt++;
559
                }
560
            if((modell_fliegt < 200) || (GasMischanteil < 40))
561
                {
562
                SummeNick = 0;
563
                SummeRoll = 0;
564
                Mess_Integral_Gier = 0;
565
                Mess_Integral_Gier2 = 0;
566
                }
567
            if((GasMischanteil > 200) && MotorenEin == 0)
568
                {
569
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
570
// auf Nullwerte kalibrieren
571
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
572
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
573
                    {
574
                    unsigned char setting;
575
                    if(++delay_neutral > 200)  // nicht sofort
576
                        {
577
                        GRN_OFF;
330 salvo 578
                        SetNeutral();
1 ingob 579
                        MotorenEin = 0;
580
                        delay_neutral = 0;
581
                        modell_fliegt = 0;
582
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
583
                        {
584
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
585
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
586
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
587
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
588
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
589
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
590
                        }
330 salvo 591
 
592
 
593
 
594
 
173 holgerb 595
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
330 salvo 596
 
173 holgerb 597
                        Piep(GetActiveParamSetNumber());
330 salvo 598
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
599
                        {
600
                          if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
601
                        }  
602
                                                GPS_Save_Home(); //Daten sind jetzt hoffentlich verfuegbar
603
                                                if (gps_home_position.status > 0 )
604
                                                {
605
                                                        Delay_ms(1000);  //akustisch verkuenden dass GPS Home Daten da sind
606
                                                        beeptime = 2000;
607
                                                        Delay_ms(500);
608
                                                }
609
                       }
1 ingob 610
                    }
611
                 else delay_neutral = 0;
612
                }
613
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
614
// Gas ist unten
615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
616
            if(GasMischanteil < 35)
617
                {
618
                // Starten
619
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
620
                    {
621
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
622
// Einschalten
623
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
624
                    if(++delay_einschalten > 200)
625
                        {
626
                        delay_einschalten = 200;
627
                        modell_fliegt = 1;
628
                        MotorenEin = 1;
629
                        sollGier = 0;
630
                        Mess_Integral_Gier = 0;
631
                        Mess_Integral_Gier2 = 0;
632
                        Mess_IntegralNick = 0;
633
                        Mess_IntegralRoll = 0;
634
                        Mess_IntegralNick2 = IntegralNick;
635
                        Mess_IntegralRoll2 = IntegralRoll;
636
                        SummeNick = 0;
637
                        SummeRoll = 0;
638
                        }          
639
                    }  
640
                    else delay_einschalten = 0;
641
                //Auf Neutralwerte setzen
642
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
643
// Auschalten
644
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
645
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
646
                    {
647
                    if(++delay_ausschalten > 200)  // nicht sofort
648
                        {
649
                        MotorenEin = 0;
650
                        delay_ausschalten = 200;
651
                        modell_fliegt = 0;
652
                        }
653
                    }
654
                else delay_ausschalten = 0;
655
                }
656
            }
657
 
658
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
659
// neue Werte von der Funke
660
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
661
 if(!NewPpmData-- || Notlandung)  
662
  {
663
    ParameterZuordnung();
664
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
665
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
666
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
667
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
668
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
669
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
670
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
671
 
672
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
673
    if(GyroFaktor < 0) GyroFaktor = 0;
674
    if(IntegralFaktor < 0) IntegralFaktor = 0;
173 holgerb 675
    // greift in den Stick ein, um ungewolltes überschlagen zu verhindern
676
    if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
677
     {
678
      if(IntegralNick >  60000)  
679
      {
680
       StickNick -=  8 * EE_Parameter.Stick_P;      
681
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
682
      }
683
      else
684
      if(IntegralNick < -60000)  
685
      {
686
       StickNick += 8 * EE_Parameter.Stick_P;
687
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
688
      }
689
      if(IntegralRoll >  60000)  
690
      {
691
       StickRoll -=  8 * EE_Parameter.Stick_P;      
692
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
693
      }
694
      else
695
      if(IntegralRoll < -60000)  
696
      {
697
       StickRoll += 8 * EE_Parameter.Stick_P;
698
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
699
      }
700
     }
701
 
1 ingob 702
  }
173 holgerb 703
 
1 ingob 704
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 705
// Looping?
706
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
707
  if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) ||
708
     ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
709
   {
710
    Looping_Roll = 1;
711
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
712
   }
713
   else Looping_Roll = 0;  
714
 
715
  if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) ||
716
     ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN))
717
   {
718
    Looping_Nick = 1;
719
    Looping_Roll = 0;
720
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
721
   }
722
   else Looping_Nick = 0;  
723
 
724
 
725
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1 ingob 726
// Bei Empfangsausfall im Flug 
727
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
728
   if(Notlandung)
729
    {
730
     StickGier = 0;
731
     StickNick = 0;
732
     StickRoll = 0;
733
     GyroFaktor  = 0.1;
734
     IntegralFaktor = 0.005;
173 holgerb 735
     Looping_Roll = 0;
736
     Looping_Nick = 0;
1 ingob 737
    }  
738
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
739
// Gyro-Drift kompensieren
740
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
741
#define DRIFT_FAKTOR 3
742
    if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR)
330 salvo 743
                {
744
// Salvo 12.9.2007 Ersatzkompass *******
745
                    ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern 
746
                        if (GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT >=360 ) GyroKomp_Int = 0;
747
                        ANALOG_ON;      // ADC einschalten
748
                        ROT_OFF;
749
// Salvo End
750
 
751
               IntegralFehlerNick = IntegralNick2 - IntegralNick;
752
           IntegralFehlerRoll = IntegralRoll2 - IntegralRoll;
753
           ZaehlMessungen = 0;
754
// Salvo 1.9.2007 *************************
755
// Abgleich Roll und Nick Gyro vollsteandig nur, wenn nahezu waagrechte Lage, ansonsten abschwaechen
756
                   ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
757
                        w = (abs(Mittelwert_AccNick));
758
                        v = (abs(Mittelwert_AccRoll));
759
                ANALOG_ON;      // ADC einschalten
760
                        // Abgleich Roll und Nick Gyro nur wenn auch keine wilden Manoever stattfinden 26.9.2007
761
                        if ((abs(StickNick - GPS_Nick) < 30) && (abs(StickRoll - GPS_Roll) < 30))
762
                        {
763
                                if ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT))
764
                                {              
765
                         if(IntegralFehlerNick > 500/DRIFT_FAKTOR)   AdNeutralNick++;
766
                         if(IntegralFehlerNick < -500/DRIFT_FAKTOR)  AdNeutralNick--;
767
                         if(IntegralFehlerRoll > 500/DRIFT_FAKTOR)   AdNeutralRoll++;
768
                         if(IntegralFehlerRoll < -500/DRIFT_FAKTOR)  AdNeutralRoll--;
769
                                }
770
                                else if ((w < 2*ACC_WAAGRECHT_LIMIT) && (v < 2*ACC_WAAGRECHT_LIMIT)) // langsamer kompensieren, weil ACC Werte unsicherer sind, was die Neigung angeht
771
                                {
772
                         if(IntegralFehlerNick > 500*2/DRIFT_FAKTOR)   AdNeutralNick++;
773
                         if(IntegralFehlerNick < -500*2/DRIFT_FAKTOR)  AdNeutralNick--;
774
                         if(IntegralFehlerRoll > 500*2/DRIFT_FAKTOR)   AdNeutralRoll++;
775
                         if(IntegralFehlerRoll < -500*2/DRIFT_FAKTOR)  AdNeutralRoll--;
776
                                }
777
/*                              else  // noch langsamer kompensieren, weil ACC Werte unsicherer sind, was die Neigung angeht
778
                                {
779
                         if(IntegralFehlerNick > 500*4/DRIFT_FAKTOR)   AdNeutralNick++;
780
                         if(IntegralFehlerNick < -500*4/DRIFT_FAKTOR)  AdNeutralNick--;
781
                         if(IntegralFehlerRoll > 500*4/DRIFT_FAKTOR)   AdNeutralRoll++;
782
                         if(IntegralFehlerRoll < -500*4/DRIFT_FAKTOR)  AdNeutralRoll--;
783
                                }
784
*/                      }
785
 
786
// Salvo End
787
 
788
                        ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
789
                Mess_IntegralNick2 = IntegralNick;
790
                Mess_IntegralRoll2 = IntegralRoll;
791
                Mess_Integral_Gier2 = Integral_Gier;
792
                ANALOG_ON;      // ADC einschalten
1 ingob 793
        }
794
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
795
// Integrale auf ACC-Signal abgleichen
796
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 797
  if(IntegralFaktor && !Looping_Nick && !Looping_Roll)
798
  {
799
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
800
    if(labs(Mittelwert_AccNick) < 200) tmp_long /= 8;
801
    else tmp_long /= 16;
802
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
803
    if(labs(Mittelwert_AccRoll) < 200) tmp_long2 /= 8;
804
    else tmp_long2 /= 16;
805
 
806
 #define AUSGLEICH 500
1 ingob 807
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
808
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
809
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
810
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
173 holgerb 811
  }
812
  else
813
  {
814
   tmp_long = 0;
815
   tmp_long2 = 0;
816
  }
1 ingob 817
 ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
330 salvo 818
 // Salvo 1.9.2007 Volle Korrektur nur wenn waagrechte Lage, sonst abgeschawecht *****************
819
 
820
        w = (abs(Mittelwert_AccNick));
821
        v = (abs(Mittelwert_AccRoll));
822
        if ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT))
823
        {
824
        Mess_IntegralNick -= tmp_long;
825
        Mess_IntegralRoll -= tmp_long2;
826
        }
827
        else if ((w  < 2 * ACC_WAAGRECHT_LIMIT) && (v < 2 * ACC_WAAGRECHT_LIMIT))
828
        {
829
        Mess_IntegralNick -= tmp_long/2; //Vorher 8
830
        Mess_IntegralRoll -= tmp_long2/2;
831
        }
832
        else if ((w  < 4 * ACC_WAAGRECHT_LIMIT) && (v < 4 * ACC_WAAGRECHT_LIMIT))
833
        {
834
        Mess_IntegralNick -= tmp_long/4;
835
        Mess_IntegralRoll -= tmp_long2/4;
836
        }
837
        else
838
        {
839
        Mess_IntegralNick -= tmp_long/8;
840
        Mess_IntegralRoll -= tmp_long2/8;              
841
        }
842
// Salvo End ***********************
1 ingob 843
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
844
//  Gieren
845
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
188 holgerb 846
    if(abs(StickGier) > 20) // war 35 
1 ingob 847
     {
848
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
849
     }
173 holgerb 850
    tmp_int  = EE_Parameter.Gier_P * (StickGier * abs(StickGier)) / 512; // expo  y = ax + bx²
851
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
852
    sollGier = tmp_int;
1 ingob 853
    Mess_Integral_Gier -= tmp_int;  
173 holgerb 854
    if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000;  // begrenzen
855
    if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000;
1 ingob 856
 
330 salvo 857
 // Salvo Gewolltes Gieren ignorieren 30.8.2007 **********************
858
    Mess_Integral_Gier2  -= tmp_int;  
859
// Salvo End *************************
1 ingob 860
 ANALOG_ON;     // ADC einschalten
861
 
330 salvo 862
// Salvo Ersatzkompass  26.9.2007 **********************
863
        if ((Kompass_Neuer_Wert > 0))
864
        {
865
           Kompass_Neuer_Wert = 0;
866
           w = (abs(Mittelwert_AccNick));
867
           v = (abs(Mittelwert_AccRoll));
868
           if  ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) //Ersatzkompass nur mit Magnetkompass aktualisieren wenn alle sok
869
           {
870
                if  ((abs(KompassValue - Kompass_Value_Old)) <= 5) // Aufeinanderfolgende Werte duerfen nur minimal abweichen
871
                 {
872
                  ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
873
                  magkompass_ok = 1; // Flag dass Magnetkompass stabil arbeitet 
874
                  GyroKomp_Int = (GyroKomp_Int )/GYROKOMP_INC_GRAD_DEFAULT;
875
                  w = KompassValue - GyroKomp_Int;
876
                  if ((w > 0) && (w < 180))
877
                  {
878
                   ++GyroKomp_Int;
879
                  }
880
                  else if ((w > 0) && (w >= 180))
881
                  {
882
                   --GyroKomp_Int;
883
                  }
884
                  else if ((w < 0) && (w >= -180))
885
                  {
886
                   --GyroKomp_Int;
887
                  }
888
                  else if ((w < 0) && (w < -180))
889
                  {
890
                   ++GyroKomp_Int;
891
                  }
892
                  if (GyroKomp_Int < 0)  GyroKomp_Int = GyroKomp_Int + 360;
893
                  GyroKomp_Int = (GyroKomp_Int%360) * GYROKOMP_INC_GRAD_DEFAULT; // An Magnetkompasswert annaehern
894
                  ANALOG_ON;    // ADC einschalten
895
                 }
896
           }
897
           else magkompass_ok = 0;
898
        }
899
// Salvo End *************************
900
 
901
// Salvo 6.10.2007 
902
        // GPS Home aktivieren wenn Knueppel in Ruhelage und Hoehenschalter aktiviert ist
903
        //GPS Hold Aktiveren wenn Knueppel in Ruhelage sind
904
        if ((EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) && (abs(StickRoll) < GPS_STICK_HOLDOFF) && (abs(StickNick) < GPS_STICK_HOLDOFF) && (gps_alive_cnt > 0))
905
        {
906
                if (Parameter_MaxHoehe > 200)  
907
                {      
908
                        if ( gps_cmd == GPS_CMD_REQ_HOLD) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
909
                        else gps_cmd = GPS_CMD_REQ_HOME;
910
                        n = GPS_CRTL(gps_cmd);
911
                }
912
                else
913
                {
914
                        if ( gps_cmd == GPS_CMD_REQ_HOME) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
915
                        else gps_cmd = GPS_CMD_REQ_HOLD;
916
                        n= GPS_CRTL(gps_cmd);
917
                }
918
        }
919
        else (n= GPS_CRTL(GPS_CMD_STOP)); //GPS Lageregelung beenden
920
 
1 ingob 921
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
922
//  Kompass
923
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
330 salvo 924
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (Kompass_present > 0))
1 ingob 925
     {
330 salvo 926
           if(v > w) w = v; // grösste Neigung ermitteln
927
 
928
// Salvo 13.9.2007 Nur wenn Magnetkompass ordentliche Werte liefert
929
                if ((magkompass_ok > 0)  &&  NeueKompassRichtungMerken)  
1 ingob 930
        {
330 salvo 931
                 KompassStartwert = KompassValue;
1 ingob 932
         NeueKompassRichtungMerken = 0;
933
        }
330 salvo 934
// Salvo 13.9.2007
935
       w=0;
936
// Salvo End
1 ingob 937
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
938
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
939
       if(w > 0)
940
        {
941
          ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
330 salvo 942
 
943
// Salvo Kompasssteuerung **********************        
944
                 if (magkompass_ok > 0) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
945
// Salvo End
1 ingob 946
          ANALOG_ON;  // ADC einschalten
947
        }  
330 salvo 948
 
1 ingob 949
     }
950
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
951
 
952
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
953
//  Debugwerte zuordnen
954
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
955
  if(!TimerWerteausgabe--)
956
   {
957
    TimerWerteausgabe = 49;
958
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
959
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
960
    DebugOut.Analog[2] = Mittelwert_AccNick;
961
    DebugOut.Analog[3] = Mittelwert_AccRoll;
962
    DebugOut.Analog[4] = MesswertGier;
963
    DebugOut.Analog[5] = HoehenWert;
964
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
965
    DebugOut.Analog[8] = KompassValue;
330 salvo 966
        DebugOut.Analog[9] = GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT;
173 holgerb 967
 
968
/*    DebugOut.Analog[16] = motor_rx[0];
969
    DebugOut.Analog[17] = motor_rx[1];
970
    DebugOut.Analog[18] = motor_rx[2];
971
    DebugOut.Analog[19] = motor_rx[3];
972
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
973
    DebugOut.Analog[20] /= 14;
974
    DebugOut.Analog[21] = motor_rx[4];
975
    DebugOut.Analog[22] = motor_rx[5];
976
    DebugOut.Analog[23] = motor_rx[6];
977
    DebugOut.Analog[24] = motor_rx[7];
978
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
979
*/
980
//    DebugOut.Analog[9] = MesswertNick;
1 ingob 981
//    DebugOut.Analog[9] = SollHoehe;
982
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
983
//    DebugOut.Analog[11] = KompassStartwert;
984
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
985
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
986
//    DebugOut.Analog[9] = KompassRichtung;    
987
//    DebugOut.Analog[10] = GasMischanteil;
988
//    DebugOut.Analog[3] = HoeheD * 32;
989
//    DebugOut.Analog[4] = hoehenregler;
990
  }
991
 
992
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
993
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
994
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 995
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
996
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
997
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
998
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
999
//    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
1000
    MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2;
1 ingob 1001
 
1002
    // Maximalwerte abfangen
1003
    #define MAX_SENSOR  2048
1004
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1005
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1006
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1007
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1008
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1009
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1010
 
1011
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1012
// Höhenregelung
1013
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1014
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1015
//OCR0B = 180 - (Poti1 + 120) / 4;
1016
//DruckOffsetSetting = OCR0B;
1017
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1018
  {
1019
    int tmp_int;
1020
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1021
    {
1022
     if(Parameter_MaxHoehe < 50)
1023
      {
1024
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1025
       HoehenReglerAktiv = 0;
1026
      }
1027
      else  
1028
        HoehenReglerAktiv = 1;
1029
    }
1030
    else
1031
    {
1032
     SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20;
1033
     HoehenReglerAktiv = 1;
1034
    }
1035
 
1036
    if(Notlandung) SollHoehe = 0;
1037
    h = HoehenWert;
1038
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1039
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1040
      h = GasMischanteil - h;         // vom Gas abziehen
1041
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1042
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1043
      if(tmp_int > 50) tmp_int = 50;
1044
      else if(tmp_int < -50) tmp_int = -50;
1045
      h -= tmp_int;
1046
      hoehenregler = (hoehenregler*15 + h) / 16;      
1047
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1048
       {
1049
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1050
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1051
       }  
1052
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1053
      GasMischanteil = hoehenregler;
1054
     }
1055
  }
1056
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1057
// + Mischer und PI-Regler
1058
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 1059
  DebugOut.Analog[7] = GasMischanteil;
1 ingob 1060
 
1061
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1062
// Gier-Anteil
1063
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
188 holgerb 1064
#define MUL_G  1.0
173 holgerb 1065
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1066
//GierMischanteil = 0;
1067
    if(GierMischanteil > (MUL_G * GasMischanteil))  GierMischanteil = MUL_G * GasMischanteil;
1068
    if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil);
188 holgerb 1069
    if(GierMischanteil > 100)  GierMischanteil = 100;
1070
    if(GierMischanteil < -100) GierMischanteil = -100;
173 holgerb 1071
 
188 holgerb 1072
    if(GasMischanteil < 20) GierMischanteil = 0;
1 ingob 1073
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1074
// Nick-Achse
1075
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
173 holgerb 1076
 
1 ingob 1077
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
1078
    SummeNick += DiffNick;                                   // I-Anteil
1079
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
1080
    if(SummeNick >  16000) SummeNick =  16000;
1081
    if(SummeNick < -16000) SummeNick = -16000;
173 holgerb 1082
    pd_ergebnis = DiffNick;// + Ki * SummeNick; // PI-Regler für Nick                                   
1 ingob 1083
    // Motor Vorn
173 holgerb 1084
#define MUL  2
188 holgerb 1085
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1086
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
173 holgerb 1087
 
1 ingob 1088
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
173 holgerb 1089
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1090
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1091
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1092
        Motor_Vorne = motorwert;           
1093
    // Motor Heck
1094
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
173 holgerb 1095
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1096
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1097
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1098
        Motor_Hinten = motorwert;              
1099
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1100
// Roll-Achse
1101
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1102
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
1103
        SummeRoll += DiffRoll;                                                              // I-Anteil
1104
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
1105
    if(SummeRoll >  16000) SummeRoll =  16000;
1106
    if(SummeRoll < -16000) SummeRoll = -16000;
173 holgerb 1107
    pd_ergebnis = DiffRoll;// + Ki * SummeRoll; // PI-Regler für Roll
188 holgerb 1108
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1109
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1 ingob 1110
    // Motor Links
1111
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
173 holgerb 1112
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1113
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1114
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1115
        Motor_Links = motorwert;               
1116
    // Motor Rechts
1117
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
173 holgerb 1118
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1119
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1120
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1121
        Motor_Rechts = motorwert;
1122
   // +++++++++++++++++++++++++++++++++++++++++++++++
1123
}
1124