Subversion Repositories FlightCtrl

Rev

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

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