Subversion Repositories FlightCtrl

Rev

Rev 918 | Rev 927 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 918 Rev 921
1
/*#######################################################################################
1
/*#######################################################################################
2
Flight Control
2
Flight Control
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
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. 
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 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
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
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
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"
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
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
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + this list of conditions and the following disclaimer.
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
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.
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 
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
37
// +     for non-commercial use (directly or indirectly)
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     with our written permission
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +     clearly linked as origin 
41
// +     clearly linked as origin 
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
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"
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
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
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// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  POSSIBILITY OF SUCH DAMAGE. 
52
// +  POSSIBILITY OF SUCH DAMAGE. 
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
 
54
 
55
#include "main.h"
55
#include "main.h"
56
#include "eeprom.c"
56
#include "eeprom.c"
57
 
57
 
58
unsigned char h,m,s;
58
unsigned char h,m,s;
59
volatile unsigned int I2CTimeout = 100;
59
volatile unsigned int I2CTimeout = 100;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
63
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
63
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
64
volatile float NeutralAccZ = 0;
64
volatile float NeutralAccZ = 0;
65
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
65
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
66
long IntegralNick = 0,IntegralNick2 = 0;
66
long IntegralNick = 0,IntegralNick2 = 0;
67
long IntegralRoll = 0,IntegralRoll2 = 0;
67
long IntegralRoll = 0,IntegralRoll2 = 0;
68
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
68
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
69
long Integral_Gier = 0;
69
long Integral_Gier = 0;
70
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
70
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
71
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
71
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
72
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
72
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
73
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
73
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
74
volatile long Mess_Integral_Hoch = 0;
74
volatile long Mess_Integral_Hoch = 0;
75
volatile int  KompassValue = 0;
75
volatile int  KompassValue = 0;
76
volatile int  KompassStartwert = 0;
76
volatile int  KompassStartwert = 0;
77
volatile int  KompassRichtung = 0;
77
volatile int  KompassRichtung = 0;
78
unsigned int  KompassSignalSchlecht = 500;
78
unsigned int  KompassSignalSchlecht = 500;
79
unsigned char  MAX_GAS,MIN_GAS;
79
unsigned char  MAX_GAS,MIN_GAS;
80
unsigned char Notlandung = 0;
80
unsigned char Notlandung = 0;
81
unsigned char HoehenReglerAktiv = 0;
81
unsigned char HoehenReglerAktiv = 0;
82
unsigned char TrichterFlug = 0;
82
unsigned char TrichterFlug = 0;
83
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
83
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
84
long  ErsatzKompass;
84
long  ErsatzKompass;
85
int   ErsatzKompassInGrad; // Kompasswert in Grad
85
int   ErsatzKompassInGrad; // Kompasswert in Grad
86
int   GierGyroFehler = 0;
86
int   GierGyroFehler = 0;
87
float GyroFaktor;
87
float GyroFaktor;
88
float IntegralFaktor;
88
float IntegralFaktor;
89
volatile int  DiffNick,DiffRoll;
89
volatile int  DiffNick,DiffRoll;
90
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
90
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
91
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
91
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
92
volatile unsigned char SenderOkay = 0;
92
volatile unsigned char SenderOkay = 0;
93
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
93
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
94
char MotorenEin = 0;
94
char MotorenEin = 0;
95
int HoehenWert = 0;
95
int HoehenWert = 0;
96
int SollHoehe = 0;
96
int SollHoehe = 0;
97
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
97
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
98
float Ki =  FAKTOR_I;
98
float Ki =  FAKTOR_I;
99
unsigned char Looping_Nick = 0,Looping_Roll = 0;
99
unsigned char Looping_Nick = 0,Looping_Roll = 0;
100
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
100
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
101
 
101
 
102
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
102
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
103
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
103
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
104
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
104
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
105
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
105
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
106
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
106
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
107
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
107
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
108
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
108
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
109
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
109
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
110
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
110
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
111
unsigned char Parameter_UserParam1 = 0;
111
unsigned char Parameter_UserParam1 = 0;
112
unsigned char Parameter_UserParam2 = 0;
112
unsigned char Parameter_UserParam2 = 0;
113
unsigned char Parameter_UserParam3 = 0;
113
unsigned char Parameter_UserParam3 = 0;
114
unsigned char Parameter_UserParam4 = 0;
114
unsigned char Parameter_UserParam4 = 0;
115
unsigned char Parameter_UserParam5 = 0;
115
unsigned char Parameter_UserParam5 = 0;
116
unsigned char Parameter_UserParam6 = 0;
116
unsigned char Parameter_UserParam6 = 0;
117
unsigned char Parameter_UserParam7 = 0;
117
unsigned char Parameter_UserParam7 = 0;
118
unsigned char Parameter_UserParam8 = 0;
118
unsigned char Parameter_UserParam8 = 0;
119
unsigned char Parameter_ServoNickControl = 100;
119
unsigned char Parameter_ServoNickControl = 100;
120
unsigned char Parameter_LoopGasLimit = 70;
120
unsigned char Parameter_LoopGasLimit = 70;
121
unsigned char Parameter_AchsKopplung1 = 0;
121
unsigned char Parameter_AchsKopplung1 = 0;
122
unsigned char Parameter_AchsGegenKopplung1 = 0;
122
unsigned char Parameter_AchsGegenKopplung1 = 0;
123
unsigned char Parameter_DynamicStability = 100;
123
unsigned char Parameter_DynamicStability = 100;
-
 
124
unsigned char Parameter_J16Bitmask;             // for the J16 Output
-
 
125
unsigned char Parameter_J16Timing;              // for the J16 Output
-
 
126
unsigned char Parameter_J17Bitmask;             // for the J17 Output
-
 
127
unsigned char Parameter_J17Timing;              // for the J17 Output
-
 
128
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
-
 
129
unsigned char Parameter_NaviGpsGain;    
-
 
130
unsigned char Parameter_NaviGpsP;        
-
 
131
unsigned char Parameter_NaviGpsI;        
-
 
132
unsigned char Parameter_NaviGpsD;        
-
 
133
unsigned char Parameter_NaviGpsACC;        
-
 
134
unsigned char Parameter_ExternalControl;
124
struct mk_param_struct EE_Parameter;
135
struct mk_param_struct EE_Parameter;
125
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
136
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
126
int MaxStickNick = 0,MaxStickRoll = 0;
137
int MaxStickNick = 0,MaxStickRoll = 0;
127
unsigned int  modell_fliegt = 0;
138
unsigned int  modell_fliegt = 0;
-
 
139
unsigned char MikroKopterFlags = 0;
128
 
140
 
129
void Piep(unsigned char Anzahl)
141
void Piep(unsigned char Anzahl)
130
{
142
{
131
 while(Anzahl--)
143
 while(Anzahl--)
132
 {
144
 {
133
  if(MotorenEin) return; //auf keinen Fall im Flug!
145
  if(MotorenEin) return; //auf keinen Fall im Flug!
134
  beeptime = 100;
146
  beeptime = 100;
135
  Delay_ms(250);
147
  Delay_ms(250);
136
 }
148
 }
137
}
149
}
138
 
150
 
139
//############################################################################
151
//############################################################################
140
//  Nullwerte ermitteln
152
//  Nullwerte ermitteln
141
void SetNeutral(void)
153
void SetNeutral(void)
142
//############################################################################
154
//############################################################################
143
{
155
{
144
        NeutralAccX = 0;
156
        NeutralAccX = 0;
145
        NeutralAccY = 0;
157
        NeutralAccY = 0;
146
        NeutralAccZ = 0;
158
        NeutralAccZ = 0;
147
    AdNeutralNick = 0; 
159
    AdNeutralNick = 0; 
148
        AdNeutralRoll = 0;     
160
        AdNeutralRoll = 0;     
149
        AdNeutralGier = 0;
161
        AdNeutralGier = 0;
150
    Parameter_AchsKopplung1 = 0;
162
    Parameter_AchsKopplung1 = 0;
151
    Parameter_AchsGegenKopplung1 = 0;
163
    Parameter_AchsGegenKopplung1 = 0;
152
    CalibrierMittelwert();     
164
    CalibrierMittelwert();     
153
    Delay_ms_Mess(100);
165
    Delay_ms_Mess(100);
154
        CalibrierMittelwert();
166
        CalibrierMittelwert();
155
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
167
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
156
     {    
168
     {    
157
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
169
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
158
     }
170
     }
159
 
171
 
160
     AdNeutralNick= AdWertNick;
172
     AdNeutralNick= AdWertNick;
161
         AdNeutralRoll= AdWertRoll;    
173
         AdNeutralRoll= AdWertRoll;    
162
         AdNeutralGier= AdWertGier;
174
         AdNeutralGier= AdWertGier;
163
     StartNeutralRoll = AdNeutralRoll;
175
     StartNeutralRoll = AdNeutralRoll;
164
     StartNeutralNick = AdNeutralNick;
176
     StartNeutralNick = AdNeutralNick;
165
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
177
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
166
    {
178
    {
167
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
179
      NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
168
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
180
          NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
169
          NeutralAccZ = Aktuell_az;
181
          NeutralAccZ = Aktuell_az;
170
    }
182
    }
171
    else
183
    else
172
    {
184
    {
173
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
185
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
174
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
186
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
175
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
187
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
176
    }
188
    }
177
   
189
   
178
        Mess_IntegralNick = 0; 
190
        Mess_IntegralNick = 0; 
179
    Mess_IntegralNick2 = 0;
191
    Mess_IntegralNick2 = 0;
180
    Mess_IntegralRoll = 0;     
192
    Mess_IntegralRoll = 0;     
181
    Mess_IntegralRoll2 = 0;
193
    Mess_IntegralRoll2 = 0;
182
    Mess_Integral_Gier = 0;    
194
    Mess_Integral_Gier = 0;    
183
    MesswertNick = 0;
195
    MesswertNick = 0;
184
    MesswertRoll = 0;
196
    MesswertRoll = 0;
185
    MesswertGier = 0;
197
    MesswertGier = 0;
186
    StartLuftdruck = Luftdruck;
198
    StartLuftdruck = Luftdruck;
187
    HoeheD = 0;
199
    HoeheD = 0;
188
    Mess_Integral_Hoch = 0;
200
    Mess_Integral_Hoch = 0;
189
    KompassStartwert = KompassValue;
201
    KompassStartwert = KompassValue;
190
    GPS_Neutral();
202
    GPS_Neutral();
191
    beeptime = 50;  
203
    beeptime = 50;  
192
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
204
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
193
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
205
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
194
    ExternHoehenValue = 0;
206
    ExternHoehenValue = 0;
195
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
207
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
196
    GierGyroFehler = 0;
208
    GierGyroFehler = 0;
197
    SendVersionToNavi = 1;
209
    SendVersionToNavi = 1;
-
 
210
    LED_Init();
-
 
211
    MikroKopterFlags |= FLAG_CALIBRATE;
198
}
212
}
199
 
213
 
200
//############################################################################
214
//############################################################################
201
// Bearbeitet die Messwerte
215
// Bearbeitet die Messwerte
202
void Mittelwert(void)
216
void Mittelwert(void)
203
//############################################################################
217
//############################################################################
204
{      
218
{      
205
    static signed long tmpl,tmpl2;     
219
    static signed long tmpl,tmpl2;     
206
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
220
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
207
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
221
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
208
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
222
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
209
 
223
 
210
//DebugOut.Analog[26] = MesswertNick;
224
//DebugOut.Analog[26] = MesswertNick;
211
DebugOut.Analog[28] = MesswertRoll;
225
DebugOut.Analog[28] = MesswertRoll;
212
 
226
 
213
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
227
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
214
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
228
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
215
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
229
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
216
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
230
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
217
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
231
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
218
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
232
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
219
    NaviAccNick    += AdWertAccNick;
233
    NaviAccNick    += AdWertAccNick;
220
    NaviAccRoll    += AdWertAccRoll;
234
    NaviAccRoll    += AdWertAccRoll;
221
    NaviCntAcc++;
235
    NaviCntAcc++;
222
    IntegralAccZ    += Aktuell_az - NeutralAccZ;
236
    IntegralAccZ    += Aktuell_az - NeutralAccZ;
223
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
237
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
224
            ErsatzKompass +=  MesswertGier;
238
            ErsatzKompass +=  MesswertGier;
225
            Mess_Integral_Gier +=  MesswertGier;
239
            Mess_Integral_Gier +=  MesswertGier;
226
            Mess_Integral_Gier2 += MesswertGier;
240
            Mess_Integral_Gier2 += MesswertGier;
227
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
241
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
228
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
242
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
229
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
243
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
230
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
244
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
231
         {
245
         {
232
            tmpl = (MesswertGier * Mess_IntegralNick) / 2048L;
246
            tmpl = (MesswertGier * Mess_IntegralNick) / 2048L;
233
            tmpl *= Parameter_AchsKopplung1;  //125
247
            tmpl *= Parameter_AchsKopplung1;  //125
234
            tmpl /= 4096L;
248
            tmpl /= 4096L;
235
            tmpl2 = (MesswertGier * Mess_IntegralRoll) / 2048L;
249
            tmpl2 = (MesswertGier * Mess_IntegralRoll) / 2048L;
236
            tmpl2 *= Parameter_AchsKopplung1;
250
            tmpl2 *= Parameter_AchsKopplung1;
237
            tmpl2 /= 4096L;
251
            tmpl2 /= 4096L;
238
            if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
252
            if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
239
         }
253
         }
240
      else  tmpl = tmpl2 = 0;
254
      else  tmpl = tmpl2 = 0;
241
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
255
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
242
            MesswertRoll += tmpl;
256
            MesswertRoll += tmpl;
243
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
257
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
244
            Mess_IntegralRoll2 += MesswertRoll;
258
            Mess_IntegralRoll2 += MesswertRoll;
245
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
259
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
246
            if(Mess_IntegralRoll > Umschlag180Roll)
260
            if(Mess_IntegralRoll > Umschlag180Roll)
247
            {
261
            {
248
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
262
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
249
             Mess_IntegralRoll2 = Mess_IntegralRoll;
263
             Mess_IntegralRoll2 = Mess_IntegralRoll;
250
            }
264
            }
251
            if(Mess_IntegralRoll <-Umschlag180Roll)
265
            if(Mess_IntegralRoll <-Umschlag180Roll)
252
            {
266
            {
253
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
267
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
254
             Mess_IntegralRoll2 = Mess_IntegralRoll;
268
             Mess_IntegralRoll2 = Mess_IntegralRoll;
255
            }  
269
            }  
256
            if(AdWertRoll < 15)   MesswertRoll = -1000;
270
            if(AdWertRoll < 15)   MesswertRoll = -1000;
257
            if(AdWertRoll <  7)   MesswertRoll = -2000;
271
            if(AdWertRoll <  7)   MesswertRoll = -2000;
258
            if(PlatinenVersion == 10)
272
            if(PlatinenVersion == 10)
259
                         {
273
                         {
260
              if(AdWertRoll > 1010) MesswertRoll = +1000;
274
              if(AdWertRoll > 1010) MesswertRoll = +1000;
261
              if(AdWertRoll > 1017) MesswertRoll = +2000;
275
              if(AdWertRoll > 1017) MesswertRoll = +2000;
262
                         }
276
                         }
263
                         else
277
                         else
264
                         {
278
                         {
265
              if(AdWertRoll > 2020) MesswertRoll = +1000;
279
              if(AdWertRoll > 2020) MesswertRoll = +1000;
266
              if(AdWertRoll > 2034) MesswertRoll = +2000;
280
              if(AdWertRoll > 2034) MesswertRoll = +2000;
267
                         }
281
                         }
268
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
282
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
269
            MesswertNick -= tmpl2;
283
            MesswertNick -= tmpl2;
270
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
284
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
271
            Mess_IntegralNick2 += MesswertNick;
285
            Mess_IntegralNick2 += MesswertNick;
272
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
286
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
273
 
287
 
274
            if(Mess_IntegralNick > Umschlag180Nick)
288
            if(Mess_IntegralNick > Umschlag180Nick)
275
             {
289
             {
276
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
290
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
277
              Mess_IntegralNick2 = Mess_IntegralNick;
291
              Mess_IntegralNick2 = Mess_IntegralNick;
278
             }
292
             }
279
            if(Mess_IntegralNick <-Umschlag180Nick)
293
            if(Mess_IntegralNick <-Umschlag180Nick)
280
            {
294
            {
281
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
295
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
282
             Mess_IntegralNick2 = Mess_IntegralNick;
296
             Mess_IntegralNick2 = Mess_IntegralNick;
283
            }
297
            }
284
            if(AdWertNick < 15)   MesswertNick = -1000;
298
            if(AdWertNick < 15)   MesswertNick = -1000;
285
            if(AdWertNick <  7)   MesswertNick = -2000;
299
            if(AdWertNick <  7)   MesswertNick = -2000;
286
            if(PlatinenVersion == 10)
300
            if(PlatinenVersion == 10)
287
                         {
301
                         {
288
              if(AdWertNick > 1010) MesswertNick = +1000;
302
              if(AdWertNick > 1010) MesswertNick = +1000;
289
              if(AdWertNick > 1017) MesswertNick = +2000;
303
              if(AdWertNick > 1017) MesswertNick = +2000;
290
                         }
304
                         }
291
                         else
305
                         else
292
                         {
306
                         {
293
              if(AdWertNick > 2020) MesswertNick = +1000;
307
              if(AdWertNick > 2020) MesswertNick = +1000;
294
              if(AdWertNick > 2034) MesswertNick = +2000;
308
              if(AdWertNick > 2034) MesswertNick = +2000;
295
                         }
309
                         }
296
//++++++++++++++++++++++++++++++++++++++++++++++++
310
//++++++++++++++++++++++++++++++++++++++++++++++++
297
// ADC einschalten
311
// ADC einschalten
298
    ANALOG_ON; 
312
    ANALOG_ON; 
299
//++++++++++++++++++++++++++++++++++++++++++++++++
313
//++++++++++++++++++++++++++++++++++++++++++++++++
300
 
314
 
301
    Integral_Gier  = Mess_Integral_Gier;
315
    Integral_Gier  = Mess_Integral_Gier;
302
    IntegralNick = Mess_IntegralNick;
316
    IntegralNick = Mess_IntegralNick;
303
    IntegralRoll = Mess_IntegralRoll;
317
    IntegralRoll = Mess_IntegralRoll;
304
    IntegralNick2 = Mess_IntegralNick2;
318
    IntegralNick2 = Mess_IntegralNick2;
305
    IntegralRoll2 = Mess_IntegralRoll2;
319
    IntegralRoll2 = Mess_IntegralRoll2;
306
 
320
 
307
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
321
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
308
  {
322
  {
309
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
323
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
310
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
324
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
311
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
325
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
312
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
326
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
313
  }
327
  }
314
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
328
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
315
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
329
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
316
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
330
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
317
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
331
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
318
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
332
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
319
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
333
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
320
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
334
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
321
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
335
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
322
}
336
}
323
 
337
 
324
//############################################################################
338
//############################################################################
325
// Messwerte beim Ermitteln der Nullage
339
// Messwerte beim Ermitteln der Nullage
326
void CalibrierMittelwert(void)
340
void CalibrierMittelwert(void)
327
//############################################################################
341
//############################################################################
328
{                
342
{                
329
    if(PlatinenVersion >= 12) SucheGyroOffset();
343
    if(PlatinenVersion >= 12) SucheGyroOffset();
330
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
344
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
331
        ANALOG_OFF;
345
        ANALOG_OFF;
332
        MesswertNick = AdWertNick;
346
        MesswertNick = AdWertNick;
333
        MesswertRoll = AdWertRoll;
347
        MesswertRoll = AdWertRoll;
334
        MesswertGier = AdWertGier;
348
        MesswertGier = AdWertGier;
335
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
349
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
336
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
350
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
337
        Mittelwert_AccHoch = (long)AdWertAccHoch;
351
        Mittelwert_AccHoch = (long)AdWertAccHoch;
338
   // ADC einschalten
352
   // ADC einschalten
339
    ANALOG_ON; 
353
    ANALOG_ON; 
340
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
354
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
341
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
355
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
342
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
356
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
343
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
357
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
344
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
358
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
345
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
359
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
346
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
360
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
347
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
361
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
348
 
362
 
349
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
363
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
350
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
364
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
351
}
365
}
352
 
366
 
353
//############################################################################
367
//############################################################################
354
// Senden der Motorwerte per I2C-Bus
368
// Senden der Motorwerte per I2C-Bus
355
void SendMotorData(void)
369
void SendMotorData(void)
356
//############################################################################
370
//############################################################################
357
{
371
{
358
    if(MOTOR_OFF || !MotorenEin)
372
    if(!MotorenEin)
359
        {
373
        {
360
        Motor_Hinten = 0;
374
        Motor_Hinten = 0;
361
        Motor_Vorne = 0;
375
        Motor_Vorne = 0;
362
        Motor_Rechts = 0;
376
        Motor_Rechts = 0;
363
        Motor_Links = 0;
377
        Motor_Links = 0;
364
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
378
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
365
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
379
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
366
        if(MotorTest[2]) Motor_Links = MotorTest[2];
380
        if(MotorTest[2]) Motor_Links = MotorTest[2];
367
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
381
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
-
 
382
        MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
368
        }
383
        } else MikroKopterFlags |= FLAG_MOTOR_RUN;
369
 
384
 
370
    DebugOut.Analog[12] = Motor_Vorne;
385
    DebugOut.Analog[12] = Motor_Vorne;
371
    DebugOut.Analog[13] = Motor_Hinten;
386
    DebugOut.Analog[13] = Motor_Hinten;
372
    DebugOut.Analog[14] = Motor_Links;
387
    DebugOut.Analog[14] = Motor_Links;
373
    DebugOut.Analog[15] = Motor_Rechts;  
388
    DebugOut.Analog[15] = Motor_Rechts;  
374
 
389
 
375
    //Start I2C Interrupt Mode
390
    //Start I2C Interrupt Mode
376
    twi_state = 0;
391
    twi_state = 0;
377
    motor = 0;
392
    motor = 0;
378
    i2c_start();
393
    i2c_start();
379
}
394
}
380
 
395
 
381
 
396
 
382
 
397
 
383
//############################################################################
398
//############################################################################
384
// Trägt ggf. das Poti als Parameter ein
399
// Trägt ggf. das Poti als Parameter ein
385
void ParameterZuordnung(void)
400
void ParameterZuordnung(void)
386
//############################################################################
401
//############################################################################
387
{
402
{
388
 
403
 
-
 
404
 #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;}
389
 #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;}
405
 #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; }
390
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
406
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
391
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
407
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
392
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
408
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
393
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
409
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
394
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
410
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
395
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
411
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
396
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
412
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
397
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
413
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
398
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
414
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
399
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
415
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
400
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
416
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
401
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
417
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
402
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
418
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
403
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
419
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
404
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
420
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
405
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
421
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
406
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
422
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
407
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
423
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
408
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
424
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
409
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
425
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
410
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
426
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
-
 
427
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
-
 
428
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
-
 
429
 CHK_POTI(Parameter_NaviGpsModeControl,EE_Parameter.NaviGpsModeControl,0,255);
-
 
430
 CHK_POTI(Parameter_NaviGpsGain,EE_Parameter.NaviGpsGain,0,255);
-
 
431
 CHK_POTI(Parameter_NaviGpsP,EE_Parameter.NaviGpsP,0,255);
-
 
432
 CHK_POTI(Parameter_NaviGpsI,EE_Parameter.NaviGpsI,0,255);
-
 
433
 CHK_POTI(Parameter_NaviGpsD,EE_Parameter.NaviGpsD,0,255);
-
 
434
 CHK_POTI(Parameter_NaviGpsACC,EE_Parameter.NaviGpsACC,0,255);
-
 
435
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
411
 
436
 
412
 Ki = (float) Parameter_I_Faktor * 0.0001;
437
 Ki = (float) Parameter_I_Faktor * 0.0001;
413
 MAX_GAS = EE_Parameter.Gas_Max;
438
 MAX_GAS = EE_Parameter.Gas_Max;
414
 MIN_GAS = EE_Parameter.Gas_Min;
439
 MIN_GAS = EE_Parameter.Gas_Min;
415
}
440
}
416
 
441
 
417
 
442
 
418
 
443
 
419
 
444
 
420
//############################################################################
445
//############################################################################
421
//
446
//
422
void MotorRegler(void)
447
void MotorRegler(void)
423
//############################################################################
448
//############################################################################
424
{
449
{
425
         int motorwert,pd_ergebnis,h,tmp_int;
450
         int motorwert,pd_ergebnis,h,tmp_int;
426
         int GierMischanteil,GasMischanteil;
451
         int GierMischanteil,GasMischanteil;
427
     static long SummeNick=0,SummeRoll=0;
452
     static long SummeNick=0,SummeRoll=0;
428
     static long sollGier = 0,tmp_long,tmp_long2;
453
     static long sollGier = 0,tmp_long,tmp_long2;
429
     static long IntegralFehlerNick = 0;
454
     static long IntegralFehlerNick = 0;
430
     static long IntegralFehlerRoll = 0;
455
     static long IntegralFehlerRoll = 0;
431
         static unsigned int RcLostTimer;
456
         static unsigned int RcLostTimer;
432
         static unsigned char delay_neutral = 0;
457
         static unsigned char delay_neutral = 0;
433
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
458
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
434
     static int hoehenregler = 0;
459
     static int hoehenregler = 0;
435
     static char TimerWerteausgabe = 0;
460
     static char TimerWerteausgabe = 0;
436
     static char NeueKompassRichtungMerken = 0;
461
     static char NeueKompassRichtungMerken = 0;
437
     static long ausgleichNick, ausgleichRoll;
462
     static long ausgleichNick, ausgleichRoll;
438
     
463
     
439
        Mittelwert();
464
        Mittelwert();
440
 
465
 
441
    GRN_ON;
466
    GRN_ON;
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
467
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
443
// Gaswert ermitteln
468
// Gaswert ermitteln
444
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
469
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
445
        GasMischanteil = StickGas;
470
        GasMischanteil = StickGas;
446
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
471
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
447
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
472
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
448
// Empfang schlecht
473
// Empfang schlecht
449
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
474
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
450
   if(SenderOkay < 100)
475
   if(SenderOkay < 100)
451
        {
476
        {
452
        if(!PcZugriff)
477
        if(!PcZugriff)
453
         {
478
         {
454
           if(BeepMuster == 0xffff)
479
           if(BeepMuster == 0xffff)
455
            {
480
            {
456
             beeptime = 15000;
481
             beeptime = 15000;
457
             BeepMuster = 0x0c00;
482
             BeepMuster = 0x0c00;
458
            }
483
            }
459
         }
484
         }
460
        if(RcLostTimer) RcLostTimer--;
485
        if(RcLostTimer) RcLostTimer--;
461
        else
486
        else
462
         {
487
         {
463
          MotorenEin = 0;
488
          MotorenEin = 0;
464
          Notlandung = 0;
489
          Notlandung = 0;
465
         }
490
         }
466
        ROT_ON;
491
        ROT_ON;
467
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
492
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
468
            {
493
            {
469
            GasMischanteil = EE_Parameter.NotGas;
494
            GasMischanteil = EE_Parameter.NotGas;
470
            Notlandung = 1;
495
            Notlandung = 1;
471
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
496
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
472
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;            
497
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;            
473
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
498
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
474
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
499
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
475
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
500
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
476
            }
501
            }
477
         else MotorenEin = 0;
502
         else MotorenEin = 0;
478
        }
503
        }
479
        else
504
        else
480
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
505
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
481
// Emfang gut
506
// Emfang gut
482
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
507
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
483
        if(SenderOkay > 140)
508
        if(SenderOkay > 140)
484
            {
509
            {
485
            Notlandung = 0;
510
            Notlandung = 0;
486
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
511
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
487
            if(GasMischanteil > 40)
512
            if(GasMischanteil > 40 && MotorenEin)
488
                {
513
                {
489
                if(modell_fliegt < 0xffff) modell_fliegt++;
514
                if(modell_fliegt < 0xffff) modell_fliegt++;
490
                }
515
                }
491
            if((modell_fliegt < 256))
516
            if((modell_fliegt < 256))
492
                {
517
                {
493
                SummeNick = 0;
518
                SummeNick = 0;
494
                SummeRoll = 0;
519
                SummeRoll = 0;
495
                if(modell_fliegt == 250)
520
                if(modell_fliegt == 250)
496
                 {
521
                 {
497
                  NeueKompassRichtungMerken = 1;
522
                  NeueKompassRichtungMerken = 1;
498
                  sollGier = 0;
523
                  sollGier = 0;
499
                  Mess_Integral_Gier = 0;      
524
                  Mess_Integral_Gier = 0;      
500
                  Mess_Integral_Gier2 = 0;
525
                  Mess_Integral_Gier2 = 0;
501
                 }
526
                 }
502
                }
527
                } else MikroKopterFlags |= FLAG_FLY;
-
 
528
               
503
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
529
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
504
                {
530
                {
505
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
531
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
506
// auf Nullwerte kalibrieren
532
// auf Nullwerte kalibrieren
507
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
533
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
508
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
534
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
509
                    {
535
                    {
510
                    if(++delay_neutral > 200)  // nicht sofort
536
                    if(++delay_neutral > 200)  // nicht sofort
511
                        {
537
                        {
512
                        GRN_OFF;
538
                        GRN_OFF;
513
                        MotorenEin = 0;
539
                        MotorenEin = 0;
514
                        delay_neutral = 0;
540
                        delay_neutral = 0;
515
                        modell_fliegt = 0;
541
                        modell_fliegt = 0;
516
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
542
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
517
                        {
543
                        {
518
                         unsigned char setting=1;
544
                         unsigned char setting=1;
519
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
545
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
520
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
546
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
521
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
547
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
522
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
548
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
523
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
549
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
524
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
550
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
525
                        }
551
                        }
526
//                        else
552
//                        else
527
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 20 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
553
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 20 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
528
                          {
554
                          {
529
                           WinkelOut.CalcState = 1;
555
                           WinkelOut.CalcState = 1;
530
                           beeptime = 1000;
556
                           beeptime = 1000;
531
                          }
557
                          }
532
                          else
558
                          else
533
                          {
559
                          {
534
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
560
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
535
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
561
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
536
                            {
562
                            {
537
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
563
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
538
                            }  
564
                            }  
539
                           SetNeutral();
565
                           SetNeutral();
540
                           Piep(GetActiveParamSetNumber());
566
                           Piep(GetActiveParamSetNumber());
541
                         }
567
                         }
542
                        }
568
                        }
543
                    }
569
                    }
544
                 else
570
                 else
545
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
571
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
546
                    {
572
                    {
547
                    if(++delay_neutral > 200)  // nicht sofort
573
                    if(++delay_neutral > 200)  // nicht sofort
548
                        {
574
                        {
549
                        GRN_OFF;
575
                        GRN_OFF;
550
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
576
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
551
                        MotorenEin = 0;
577
                        MotorenEin = 0;
552
                        delay_neutral = 0;
578
                        delay_neutral = 0;
553
                        modell_fliegt = 0;
579
                        modell_fliegt = 0;
554
                        SetNeutral();
580
                        SetNeutral();
555
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
581
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
556
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
582
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
557
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
583
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
558
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
584
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
559
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
585
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
560
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
586
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
561
                        Piep(GetActiveParamSetNumber());
587
                        Piep(GetActiveParamSetNumber());
562
                        }
588
                        }
563
                    }
589
                    }
564
                 else delay_neutral = 0;
590
                 else delay_neutral = 0;
565
                }
591
                }
566
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
592
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
567
// Gas ist unten
593
// Gas ist unten
568
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
594
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
569
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
595
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
570
                {
596
                {
571
                // Starten
597
                // Starten
572
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
598
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
573
                    {
599
                    {
574
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
600
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
575
// Einschalten
601
// Einschalten
576
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
602
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
577
                    if(++delay_einschalten > 200)
603
                    if(++delay_einschalten > 200)
578
                        {
604
                        {
579
                        delay_einschalten = 200;
605
                        delay_einschalten = 200;
580
                        modell_fliegt = 1;
606
                        modell_fliegt = 1;
581
                        MotorenEin = 1;
607
                        MotorenEin = 1;
582
                        sollGier = 0;
608
                        sollGier = 0;
583
                        Mess_Integral_Gier = 0;
609
                        Mess_Integral_Gier = 0;
584
                        Mess_Integral_Gier2 = 0;
610
                        Mess_Integral_Gier2 = 0;
585
                        Mess_IntegralNick = 0;
611
                        Mess_IntegralNick = 0;
586
                        Mess_IntegralRoll = 0;
612
                        Mess_IntegralRoll = 0;
587
                        Mess_IntegralNick2 = IntegralNick;
613
                        Mess_IntegralNick2 = IntegralNick;
588
                        Mess_IntegralRoll2 = IntegralRoll;
614
                        Mess_IntegralRoll2 = IntegralRoll;
589
                        SummeNick = 0;
615
                        SummeNick = 0;
590
                        SummeRoll = 0;
616
                        SummeRoll = 0;
-
 
617
                        MikroKopterFlags |= FLAG_START;
591
                        }          
618
                        }          
592
                    }  
619
                    }  
593
                    else delay_einschalten = 0;
620
                    else delay_einschalten = 0;
594
                //Auf Neutralwerte setzen
621
                //Auf Neutralwerte setzen
595
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
622
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
596
// Auschalten
623
// Auschalten
597
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
624
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
598
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
625
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
599
                    {
626
                    {
600
                    if(++delay_ausschalten > 200)  // nicht sofort
627
                    if(++delay_ausschalten > 200)  // nicht sofort
601
                        {
628
                        {
602
                        MotorenEin = 0;
629
                        MotorenEin = 0;
603
                        delay_ausschalten = 200;
630
                        delay_ausschalten = 200;
604
                        modell_fliegt = 0;
631
                        modell_fliegt = 0;
605
                        }
632
                        }
606
                    }
633
                    }
607
                else delay_ausschalten = 0;
634
                else delay_ausschalten = 0;
608
                }
635
                }
609
            }
636
            }
610
 
637
 
611
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
638
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
612
// neue Werte von der Funke
639
// neue Werte von der Funke
613
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
640
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
614
 if(!NewPpmData-- || Notlandung)  
641
 if(!NewPpmData-- || Notlandung)  
615
  {
642
  {
616
    int tmp_int;
643
    int tmp_int;
617
        static int stick_nick,stick_roll;
644
        static int stick_nick,stick_roll;
618
    ParameterZuordnung();
645
    ParameterZuordnung();
619
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
646
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
620
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
647
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
621
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
648
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
622
//    StickNick  = (StickNick  * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; 
649
//    StickNick  = (StickNick  * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; 
623
 
650
 
624
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
651
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
625
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
652
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
626
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
653
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
627
 
654
 
628
//    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
655
//    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
629
 
656
 
630
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
657
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
631
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
658
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
632
 
659
 
633
/*   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick)
660
/*   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick)
634
     MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--;
661
     MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--;
635
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll)
662
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll)
636
     MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--;
663
     MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--;
637
*/
664
*/
638
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN);
665
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN);
639
    IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN);
