Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################
2
Flight Control
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1051 killagreg 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.
1 ingob 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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1051 killagreg 16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
1 ingob 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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1051 killagreg 27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
1 ingob 28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1051 killagreg 32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
1 ingob 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.
1051 killagreg 36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
1 ingob 37
// +     for non-commercial use (directly or indirectly)
1051 killagreg 38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
1 ingob 39
// +     with our written permission
1051 killagreg 40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// +     clearly linked as origin
831 hbuss 42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
1 ingob 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
492 hbuss 50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1 ingob 51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1051 killagreg 52
// +  POSSIBILITY OF SUCH DAMAGE.
1 ingob 53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1086 salvo 54
// Aenderungen von Peter Muehlenbrock ("Salvo") Stand 9.11.2008
55
/*
56
Driftkompensation fuer Gyros verbessert
57
Linearsensor optional mit fixem Neutralwert
58
Ersatzkompass abgeleitet aus Magnetkompass und Giergyro fuer nahezu neigungsunabhaengige Kompassfunktion
59
*/
1 ingob 60
 
61
#include "main.h"
395 hbuss 62
#include "eeprom.c"
1 ingob 63
 
64
unsigned char h,m,s;
173 holgerb 65
volatile unsigned int I2CTimeout = 100;
927 hbuss 66
volatile int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias;
1051 killagreg 67
int AdNeutralGierBias;
927 hbuss 68
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
69
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
805 hbuss 70
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
1 ingob 71
volatile float NeutralAccZ = 0;
72
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
693 hbuss 73
long IntegralNick = 0,IntegralNick2 = 0;
74
long IntegralRoll = 0,IntegralRoll2 = 0;
75
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
76
long Integral_Gier = 0;
77
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
78
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
79
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
80
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
1 ingob 81
volatile long Mess_Integral_Hoch = 0;
82
volatile int  KompassValue = 0;
83
volatile int  KompassStartwert = 0;
84
volatile int  KompassRichtung = 0;
693 hbuss 85
unsigned int  KompassSignalSchlecht = 500;
855 hbuss 86
unsigned char  MAX_GAS,MIN_GAS;
1 ingob 87
unsigned char Notlandung = 0;
88
unsigned char HoehenReglerAktiv = 0;
880 hbuss 89
unsigned char TrichterFlug = 0;
395 hbuss 90
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
693 hbuss 91
long  ErsatzKompass;
92
int   ErsatzKompassInGrad; // Kompasswert in Grad
93
int   GierGyroFehler = 0;
1086 salvo 94
//Salvo 12.10.2007
95
uint8_t magkompass_ok=0;
96
uint8_t gps_cmd = GPS_CMD_STOP;
97
static int       ubat_cnt =0;
98
static int gas_actual,gas_mittel; //Parameter fuer Gasreduzierung bei unterspannung
99
int w,v;
100
//Salvo End
101
 
102
 //Salvo 15.12.2007 Ersatzkompass und Giergyrokompensation
103
long GyroKomp_Int;
104
long int GyroGier_Comp;
105
int GyroKomp_Value; //  Der ermittelte Kompasswert aus Gyro und Magnetkompass
106
short int cnt_stickgier_zero =0;
107
int gyrogier_kompass;
108
//Salvo End
109
 
110
 //Salvo 2.1.2008 Allgemeine Debugvariablen
111
int debug_gp_0,debug_gp_1,debug_gp_2,debug_gp_3,debug_gp_4,debug_gp_5,debug_gp_6,debug_gp_7;
112
//Salvo End
1 ingob 113
float GyroFaktor;
114
float IntegralFaktor;
115
volatile int  DiffNick,DiffRoll;
1051 killagreg 116
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
1 ingob 117
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
118
volatile unsigned char SenderOkay = 0;
595 hbuss 119
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
1 ingob 120
char MotorenEin = 0;
121
int HoehenWert = 0;
122
int SollHoehe = 0;
498 hbuss 123
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
1 ingob 124
float Ki =  FAKTOR_I;
395 hbuss 125
unsigned char Looping_Nick = 0,Looping_Roll = 0;
126
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
1 ingob 127
 
128
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
129
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
130
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
131
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
132
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
173 holgerb 133
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
1 ingob 134
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
135
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
136
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
137
unsigned char Parameter_UserParam1 = 0;
138
unsigned char Parameter_UserParam2 = 0;
139
unsigned char Parameter_UserParam3 = 0;
140
unsigned char Parameter_UserParam4 = 0;
499 hbuss 141
unsigned char Parameter_UserParam5 = 0;
142
unsigned char Parameter_UserParam6 = 0;
143
unsigned char Parameter_UserParam7 = 0;
144
unsigned char Parameter_UserParam8 = 0;
1 ingob 145
unsigned char Parameter_ServoNickControl = 100;
173 holgerb 146
unsigned char Parameter_LoopGasLimit = 70;
395 hbuss 147
unsigned char Parameter_AchsKopplung1 = 0;
148
unsigned char Parameter_AchsGegenKopplung1 = 0;
499 hbuss 149
unsigned char Parameter_DynamicStability = 100;
921 hbuss 150
unsigned char Parameter_J16Bitmask;             // for the J16 Output
151
unsigned char Parameter_J16Timing;              // for the J16 Output
152
unsigned char Parameter_J17Bitmask;             // for the J17 Output
153
unsigned char Parameter_J17Timing;              // for the J17 Output
154
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
1051 killagreg 155
unsigned char Parameter_NaviGpsGain;
156
unsigned char Parameter_NaviGpsP;
157
unsigned char Parameter_NaviGpsI;
158
unsigned char Parameter_NaviGpsD;
159
unsigned char Parameter_NaviGpsACC;
1086 salvo 160
unsigned char Parameter_NaviStickThreshold; //salvo 16.10.2008      
993 hbuss 161
unsigned char Parameter_NaviOperatingRadius;
162
unsigned char Parameter_NaviWindCorrection;
163
unsigned char Parameter_NaviSpeedCompensation;
921 hbuss 164
unsigned char Parameter_ExternalControl;
1 ingob 165
struct mk_param_struct EE_Parameter;
492 hbuss 166
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
614 hbuss 167
int MaxStickNick = 0,MaxStickRoll = 0;
871 hbuss 168
unsigned int  modell_fliegt = 0;
921 hbuss 169
unsigned char MikroKopterFlags = 0;
1 ingob 170
 
1086 salvo 171
//Salvo 2.1.2008 Allgemeine Debugvariablen
172
int debug_gp_0,debug_gp_1,debug_gp_2,debug_gp_3,debug_gp_4,debug_gp_5,debug_gp_6,debug_gp_7;
173
//Salvo End
174
 
175
 
176
 
177
 
1 ingob 178
void Piep(unsigned char Anzahl)
179
{
180
 while(Anzahl--)
181
 {
182
  if(MotorenEin) return; //auf keinen Fall im Flug!
183
  beeptime = 100;
184
  Delay_ms(250);
185
 }
186
}
187
 
