Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
425 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;
467 Nick666 71
int  KompassValue = 0;
72
int  KompassStartwert = 0;
73
int  KompassRichtung = 0;
455 Nick666 74
uint8_t updKompass = 0;
425 Nick666 75
unsigned char MAX_GAS,MIN_GAS;
76
unsigned char Notlandung = 0;
77
unsigned char HoehenReglerAktiv = 0;
78
 
79
float GyroFaktor;
80
float IntegralFaktor;
81
 
82
volatile int  DiffNick,DiffRoll;
83
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
84
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
85
unsigned char MotorWert[5];
86
volatile unsigned char SenderOkay = 0;
87
int StickNick = 0,StickRoll = 0,StickGier = 0;
88
char MotorenEin = 0;
89
int HoehenWert = 0;
90
int SollHoehe = 0;
91
 
92
float Kp =  FAKTOR_P;
93
float Ki =  FAKTOR_I;
94
 
95
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
96
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
97
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
98
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
99
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
100
unsigned char Parameter_Gyro_P = 50;            // Wert : 10-250
101
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
102
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
103
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
104
unsigned char Parameter_UserParam1 = 0;
105
unsigned char Parameter_UserParam2 = 0;
106
unsigned char Parameter_UserParam3 = 0;
107
unsigned char Parameter_UserParam4 = 0;
108
unsigned char Parameter_ServoNickControl = 100;
109
struct mk_param_struct EE_Parameter;
110
 
430 Nick666 111
struct acc_neutral_struct ee_acc_neutral EEMEM;         // Reservierung im EEPROM
425 Nick666 112
struct acc_neutral_struct acc_neutral;
113
 
114
void Piep(unsigned char Anzahl)
115
{
116
 while(Anzahl--)
117
 {
118
  if(MotorenEin) return; //auf keinen Fall im Flug!
119
  beeptime = 100;
120
  Delay_ms(250);
121
 }
122
}
123
 
124
 
125
//############################################################################
126
//  Neutrallage kalibrieren und fest im EEPROM abspeichern
127
void calib_acc(void)
128
//############################################################################
129
{
130
    unsigned int timer;
131
        acc_neutral.X = 0;
132
        acc_neutral.Y = 0;
133
        acc_neutral.Z = 0;
134
    CalibrierMittelwert();     
135
    timer = SetDelay(5);    
136
        while (!CheckDelay(timer));
137
        CalibrierMittelwert(); 
138
 
139
        acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
140
        acc_neutral.Y = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
141
        acc_neutral.Z = Aktuell_az;
142
 
143
        eeprom_write_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
144
}
145
 
146
//############################################################################
147
//  Nullwerte ermitteln
148
void SetNeutral(void)
149
//############################################################################
150
{
151
    unsigned int timer;
152
        acc_neutral.X = 0;
153
        acc_neutral.Y = 0;
154
        acc_neutral.Z = 0;
155
    AdNeutralNick = 0; 
156
        AdNeutralRoll = 0;     
157
        AdNeutralGier = 0;
158
    CalibrierMittelwert();     
159
    timer = SetDelay(5);    
160
        while (!CheckDelay(timer));
161
        CalibrierMittelwert();
162
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
163
     {    
164
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
165
     }
166
    AdNeutralNick= abs(MesswertNick);  
167
        AdNeutralRoll= abs(MesswertRoll);      
168
        AdNeutralGier= abs(MesswertGier);
169
 
170
        eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
171
 
172
        Mess_IntegralNick = 0; 
173
    Mess_IntegralNick2 = 0;
174
    Mess_IntegralRoll = 0;     
175
    Mess_IntegralRoll2 = 0;
176
    Mess_Integral_Gier = 0;    
177
    MesswertNick = 0;
178
    MesswertRoll = 0;
179
    MesswertGier = 0;
180
    StartLuftdruck = Luftdruck;
181
    HoeheD = 0;
182
    Mess_Integral_Hoch = 0;
183
    KompassStartwert = KompassValue;
184
    GPS_Neutral();
185
    beeptime = 50;  
186
}
187
 
