Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
366 Nick666 1
/*#######################################################################################
2
Flight Control
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + this list of conditions and the following disclaimer.
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +     from this software without specific prior written permission.
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +     clearly linked as origin 
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53
// +  POSSIBILITY OF SUCH DAMAGE. 
54
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
 
56
#include "main.h"
57
 
58
unsigned char h,m,s;
59
volatile unsigned char Timeout = 0;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch;
63
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
64
volatile long IntegralNick = 0,IntegralNick2 = 0;
65
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
66
volatile long Integral_Gier = 0;
67
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
68
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
69
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
70
volatile long Mess_Integral_Hoch = 0;
71
volatile int  KompassValue = 0;
72
volatile int  KompassStartwert = 0;
73
volatile int  KompassRichtung = 0;
74
unsigned char MAX_GAS,MIN_GAS;
75
unsigned char Notlandung = 0;
76
unsigned char HoehenReglerAktiv = 0;
77
 
78
float GyroFaktor;
79
float IntegralFaktor;
80
 
81
volatile int  DiffNick,DiffRoll;
82
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
83
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
84
unsigned char MotorWert[5];
85
volatile unsigned char SenderOkay = 0;
86
int StickNick = 0,StickRoll = 0,StickGier = 0;
87
char MotorenEin = 0;
88
int HoehenWert = 0;
89
int SollHoehe = 0;
90
 
91
float Kp =  FAKTOR_P;
92
float Ki =  FAKTOR_I;
93
 
94
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
95
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
96
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
97
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
98
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
99
unsigned char Parameter_Gyro_P = 50;            // Wert : 10-250
100
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
101
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
102
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
103
unsigned char Parameter_UserParam1 = 0;
104
unsigned char Parameter_UserParam2 = 0;
105
unsigned char Parameter_UserParam3 = 0;
106
unsigned char Parameter_UserParam4 = 0;
107
unsigned char Parameter_ServoNickControl = 100;
108
struct mk_param_struct EE_Parameter;
109
 
110
acc_neutral_struct ee_acc_neutral EEMEM;                // Reservierung im EEPROM
111
acc_neutral_struct acc_neutral;
112
 
113
void Piep(unsigned char Anzahl)
114
{
115
 while(Anzahl--)
116
 {
117
  if(MotorenEin) return; //auf keinen Fall im Flug!
118
  beeptime = 100;
119
  Delay_ms(250);
120
 }
121
}
122
 
123
 
124
//############################################################################
125
//  Neutrallage kalibrieren und fest im EEPROM abspeichern
369 Nick666 126
void calib_acc(void)
366 Nick666 127
//############################################################################
128
{
368 Nick666 129
    unsigned int timer;
130
        acc_neutral.X = 0;
131
        acc_neutral.Y = 0;
132
        acc_neutral.Z = 0;
366 Nick666 133
    CalibrierMittelwert();     
134
    timer = SetDelay(5);    
135
        while (!CheckDelay(timer));
368 Nick666 136
        CalibrierMittelwert(); 
366 Nick666 137
 
138
        acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
139
        acc_neutral.Y = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
140
        acc_neutral.Z = Aktuell_az;
141
 
142
        eeprom_write_block(&acc_neutral,&ee_acc_neutral,sizeof(acc_neutral_struct));
143
}
144
 
145
//############################################################################
146
//  Nullwerte ermitteln
147
void SetNeutral(void)
148
//############################################################################
149
{
150
    unsigned int timer;
151
        acc_neutral.X = 0;
152
        acc_neutral.Y = 0;
153
        acc_neutral.Z = 0;
154
    AdNeutralNick = 0; 
155
        AdNeutralRoll = 0;     
156
        AdNeutralGier = 0;
157
    CalibrierMittelwert();     
158
    timer = SetDelay(5);    
159
        while (!CheckDelay(timer));
160
        CalibrierMittelwert();
161
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
162
     {    
163
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
164
     }
165
    AdNeutralNick= abs(MesswertNick);  
166
        AdNeutralRoll= abs(MesswertRoll);      
167
        AdNeutralGier= abs(MesswertGier);
168
 
169
        eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(acc_neutral_struct));
170
 
171
        Mess_IntegralNick = 0; 
172
    Mess_IntegralNick2 = 0;
173
    Mess_IntegralRoll = 0;     
174
    Mess_IntegralRoll2 = 0;
175
    Mess_Integral_Gier = 0;    
176
    MesswertNick = 0;
177
    MesswertRoll = 0;
178
    MesswertGier = 0;
179
    StartLuftdruck = Luftdruck;
180
    HoeheD = 0;
181
    Mess_Integral_Hoch = 0;
182
    KompassStartwert = KompassValue;
183
    GPS_Neutral();
184
    beeptime = 50;  
185
}
186
 
187
//############################################################################
188
// Bildet den Mittelwert aus den Messwerten
189
void Mittelwert(void)
190
//############################################################################
191
{      
192
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
193
    ANALOG_OFF;
194
        if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
195
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
196
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
197
        if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L;
198
        if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L;
199
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L;
200
    AccumulateNick = 0;   MessanzahlNick = 0;
201
    AccumulateRoll = 0;   MessanzahlRoll = 0;
202
    AccumulateGier = 0;   MessanzahlGier = 0;
203
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
204
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
205
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
206
    Integral_Gier  = Mess_Integral_Gier;
207
//    Integral_Gier2 = Mess_Integral_Gier2;
208
    IntegralNick = Mess_IntegralNick;
209
    IntegralRoll = Mess_IntegralRoll;
210
    IntegralNick2 = Mess_IntegralNick2;
211
    IntegralRoll2 = Mess_IntegralRoll2;
212
    // ADC einschalten
213
    ANALOG_ON; 
214
 
215
//------------------------------------------------------------------------------
216
    if(MesswertNick > 200)  MesswertNick += 4 * (MesswertNick - 200);
217
    else                                         
218
    if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
219
 
220
    if(MesswertRoll > 200)  MesswertRoll += 4 * (MesswertRoll - 200);
221
    else                                         
222
    if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
223
//------------------------------------------------------------------------------
224
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
225
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
226
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
227
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
228
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
229
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
230
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
231
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
232
}
233
 
234
//############################################################################
235
// Messwerte beim Ermitteln der Nullage
236
void CalibrierMittelwert(void)
237
//############################################################################
238
{                
239
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
240
        ANALOG_OFF;
241
    if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
242
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
243
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
244
        if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick);
245
        if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll;
246
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch;
247
    AccumulateNick = 0;   MessanzahlNick = 0;
248
    AccumulateRoll = 0;   MessanzahlRoll = 0;
249
    AccumulateGier = 0;   MessanzahlGier = 0;
250
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
251
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
252
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
253
    // ADC einschalten
254
    ANALOG_ON; 
255
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
256
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
257
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
258
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
259
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
260
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
261
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
262
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
263
}
264
 
265
//############################################################################
266
// Senden der Motorwerte per I2C-Bus
267
void SendMotorData(void)
268
//############################################################################
269
{
270
    if(MOTOR_OFF || !MotorenEin)
271
        {
272
        Motor_Hinten = 0;
273
        Motor_Vorne = 0;
274
        Motor_Rechts = 0;
275
        Motor_Links = 0;
276
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
277
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
278
        if(MotorTest[2]) Motor_Links = MotorTest[2];
279
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
280
        }
281
 
282
    DebugOut.Analog[12] = Motor_Vorne;
283
    DebugOut.Analog[13] = Motor_Hinten;
284
    DebugOut.Analog[14] = Motor_Links;
285
    DebugOut.Analog[15] = Motor_Rechts;  
286
 
287
    //Start I2C Interrupt Mode
288
    twi_state = 0;
289
    motor = 0;
290
    i2c_start();
291
}
292
 
293
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
294
// + Konstanten 
295
// + 0-250 -> normale Werte
296
// + 251 -> Poti1
297
// + 252 -> Poti2
298
// + 253 -> Poti3
299
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
300
void DefaultKonstanten1(void)
301
{
302
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
303
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
304
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
305
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
306
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
307
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
308
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
309
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
310
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01;    
311
 EE_Parameter.Hoehe_MinGas = 30;
312
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
313
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
314
 EE_Parameter.Luftdruck_D  = 70;      // Wert : 0-250
315
 EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250
316
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
317
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
318
 EE_Parameter.Stick_D = 8; //8           // Wert : 0-64
319
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
320
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
321
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
322
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
323
 EE_Parameter.KompassWirkung = 16;    // Wert : 0-250
324
 EE_Parameter.Gyro_P = 120; //80          // Wert : 0-250
325
 EE_Parameter.Gyro_I = 150;               // Wert : 0-250
326
 EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250
327
 EE_Parameter.NotGas = 35;                // Wert : 0-250     // Gaswert bei Empangsverlust
328
 EE_Parameter.NotGasZeit = 20;            // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
329
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
330
 EE_Parameter.I_Faktor = 5;
331
 EE_Parameter.UserParam1 = 120;             //zur freien Verwendung
332
 EE_Parameter.UserParam2 = 120;             //zur freien Verwendung
333
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
334
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
335
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
336
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
337
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
338
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
339
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
340
 EE_Parameter.ServoNickRefresh = 5;
341
 memcpy(EE_Parameter.Name, "Normal\0", 12);  
342
}
343
 
344
void DefaultKonstanten2(void)
345
{
346
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
347
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
348
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
349
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
350
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
351
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
352
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
353
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01;    
354
 EE_Parameter.Hoehe_MinGas = 30;
355
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
356
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
357
 EE_Parameter.Luftdruck_D  = 50;      // Wert : 0-250
358
 EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250
359
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
360
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
361
 EE_Parameter.Stick_D = 0; //8           // Wert : 0-64
362
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
363
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
364
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
365
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
366
 EE_Parameter.KompassWirkung = 16;    // Wert : 0-250
367
 EE_Parameter.Gyro_P = 175; //80           // Wert : 0-250
368
 EE_Parameter.Gyro_I = 175;           // Wert : 0-250
369
 EE_Parameter.UnterspannungsWarnung = 90;  // Wert : 0-250
370
 EE_Parameter.NotGas = 35;                 // Wert : 0-250     // Gaswert bei Empangsverlust
371
 EE_Parameter.NotGasZeit = 20;             // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
372
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
373
 EE_Parameter.I_Faktor = 5;
374
 EE_Parameter.UserParam1 = 120;   //zur freien Verwendung
375
 EE_Parameter.UserParam2 = 120;   //zur freien Verwendung
376
 EE_Parameter.UserParam3 = 0;   //zur freien Verwendung
377
 EE_Parameter.UserParam4 = 0;   //zur freien Verwendung
378
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
379
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
380
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
381
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
382
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
383
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
384
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
385
 EE_Parameter.ServoNickRefresh = 5;
386
 memcpy(EE_Parameter.Name, "Kamera\0", 12);  
387
}
388
 
389
 
390
//############################################################################
391
// Trägt ggf. das Poti als Parameter ein
392
void ParameterZuordnung(void)
393
//############################################################################
394
{
395
 
396
 #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;}
397
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
398
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
399
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
400
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
401
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
402
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
403
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
404
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
405
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
406
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
407
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
408
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
409
 
410
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
411
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
412
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
413
 
414
 Ki = (float) Parameter_I_Faktor * 0.0001;
415
 MAX_GAS = EE_Parameter.Gas_Max;
416
 MIN_GAS = EE_Parameter.Gas_Min;
417
}
418
 
419
 
420
//############################################################################
421
//
422
void MotorRegler(void)
423
//############################################################################
424
{
425
         int motorwert,pd_ergebnis,h,tmp_int;
426
         int GierMischanteil,GasMischanteil;
427
     static long SummeNick=0,SummeRoll=0;
428
     static long sollGier = 0,tmp_long,tmp_long2;
429
     static int IntegralFehlerNick = 0;
430
     static int IntegralFehlerRoll = 0;
431
         static unsigned int RcLostTimer;
432
         static unsigned char delay_neutral = 0;
433
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
434
         static unsigned int  modell_fliegt = 0;
435
     static int hoehenregler = 0;
436
     static char TimerWerteausgabe = 0;
437
     static char NeueKompassRichtungMerken = 0;
438
        Mittelwert();
439
 
440
    GRN_ON;
441
 
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
443
// Gaswert ermitteln
444
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
445
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
446
    if(GasMischanteil < 0) GasMischanteil = 0;
447
 
448
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
449
// Emfang schlecht
450
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
451
   if(SenderOkay < 100)
452
        {
453
        if(!PcZugriff)  beeptime = 500;
454
        if(RcLostTimer) RcLostTimer--;
455
        else
456
         {
457
          MotorenEin = 0;
458
          Notlandung = 0;
459
         }
460
        ROT_ON;
461
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
462
            {
463
            GasMischanteil = EE_Parameter.NotGas;
464
            Notlandung = 1;
465
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
466
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
467
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
468
/*          Poti1 = 65;
469
            Poti2 = 48;
470
            Poti3 = 0;
471
*/          }
472
         else MotorenEin = 0;