188
//############################################################################
189
//  Nullwerte ermitteln
190
void SetNeutral(void)
191
//############################################################################
192
{
1086 salvo 193
        // Salvo 9.12.2007
194
        RX_SWTCH_ON; //GPS Daten auf RX eingang schalten 
195
        // Salvo End
196
        NeutralAccX = 0;
1 ingob 197
        NeutralAccY = 0;
198
        NeutralAccZ = 0;
1051 killagreg 199
    AdNeutralNick = 0;
200
        AdNeutralRoll = 0;
1 ingob 201
        AdNeutralGier = 0;
927 hbuss 202
    AdNeutralGierBias = 0;
395 hbuss 203
    Parameter_AchsKopplung1 = 0;
204
    Parameter_AchsGegenKopplung1 = 0;
1036 hbuss 205
    ExpandBaro = 0;
1051 killagreg 206
    CalibrierMittelwert();
395 hbuss 207
    Delay_ms_Mess(100);
1 ingob 208
        CalibrierMittelwert();
209
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
1051 killagreg 210
     {
1 ingob 211
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
212
     }
173 holgerb 213
 
1051 killagreg 214
     AdNeutralNick= AdWertNick;
215
         AdNeutralRoll= AdWertRoll;
395 hbuss 216
         AdNeutralGier= AdWertGier;
927 hbuss 217
     AdNeutralGierBias = AdWertGier;
401 hbuss 218
     StartNeutralRoll = AdNeutralRoll;
219
     StartNeutralNick = AdNeutralNick;
1051 killagreg 220
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
513 hbuss 221
    {
222
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
223
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
224
          NeutralAccZ = Aktuell_az;
225
    }
1051 killagreg 226
    else
513 hbuss 227
    {
228
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
229
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
230
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
231
    }
1051 killagreg 232
 
233
        Mess_IntegralNick = 0;
1 ingob 234
    Mess_IntegralNick2 = 0;
1051 killagreg 235
    Mess_IntegralRoll = 0;
1 ingob 236
    Mess_IntegralRoll2 = 0;
1051 killagreg 237
    Mess_Integral_Gier = 0;
1 ingob 238
    MesswertNick = 0;
239
    MesswertRoll = 0;
240
    MesswertGier = 0;
927 hbuss 241
 Delay_ms_Mess(100);
1 ingob 242
    StartLuftdruck = Luftdruck;
243
    HoeheD = 0;
244
    Mess_Integral_Hoch = 0;
245
    KompassStartwert = KompassValue;
246
    GPS_Neutral();
1051 killagreg 247
    beeptime = 50;
882 hbuss 248
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
249
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
492 hbuss 250
    ExternHoehenValue = 0;
693 hbuss 251
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
252
    GierGyroFehler = 0;
723 hbuss 253
    SendVersionToNavi = 1;
921 hbuss 254
    LED_Init();
255
    MikroKopterFlags |= FLAG_CALIBRATE;
992 hbuss 256
    FromNaviCtrl_Value.Kalman_K = -1;
257
    FromNaviCtrl_Value.Kalman_MaxDrift = EE_Parameter.Driftkomp * 16;
258
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
1086 salvo 259
 
260
//Salvo 13.10.2007 Ersatzkompass und Gas
261
        GyroKomp_Int =  KompassValue * GIER_GRAD_FAKTOR; //Neu ab 15.10.2008
262
//      gas_mittel      =       30;
263
//      gas_actual      =       gas_mittel;
264
// Salvo End
265
 
1 ingob 266
}
267
 
268
//############################################################################
395 hbuss 269
// Bearbeitet die Messwerte
1 ingob 270
void Mittelwert(void)
271
//############################################################################
1051 killagreg 272
{
273
    static signed long tmpl,tmpl2;
395 hbuss 274
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
927 hbuss 275
    MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier;
395 hbuss 276
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
277
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
401 hbuss 278
 
604 hbuss 279
//DebugOut.Analog[26] = MesswertNick;
1086 salvo 280
//DebugOut.Analog[28] = MesswertRoll;
604 hbuss 281
 
395 hbuss 282
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
283
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
284
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
285
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
286
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
287
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
805 hbuss 288
    NaviAccNick    += AdWertAccNick;
289
    NaviAccRoll    += AdWertAccRoll;
290
    NaviCntAcc++;
513 hbuss 291
    IntegralAccZ    += Aktuell_az - NeutralAccZ;
395 hbuss 292
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
693 hbuss 293
            ErsatzKompass +=  MesswertGier;
1086 salvo 294
//Salvo 12.11.2007
295
                        GyroKomp_Int   += (long)MesswertGier;
296
                        GyroGier_Comp  += (long)MesswertGier;
297
//Salvo End
395 hbuss 298
            Mess_Integral_Gier +=  MesswertGier;
927 hbuss 299
//            Mess_Integral_Gier2 += MesswertGier;
693 hbuss 300
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
301
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
395 hbuss 302
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
303
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
304
         {
927 hbuss 305
            tmpl = (MesswertGierBias * Mess_IntegralNick) / 2048L;
395 hbuss 306
            tmpl *= Parameter_AchsKopplung1;  //125
880 hbuss 307
            tmpl /= 4096L;
927 hbuss 308
            tmpl2 = (MesswertGierBias * Mess_IntegralRoll) / 2048L;
395 hbuss 309
            tmpl2 *= Parameter_AchsKopplung1;
880 hbuss 310
            tmpl2 /= 4096L;
1051 killagreg 311
            if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
395 hbuss 312
         }
313
      else  tmpl = tmpl2 = 0;
314
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
315
            MesswertRoll += tmpl;
316
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
317
            Mess_IntegralRoll2 += MesswertRoll;
498 hbuss 318
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
1051 killagreg 319
            if(Mess_IntegralRoll > Umschlag180Roll)
395 hbuss 320
            {
882 hbuss 321
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
395 hbuss 322
             Mess_IntegralRoll2 = Mess_IntegralRoll;
1051 killagreg 323
            }
395 hbuss 324
            if(Mess_IntegralRoll <-Umschlag180Roll)
325
            {
882 hbuss 326
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
395 hbuss 327
             Mess_IntegralRoll2 = Mess_IntegralRoll;
1051 killagreg 328
            }
395 hbuss 329
            if(AdWertRoll < 15)   MesswertRoll = -1000;
330
            if(AdWertRoll <  7)   MesswertRoll = -2000;
401 hbuss 331
            if(PlatinenVersion == 10)
332
                         {
333
              if(AdWertRoll > 1010) MesswertRoll = +1000;
334
              if(AdWertRoll > 1017) MesswertRoll = +2000;
335
                         }
1051 killagreg 336
                         else
401 hbuss 337
                         {
338
              if(AdWertRoll > 2020) MesswertRoll = +1000;
339
              if(AdWertRoll > 2034) MesswertRoll = +2000;
340
                         }
395 hbuss 341
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
342
            MesswertNick -= tmpl2;
343
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
344
            Mess_IntegralNick2 += MesswertNick;
498 hbuss 345
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
882 hbuss 346
 
1051 killagreg 347
            if(Mess_IntegralNick > Umschlag180Nick)
882 hbuss 348
             {
349
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
350
              Mess_IntegralNick2 = Mess_IntegralNick;
1051 killagreg 351
             }
352
            if(Mess_IntegralNick <-Umschlag180Nick)
395 hbuss 353
            {
882 hbuss 354
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
395 hbuss 355
             Mess_IntegralNick2 = Mess_IntegralNick;
1051 killagreg 356
            }
395 hbuss 357
            if(AdWertNick < 15)   MesswertNick = -1000;
358
            if(AdWertNick <  7)   MesswertNick = -2000;
401 hbuss 359
            if(PlatinenVersion == 10)
360
                         {
361
              if(AdWertNick > 1010) MesswertNick = +1000;
362
              if(AdWertNick > 1017) MesswertNick = +2000;
363
                         }
1051 killagreg 364
                         else
401 hbuss 365
                         {
366
              if(AdWertNick > 2020) MesswertNick = +1000;
367
              if(AdWertNick > 2034) MesswertNick = +2000;
368
                         }
395 hbuss 369
//++++++++++++++++++++++++++++++++++++++++++++++++
370
// ADC einschalten
1051 killagreg 371
    ANALOG_ON;
395 hbuss 372
//++++++++++++++++++++++++++++++++++++++++++++++++
373
 
1 ingob 374
    Integral_Gier  = Mess_Integral_Gier;
375
    IntegralNick = Mess_IntegralNick;
376
    IntegralRoll = Mess_IntegralRoll;
1051 killagreg 377
    IntegralNick2 = Mess_IntegralNick2;
1 ingob 378
    IntegralRoll2 = Mess_IntegralRoll2;
379
 
395 hbuss 380
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
381
  {
382
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
1051 killagreg 383
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
395 hbuss 384
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
1051 killagreg 385
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
395 hbuss 386
  }
1 ingob 387
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
388
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
389
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
390
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
391
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
392
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
393
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
394
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
395
}
396
 