188
//############################################################################
189
// Bildet den Mittelwert aus den Messwerten
190
void Mittelwert(void)
191
//############################################################################
192
{      
193
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
194
    ANALOG_OFF;
195
        if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
196
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
197
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
198
        if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L;
199
        if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L;
200
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L;
201
    AccumulateNick = 0;   MessanzahlNick = 0;
202
    AccumulateRoll = 0;   MessanzahlRoll = 0;
203
    AccumulateGier = 0;   MessanzahlGier = 0;
204
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
205
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
206
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
207
    Integral_Gier  = Mess_Integral_Gier;
208
//    Integral_Gier2 = Mess_Integral_Gier2;
209
    IntegralNick = Mess_IntegralNick;
210
    IntegralRoll = Mess_IntegralRoll;
211
    IntegralNick2 = Mess_IntegralNick2;
212
    IntegralRoll2 = Mess_IntegralRoll2;
213
    // ADC einschalten
214
    ANALOG_ON; 
215
 
216
/*
217
//------------------------------------------------------------------------------
218
    if(MesswertNick > 200)  MesswertNick += 4 * (MesswertNick - 200);
219
    else                                         
220
    if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
221
 
222
    if(MesswertRoll > 200)  MesswertRoll += 4 * (MesswertRoll - 200);
223
    else                                         
224
    if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
225
//------------------------------------------------------------------------------
226
*/
227
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
228
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
229
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
230
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
231
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
232
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
233
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
234
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
235
}
236
 
237
//############################################################################
238
// Messwerte beim Ermitteln der Nullage
239
void CalibrierMittelwert(void)
240
//############################################################################
241
{                
242
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
243
        ANALOG_OFF;
244
    if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
245
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
246
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
247
        if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick);
248
        if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll;
249
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch;
250
    AccumulateNick = 0;   MessanzahlNick = 0;
251
    AccumulateRoll = 0;   MessanzahlRoll = 0;
252
    AccumulateGier = 0;   MessanzahlGier = 0;
253
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
254
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
255
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
256
    // ADC einschalten
257
    ANALOG_ON; 
258
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
259
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
260
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
261
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
262
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
263
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
264
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
265
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
266
}
267
 
268
//############################################################################
269
// Senden der Motorwerte per I2C-Bus
270
void SendMotorData(void)
271
//############################################################################
272
{
273
    if(MOTOR_OFF || !MotorenEin)
274
        {
275
        Motor_Hinten = 0;
276
        Motor_Vorne = 0;
277
        Motor_Rechts = 0;
278
        Motor_Links = 0;
279
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
280
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
281
        if(MotorTest[2]) Motor_Links = MotorTest[2];
282
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
283
        }
284
 
285
    DebugOut.Analog[12] = Motor_Vorne;
286
    DebugOut.Analog[13] = Motor_Hinten;
287
    DebugOut.Analog[14] = Motor_Links;
288
    DebugOut.Analog[15] = Motor_Rechts;  
289
 
290
    //Start I2C Interrupt Mode
291
    twi_state = 0;
292
    motor = 0;
293
    i2c_start();
294
}
295
 