666
    IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN);
640
 
667
 
641
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
668
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
642
//+ Digitale Steuerung per DubWise
669
//+ Digitale Steuerung per DubWise
643
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
670
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
644
#define KEY_VALUE (Parameter_UserParam8 * 4)  //(Poti3 * 8)
671
#define KEY_VALUE (Parameter_ExternalControl * 4)  //(Poti3 * 8)
645
if(DubWiseKeys[1]) beeptime = 10;
672
if(DubWiseKeys[1]) beeptime = 10;
646
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
673
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
647
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
674
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
648
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
675
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
649
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
676
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
650
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
677
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
651
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
678
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
652
 
679
 
653
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
680
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
654
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
681
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
655
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
682
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
656
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
683
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
657
 
684
 
658
    StickNick += (STICK_GAIN * ExternStickNick) / 8;
685
    StickNick += (STICK_GAIN * ExternStickNick) / 8;
659
    StickRoll += (STICK_GAIN * ExternStickRoll) / 8;
686
    StickRoll += (STICK_GAIN * ExternStickRoll) / 8;
660
    StickGier += STICK_GAIN * ExternStickGier;
687
    StickGier += STICK_GAIN * ExternStickGier;
661
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
688
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
662
//+ Analoge Steuerung per Seriell
689
//+ Analoge Steuerung per Seriell
663
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
690
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
664
   if(ExternControl.Config & 0x01 && Parameter_UserParam8 > 128)