397
//############################################################################
398
// Messwerte beim Ermitteln der Nullage
399
void CalibrierMittelwert(void)
400
//############################################################################
1051 killagreg 401
{
1021 hbuss 402
    if(PlatinenVersion == 13) SucheGyroOffset();
1 ingob 403
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
404
        ANALOG_OFF;
395 hbuss 405
        MesswertNick = AdWertNick;
406
        MesswertRoll = AdWertRoll;
407
        MesswertGier = AdWertGier;
408
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
409
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
410
        Mittelwert_AccHoch = (long)AdWertAccHoch;
411
   // ADC einschalten
1051 killagreg 412
    ANALOG_ON;
1 ingob 413
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
414
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
415
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
416
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
417
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
418
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
419
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
420
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
395 hbuss 421
 
422
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
720 ingob 423
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
1 ingob 424
}
425
 
426
//############################################################################
427
// Senden der Motorwerte per I2C-Bus
428
void SendMotorData(void)
429
//############################################################################
1051 killagreg 430
{
921 hbuss 431
    if(!MotorenEin)
1 ingob 432
        {
433
        Motor_Hinten = 0;
434
        Motor_Vorne = 0;
435
        Motor_Rechts = 0;
436
        Motor_Links = 0;
437
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
438
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
439
        if(MotorTest[2]) Motor_Links = MotorTest[2];
440
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
921 hbuss 441
        MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
442
        } else MikroKopterFlags |= FLAG_MOTOR_RUN;
1 ingob 443
 
444
    DebugOut.Analog[12] = Motor_Vorne;
445
    DebugOut.Analog[13] = Motor_Hinten;
446
    DebugOut.Analog[14] = Motor_Links;
1051 killagreg 447
    DebugOut.Analog[15] = Motor_Rechts;
1 ingob 448
 
449
    //Start I2C Interrupt Mode
450
    twi_state = 0;
451
    motor = 0;
1051 killagreg 452
    i2c_start();
1 ingob 453
}
454
 
455
 
456
 
457
//############################################################################
458
// Trägt ggf. das Poti als Parameter ein
1051 killagreg 459
void ParameterZuordnung(void)
1 ingob 460
//############################################################################
461
{
921 hbuss 462
 #define CHK_POTI_MM(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;}
463
 #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; }
1 ingob 464
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
921 hbuss 465
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
466
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
1 ingob 467
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
468
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
921 hbuss 469
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
1 ingob 470
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
1051 killagreg 471
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
472
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
473
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
474
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
475
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
476
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
477
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
478
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
479
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
1 ingob 480
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
173 holgerb 481
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
395 hbuss 482
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
483
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
499 hbuss 484
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
921 hbuss 485
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
486
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
993 hbuss 487
 
1086 salvo 488
 CHK_POTI(Parameter_NaviGpsModeControl,EE_Parameter.NaviGpsModeControl,0,255);
489
 CHK_POTI(Parameter_NaviGpsGain,EE_Parameter.NaviGpsGain,0,255);
490
 CHK_POTI(Parameter_NaviGpsP,EE_Parameter.NaviGpsP,0,255);
491
 CHK_POTI(Parameter_NaviGpsI,EE_Parameter.NaviGpsI,0,255);
492
 CHK_POTI(Parameter_NaviGpsD,EE_Parameter.NaviGpsD,0,255);
493
 CHK_POTI(Parameter_NaviGpsACC,EE_Parameter.NaviGpsACC,0,255);
993 hbuss 494
// CHK_POTI_MM(Parameter_NaviOperatingRadius,EE_Parameter.NaviOperatingRadius,10,255);
495
// CHK_POTI(Parameter_NaviWindCorrection,EE_Parameter.NaviWindCorrection,0,255);
496
// CHK_POTI(Parameter_NaviSpeedCompensation,EE_Parameter.NaviSpeedCompensation,0,255);
497
 
921 hbuss 498
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
1 ingob 499
 
500
 Ki = (float) Parameter_I_Faktor * 0.0001;
501
 MAX_GAS = EE_Parameter.Gas_Max;
502
 MIN_GAS = EE_Parameter.Gas_Min;
503
}
504
 
505
 
819 hbuss 506
 
