Subversion Repositories FlightCtrl

Rev

Rev 127 | Details | Compare with Previous | Last modification | View Log | RSS feed

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