691
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
665
    {
692
    {
666
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
693
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
667
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
694
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
668
         StickGier += ExternControl.Gier;
695
         StickGier += ExternControl.Gier;
669
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
696
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
670
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
697
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
671
    }
698
    }
672
    if(StickGas < 0) StickGas = 0;
699
    if(StickGas < 0) StickGas = 0;
673
 
700
 
674
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
701
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
675
    if(GyroFaktor < 0) GyroFaktor = 0;
702
    if(GyroFaktor < 0) GyroFaktor = 0;
676
    if(IntegralFaktor < 0) IntegralFaktor = 0;
703
    if(IntegralFaktor < 0) IntegralFaktor = 0;
677
 
704
 
678
    if(abs(StickNick/STICK_GAIN) > MaxStickNick) MaxStickNick = abs(StickNick)/STICK_GAIN; else MaxStickNick--;
705
    if(abs(StickNick/STICK_GAIN) > MaxStickNick) MaxStickNick = abs(StickNick)/STICK_GAIN; else MaxStickNick--;
679
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) MaxStickRoll = abs(StickRoll)/STICK_GAIN; else MaxStickRoll--;
706
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) MaxStickRoll = abs(StickRoll)/STICK_GAIN; else MaxStickRoll--;
680
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
707
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
681
 