1 ingob 507
//############################################################################
508
//
509
void MotorRegler(void)
510
//############################################################################
511
{
512
         int motorwert,pd_ergebnis,h,tmp_int;
513
         int GierMischanteil,GasMischanteil;
514
     static long SummeNick=0,SummeRoll=0;
515
     static long sollGier = 0,tmp_long,tmp_long2;
395 hbuss 516
     static long IntegralFehlerNick = 0;
517
     static long IntegralFehlerRoll = 0;
1 ingob 518
         static unsigned int RcLostTimer;
519
         static unsigned char delay_neutral = 0;
520
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
521
     static int hoehenregler = 0;
522
     static char TimerWerteausgabe = 0;
523
     static char NeueKompassRichtungMerken = 0;
395 hbuss 524
     static long ausgleichNick, ausgleichRoll;
1086 salvo 525
 
526
        Mittelwert();
527
//****** GPS Daten holen ***************
528
        short int n;
529
        if (gps_alive_cnt > 0) gps_alive_cnt--; //Dekrementieren. Wenn 0 kommen keine ausreichenden GPS Meldungen (Timeout)
530
        n = Get_Rel_Position();
531
        if (n == 0)    
532
        {
533
                ROT_ON; //led blitzen lassen
534
        }
535
//******PROVISORISCH***************
1 ingob 536
    GRN_ON;
1051 killagreg 537
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 538
// Gaswert ermitteln
1051 killagreg 539
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
540
        GasMischanteil = StickGas;
831 hbuss 541
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
1051 killagreg 542
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
693 hbuss 543
// Empfang schlecht
1051 killagreg 544
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 545
   if(SenderOkay < 100)
546
        {
1051 killagreg 547
        if(!PcZugriff)
173 holgerb 548
         {
1051 killagreg 549
           if(BeepMuster == 0xffff)
550
            {
173 holgerb 551
             beeptime = 15000;
552
             BeepMuster = 0x0c00;
1051 killagreg 553
            }
173 holgerb 554
         }
1051 killagreg 555
        if(RcLostTimer) RcLostTimer--;
556
        else
1 ingob 557
         {
558
          MotorenEin = 0;
559
          Notlandung = 0;
1051 killagreg 560
         }
1 ingob 561
        ROT_ON;
693 hbuss 562
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
1 ingob 563
            {
564
            GasMischanteil = EE_Parameter.NotGas;
565
            Notlandung = 1;
744 hbuss 566
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
1051 killagreg 567
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
1 ingob 568
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
569
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
570
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
173 holgerb 571
            }
1 ingob 572
         else MotorenEin = 0;
573
        }
1051 killagreg 574
        else
575
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 576
// Emfang gut
1051 killagreg 577
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 578
        if(SenderOkay > 140)
579
            {
580
            Notlandung = 0;
581
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
921 hbuss 582
            if(GasMischanteil > 40 && MotorenEin)
1 ingob 583
                {
584
                if(modell_fliegt < 0xffff) modell_fliegt++;
585
                }
871 hbuss 586
            if((modell_fliegt < 256))
1 ingob 587
                {
588
                SummeNick = 0;
589
                SummeRoll = 0;
1051 killagreg 590
                if(modell_fliegt == 250)
918 hbuss 591
                 {
1051 killagreg 592
                  NeueKompassRichtungMerken = 1;
918 hbuss 593
                  sollGier = 0;
1051 killagreg 594
                  Mess_Integral_Gier = 0;
927 hbuss 595
//                  Mess_Integral_Gier2 = 0;
1051 killagreg 596
                 }
921 hbuss 597
                } else MikroKopterFlags |= FLAG_FLY;
1051 killagreg 598
 
595 hbuss 599
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
1 ingob 600
                {
1051 killagreg 601
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 602
// auf Nullwerte kalibrieren
1051 killagreg 603
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 604
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
605
                    {
606
                    if(++delay_neutral > 200)  // nicht sofort
607
                        {
608
                        GRN_OFF;
1086 salvo 609
                        SetNeutral();
1 ingob 610
                        MotorenEin = 0;
611
                        delay_neutral = 0;
612
                        modell_fliegt = 0;
613
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
614
                        {
304 ingob 615
                         unsigned char setting=1;
1 ingob 616
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
617
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
618
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
619
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
620
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
1063 killagreg 621
                         SetActiveParamSetNumber(setting);  // aktiven Datensatz merken
1 ingob 622
                        }
820 hbuss 623
//                        else
1051 killagreg 624
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
625
                          {
819 hbuss 626
                           WinkelOut.CalcState = 1;
627
                           beeptime = 1000;
628
                          }
629
                          else
1 ingob 630
                          {
819 hbuss 631
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
632
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
633
                            {
1 ingob 634
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
1051 killagreg 635
                            }
819 hbuss 636
                           SetNeutral();
637
                           Piep(GetActiveParamSetNumber());
1086 salvo 638
                                                        GPS_Save_Home(); //Daten sind jetzt hoffentlich verfuegbar
639
                                                        if (gps_home_position.status > 0 )
640
                                                        {
641
                                                                Delay_ms(1000);  //akustisch verkuenden dass GPS Home Daten da sind
642
                                                                beeptime = 1000;
643
                                                                Delay_ms(500);
644
                                                        }
819 hbuss 645
                         }
1051 killagreg 646
                        }
1 ingob 647
                    }
1051 killagreg 648
                 else
513 hbuss 649
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
650
                    {
651
                    if(++delay_neutral > 200)  // nicht sofort
652
                        {
653
                        GRN_OFF;
654
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
655
                        MotorenEin = 0;
656
                        delay_neutral = 0;
657
                        modell_fliegt = 0;
658
                        SetNeutral();
659
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
660
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
661
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
662
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
663
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
664
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
665
                        Piep(GetActiveParamSetNumber());
1051 killagreg 666
                        }
513 hbuss 667
                    }
1 ingob 668
                 else delay_neutral = 0;
669
                }
1051 killagreg 670
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 671
// Gas ist unten
1051 killagreg 672
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
595 hbuss 673
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
1 ingob 674
                {
675
                // Starten
676
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
677
                    {
1051 killagreg 678
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 679
// Einschalten
1051 killagreg 680
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 681
                    if(++delay_einschalten > 200)
682
                        {
1086 salvo 683
                                                int n;
684
                                                // Salvo 9.12.2007
685
                                                RX_SWTCH_ON; //GPS Daten auf RX eingang schalten 
686
                                                // Salvo End
1 ingob 687
                        delay_einschalten = 200;
688
                        modell_fliegt = 1;
689
                        MotorenEin = 1;
690
                        sollGier = 0;
1051 killagreg 691
                        Mess_Integral_Gier = 0;
1 ingob 692
                        Mess_Integral_Gier2 = 0;
693
                        Mess_IntegralNick = 0;
694
                        Mess_IntegralRoll = 0;
695
                        Mess_IntegralNick2 = IntegralNick;
696
                        Mess_IntegralRoll2 = IntegralRoll;
697
                        SummeNick = 0;
698
                        SummeRoll = 0;
1086 salvo 699
                        n= GPS_CRTL(GPS_CMD_STOP); //GPS Lageregelung beenden
700
 
921 hbuss 701
                        MikroKopterFlags |= FLAG_START;
1051 killagreg 702
                        }
703
                    }
1 ingob 704
                    else delay_einschalten = 0;
705
                //Auf Neutralwerte setzen
1051 killagreg 706
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 707
// Auschalten
1051 killagreg 708
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 709
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
710
                    {
711
                    if(++delay_ausschalten > 200)  // nicht sofort
712
                        {
1086 salvo 713
                                                // Salvo 9.12.2007
714
                                                RX_SWTCH_OFF; //Bluetooth Daten auf RX eingang schalten 
715
                                                // Salvo End
716
 
1 ingob 717
                        MotorenEin = 0;
718
                        delay_ausschalten = 200;
719
                        modell_fliegt = 0;
1051 killagreg 720
                        }
1 ingob 721
                    }
722
                else delay_ausschalten = 0;
723
                }
724
            }
725
 
1051 killagreg 726
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 727
// neue Werte von der Funke
1051 killagreg 728
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
729
 if(!NewPpmData-- || Notlandung)
1 ingob 730
  {
492 hbuss 731
    int tmp_int;
604 hbuss 732
        static int stick_nick,stick_roll;
1 ingob 733
    ParameterZuordnung();
1051 killagreg 734
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
723 hbuss 735
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
805 hbuss 736
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
1051 killagreg 737
//    StickNick  = (StickNick  * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
604 hbuss 738
 
723 hbuss 739
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
740
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
805 hbuss 741
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
723 hbuss 742
 
743
//    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
744
 
1 ingob 745
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
595 hbuss 746
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
747
 
1051 killagreg 748
/*   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick)
614 hbuss 749
     MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--;
1051 killagreg 750
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll)
614 hbuss 751
     MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--;
723 hbuss 752
*/
855 hbuss 753
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN);
754
    IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN);
1 ingob 755
 
595 hbuss 756
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
757
//+ Analoge Steuerung per Seriell
758
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
921 hbuss 759
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
595 hbuss 760
    {
761
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
762
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
763
         StickGier += ExternControl.Gier;
764
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
765
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
766
    }
855 hbuss 767
    if(StickGas < 0) StickGas = 0;
492 hbuss 768
 
1 ingob 769
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
770
    if(GyroFaktor < 0) GyroFaktor = 0;
771
    if(IntegralFaktor < 0) IntegralFaktor = 0;
723 hbuss 772
 