296
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
297
// + Konstanten 
298
// + 0-250 -> normale Werte
299
// + 251 -> Poti1
300
// + 252 -> Poti2
301
// + 253 -> Poti3
302
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
303
void DefaultKonstanten1(void)
304
{
305
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
306
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
307
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
308
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
309
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
310
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
311
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
312
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
313
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01;    
314
 EE_Parameter.Hoehe_MinGas = 30;
315
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
316
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
317
 EE_Parameter.Luftdruck_D  = 70;      // Wert : 0-250
318
 EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250
319
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
320
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
321
 EE_Parameter.Stick_D = 8; //8           // Wert : 0-64
322
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
323
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
324
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
325
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
326
 EE_Parameter.KompassWirkung = 16;    // Wert : 0-250
327
 EE_Parameter.Gyro_P = 120; //80          // Wert : 0-250
328
 EE_Parameter.Gyro_I = 150;               // Wert : 0-250
329
 EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250
330
 EE_Parameter.NotGas = 35;                // Wert : 0-250     // Gaswert bei Empangsverlust
331
 EE_Parameter.NotGasZeit = 20;            // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
332
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
333
 EE_Parameter.I_Faktor = 5;
433 Nick666 334
 EE_Parameter.UserParam1 = 178;             //zur freien Verwendung
335
 EE_Parameter.UserParam2 = 0;             //zur freien Verwendung
425 Nick666 336
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
337
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
338
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
339
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
340
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
341
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
342
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
343
 EE_Parameter.ServoNickRefresh = 5;
344
 memcpy(EE_Parameter.Name, "Normal\0", 12);  
345
}
346
 
347
void DefaultKonstanten2(void)
348
{
349
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
350
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
351
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
352
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
353
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
354
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
355
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
356
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01;    
357
 EE_Parameter.Hoehe_MinGas = 30;
358
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
359
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
360
 EE_Parameter.Luftdruck_D  = 50;      // Wert : 0-250
361
 EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250
362
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
363
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
364
 EE_Parameter.Stick_D = 0; //8           // Wert : 0-64
365
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
366
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
367
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
368
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
369
 EE_Parameter.KompassWirkung = 16;    // Wert : 0-250
370
 EE_Parameter.Gyro_P = 175; //80           // Wert : 0-250
371
 EE_Parameter.Gyro_I = 175;           // Wert : 0-250
372
 EE_Parameter.UnterspannungsWarnung = 90;  // Wert : 0-250
373
 EE_Parameter.NotGas = 35;                 // Wert : 0-250     // Gaswert bei Empangsverlust
374
 EE_Parameter.NotGasZeit = 20;             // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
375
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
376
 EE_Parameter.I_Faktor = 5;
433 Nick666 377
 EE_Parameter.UserParam1 = 178;   //zur freien Verwendung
378
 EE_Parameter.UserParam2 = 0;   //zur freien Verwendung
425 Nick666 379
 EE_Parameter.UserParam3 = 0;   //zur freien Verwendung
380
 EE_Parameter.UserParam4 = 0;   //zur freien Verwendung
381
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
382
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
383
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
384
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
385
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
386
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
387
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
388
 EE_Parameter.ServoNickRefresh = 5;
389
 memcpy(EE_Parameter.Name, "Kamera\0", 12);  
390
}
391
 
392
 
393
//############################################################################
394
// Trägt ggf. das Poti als Parameter ein
395
void ParameterZuordnung(void)
396
//############################################################################
397
{
398
 
399
 #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;}
400
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
401
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
402
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
403
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
404
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
405
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
406
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
407
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
408
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
409
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
410
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
411
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
412
 
413
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
414
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
415
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
416
 
417
 Ki = (float) Parameter_I_Faktor * 0.0001;
418
 MAX_GAS = EE_Parameter.Gas_Max;
419
 MIN_GAS = EE_Parameter.Gas_Min;
420
}
421
 
422
 
