Subversion Repositories FlightCtrl

Rev

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

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