1051 killagreg 773
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
928 hbuss 774
     {
1051 killagreg 775
      MaxStickNick = abs(StickNick)/STICK_GAIN;
928 hbuss 776
      if(MaxStickNick > 100) MaxStickNick = 100;
1051 killagreg 777
     }
928 hbuss 778
     else MaxStickNick--;
1051 killagreg 779
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
928 hbuss 780
     {
1051 killagreg 781
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
928 hbuss 782
      if(MaxStickRoll > 100) MaxStickRoll = 100;
1051 killagreg 783
     }
928 hbuss 784
     else MaxStickRoll--;
723 hbuss 785
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
786
 
1051 killagreg 787
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173 holgerb 788
// Looping?
1051 killagreg 789
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
993 hbuss 790
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
1051 killagreg 791
  else
792
   {
395 hbuss 793
     {
1051 killagreg 794
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
795
     }
796
   }
993 hbuss 797
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
1051 killagreg 798
   else
395 hbuss 799
   {
800
   if(Looping_Rechts) // Hysterese
801
     {
802
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
803
     }
1051 killagreg 804
   }
173 holgerb 805
 
993 hbuss 806
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
1051 killagreg 807
  else
808
   {
395 hbuss 809
    if(Looping_Oben)  // Hysterese
810
     {
1051 killagreg 811
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
812
     }
813
   }
993 hbuss 814
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
1051 killagreg 815
   else
395 hbuss 816
   {
817
    if(Looping_Unten) // Hysterese
818
     {
819
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
820
     }
1051 killagreg 821
   }
395 hbuss 822
 
823
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
824
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
825
  } // Ende neue Funken-Werte
826
 
827
  if(Looping_Roll || Looping_Nick)
828
   {
173 holgerb 829
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
830
   }
831
 
1051 killagreg 832
 
833
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
834
// Bei Empfangsausfall im Flug
835
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 836
   if(Notlandung)
837
    {
838
     StickGier = 0;
839
     StickNick = 0;
840
     StickRoll = 0;
855 hbuss 841
     GyroFaktor     = (float) 100 / (256.0 / STICK_GAIN);
842
     IntegralFaktor = (float) 120 / (44000 / STICK_GAIN);
173 holgerb 843
     Looping_Roll = 0;
844
     Looping_Nick = 0;
1051 killagreg 845
    }
395 hbuss 846
 
847
 
1051 killagreg 848
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 849
// Integrale auf ACC-Signal abgleichen
1051 killagreg 850
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
395 hbuss 851
#define ABGLEICH_ANZAHL 256L
852
 
853
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
854
 MittelIntegralRoll  += IntegralRoll;
855
 MittelIntegralNick2 += IntegralNick2;
856
 MittelIntegralRoll2 += IntegralRoll2;
857
 
858
 if(Looping_Nick || Looping_Roll)
859
  {
860
    IntegralAccNick = 0;
861
    IntegralAccRoll = 0;
862
    MittelIntegralNick = 0;
863
    MittelIntegralRoll = 0;
864
    MittelIntegralNick2 = 0;
865
    MittelIntegralRoll2 = 0;
866
    Mess_IntegralNick2 = Mess_IntegralNick;
867
    Mess_IntegralRoll2 = Mess_IntegralRoll;
868
    ZaehlMessungen = 0;
498 hbuss 869
    LageKorrekturNick = 0;
870
    LageKorrekturRoll = 0;
395 hbuss 871
  }
872
 
1051 killagreg 873
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
498 hbuss 874
  if(!Looping_Nick && !Looping_Roll)
469 hbuss 875
  {
876
   long tmp_long, tmp_long2;
992 hbuss 877
   if(FromNaviCtrl_Value.Kalman_K != -1)
878
     {
879
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1051 killagreg 880
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
881
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
882
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
992 hbuss 883
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
884
      {
885
      tmp_long  /= 2;
886
      tmp_long2 /= 2;
887
      }
888
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
889
      {
890
      tmp_long  /= 3;
891
      tmp_long2 /= 3;
892
      }
893
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
894
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
895
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
896
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
897
     }
1051 killagreg 898
     else
992 hbuss 899
     {
900
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1051 killagreg 901
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
992 hbuss 902
      tmp_long /= 16;
903
      tmp_long2 /= 16;
904
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
905
      {
906
      tmp_long  /= 3;
907
      tmp_long2 /= 3;
908
      }
909
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
910
      {
911
      tmp_long  /= 3;
912
      tmp_long2 /= 3;
913
      }
614 hbuss 914
 #define AUSGLEICH 32
992 hbuss 915
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
916
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
917
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
918
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
919
     }
1051 killagreg 920
 
469 hbuss 921
    Mess_IntegralNick -= tmp_long;
922
    Mess_IntegralRoll -= tmp_long2;
923
  }
1051 killagreg 924
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
395 hbuss 925
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
926
 {
927
  static int cnt = 0;
928
  static char last_n_p,last_n_n,last_r_p,last_r_n;
929
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
880 hbuss 930
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug)
173 holgerb 931
  {
395 hbuss 932
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
933
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
934
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
935
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
936
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
492 hbuss 937
#define MAX_I 0//(Poti2/10)
395 hbuss 938
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
939
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
940
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
1051 killagreg 941
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
942
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
395 hbuss 943
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
614 hbuss 944
 
945
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
498 hbuss 946
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
395 hbuss 947
 
992 hbuss 948
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
614 hbuss 949
    {
950
     LageKorrekturNick /= 2;
720 ingob 951
     LageKorrekturRoll /= 2;
614 hbuss 952
    }
498 hbuss 953
 
1051 killagreg 954
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
395 hbuss 955
// Gyro-Drift ermitteln
1051 killagreg 956
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
395 hbuss 957
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
958
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
1051 killagreg 959
    tmp_long  = IntegralNick2 - IntegralNick;
960
    tmp_long2 = IntegralRoll2 - IntegralRoll;
395 hbuss 961
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
962
 
963
    IntegralFehlerNick = tmp_long;
964
    IntegralFehlerRoll = tmp_long2;
965
    Mess_IntegralNick2 -= IntegralFehlerNick;
966
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
967
 
968
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
969
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
927 hbuss 970
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
971
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
395 hbuss 972
 
1086 salvo 973
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
921 hbuss 974
//DebugOut.Analog[24] = GierGyroFehler;
693 hbuss 975
    GierGyroFehler = 0;
720 ingob 976
 
1086 salvo 977
//Salvo Ersatzkompass Ueberlauf korrigieren
978
                if (GyroKomp_Int >= ((long)360 * GIER_GRAD_FAKTOR)) GyroKomp_Int = GyroKomp_Int - (GIER_GRAD_FAKTOR *(long)360); //neu ab 3.11.2007
979
                if (GyroKomp_Int < 0) GyroKomp_Int = GyroKomp_Int + (GIER_GRAD_FAKTOR *(long)360); //neu ab 3.11.2007
980
                ROT_OFF;
981
// Salvo End
720 ingob 982
 
983
/*DebugOut.Analog[17] = IntegralAccNick / 26;
395 hbuss 984
DebugOut.Analog[18] = IntegralAccRoll / 26;
985
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
986
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
720 ingob 987
*/
988
//DebugOut.Analog[21] = MittelIntegralNick / 26;
989
//MittelIntegralRoll = MittelIntegralRoll;
469 hbuss 990
//DebugOut.Analog[28] = ausgleichNick;
720 ingob 991
/*
395 hbuss 992
DebugOut.Analog[29] = ausgleichRoll;
498 hbuss 993
DebugOut.Analog[30] = LageKorrekturRoll * 10;
720 ingob 994
*/
395 hbuss 995
 
492 hbuss 996
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
997
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
998
#define BEWEGUNGS_LIMIT 20000
395 hbuss 999
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1000
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
992 hbuss 1001
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*16))
492 hbuss 1002
        {
1051 killagreg 1003
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
395 hbuss 1004
         {
1051 killagreg 1005
           if(last_n_p)
395 hbuss 1006
           {
1051 killagreg 1007
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
492 hbuss 1008
            ausgleichNick = IntegralFehlerNick / 8;
401 hbuss 1009
            if(ausgleichNick > 5000) ausgleichNick = 5000;
498 hbuss 1010
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1051 killagreg 1011
           }
395 hbuss 1012
           else last_n_p = 1;
1013
         } else  last_n_p = 0;
1051 killagreg 1014
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
395 hbuss 1015
         {
1016
           if(last_n_n)
1051 killagreg 1017
            {
1018
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
492 hbuss 1019
             ausgleichNick = IntegralFehlerNick / 8;
401 hbuss 1020
             if(ausgleichNick < -5000) ausgleichNick = -5000;
498 hbuss 1021
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1051 killagreg 1022
            }
395 hbuss 1023
           else last_n_n = 1;
1024
         } else  last_n_n = 0;
1051 killagreg 1025
        }
