Subversion Repositories FlightCtrl

Rev

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