423
//############################################################################
424
//
425
void MotorRegler(void)
426
//############################################################################
427
{
428
         int motorwert,pd_ergebnis,h,tmp_int;
429
         int GierMischanteil,GasMischanteil;
430
     static long SummeNick=0,SummeRoll=0;
431
     static long sollGier = 0,tmp_long,tmp_long2;
432
     static int IntegralFehlerNick = 0;
433
     static int IntegralFehlerRoll = 0;
434
         static unsigned int RcLostTimer;
435
         static unsigned char delay_neutral = 0;
436
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
437
         static unsigned int  modell_fliegt = 0;
438
     static int hoehenregler = 0;
439
     static char TimerWerteausgabe = 0;
461 Nick666 440
     static char NeueKompassRichtungMerken = 1;
425 Nick666 441
        Mittelwert();
442
 
443
    GRN_ON;
444
 
445
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
446
// Gaswert ermitteln
447
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
448
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
449
    if(GasMischanteil < 0) GasMischanteil = 0;
450
 
451
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
452
// Emfang schlecht
453
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
454
   if(SenderOkay < 100)
455
        {
456
        if(!PcZugriff)  beeptime = 500;
457
        if(RcLostTimer) RcLostTimer--;
458
        else
459
         {
460
          MotorenEin = 0;
461
          Notlandung = 0;
462
         }
463
        ROT_ON;
464
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
465
            {
466
            GasMischanteil = EE_Parameter.NotGas;
467
            Notlandung = 1;
468
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
469
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
470
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
471
/*          Poti1 = 65;
472
            Poti2 = 48;
473
            Poti3 = 0;
474
*/          }
475
         else MotorenEin = 0;
476
        }
477
        else
478
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
479
// Emfang gut
480
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
481
        if(SenderOkay > 140)
482
            {
483
            Notlandung = 0;
484
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
485
            if(GasMischanteil > 40)
486
                {
487
                if(modell_fliegt < 0xffff) modell_fliegt++;
488
                }
489
            if((modell_fliegt < 200) || (GasMischanteil < 40))
490
                {
491
                SummeNick = 0;
492
                SummeRoll = 0;
493
                Mess_Integral_Gier = 0;
494
                Mess_Integral_Gier2 = 0;
495
                }
496
            if((GasMischanteil > 200) && MotorenEin == 0)
497
                {
498
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
499
// auf Nullwerte kalibrieren
500
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
501
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
502
                    {
503
                    unsigned char setting;
504
                    if(++delay_neutral > 200)  // nicht sofort
505
                        {
506
                        GRN_OFF;
507
                        SetNeutral();
508
                        MotorenEin = 0;
509
                        delay_neutral = 0;
510
                        modell_fliegt = 0;
511
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
512
                        {
513
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
514
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
515
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
516
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
517
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
518
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
519
                        }
520
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], sizeof(struct mk_param_struct));
521
                        Piep(GetActiveParamSetNumber());
522
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
523
                          {
524
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
525
                          }  
526
                        }
527
                    }
528
                 else delay_neutral = 0;
529
                }
530
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
531
// Gas ist unten
532
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
533
            if(GasMischanteil < 35)
534
                {
535
                // Starten
536
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
537
                    {
538
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
539
// Einschalten
540
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
541
                    if(++delay_einschalten > 200)
542
                        {
543
                        delay_einschalten = 200;
544
                        modell_fliegt = 1;
545
                        MotorenEin = 1;
546
                        sollGier = 0;
547
                        Mess_Integral_Gier = 0;
548
                        Mess_Integral_Gier2 = 0;
549
                        Mess_IntegralNick = 0;
550
                        Mess_IntegralRoll = 0;
551
                        Mess_IntegralNick2 = IntegralNick;
552
                        Mess_IntegralRoll2 = IntegralRoll;
553
                        SummeNick = 0;
554
                        SummeRoll = 0;
555
                        }          
556
                    }  
557
                    else delay_einschalten = 0;
558
                //Auf Neutralwerte setzen
559
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
560
// Auschalten
561
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
562
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
563
                    {
564
                    if(++delay_ausschalten > 200)  // nicht sofort
565
                        {
566
                        MotorenEin = 0;
567
                        delay_ausschalten = 200;
568
                        modell_fliegt = 0;
569
                        }
570
                    }
571
                else delay_ausschalten = 0;
572
                }
573
            }
574
 
575
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
576
// neue Werte von der Funke
577
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
578
 if(!NewPpmData-- || Notlandung)  