1026
        else
847 hbuss 1027
        {
1028
         cnt = 0;
921 hbuss 1029
         KompassSignalSchlecht = 1000;
1051 killagreg 1030
        }
499 hbuss 1031
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
992 hbuss 1032
        if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift/16;
395 hbuss 1033
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1034
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
401 hbuss 1035
 
395 hbuss 1036
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
492 hbuss 1037
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1038
 
498 hbuss 1039
        ausgleichRoll = 0;
992 hbuss 1040
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*16))
492 hbuss 1041
        {
1051 killagreg 1042
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
395 hbuss 1043
         {
1051 killagreg 1044
           if(last_r_p)
395 hbuss 1045
           {
1051 killagreg 1046
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
492 hbuss 1047
            ausgleichRoll = IntegralFehlerRoll / 8;
401 hbuss 1048
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
498 hbuss 1049
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1051 killagreg 1050
           }
395 hbuss 1051
           else last_r_p = 1;
1052
         } else  last_r_p = 0;
1051 killagreg 1053
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
395 hbuss 1054
         {
1051 killagreg 1055
           if(last_r_n)
395 hbuss 1056
           {
1051 killagreg 1057
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
492 hbuss 1058
            ausgleichRoll = IntegralFehlerRoll / 8;
401 hbuss 1059
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
498 hbuss 1060
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
395 hbuss 1061
           }
1062
           else last_r_n = 1;
1063
         } else  last_r_n = 0;
1051 killagreg 1064
        } else
492 hbuss 1065
        {
1066
         cnt = 0;
921 hbuss 1067
         KompassSignalSchlecht = 1000;
1051 killagreg 1068
        }
499 hbuss 1069
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
992 hbuss 1070
        if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift/16;
395 hbuss 1071
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1072
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
173 holgerb 1073
  }
1051 killagreg 1074
  else
498 hbuss 1075
  {
1076
   LageKorrekturRoll = 0;
1077
   LageKorrekturNick = 0;
880 hbuss 1078
   TrichterFlug = 0;
498 hbuss 1079
  }
1051 killagreg 1080
 
498 hbuss 1081
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1051 killagreg 1082
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1083
   MittelIntegralNick_Alt = MittelIntegralNick;
1084
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1085
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
395 hbuss 1086
    IntegralAccNick = 0;
1087
    IntegralAccRoll = 0;
1088
    IntegralAccZ = 0;
1089
    MittelIntegralNick = 0;
1090
    MittelIntegralRoll = 0;
1091
    MittelIntegralNick2 = 0;
1092
    MittelIntegralRoll2 = 0;
1093
    ZaehlMessungen = 0;
1094
 }
469 hbuss 1095
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
1086 salvo 1096
// Salvo Ersatzkompass  und Giergyrokompensation 15.12.2007 **********************
1097
if ((Kompass_Neuer_Wert > 0)) //nur wenn Kompass einen neuen Wert geliefert hat
1098
{
1099
           Kompass_Neuer_Wert = 0;
1100
   w = (abs(Mittelwert_AccNick));
1101
   v = (abs(Mittelwert_AccRoll));
1102
   if  ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) //Ersatzkompass und Giergyro nur mit Magnetkompass aktualisieren wenn alles ok
1103
   {
1104
        if  ((abs(KompassValue - Kompass_Value_Old)) <= 5) // Aufeinanderfolgende Werte duerfen nur minimal abweichen
1105
        {
395 hbuss 1106
 
1086 salvo 1107
          if ((abs(StickGier) < 20)) //Giergyroabgleich mit Kompass
1108
          {
1109
                        if (cnt_stickgier_zero < 255) cnt_stickgier_zero += 1;
1110
                        if (cnt_stickgier_zero > 2) // nur Abgleichen wenn keine Stickbewegung da
1111
                        {
1112
                                w = (int) (GyroGier_Comp/(long)GIER_GRAD_FAKTOR);
1113
                                v = KompassValue - gyrogier_kompass; // realen Drehwinkel seit letztem Ruecksetzen von GyroGier_Comp bestimmen
1114
                                if (v <-180) v +=360; // Uberlaufkorrektur
1115
                                if (v > 180) v -=360; // Uberlaufkorrektur
1116
 
1117
                                v = w-v;  //Differenz Gyro zu Kompass ist der Driftfehler
1118
 
1119
                                #define GIER_COMP_MAX 4
1120
                                if (v > GIER_COMP_MAX)  v= GIER_COMP_MAX;
1121
                                if (v < -GIER_COMP_MAX) v= - GIER_COMP_MAX;
1122
                                if (abs(w) > 1)
1123
                                {      
1124
                                        GyroGier_Comp           = 0;
1125
                                        gyrogier_kompass        = KompassValue; // Kompasswert merken
1126
                                        AdNeutralGier           -= v;  
1127
                                }
1128
                        }
1129
          }
1130
          else
1131
          {
1132
                gyrogier_kompass        = KompassValue; // Kompasswert merken
1133
                cnt_stickgier_zero      = 0;
1134
                GyroGier_Comp = 0;
1135
          }
1136
 
1137
          magkompass_ok = 1; // Flag dass Magnetkompass stabil arbeitet 
1138
          GyroKomp_Int = (GyroKomp_Int )/(long)GIER_GRAD_FAKTOR;
1139
 
1140
          w = KompassValue - GyroKomp_Int;
1141
          if ((w > 0) && (w < 180))
1142
          {
1143
           ++GyroKomp_Int;
1144
          }
1145
          else if ((w > 0) && (w >= 180))
1146
          {
1147
           --GyroKomp_Int;
1148
          }
1149
          else if ((w < 0) && (w >= -180))
1150
          {
1151
           --GyroKomp_Int;
1152
          }
1153
          else if ((w < 0) && (w < -180))
1154
          {
1155
           ++GyroKomp_Int;
1156
          }
1157
          if (GyroKomp_Int < 0)  GyroKomp_Int = GyroKomp_Int + 360L;
1158
          GyroKomp_Int = (GyroKomp_Int%360L) * (long)GIER_GRAD_FAKTOR; // An Magnetkompasswert annaehern
1159
        }
1160
   }