473
        }
474
        else
475
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
476
// Emfang gut
477
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
478
        if(SenderOkay > 140)
479
            {
480
            Notlandung = 0;
481
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
482
            if(GasMischanteil > 40)
483
                {
484
                if(modell_fliegt < 0xffff) modell_fliegt++;
485
                }
486
            if((modell_fliegt < 200) || (GasMischanteil < 40))
487
                {
488
                SummeNick = 0;
489
                SummeRoll = 0;
490
                Mess_Integral_Gier = 0;
491
                Mess_Integral_Gier2 = 0;
492
                }
493
            if((GasMischanteil > 200) && MotorenEin == 0)
494
                {
495
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
496
// auf Nullwerte kalibrieren
497
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
498
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
499
                    {
500
                    unsigned char setting;
501
                    if(++delay_neutral > 200)  // nicht sofort
502
                        {
503
                        GRN_OFF;
504
                        SetNeutral();
505
                        MotorenEin = 0;
506
                        delay_neutral = 0;
507
                        modell_fliegt = 0;
508
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
509
                        {
510
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
511
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
512
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
513
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
514
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
515
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
516
                        }
517
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
518
                        Piep(GetActiveParamSetNumber());
519
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
520
                          {
521
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
522
                          }  
523
                        }
524
                    }
525
                 else delay_neutral = 0;
526
                }
527
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
528
// Gas ist unten
529
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
530
            if(GasMischanteil < 35)
531
                {
532
                // Starten
533
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
534
                    {
535
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
536
// Einschalten
537
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
538
                    if(++delay_einschalten > 200)
539
                        {
540
                        delay_einschalten = 200;
541
                        modell_fliegt = 1;
542
                        MotorenEin = 1;
543
                        sollGier = 0;
544
                        Mess_Integral_Gier = 0;
545
                        Mess_Integral_Gier2 = 0;
546
                        Mess_IntegralNick = 0;
547
                        Mess_IntegralRoll = 0;
548
                        Mess_IntegralNick2 = IntegralNick;
549
                        Mess_IntegralRoll2 = IntegralRoll;
550
                        SummeNick = 0;
551
                        SummeRoll = 0;
552
                        }          
553
                    }  
554
                    else delay_einschalten = 0;
555
                //Auf Neutralwerte setzen
556
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
557
// Auschalten
558
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
559
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
560
                    {
561
                    if(++delay_ausschalten > 200)  // nicht sofort
562
                        {
563
                        MotorenEin = 0;
564
                        delay_ausschalten = 200;
565
                        modell_fliegt = 0;
566
                        }
567
                    }
568
                else delay_ausschalten = 0;
569
                }
570
            }
