Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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