1161
   else //Kompassfehler
1162
   {
1163
    magkompass_ok = 0;
1164
        GyroGier_Comp = 0;
1165
   }
1166
   Kompass_Value_Old    =       KompassValue;
1167
}
1168
// Salvo End *************************
1169
 
1170
// Salvo 6.10.2007 
1171
        // GPS Home aktivieren wenn Knueppel in Ruhelage und Hoehenschalter aktiviert ist
1172
        //GPS Hold Aktiveren wenn Knueppel in Ruhelage sind
1173
        if ((abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) < Parameter_NaviStickThreshold)
1174
        && (abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < Parameter_NaviStickThreshold) && (gps_alive_cnt > 0))
1175
        {
1176
                if ((Parameter_NaviGpsModeControl > 170) && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) //Hoehenschalter und GPS Flag aktiv
1177
                {      
1178
                        if ( gps_cmd == GPS_CMD_REQ_HOLD) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
1179
                        else gps_cmd = GPS_CMD_REQ_HOME;
1180
                        n = GPS_CRTL(gps_cmd);
1181
                }
1182
                else if ((Parameter_NaviGpsModeControl < 170) && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) //Hoehenschalter Mittelstellung und GPS Flag aktiv
1183
                {
1184
                        if ( gps_cmd == GPS_CMD_REQ_HOME) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet
1185
                        else gps_cmd = GPS_CMD_REQ_HOLD;
1186
                        n= GPS_CRTL(gps_cmd);
1187
                }
1188
                else  // GPS komplett aus
1189
                {
1190
                        if (gps_cmd != GPS_CMD_STOP)
1191
                        {
1192
                                gps_cmd = GPS_CMD_STOP;
1193
                                n= GPS_CRTL(gps_cmd); //GPS Lageregelung beenden
1194
                        }
1195
                }
1196
        }
1197
        else
1198
        {
1199
                if (gps_cmd != GPS_CMD_STOP)
1200
                {
1201
                        gps_cmd = GPS_CMD_STOP;
1202
                        n= GPS_CRTL(gps_cmd); //GPS Lageregelung beenden
1203
                }
1204
        }
1205
        if (gps_state != GPS_CRTL_IDLE) if (TimerWerteausgabe == 12)  LED_J16_OFF; //led im GPS Mode schnell blinken lassen
1206
 
1207
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1 ingob 1208
//  Gieren
1051 killagreg 1209
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
693 hbuss 1210
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
1051 killagreg 1211
    if(abs(StickGier) > 15) // war 35
1 ingob 1212
     {
921 hbuss 1213
      KompassSignalSchlecht = 1000;
1051 killagreg 1214
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1215
       {
1216
         NeueKompassRichtungMerken = 1;
824 hbuss 1217
        };
1 ingob 1218
     }
395 hbuss 1219
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1051 killagreg 1220
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
173 holgerb 1221
    sollGier = tmp_int;
1051 killagreg 1222
    Mess_Integral_Gier -= tmp_int;
395 hbuss 1223
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1224
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1051 killagreg 1225
 
1226
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1227
//  Kompass
1051 killagreg 1228
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
846 hbuss 1229
//DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll);
819 hbuss 1230
 
1086 salvo 1231
// Salvo 13.9.2007 Nur wenn Magnetkompass ordentliche Werte liefert
1232
                if ((magkompass_ok > 0)  &&  NeueKompassRichtungMerken)  
1233
        {
1234
                 KompassStartwert = KompassValue;
1235
         NeueKompassRichtungMerken = 0;
1 ingob 1236
        }
1086 salvo 1237
// Salvo 13.9.2007
1238
       w=0;
1239
// Salvo End
1240
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1 ingob 1241
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
921 hbuss 1242
       if(w >= 0)
1 ingob 1243
        {
1086 salvo 1244
// Salvo Kompasssteuerung **********************        
1245
                 if (magkompass_ok > 0) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
1246
// Salvo End
1247
        }
1248
 
1 ingob 1249
 
1086 salvo 1250
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1251
 
1051 killagreg 1252
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1253
//  Debugwerte zuordnen
1051 killagreg 1254
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1255
  if(!TimerWerteausgabe--)
1256
   {
395 hbuss 1257
    TimerWerteausgabe = 24;
1086 salvo 1258
        // Salvo 13.12.2007 Beleuchtung steuern
1259
        if (!(beeptime & BeepMuster)) LED_J16_FLASH;
1260
        else if (MotorenEin) LED_J16_ON;
1261
        else LED_J16_OFF;
1262
        // Salvo End
805 hbuss 1263
 
1 ingob 1264
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
1265
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
1266
    DebugOut.Analog[2] = Mittelwert_AccNick;
1267
    DebugOut.Analog[3] = Mittelwert_AccRoll;
1268
    DebugOut.Analog[4] = MesswertGier;
1269
    DebugOut.Analog[5] = HoehenWert;
1086 salvo 1270
//    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
1271
 
1 ingob 1272
    DebugOut.Analog[8] = KompassValue;
297 holgerb 1273
    DebugOut.Analog[9] = UBat;
1086 salvo 1274
    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1275
//    DebugOut.Analog[10] = SenderOkay;
1276
    DebugOut.Analog[11] = GyroKomp_Int / GIER_GRAD_FAKTOR;  
929 hbuss 1277
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1086 salvo 1278
//    DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1279
//    DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1280
//    DebugOut.Analog[19] = WinkelOut.CalcState;
1281
//    DebugOut.Analog[20] = ServoValue;
720 ingob 1282
 
805 hbuss 1283
 
1284
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1285
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1086 salvo 1286
        DebugOut.Analog[23] = debug_gp_0;
1287
    DebugOut.Analog[24] = debug_gp_1;
1288
    DebugOut.Analog[25] = debug_gp_2;
1289
        DebugOut.Analog[26] = gps_rel_act_position.utm_east; //in 10cm ausgeben
1290
        DebugOut.Analog[27] = gps_rel_act_position.utm_north;
1291
        DebugOut.Analog[28] = gps_rel_act_position.utm_alt;
1292
        DebugOut.Analog[29] = gps_state + (gps_sub_state*10)+(50*gps_cmd);
805 hbuss 1293
 
1086 salvo 1294
    DebugOut.Analog[30] = GPS_Nick;
1295
    DebugOut.Analog[31] = GPS_Roll;
1296
 
1297
 
173 holgerb 1298
/*    DebugOut.Analog[16] = motor_rx[0];
1299
    DebugOut.Analog[17] = motor_rx[1];
1300
    DebugOut.Analog[18] = motor_rx[2];
1301
    DebugOut.Analog[19] = motor_rx[3];
1302
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1303
    DebugOut.Analog[20] /= 14;
1304
    DebugOut.Analog[21] = motor_rx[4];
1305
    DebugOut.Analog[22] = motor_rx[5];
1306
    DebugOut.Analog[23] = motor_rx[6];
1307
    DebugOut.Analog[24] = motor_rx[7];
1308
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1309
*/
1310
//    DebugOut.Analog[9] = MesswertNick;
1 ingob 1311
//    DebugOut.Analog[9] = SollHoehe;
1312
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1313
//    DebugOut.Analog[11] = KompassStartwert;
1051 killagreg 1314
//    DebugOut.Analog[10] = Parameter_Gyro_I;
1315
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;
1316
//    DebugOut.Analog[9] = KompassRichtung;
1 ingob 1317
//    DebugOut.Analog[10] = GasMischanteil;
1318
//    DebugOut.Analog[3] = HoeheD * 32;
1319
//    DebugOut.Analog[4] = hoehenregler;
1320
  }