571
 
572
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
573
// neue Werte von der Funke
574
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
575
 if(!NewPpmData-- || Notlandung)  
576
  {
577
    ParameterZuordnung();
578
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
579
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
580
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
581
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
582
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
583
 
584
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
585
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
586
 
587
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
588
    if(GyroFaktor < 0) GyroFaktor = 0;
589
    if(IntegralFaktor < 0) IntegralFaktor = 0;
590
  }
591
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
592
// Bei Empfangsausfall im Flug 
593
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
594
   if(Notlandung)
595
    {
596
     StickGier = 0;
597
     StickNick = 0;
598
     StickRoll = 0;
599
     GyroFaktor  = 0.1;
600
     IntegralFaktor = 0.005;
601
    }  
602
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
603
// Gyro-Drift kompensieren
604
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
605
#define DRIFT_FAKTOR 3
606
    if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR)
607
        {
608
        IntegralFehlerNick = IntegralNick2 - IntegralNick;
609
        IntegralFehlerRoll = IntegralRoll2 - IntegralRoll;
610
        ZaehlMessungen = 0;
611
        if(IntegralFehlerNick > 500/DRIFT_FAKTOR)   AdNeutralNick++;
612
        if(IntegralFehlerNick < -500/DRIFT_FAKTOR)  AdNeutralNick--;
613
        if(IntegralFehlerRoll > 500/DRIFT_FAKTOR)   AdNeutralRoll++;
614
        if(IntegralFehlerRoll < -500/DRIFT_FAKTOR)  AdNeutralRoll--;
615
        //if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR)  AdNeutralGier--;         
616
        //if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR)  AdNeutralGier++;         
617
    ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
618
        Mess_IntegralNick2 = IntegralNick;
619
        Mess_IntegralRoll2 = IntegralRoll;
620
        Mess_Integral_Gier2 = Integral_Gier;
621
    ANALOG_ON;  // ADC einschalten
622
        }