708
 
682
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
709
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
683
// Looping?
710
// Looping?
684
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
711
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
685
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
712
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
686
  else
713
  else
687
   {
714
   {
688
     {
715
     {
689
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
716
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
690
     }  
717
     }  
691
   }
718
   }
692
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
719
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
693
   else
720
   else
694
   {
721
   {
695
   if(Looping_Rechts) // Hysterese
722
   if(Looping_Rechts) // Hysterese
696
     {
723
     {
697
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
724
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
698
     }
725
     }
699
   }
726
   }
700
 
727
 
701
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
728
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
702
  else
729
  else
703
   {
730
   {
704
    if(Looping_Oben)  // Hysterese
731
    if(Looping_Oben)  // Hysterese
705
     {
732
     {
706
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
733
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
707
     }  
734
     }  
708
   }
735
   }
709
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
736
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
710
   else
737
   else
711
   {
738
   {
712
    if(Looping_Unten) // Hysterese
739
    if(Looping_Unten) // Hysterese
713
     {
740
     {
714
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
741
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
715
     }
742
     }
716
   }
743
   }
717
 
744
 
718
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
745
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
719
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
746
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
720
  } // Ende neue Funken-Werte
747
  } // Ende neue Funken-Werte
721
 
748
 
722
  if(Looping_Roll || Looping_Nick)