1321
 
1051 killagreg 1322
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1323
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1051 killagreg 1324
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
604 hbuss 1325
 
173 holgerb 1326
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1327
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1328
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1329
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
855 hbuss 1330
    MesswertGier =   MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
1 ingob 1331
 
854 hbuss 1332
    DebugOut.Analog[21] = MesswertNick;
1333
    DebugOut.Analog[22] = MesswertRoll;
1334
 
1 ingob 1335
    // Maximalwerte abfangen
882 hbuss 1336
    #define MAX_SENSOR  (4096*STICK_GAIN)
1 ingob 1337
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1338
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1339
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1340
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1341
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1342
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1343
 
1051 killagreg 1344
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1345
// Höhenregelung
1346
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1051 killagreg 1347
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1348
//OCR0B = 180 - (Poti1 + 120) / 4;
1349
//DruckOffsetSetting = OCR0B;
855 hbuss 1350
  GasMischanteil *= STICK_GAIN;
1036 hbuss 1351
/*
1352
  if(Poti1 > 200) {OCR0A = DruckOffsetSetting - 16; ExpandBaro = 16; }else
1353
  if(Poti1 > 150) {OCR0A = DruckOffsetSetting - 8; ExpandBaro = 8; }else
1354
  if(Poti1 > 100) {OCR0A = DruckOffsetSetting - 4; ExpandBaro = 4; }else
1355
  if(Poti1 >  50) {OCR0A = DruckOffsetSetting - 2; ExpandBaro = 1; }else
1356
  {OCR0A = DruckOffsetSetting; ExpandBaro = 0;}
1357
*/
1 ingob 1358
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1359
  {
1360
    int tmp_int;
1036 hbuss 1361
        static char delay = 100;
1 ingob 1362
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1363
    {
1036 hbuss 1364
    if(((EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && ((Parameter_MaxHoehe > 80) && (Parameter_MaxHoehe < 140))) ||
993 hbuss 1365
      (!(EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && (Parameter_MaxHoehe < 50)))
1 ingob 1366
      {
1036 hbuss 1367
       if(!delay--)
1368
            {
1051 killagreg 1369
         if(MessLuftdruck > 1000)
1036 hbuss 1370
                  {
1371
                   ExpandBaro -= 10;
1051 killagreg 1372
                   OCR0A = DruckOffsetSetting - ExpandBaro;
1036 hbuss 1373
                   beeptime = 300;
1374
           delay = 250;
1375
                  }
1376
                  else
1051 killagreg 1377
         if(MessLuftdruck < 100)
1036 hbuss 1378
                  {
1379
                   ExpandBaro += 10;
1051 killagreg 1380
                   OCR0A = DruckOffsetSetting - ExpandBaro;
1036 hbuss 1381
                   beeptime = 300;
1382
           delay = 250;
1383
                  }
1384
          else
1051 killagreg 1385
          {
1036 hbuss 1386
               SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1387
           HoehenReglerAktiv = 0;
1388
                   delay = 1;
1389
                  }
1051 killagreg 1390
                }
1 ingob 1391
      }
1051 killagreg 1392
      else
1393
        {
1036 hbuss 1394
         HoehenReglerAktiv = 1;
1395
                 delay = 200;
1051 killagreg 1396
                }
1 ingob 1397
    }
1051 killagreg 1398
    else
1 ingob 1399
    {
492 hbuss 1400
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1 ingob 1401
     HoehenReglerAktiv = 1;
1402
    }
1403
 
1404
    if(Notlandung) SollHoehe = 0;
1405
    h = HoehenWert;
1406
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1051 killagreg 1407
     {
855 hbuss 1408
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1 ingob 1409
      h = GasMischanteil - h;         // vom Gas abziehen
871 hbuss 1410
//      h -= (HoeheD * Parameter_Luftdruck_D)/(8/STICK_GAIN);    // D-Anteil
1411
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1412
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1413
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1414
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1 ingob 1415
      h -= tmp_int;
1051 killagreg 1416
      hoehenregler = (hoehenregler*15 + h) / 16;
855 hbuss 1417
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1 ingob 1418
       {
855 hbuss 1419
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1420
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1051 killagreg 1421
       }
1 ingob 1422
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1423
      GasMischanteil = hoehenregler;
1051 killagreg 1424
     }
1 ingob 1425
  }
855 hbuss 1426
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1051 killagreg 1427
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1428
// + Mischer und PI-Regler
1051 killagreg 1429
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173 holgerb 1430
  DebugOut.Analog[7] = GasMischanteil;
1051 killagreg 1431
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1432
// Gier-Anteil
1051 killagreg 1433
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
188 holgerb 1434
#define MUL_G  1.0
855 hbuss 1435
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
604 hbuss 1436
// GierMischanteil = 0;
855 hbuss 1437
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
693 hbuss 1438
   if(GasMischanteil > MIN_GIERGAS)
1439
    {
1051 killagreg 1440
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1441
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
693 hbuss 1442
    }
1051 killagreg 1443
    else
693 hbuss 1444
    {
1051 killagreg 1445
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1446
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
693 hbuss 1447
    }
855 hbuss 1448
    tmp_int = MAX_GAS*STICK_GAIN;
1051 killagreg 1449
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
855 hbuss 1450
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
513 hbuss 1451
 
1051 killagreg 1452
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1453
// Nick-Achse
1051 killagreg 1454
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
723 hbuss 1455
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1456
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung
1051 killagreg 1457
    else  SummeNick += DiffNick; // I-Anteil bei HH
855 hbuss 1458
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1459
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1051 killagreg 1460
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick
1 ingob 1461
    // Motor Vorn
499 hbuss 1462
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1051 killagreg 1463
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1464
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
173 holgerb 1465
 
1 ingob 1466
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
855 hbuss 1467
    motorwert /= STICK_GAIN;
173 holgerb 1468
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1469
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1051 killagreg 1470
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1471
        Motor_Vorne = motorwert;
1 ingob 1472
    // Motor Heck
1473
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
855 hbuss 1474
    motorwert /= STICK_GAIN;
173 holgerb 1475
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1476
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1477
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1051 killagreg 1478
        Motor_Hinten = motorwert;
1479
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 1480
// Roll-Achse
1051 killagreg 1481
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
723 hbuss 1482
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1483
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll;// I-Anteil bei Winkelregelung
498 hbuss 1484
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
918 hbuss 1485
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1486
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
297 holgerb 1487
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
499 hbuss 1488
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1051 killagreg 1489
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1490
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1 ingob 1491
    // Motor Links
1492
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
855 hbuss 1493
    motorwert /= STICK_GAIN;
173 holgerb 1494
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1495
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1496
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1051 killagreg 1497
    Motor_Links = motorwert;
1 ingob 1498
    // Motor Rechts
1499
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
855 hbuss 1500
    motorwert /= STICK_GAIN;
173 holgerb 1501
        if ((motorwert < 0)) motorwert = 0;
1 ingob 1502
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1051 killagreg 1503
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1504
    Motor_Rechts = motorwert;
1 ingob 1505
   // +++++++++++++++++++++++++++++++++++++++++++++++
1506
}
1507