623
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
624
// Integrale auf ACC-Signal abgleichen
625
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
626
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16;  
627
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16;  
628
#define AUSGLEICH 500
629
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
630
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
631
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
632
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
633
 ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
634
    Mess_IntegralNick -= tmp_long;
635
    Mess_IntegralRoll -= tmp_long2;
636
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
637
//  Gieren
638
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
639
    sollGier = StickGier;
640
    if(abs(StickGier) > 35)
641
     {
642
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
643
     }
644
    tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo
645
    Mess_Integral_Gier -= tmp_int;  
646
    if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000;  // begrenzen
647
    if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000;
648
 
649
 ANALOG_ON;     // ADC einschalten
650
 
651
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
652
//  Kompass
653
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
654
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
655
     {
656
       if(NeueKompassRichtungMerken)    
657
        {
658
         KompassStartwert = KompassValue;
659
         NeueKompassRichtungMerken = 0;
660
        }
661
       ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
662
       Mess_Integral_Gier -= (KompassRichtung * Parameter_KompassWirkung) / 32;  // nach Kompass ausrichten
663
       ANALOG_ON;  // ADC einschalten
664
     }
665
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
666
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
667
 
668
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
669
//  Debugwerte zuordnen
670
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
671
DebugOut.Sekunden++;
672
  if(!TimerWerteausgabe--)