749
  if(Looping_Roll || Looping_Nick)
723
   {
750
   {
724
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
751
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
725
   }
752
   }
726
   
753
   
727
 
754
 
728
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
755
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
729
// Bei Empfangsausfall im Flug 
756
// Bei Empfangsausfall im Flug 
730
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
757
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
731
   if(Notlandung)
758
   if(Notlandung)
732
    {
759
    {
733
     StickGier = 0;
760
     StickGier = 0;
734
     StickNick = 0;
761
     StickNick = 0;
735
     StickRoll = 0;
762
     StickRoll = 0;
736
     GyroFaktor     = (float) 100 / (256.0 / STICK_GAIN);
763
     GyroFaktor     = (float) 100 / (256.0 / STICK_GAIN);
737
     IntegralFaktor = (float) 120 / (44000 / STICK_GAIN);
764
     IntegralFaktor = (float) 120 / (44000 / STICK_GAIN);
738
     Looping_Roll = 0;
765
     Looping_Roll = 0;
739
     Looping_Nick = 0;
766
     Looping_Nick = 0;
740
    }  
767
    }  
741
 
768
 
742
 
769
 
743
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
770
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
744
// Integrale auf ACC-Signal abgleichen
771
// Integrale auf ACC-Signal abgleichen
745
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
772
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
746
#define ABGLEICH_ANZAHL 256L
773
#define ABGLEICH_ANZAHL 256L
747
 
774
 
748
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
775
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
749
 MittelIntegralRoll  += IntegralRoll;
776
 MittelIntegralRoll  += IntegralRoll;
750
 MittelIntegralNick2 += IntegralNick2;
777
 MittelIntegralNick2 += IntegralNick2;
751
 MittelIntegralRoll2 += IntegralRoll2;
778
 MittelIntegralRoll2 += IntegralRoll2;
752
 
779
 
753
 if(Looping_Nick || Looping_Roll)
780
 if(Looping_Nick || Looping_Roll)
754
  {
781
  {
755
    IntegralAccNick = 0;
782
    IntegralAccNick = 0;
756
    IntegralAccRoll = 0;
783
    IntegralAccRoll = 0;
757
    MittelIntegralNick = 0;
784
    MittelIntegralNick = 0;
758
    MittelIntegralRoll = 0;
785
    MittelIntegralRoll = 0;
759
    MittelIntegralNick2 = 0;
786
    MittelIntegralNick2 = 0;
760
    MittelIntegralRoll2 = 0;
787
    MittelIntegralRoll2 = 0;
761
    Mess_IntegralNick2 = Mess_IntegralNick;
788
    Mess_IntegralNick2 = Mess_IntegralNick;
762
    Mess_IntegralRoll2 = Mess_IntegralRoll;
789
    Mess_IntegralRoll2 = Mess_IntegralRoll;
763
    ZaehlMessungen = 0;
790
    ZaehlMessungen = 0;
764
    LageKorrekturNick = 0;
791
    LageKorrekturNick = 0;
765
    LageKorrekturRoll = 0;
792
    LageKorrekturRoll = 0;
766
  }
793
  }
767
 
794
 
