Subversion Repositories FlightCtrl

Rev

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