673
   {
674
    TimerWerteausgabe = 49;
675
//    DebugOut.Analog[0] = MesswertNick;
676
//    DebugOut.Analog[1] = MesswertRoll;
677
//    DebugOut.Analog[2] = MesswertGier;
678
//    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
679
//    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
680
 
681
    DebugOut.Analog[0] = MM3.NickGrad;
682
    DebugOut.Analog[1] = MM3.RollGrad;
683
    DebugOut.Analog[2] = Mittelwert_AccNick;
684
    DebugOut.Analog[3] = Mittelwert_AccRoll;
685
    DebugOut.Analog[4] = MesswertGier;
686
    DebugOut.Analog[5] = HoehenWert;
687
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
688
    DebugOut.Analog[7] = GasMischanteil;
689
    DebugOut.Analog[8] = KompassValue;
371 Nick666 690
 
366 Nick666 691
DebugOut.Analog[9] = MM3.x_axis;
692
DebugOut.Analog[10] = MM3.y_axis;
693
DebugOut.Analog[11] = MM3.z_axis;
694
 
695
//    DebugOut.Analog[9] = SollHoehe;
696
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
697
//    DebugOut.Analog[11] = KompassStartwert;
698
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
699
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
700
//    DebugOut.Analog[9] = KompassRichtung;    
701
//    DebugOut.Analog[10] = GasMischanteil;
702
//    DebugOut.Analog[3] = HoeheD * 32;
703
//    DebugOut.Analog[4] = hoehenregler;
704
  }