768
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
795
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
769
  if(!Looping_Nick && !Looping_Roll)
796
  if(!Looping_Nick && !Looping_Roll)
770
  {
797
  {
771
   long tmp_long, tmp_long2;
798
   long tmp_long, tmp_long2;
772
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
799
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
773
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
800
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
774
    tmp_long /= 16;
801
    tmp_long /= 16;
775
    tmp_long2 /= 16;
802
    tmp_long2 /= 16;
776
   if((MaxStickNick > 32) || (MaxStickRoll > 32))
803
   if((MaxStickNick > 32) || (MaxStickRoll > 32))
777
    {
804
    {
778
    tmp_long  /= 3;
805
    tmp_long  /= 3;
779
    tmp_long2 /= 3;
806
    tmp_long2 /= 3;
780
    }
807
    }
781
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
808
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
782
    {
809
    {
783
    tmp_long  /= 3;
810
    tmp_long  /= 3;
784
    tmp_long2 /= 3;
811
    tmp_long2 /= 3;
785
    }
812
    }
786
 
813
 
787
 #define AUSGLEICH 32
814
 #define AUSGLEICH 32
788
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
815
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
789
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
816
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
790
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
817
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
791
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
818
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
792
 
819
 
793
    Mess_IntegralNick -= tmp_long;
820
    Mess_IntegralNick -= tmp_long;
794
    Mess_IntegralRoll -= tmp_long2;
821
    Mess_IntegralRoll -= tmp_long2;
795
  }
822
  }
796
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
823
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
797
 
824
 
798
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
825
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
799
 {
826
 {
800
  static int cnt = 0;
827
  static int cnt = 0;
801
  static char last_n_p,last_n_n,last_r_p,last_r_n;
828
  static char last_n_p,last_n_n,last_r_p,last_r_n;
802
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
829
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
803
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug)
830
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug)
804
  {
831
  {
805
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
832
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
806
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
833
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
807
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
834
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
808
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
835
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
809
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
836
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
810
#define MAX_I 0//(Poti2/10)
837
#define MAX_I 0//(Poti2/10)
811
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
838
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
812
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
839
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
813
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
840
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
814
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
841
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
815
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
842
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
816
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
843
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
817
 
844
 
818
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
845
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
819
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
846
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
820
 
847
 
821
   if((MaxStickNick > 32) || (MaxStickRoll > 32) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25))
848
   if((MaxStickNick > 32) || (MaxStickRoll > 32) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25))
822
    {
849
    {
823
     LageKorrekturNick /= 2;
850
     LageKorrekturNick /= 2;
824
     LageKorrekturRoll /= 2;
851
     LageKorrekturRoll /= 2;
825
    }
852
    }
826
 
853
 
827
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
854
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
828
// Gyro-Drift ermitteln
855
// Gyro-Drift ermitteln
829
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
856
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
830
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
857
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
831
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
858
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
832
    tmp_long  = IntegralNick2 - IntegralNick;
859
    tmp_long  = IntegralNick2 - IntegralNick;
833
    tmp_long2 = IntegralRoll2 - IntegralRoll;
860
    tmp_long2 = IntegralRoll2 - IntegralRoll;
834
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
861
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
835
 
862
 
836
    IntegralFehlerNick = tmp_long;
863
    IntegralFehlerNick = tmp_long;
837
    IntegralFehlerRoll = tmp_long2;
864
    IntegralFehlerRoll = tmp_long2;
838
    Mess_IntegralNick2 -= IntegralFehlerNick;
865
    Mess_IntegralNick2 -= IntegralFehlerNick;
839
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
866
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
840
 
867
 
841
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
868
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
842
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
869
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
843
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) AdNeutralGier++;
870
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) AdNeutralGier++;
844
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) AdNeutralGier--;
871
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) AdNeutralGier--;
845
 
872
 
846
DebugOut.Analog[22] = MittelIntegralRoll / 26;
873
DebugOut.Analog[22] = MittelIntegralRoll / 26;
847
 
-
 
-
 
874
//DebugOut.Analog[24] = GierGyroFehler;
848
    GierGyroFehler = 0;
875
    GierGyroFehler = 0;
849
 
876
 
850
 
877
 
851
/*DebugOut.Analog[17] = IntegralAccNick / 26;
878
/*DebugOut.Analog[17] = IntegralAccNick / 26;
852
DebugOut.Analog[18] = IntegralAccRoll / 26;
879
DebugOut.Analog[18] = IntegralAccRoll / 26;
853
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
880
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
854
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
881
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
855
*/
882
*/
856
//DebugOut.Analog[21] = MittelIntegralNick / 26;
883
//DebugOut.Analog[21] = MittelIntegralNick / 26;
857
//MittelIntegralRoll = MittelIntegralRoll;
884
//MittelIntegralRoll = MittelIntegralRoll;
858
//DebugOut.Analog[28] = ausgleichNick;
885
//DebugOut.Analog[28] = ausgleichNick;
859
/*
886
/*
860
DebugOut.Analog[29] = ausgleichRoll;
887
DebugOut.Analog[29] = ausgleichRoll;
861
DebugOut.Analog[30] = LageKorrekturRoll * 10;
888
DebugOut.Analog[30] = LageKorrekturRoll * 10;
862
*/
889
*/
863
 
890
 
864
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
891
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
865
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
892
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
866
#define BEWEGUNGS_LIMIT 20000
893
#define BEWEGUNGS_LIMIT 20000
867
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
894
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
868
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
895
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
869
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
896
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
870
        {
897
        {
871
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
898
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
872
         {
899
         {
873
           if(last_n_p)
900
           if(last_n_p)
874
           {
901
           {
875
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
902
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
876
            ausgleichNick = IntegralFehlerNick / 8;
903
            ausgleichNick = IntegralFehlerNick / 8;
877
            if(ausgleichNick > 5000) ausgleichNick = 5000;
904
            if(ausgleichNick > 5000) ausgleichNick = 5000;
878
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
905
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
879
           }
906
           }
880
           else last_n_p = 1;
907
           else last_n_p = 1;
881
         } else  last_n_p = 0;
908
         } else  last_n_p = 0;
882
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
909
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
883
         {
910
         {
884
           if(last_n_n)
911
           if(last_n_n)
885
            {
912
            {
886
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
913
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
887
             ausgleichNick = IntegralFehlerNick / 8;
914
             ausgleichNick = IntegralFehlerNick / 8;
888
             if(ausgleichNick < -5000) ausgleichNick = -5000;
915
             if(ausgleichNick < -5000) ausgleichNick = -5000;
889
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
916
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
890
            }
917
            }
891
           else last_n_n = 1;
918
           else last_n_n = 1;
892
         } else  last_n_n = 0;
919
         } else  last_n_n = 0;
893
        }
920
        }
894
        else
921
        else
895
        {
922
        {
896
         cnt = 0;
923
         cnt = 0;
897
         KompassSignalSchlecht = 500;
924
         KompassSignalSchlecht = 1000;
898
        }
925
        }
899
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
926
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
900
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
927
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
901
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
928
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
902
 
929
 
903
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
930
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
904
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
931
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
905
 
932
 
906
        ausgleichRoll = 0;
933
        ausgleichRoll = 0;
907
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
934
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
908
        {
935
        {
909
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
936
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
910
         {
937
         {
911
           if(last_r_p)
938
           if(last_r_p)
912
           {
939
           {
913
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
940
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
914
            ausgleichRoll = IntegralFehlerRoll / 8;
941
            ausgleichRoll = IntegralFehlerRoll / 8;
915
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
942
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
916
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
943
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
917
           }
944
           }
918
           else last_r_p = 1;
945
           else last_r_p = 1;
919
         } else  last_r_p = 0;
946
         } else  last_r_p = 0;
920
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
947
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
921
         {
948
         {
922
           if(last_r_n)
949
           if(last_r_n)
923
           {
950
           {
924
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
951
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
925
            ausgleichRoll = IntegralFehlerRoll / 8;
952
            ausgleichRoll = IntegralFehlerRoll / 8;
926
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
953
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
927
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
954
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
928
           }
955
           }
929
           else last_r_n = 1;
956
           else last_r_n = 1;
930
         } else  last_r_n = 0;
957
         } else  last_r_n = 0;
931
        } else
958
        } else
932
        {
959
        {
933
         cnt = 0;
960
         cnt = 0;
934
         KompassSignalSchlecht = 500;
961
         KompassSignalSchlecht = 1000;
935
        }
962
        }
936
 
963
 
937
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
964
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
938
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
965
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
939
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
966
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
940
/*DebugOut.Analog[27] = ausgleichRoll;
-
 
941
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
-
 
942
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
-
 
943
*/
-
 