579
  {
580
    ParameterZuordnung();
581
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
582
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
583
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
584
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
585
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
586
 
587
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
588
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
589
 
590
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
591
    if(GyroFaktor < 0) GyroFaktor = 0;
592
    if(IntegralFaktor < 0) IntegralFaktor = 0;
593
  }
594
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
595
// Bei Empfangsausfall im Flug 
596
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
597
   if(Notlandung)
598
    {
599
     StickGier = 0;
600
     StickNick = 0;
601
     StickRoll = 0;
602
     GyroFaktor  = 0.1;
603
     IntegralFaktor = 0.005;
604
    }  
605
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
606
// Gyro-Drift kompensieren
607
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
608
#define DRIFT_FAKTOR 3
609
    if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR)
610
        {
611
        IntegralFehlerNick = IntegralNick2 - IntegralNick;
612
        IntegralFehlerRoll = IntegralRoll2 - IntegralRoll;
613
        ZaehlMessungen = 0;
614
        if(IntegralFehlerNick > 500/DRIFT_FAKTOR)   AdNeutralNick++;
615
        if(IntegralFehlerNick < -500/DRIFT_FAKTOR)  AdNeutralNick--;
616
        if(IntegralFehlerRoll > 500/DRIFT_FAKTOR)   AdNeutralRoll++;
617
        if(IntegralFehlerRoll < -500/DRIFT_FAKTOR)  AdNeutralRoll--;
618
        //if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR)  AdNeutralGier--;         
619
        //if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR)  AdNeutralGier++;         
620
    ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
621
        Mess_IntegralNick2 = IntegralNick;
622
        Mess_IntegralRoll2 = IntegralRoll;
623
        Mess_Integral_Gier2 = Integral_Gier;
624
    ANALOG_ON;  // ADC einschalten
625
        }
626
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
627
// Integrale auf ACC-Signal abgleichen
628
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
629
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16;  
630
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16;  
631
#define AUSGLEICH 500
632
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
633
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
634
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
635
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
636
 ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
637
    Mess_IntegralNick -= tmp_long;
638
    Mess_IntegralRoll -= tmp_long2;
639
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
640
//  Gieren
641
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
642
    sollGier = StickGier;
643
    if(abs(StickGier) > 35)
644
     {
645
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
646
     }
647
    tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo
648
    Mess_Integral_Gier -= tmp_int;  
649
    if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000;  // begrenzen
650
    if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000;
651
 
652
 ANALOG_ON;     // ADC einschalten
653
 
654
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
655
//  Kompass
656
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
657
    if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
658
     {
659
       int w,v;
455 Nick666 660
       static uint8_t SignalSchlecht = 0;
661
 
662
                if (!updKompass--)              // Aufruf mit ~10 Hz
663
                {
664
                        KompassValue = heading_MM3();
665
                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
666
                        updKompass = 50;
667
                }
668
 
425 Nick666 669
       w = abs(IntegralNick /1024); // mit zunehmender Neigung den Einfluss drosseln
670
       v = abs(IntegralRoll /1024);
671
       if(v > w) w = v; // grösste Neigung ermitteln
672
       if(w < 35 && NeueKompassRichtungMerken && !SignalSchlecht)    
673
        {
674
         KompassStartwert = KompassValue;
675
         NeueKompassRichtungMerken = 0;
676
        }
677
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
678
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
679
       if(w > 0)
461 Nick666 680
       {
681
                if(!SignalSchlecht)
682
                {
683
                        ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
684
                        Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
685
                        ANALOG_ON;  // ADC einschalten
686
                }
687
                else SignalSchlecht--;
688
 
689
       }  
690
       else SignalSchlecht = 250; // so lange das Signal taub stellen --> ca. 1/2 sek
425 Nick666 691
     }
692
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
693
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
694
 
695
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
696
//  Debugwerte zuordnen
697
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
698
DebugOut.Sekunden++;
699
  if(!TimerWerteausgabe--)