705
 
706
 
707
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
708
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
709
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
710
    MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
711
    MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
712
    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;    
713
    // Maximalwerte abfangen
714
    #define MAX_SENSOR  2048
715
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
716
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
717
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
718
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
719
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
720
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
721
 
722
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
723
// Höhenregelung
724
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
725
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
726
//OCR0B = 180 - (Poti1 + 120) / 4;
727
//DruckOffsetSetting = OCR0B;
728
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
729
  {
730
    int tmp_int;
731
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
732
    {
733
     if(Parameter_MaxHoehe < 50)
734
      {
735
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
736
       HoehenReglerAktiv = 0;
737
      }
738
      else  
739
        HoehenReglerAktiv = 1;
740
    }
741
    else
742
    {
743
     SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20;
744
     HoehenReglerAktiv = 1;
745
    }
746
 
747
    if(Notlandung) SollHoehe = 0;
748
    h = HoehenWert;
749
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
750
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
751
      h = GasMischanteil - h;         // vom Gas abziehen
752
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
753
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
754
      if(tmp_int > 50) tmp_int = 50;
755
      else if(tmp_int < -50) tmp_int = -50;
756
      h -= tmp_int;
757
      hoehenregler = (hoehenregler*15 + h) / 16;      
758
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
759
       {
760
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
761
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
762
       }  
763
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
764
      GasMischanteil = hoehenregler;
765
     }
766
  }
767
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
768
// + Mischer und PI-Regler
769
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
770
 
771
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
772
// Gier-Anteil
773
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
774
        GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
775
    if(GierMischanteil > 100)  GierMischanteil = 100;
776
    if(GierMischanteil < -100) GierMischanteil = -100;
777
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
778
// Nick-Achse
779
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
780
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
781
    SummeNick += DiffNick;                                   // I-Anteil
782
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
783
    if(SummeNick >  16000) SummeNick =  16000;
784
    if(SummeNick < -16000) SummeNick = -16000;
785
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
786
    // Motor Vorn
787
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
788
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
789
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
790
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
791
        Motor_Vorne = motorwert;           
792
    // Motor Heck
793
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
794
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
795
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
796
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
797
        Motor_Hinten = motorwert;              
798
 
799
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
800
// Roll-Achse
801
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
802
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
803
        SummeRoll += DiffRoll;                                                              // I-Anteil
804
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
805
    if(SummeRoll >  16000) SummeRoll =  16000;
806
    if(SummeRoll < -16000) SummeRoll = -16000;
807
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
808
    // Motor Links
809
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
810
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
811
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
812
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
813
        Motor_Links = motorwert;               
814
    // Motor Rechts
815
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
816
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
817
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
818
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
819
        Motor_Rechts = motorwert;
820
   // +++++++++++++++++++++++++++++++++++++++++++++++
821
 
822
}
823