944
  }
967
  }
945
  else
968
  else
946
  {
969
  {
947
   LageKorrekturRoll = 0;
970
   LageKorrekturRoll = 0;
948
   LageKorrekturNick = 0;
971
   LageKorrekturNick = 0;
949
   TrichterFlug = 0;
972
   TrichterFlug = 0;
950
  }
973
  }
951
 
974
 
952
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
975
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
953
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
976
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
954
   MittelIntegralNick_Alt = MittelIntegralNick;      
977
   MittelIntegralNick_Alt = MittelIntegralNick;      
955
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
978
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
956
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
979
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
957
    IntegralAccNick = 0;
980
    IntegralAccNick = 0;
958
    IntegralAccRoll = 0;
981
    IntegralAccRoll = 0;
959
    IntegralAccZ = 0;
982
    IntegralAccZ = 0;
960
    MittelIntegralNick = 0;
983
    MittelIntegralNick = 0;
961
    MittelIntegralRoll = 0;
984
    MittelIntegralRoll = 0;
962
    MittelIntegralNick2 = 0;
985
    MittelIntegralNick2 = 0;
963
    MittelIntegralRoll2 = 0;
986
    MittelIntegralRoll2 = 0;
964
    ZaehlMessungen = 0;
987
    ZaehlMessungen = 0;
965
 }
988
 }
966
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
989
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
967
 
990
 
968
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
991
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
969
//  Gieren
992
//  Gieren
970
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
993
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
971
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
994
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
972
    if(abs(StickGier) > 15) // war 35 
995
    if(abs(StickGier) > 15) // war 35 
973
     {
996
     {
-
 
997
      KompassSignalSchlecht = 1000;
974
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
998
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
975
       {
999
       {
976
         NeueKompassRichtungMerken = 1;
1000
         NeueKompassRichtungMerken = 1;
977
         KompassStartwert = ErsatzKompass;
1001
         KompassStartwert = ErsatzKompass;
978
         KompassSignalSchlecht = 250;
-
 
979
        };
1002
        };
980
     }
1003
     }
981
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1004
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
982
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1005
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
983
    sollGier = tmp_int;
1006
    sollGier = tmp_int;
984
    Mess_Integral_Gier -= tmp_int;  
1007
    Mess_Integral_Gier -= tmp_int;  
985
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1008
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
986
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1009
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
987
 
1010
 
988
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1011
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
989
//  Kompass
1012
//  Kompass
990
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1013
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
991
//DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll);
1014
//DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll);
992
 
1015
 
993
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1016
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
994
     {
1017
     {
995
       int w,v,r,fehler,korrektur;
1018
       int w,v,r,fehler,korrektur;
996
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1019
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
997
       v = abs(IntegralRoll /512);
1020
       v = abs(IntegralRoll /512);
998
       if(v > w) w = v; // grösste Neigung ermitteln
1021
       if(v > w) w = v; // grösste Neigung ermitteln
999
       korrektur = w / 8 + 1;
1022
       korrektur = w / 8 + 1;
-
 
1023
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
-
 
1024
//DebugOut.Analog[25] = KompassSignalSchlecht;
-
 
1025
       if(!KompassSignalSchlecht && w < 25)
-
 
1026
        {
-
 
1027
        GierGyroFehler += fehler;
1000
       if(w < 25 && NeueKompassRichtungMerken && !KompassSignalSchlecht)    
1028
        if(NeueKompassRichtungMerken)    
1001
        {
1029
         {
1002
         beeptime = 200;
1030
          beeptime = 200;
1003
//         KompassStartwert = KompassValue;
1031
//         KompassStartwert = KompassValue;
1004
         KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1032
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1005
         NeueKompassRichtungMerken = 0;
1033
          NeueKompassRichtungMerken = 0;
-
 
1034
         }
1006
        }
1035
        }
1007
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
-
 
1008
       ErsatzKompass += (fehler * 8) / korrektur;
1036
       ErsatzKompass += (fehler * 8) / korrektur;
1009
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
1037
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1010
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1038
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1011
       if(w > 0)
1039
       if(w >= 0)
1012
        {
1040
        {
1013
          if(!KompassSignalSchlecht)
1041
          if(!KompassSignalSchlecht)
1014
          {
1042
          {
1015
           GierGyroFehler += fehler;
-
 
1016
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;  
1043
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;  
1017
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1044
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1018
//           r = KompassRichtung;
1045
//           r = KompassRichtung;
1019
           v = (r * w) / v;  // nach Kompass ausrichten
1046
           v = (r * w) / v;  // nach Kompass ausrichten
1020
           w = 3 * Parameter_KompassWirkung;
1047
           w = 3 * Parameter_KompassWirkung;
1021
           if(v > w) v = w; // Begrenzen
1048
           if(v > w) v = w; // Begrenzen
1022
           else
1049
           else
1023
           if(v < -w) v = -w;
1050
           if(v < -w) v = -w;
1024
           Mess_Integral_Gier += v;
1051
           Mess_Integral_Gier += v;
1025
          }
1052
          }
1026
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1053
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1027
        }  
1054
        }  
1028
        else KompassSignalSchlecht = 250; // so lange das Signal taub stellen --> ca. 0,5 sek
1055
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1029
       
-
 
1030
     }
1056
     }
1031
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1057
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1032
 
1058
 
1033
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1059
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1034
//  Debugwerte zuordnen
1060
//  Debugwerte zuordnen
1035
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1061
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1036
  if(!TimerWerteausgabe--)
1062
  if(!TimerWerteausgabe--)
1037
   {
1063
   {
1038
    TimerWerteausgabe = 24;
1064
    TimerWerteausgabe = 24;
1039
 
1065
 
1040
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
1066
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
1041
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
1067
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
1042
    DebugOut.Analog[2] = Mittelwert_AccNick;
1068
    DebugOut.Analog[2] = Mittelwert_AccNick;
1043
    DebugOut.Analog[3] = Mittelwert_AccRoll;
1069
    DebugOut.Analog[3] = Mittelwert_AccRoll;
1044
    DebugOut.Analog[4] = MesswertGier;
1070
    DebugOut.Analog[4] = MesswertGier;
1045
    DebugOut.Analog[5] = HoehenWert;
1071
    DebugOut.Analog[5] = HoehenWert;
1046
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
1072
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
1047
    DebugOut.Analog[8] = KompassValue;
1073
    DebugOut.Analog[8] = KompassValue;
1048
    DebugOut.Analog[9] = UBat;
1074
    DebugOut.Analog[9] = UBat;
1049
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;  
1075
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;  
1050
    DebugOut.Analog[10] = SenderOkay;
1076
    DebugOut.Analog[10] = SenderOkay;
1051
    DebugOut.Analog[16] = Mittelwert_AccHoch;
1077
    DebugOut.Analog[16] = Mittelwert_AccHoch;
1052
 
1078
 
1053
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1079
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1054
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1080
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1055
    DebugOut.Analog[19] = WinkelOut.CalcState;
1081
    DebugOut.Analog[19] = WinkelOut.CalcState;
1056
    DebugOut.Analog[20] = ServoValue;
1082
    DebugOut.Analog[20] = ServoValue;
1057
 
1083
 
1058
    DebugOut.Analog[30] = GPS_Nick;
1084
    DebugOut.Analog[30] = GPS_Nick;
1059
    DebugOut.Analog[31] = GPS_Roll;
1085
    DebugOut.Analog[31] = GPS_Roll;
1060
 
1086
 
1061
 
1087
 
1062
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1088
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1063
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1089
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1064
 
1090
 
1065
/*    DebugOut.Analog[16] = motor_rx[0];
1091
/*    DebugOut.Analog[16] = motor_rx[0];
1066
    DebugOut.Analog[17] = motor_rx[1];
1092
    DebugOut.Analog[17] = motor_rx[1];
1067
    DebugOut.Analog[18] = motor_rx[2];
1093
    DebugOut.Analog[18] = motor_rx[2];
1068
    DebugOut.Analog[19] = motor_rx[3];
1094
    DebugOut.Analog[19] = motor_rx[3];
1069
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1095
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1070
    DebugOut.Analog[20] /= 14;
1096
    DebugOut.Analog[20] /= 14;
1071
    DebugOut.Analog[21] = motor_rx[4];
1097
    DebugOut.Analog[21] = motor_rx[4];
1072
    DebugOut.Analog[22] = motor_rx[5];
1098
    DebugOut.Analog[22] = motor_rx[5];
1073
    DebugOut.Analog[23] = motor_rx[6];
1099
    DebugOut.Analog[23] = motor_rx[6];
1074
    DebugOut.Analog[24] = motor_rx[7];
1100
    DebugOut.Analog[24] = motor_rx[7];
1075
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1101
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1076
*/
1102
*/
1077
//    DebugOut.Analog[9] = MesswertNick;
1103
//    DebugOut.Analog[9] = MesswertNick;
1078
//    DebugOut.Analog[9] = SollHoehe;
1104
//    DebugOut.Analog[9] = SollHoehe;
1079
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1105
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1080
//    DebugOut.Analog[11] = KompassStartwert;
1106
//    DebugOut.Analog[11] = KompassStartwert;
1081
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
1107
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
1082
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
1108
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
1083
//    DebugOut.Analog[9] = KompassRichtung;    
1109
//    DebugOut.Analog[9] = KompassRichtung;    
1084
//    DebugOut.Analog[10] = GasMischanteil;
1110
//    DebugOut.Analog[10] = GasMischanteil;
1085
//    DebugOut.Analog[3] = HoeheD * 32;
1111
//    DebugOut.Analog[3] = HoeheD * 32;
1086
//    DebugOut.Analog[4] = hoehenregler;
1112
//    DebugOut.Analog[4] = hoehenregler;
1087
  }
1113
  }