700
   {
701
    TimerWerteausgabe = 49;
702
//    DebugOut.Analog[0] = MesswertNick;
703
//    DebugOut.Analog[1] = MesswertRoll;
704
//    DebugOut.Analog[2] = MesswertGier;
705
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
706
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
707
 
708
    DebugOut.Analog[2] = Mittelwert_AccNick;
709
    DebugOut.Analog[3] = Mittelwert_AccRoll;
710
    DebugOut.Analog[4] = MesswertGier;
711
    DebugOut.Analog[5] = HoehenWert;
712
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
713
    DebugOut.Analog[7] = GasMischanteil;
714
    DebugOut.Analog[8] = KompassValue;
715
 
716
// Kanäle 9 bis 11 in compass.c
717
 
718
//    DebugOut.Analog[9] = SollHoehe;
719
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
720
//    DebugOut.Analog[11] = KompassStartwert;
721
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
722
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
723
//    DebugOut.Analog[9] = KompassRichtung;    
724
//    DebugOut.Analog[10] = GasMischanteil;
725
//    DebugOut.Analog[3] = HoeheD * 32;
726
//    DebugOut.Analog[4] = hoehenregler;
727
  }
728
 
729
 
730
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
731
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
732
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
733
    MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
734
    MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
735
    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;    
736
    // Maximalwerte abfangen
737
    #define MAX_SENSOR  2048
738
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
739
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
740
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
741
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
742
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
743
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
744
 
745
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
746
// Höhenregelung
747
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
748
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
749
//OCR0B = 180 - (Poti1 + 120) / 4;
750
//DruckOffsetSetting = OCR0B;
751
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
752
  {
753
    int tmp_int;
754
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
755
    {
756
     if(Parameter_MaxHoehe < 50)
757
      {
758
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
759
       HoehenReglerAktiv = 0;
760
      }
761
      else  
762
        HoehenReglerAktiv = 1;
763
    }
764
    else
765
    {
766
     SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20;
767
     HoehenReglerAktiv = 1;
768
    }
769
 
770
    if(Notlandung) SollHoehe = 0;
771
    h = HoehenWert;
772
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
773
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
774
      h = GasMischanteil - h;         // vom Gas abziehen
775
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
776
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
777
      if(tmp_int > 50) tmp_int = 50;
778
      else if(tmp_int < -50) tmp_int = -50;
779
      h -= tmp_int;
780
      hoehenregler = (hoehenregler*15 + h) / 16;      
781
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
782
       {
783
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
784
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
785
       }  
786
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
787
      GasMischanteil = hoehenregler;
788
     }
789
  }
790
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
791
// + Mischer und PI-Regler
792
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
793
 
794
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
795
// Gier-Anteil
796
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
797
        GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
798
    if(GierMischanteil > 100)  GierMischanteil = 100;
799
    if(GierMischanteil < -100) GierMischanteil = -100;
800
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
801
// Nick-Achse
802
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
803
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
804
    SummeNick += DiffNick;                                   // I-Anteil
805
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
806
    if(SummeNick >  16000) SummeNick =  16000;
807
    if(SummeNick < -16000) SummeNick = -16000;
808
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
809
    // Motor Vorn
810
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
811
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
812
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
813
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
814
        Motor_Vorne = motorwert;           
815
    // Motor Heck
816
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
817
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
818
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
819
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
820
        Motor_Hinten = motorwert;              
821
 
822
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
823
// Roll-Achse
824
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
825
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
826
        SummeRoll += DiffRoll;                                                              // I-Anteil
827
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
828
    if(SummeRoll >  16000) SummeRoll =  16000;
829
    if(SummeRoll < -16000) SummeRoll = -16000;
830
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
831
    // Motor Links
832
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
833
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
834
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
835
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
836
        Motor_Links = motorwert;               
837
    // Motor Rechts
838
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
839
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
840
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
841
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
842
        Motor_Rechts = motorwert;
843
   // +++++++++++++++++++++++++++++++++++++++++++++++
844
 
845
}
846