Subversion Repositories FlightCtrl

Rev

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