1088
 
1114
 
1089
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1115
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1090
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1116
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1091
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1117
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1092
 
1118
 
1093
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1119
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
1094
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1120
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
1095
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1121
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
1096
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1122
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
1097
    MesswertGier =   MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
1123
    MesswertGier =   MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
1098
 
1124
 
1099
    DebugOut.Analog[21] = MesswertNick;
1125
    DebugOut.Analog[21] = MesswertNick;
1100
    DebugOut.Analog[22] = MesswertRoll;
1126
    DebugOut.Analog[22] = MesswertRoll;
1101
 
1127
 
1102
    // Maximalwerte abfangen
1128
    // Maximalwerte abfangen
1103
    #define MAX_SENSOR  (4096*STICK_GAIN)
1129
    #define MAX_SENSOR  (4096*STICK_GAIN)
1104
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1130
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1105
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1131
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1106
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1132
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1107
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1133
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1108
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1134
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1109
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1135
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1110
 
1136
 
1111
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1137
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1112
// Höhenregelung
1138
// Höhenregelung
1113
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1139
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1114
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1140
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1115
//OCR0B = 180 - (Poti1 + 120) / 4;
1141
//OCR0B = 180 - (Poti1 + 120) / 4;
1116
//DruckOffsetSetting = OCR0B;
1142
//DruckOffsetSetting = OCR0B;
1117
  GasMischanteil *= STICK_GAIN;
1143
  GasMischanteil *= STICK_GAIN;
1118
 
1144
 
1119
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1145
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1120
  {
1146
  {
1121
    int tmp_int;
1147
    int tmp_int;
1122
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1148
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1123
    {
1149
    {
1124
     if(Parameter_MaxHoehe < 50)
1150
     if(Parameter_MaxHoehe < 50)
1125
      {
1151
      {
1126
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1152
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1127
       HoehenReglerAktiv = 0;
1153
       HoehenReglerAktiv = 0;
1128
      }
1154
      }
1129
      else  
1155
      else  
1130
        HoehenReglerAktiv = 1;
1156
        HoehenReglerAktiv = 1;
1131
    }
1157
    }
1132
    else
1158
    else
1133
    {
1159
    {
1134
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1160
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1135
     HoehenReglerAktiv = 1;
1161
     HoehenReglerAktiv = 1;
1136
    }
1162
    }
1137
 
1163
 
1138
    if(Notlandung) SollHoehe = 0;
1164
    if(Notlandung) SollHoehe = 0;
1139
    h = HoehenWert;
1165
    h = HoehenWert;
1140
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1166
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1141
     {      
1167
     {      
1142
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1168
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1143
      h = GasMischanteil - h;         // vom Gas abziehen
1169
      h = GasMischanteil - h;         // vom Gas abziehen
1144
//      h -= (HoeheD * Parameter_Luftdruck_D)/(8/STICK_GAIN);    // D-Anteil
1170
//      h -= (HoeheD * Parameter_Luftdruck_D)/(8/STICK_GAIN);    // D-Anteil
1145
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1171
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1146
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1172
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1147
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1173
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1148
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1174
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1149
      h -= tmp_int;
1175
      h -= tmp_int;
1150
      hoehenregler = (hoehenregler*15 + h) / 16;      
1176
      hoehenregler = (hoehenregler*15 + h) / 16;      
1151
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1177
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1152
       {
1178
       {
1153
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1179
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1154
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1180
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1155
       }  
1181
       }  
1156
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1182
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1157
      GasMischanteil = hoehenregler;
1183
      GasMischanteil = hoehenregler;
1158
     }
1184
     }
1159
  }
1185
  }
1160
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1186
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1161
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1187
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1162
// + Mischer und PI-Regler
1188
// + Mischer und PI-Regler
1163
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1189
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1164
  DebugOut.Analog[7] = GasMischanteil;
1190
  DebugOut.Analog[7] = GasMischanteil;
1165
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1191
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1166
// Gier-Anteil
1192
// Gier-Anteil
1167
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1193
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1168
#define MUL_G  1.0
1194
#define MUL_G  1.0
1169
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1195
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1170
// GierMischanteil = 0;
1196
// GierMischanteil = 0;
1171
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1197
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1172
   if(GasMischanteil > MIN_GIERGAS)
1198
   if(GasMischanteil > MIN_GIERGAS)
1173
    {
1199
    {
1174
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1200
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1175
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1201
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1176
    }
1202
    }
1177
    else
1203
    else
1178
    {
1204
    {
1179
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1205
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1180
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1206
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1181
    }
1207
    }
1182
    tmp_int = MAX_GAS*STICK_GAIN;
1208
    tmp_int = MAX_GAS*STICK_GAIN;
1183
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1209
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1184
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1210
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1185
 
1211
 
1186
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1212
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1187
// Nick-Achse
1213
// Nick-Achse
1188
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1214
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1189
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1215
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1190
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung
1216
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung
1191
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1217
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1192
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1218
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1193
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1219
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1194
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1220
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1195
    // Motor Vorn
1221
    // Motor Vorn
1196
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1222
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1197
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1223
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1198
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1224
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1199
 
1225
 
1200
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1226
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1201
    motorwert /= STICK_GAIN;
1227
    motorwert /= STICK_GAIN;
1202
        if ((motorwert < 0)) motorwert = 0;
1228
        if ((motorwert < 0)) motorwert = 0;
1203
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1229
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1204
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1230
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1205
        Motor_Vorne = motorwert;           
1231
        Motor_Vorne = motorwert;           
1206
    // Motor Heck
1232
    // Motor Heck
1207
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1233
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1208
    motorwert /= STICK_GAIN;
1234
    motorwert /= STICK_GAIN;
1209
        if ((motorwert < 0)) motorwert = 0;
1235
        if ((motorwert < 0)) motorwert = 0;
1210
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1236
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1211
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1237
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1212
        Motor_Hinten = motorwert;              
1238
        Motor_Hinten = motorwert;              
1213
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1239
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1214
// Roll-Achse
1240
// Roll-Achse
1215
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1241
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1216
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1242
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1217
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll;// I-Anteil bei Winkelregelung
1243
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll;// I-Anteil bei Winkelregelung
1218
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1244
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1219
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1245
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1220
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1246
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1221
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1247
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1222
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1248
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1223
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1249
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1224
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1250
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1225
    // Motor Links
1251
    // Motor Links
1226
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1252
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1227
    motorwert /= STICK_GAIN;
1253
    motorwert /= STICK_GAIN;
1228
        if ((motorwert < 0)) motorwert = 0;
1254
        if ((motorwert < 0)) motorwert = 0;
1229
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1255
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1230
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1256
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1231
    Motor_Links = motorwert;           
1257
    Motor_Links = motorwert;           
1232
    // Motor Rechts
1258
    // Motor Rechts
1233
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1259
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1234
    motorwert /= STICK_GAIN;
1260
    motorwert /= STICK_GAIN;
1235
        if ((motorwert < 0)) motorwert = 0;
1261
        if ((motorwert < 0)) motorwert = 0;
1236
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1262
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1237
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1263
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1238
    Motor_Rechts = motorwert;          
1264
    Motor_Rechts = motorwert;          
1239
   // +++++++++++++++++++++++++++++++++++++++++++++++
1265
   // +++++++++++++++++++++++++++++++++++++++++++++++
1240
}
1266
}
1241
 
1267
 
1242
 
1268