Subversion Repositories FlightCtrl

Rev

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

Rev 1229 Rev 1244
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
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
60
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
61
int TrimNick, TrimRoll;
61
int TrimNick, TrimRoll;
62
int AdNeutralGierBias;
62
int AdNeutralGierBias;
63
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
63
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
64
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
64
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
65
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
65
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
66
volatile float NeutralAccZ = 0;
66
volatile float NeutralAccZ = 0;
67
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
67
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
68
long IntegralNick = 0,IntegralNick2 = 0;
68
long IntegralNick = 0,IntegralNick2 = 0;
69
long IntegralRoll = 0,IntegralRoll2 = 0;
69
long IntegralRoll = 0,IntegralRoll2 = 0;
70
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
70
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
71
long Integral_Gier = 0;
71
long Integral_Gier = 0;
72
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
72
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
73
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
73
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
74
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
74
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
75
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
75
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
76
volatile long Mess_Integral_Hoch = 0;
76
volatile long Mess_Integral_Hoch = 0;
77
int  KompassValue = 0;
77
int  KompassValue = 0;
78
int  KompassStartwert = 0;
78
int  KompassStartwert = 0;
79
int  KompassRichtung = 0;
79
int  KompassRichtung = 0;
80
unsigned int  KompassSignalSchlecht = 500;
80
unsigned int  KompassSignalSchlecht = 500;
81
unsigned char  MAX_GAS,MIN_GAS;
81
unsigned char  MAX_GAS,MIN_GAS;
82
unsigned char Notlandung = 0;
82
unsigned char Notlandung = 0;
83
unsigned char HoehenReglerAktiv = 0;
83
unsigned char HoehenReglerAktiv = 0;
84
unsigned char TrichterFlug = 0;
84
unsigned char TrichterFlug = 0;
85
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
85
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
86
long  ErsatzKompass;
86
long  ErsatzKompass;
87
int   ErsatzKompassInGrad; // Kompasswert in Grad
87
int   ErsatzKompassInGrad; // Kompasswert in Grad
88
int   GierGyroFehler = 0;
88
int   GierGyroFehler = 0;
89
char GyroFaktor,GyroFaktorGier;
89
char GyroFaktor,GyroFaktorGier;
90
char IntegralFaktor,IntegralFaktorGier;
90
char IntegralFaktor,IntegralFaktorGier;
91
int  DiffNick,DiffRoll;
91
int  DiffNick,DiffRoll;
92
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
92
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
93
volatile unsigned char SenderOkay = 0;
93
volatile unsigned char SenderOkay = 0;
94
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
94
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
95
char MotorenEin = 0;
95
char MotorenEin = 0;
96
int HoehenWert = 0;
96
int HoehenWert = 0;
97
int SollHoehe = 0;
97
int SollHoehe = 0;
98
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
98
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
99
//float Ki =  FAKTOR_I;
99
//float Ki =  FAKTOR_I;
100
int Ki = 10300 / 33;
100
int Ki = 10300 / 33;
101
unsigned char Looping_Nick = 0,Looping_Roll = 0;
101
unsigned char Looping_Nick = 0,Looping_Roll = 0;
102
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
102
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
103
 
103
 
104
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
104
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
105
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
105
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
106
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
106
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
107
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
107
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
108
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
108
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
109
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
109
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
110
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
110
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
111
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
111
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
112
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
112
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
113
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
113
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
114
unsigned char Parameter_UserParam1 = 0;
114
unsigned char Parameter_UserParam1 = 0;
115
unsigned char Parameter_UserParam2 = 0;
115
unsigned char Parameter_UserParam2 = 0;
116
unsigned char Parameter_UserParam3 = 0;
116
unsigned char Parameter_UserParam3 = 0;
117
unsigned char Parameter_UserParam4 = 0;
117
unsigned char Parameter_UserParam4 = 0;
118
unsigned char Parameter_UserParam5 = 0;
118
unsigned char Parameter_UserParam5 = 0;
119
unsigned char Parameter_UserParam6 = 0;
119
unsigned char Parameter_UserParam6 = 0;
120
unsigned char Parameter_UserParam7 = 0;
120
unsigned char Parameter_UserParam7 = 0;
121
unsigned char Parameter_UserParam8 = 0;
121
unsigned char Parameter_UserParam8 = 0;
122
unsigned char Parameter_ServoNickControl = 100;
122
unsigned char Parameter_ServoNickControl = 100;
123
unsigned char Parameter_LoopGasLimit = 70;
123
unsigned char Parameter_LoopGasLimit = 70;
124
unsigned char Parameter_AchsKopplung1 = 90;
124
unsigned char Parameter_AchsKopplung1 = 90;
125
unsigned char Parameter_AchsKopplung2 = 65;
125
unsigned char Parameter_AchsKopplung2 = 65;
126
unsigned char Parameter_CouplingYawCorrection = 64;
126
unsigned char Parameter_CouplingYawCorrection = 64;
127
//unsigned char Parameter_AchsGegenKopplung1 = 0;
127
//unsigned char Parameter_AchsGegenKopplung1 = 0;
128
unsigned char Parameter_DynamicStability = 100;
128
unsigned char Parameter_DynamicStability = 100;
129
unsigned char Parameter_J16Bitmask;             // for the J16 Output
129
unsigned char Parameter_J16Bitmask;             // for the J16 Output
130
unsigned char Parameter_J16Timing;              // for the J16 Output
130
unsigned char Parameter_J16Timing;              // for the J16 Output
131
unsigned char Parameter_J17Bitmask;             // for the J17 Output
131
unsigned char Parameter_J17Bitmask;             // for the J17 Output
132
unsigned char Parameter_J17Timing;              // for the J17 Output
132
unsigned char Parameter_J17Timing;              // for the J17 Output
133
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
133
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
134
unsigned char Parameter_NaviGpsGain;
134
unsigned char Parameter_NaviGpsGain;
135
unsigned char Parameter_NaviGpsP;
135
unsigned char Parameter_NaviGpsP;
136
unsigned char Parameter_NaviGpsI;
136
unsigned char Parameter_NaviGpsI;
137
unsigned char Parameter_NaviGpsD;
137
unsigned char Parameter_NaviGpsD;
138
unsigned char Parameter_NaviGpsACC;
138
unsigned char Parameter_NaviGpsACC;
139
unsigned char Parameter_NaviOperatingRadius;
139
unsigned char Parameter_NaviOperatingRadius;
140
unsigned char Parameter_NaviWindCorrection;
140
unsigned char Parameter_NaviWindCorrection;
141
unsigned char Parameter_NaviSpeedCompensation;
141
unsigned char Parameter_NaviSpeedCompensation;
142
unsigned char Parameter_ExternalControl;
142
unsigned char Parameter_ExternalControl;
143
struct mk_param_struct EE_Parameter;
143
struct mk_param_struct EE_Parameter;
144
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
144
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
145
int MaxStickNick = 0,MaxStickRoll = 0;
145
int MaxStickNick = 0,MaxStickRoll = 0;
146
unsigned int  modell_fliegt = 0;
146
unsigned int  modell_fliegt = 0;
147
volatile unsigned char MikroKopterFlags = 0;
147
volatile unsigned char MikroKopterFlags = 0;
148
long GIER_GRAD_FAKTOR = 1291;
148
long GIER_GRAD_FAKTOR = 1291;
149
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
149
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
150
unsigned char RequiredMotors = 4;
150
unsigned char RequiredMotors = 4;
151
unsigned char Motor[MAX_MOTORS];
151
unsigned char Motor[MAX_MOTORS];
152
signed int tmp_motorwert[MAX_MOTORS];
152
signed int tmp_motorwert[MAX_MOTORS];
153
 
153
 
154
int MotorSmoothing(int neu, int alt)
154
int MotorSmoothing(int neu, int alt)
155
{
155
{
156
 int motor;
156
 int motor;
-
 
157
 
-
 
158
 if(neu > alt)
-
 
159
 {
157
 if(neu > alt) motor = (1*(int)alt + neu) / 2;
160
        motor = (1*(int)alt + neu) / 2;
-
 
161
 }
-
 
162
 else
-
 
163
 
-
 
164
// Arthur P: the original code allowed the motor value to drop to 0 or negative values
-
 
165
// straight off, i.e. could amplify an intended decrease excessively while upregulation
-
 
166
// is dampened. The modification would still allow immediate drop below intended value 
-
 
167
// but would dampen this. This would still allow for airbraking of the prop to have effect
-
 
168
// but it might lead to less sudden excessive drops in rpm with only gradual recovery.
-
 
169
 
-
 
170
 {
-
 
171
        if(Parameter_UserParam1 < 1)
-
 
172
        { // Original function
158
 else   motor = neu - (alt - neu)*1;
173
                motor = neu - (alt - neu)*1;
-
 
174
        }
-
 
175
        else
-
 
176
        {
-
 
177
                if(Parameter_UserParam1 == 1)  // If userpara1 = 1 then 150% down on the first step followed by upsmoothing.
-
 
178
                {
-
 
179
                        motor = neu - (1*(alt - neu)/2);
-
 
180
                }
-
 
181
                else // If userpara1 > 1 then allow >= 50% of the intended step down to rapidly reach the intended value.
-
 
182
                {
-
 
183
                        motor = neu + ((alt - neu)/Parameter_UserParam1);
-
 
184
                }
-
 
185
        }
-
 
186
 }
159
//if(Poti2 < 20)  return(neu);
187
//if(Poti2 < 20)  return(neu);
160
 return(motor);
188
 return(motor);
161
}
189
}
162
 
190
 
163
 
191
 
164
void Piep(unsigned char Anzahl)
192
void Piep(unsigned char Anzahl)
165
{
193
{
166
 while(Anzahl--)
194
 while(Anzahl--)
167
 {
195
 {
168
  if(MotorenEin) return; //auf keinen Fall im Flug!
196
  if(MotorenEin) return; //auf keinen Fall im Flug!
169
  beeptime = 100;
197
  beeptime = 100;
170
  Delay_ms(250);
198
  Delay_ms(250);
171
 }
199
 }
172
}
200
}
173
 
201
 
174
//############################################################################
202
//############################################################################
175
//  Nullwerte ermitteln
203
//  Nullwerte ermitteln
176
void SetNeutral(void)
204
void SetNeutral(void)
177
//############################################################################
205
//############################################################################
178
{
206
{
179
 unsigned char i;
207
 unsigned char i;
180
 unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
208
 unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
181
    ServoActive = 0; HEF4017R_ON;
209
    ServoActive = 0; HEF4017R_ON;
182
        NeutralAccX = 0;
210
        NeutralAccX = 0;
183
        NeutralAccY = 0;
211
        NeutralAccY = 0;
184
        NeutralAccZ = 0;
212
        NeutralAccZ = 0;
185
    AdNeutralNick = 0;
213
    AdNeutralNick = 0;
186
        AdNeutralRoll = 0;
214
        AdNeutralRoll = 0;
187
        AdNeutralGier = 0;
215
        AdNeutralGier = 0;
188
    AdNeutralGierBias = 0;
216
    AdNeutralGierBias = 0;
189
    Parameter_AchsKopplung1 = 0;
217
    Parameter_AchsKopplung1 = 0;
190
    Parameter_AchsKopplung2 = 0;
218
    Parameter_AchsKopplung2 = 0;
191
    ExpandBaro = 0;
219
    ExpandBaro = 0;
192
    CalibrierMittelwert();
220
    CalibrierMittelwert();
193
    Delay_ms_Mess(100);
221
    Delay_ms_Mess(100);
194
        CalibrierMittelwert();
222
        CalibrierMittelwert();
195
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
223
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
196
     {
224
     {
197
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
225
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
198
     }
226
     }
199
#define NEUTRAL_FILTER 32
227
#define NEUTRAL_FILTER 32
200
    for(i=0; i<NEUTRAL_FILTER; i++)
228
    for(i=0; i<NEUTRAL_FILTER; i++)
201
         {
229
         {
202
          Delay_ms_Mess(10);
230
          Delay_ms_Mess(10);
203
          gier_neutral += AdWertGier;
231
          gier_neutral += AdWertGier;
204
          nick_neutral += AdWertNick;
232
          nick_neutral += AdWertNick;
205
          roll_neutral += AdWertRoll;
233
          roll_neutral += AdWertRoll;
206
         }
234
         }
207
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
235
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
208
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
236
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
209
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
237
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
210
     AdNeutralGierBias = AdNeutralGier;
238
     AdNeutralGierBias = AdNeutralGier;
211
     StartNeutralRoll = AdNeutralRoll;
239
     StartNeutralRoll = AdNeutralRoll;
212
     StartNeutralNick = AdNeutralNick;
240
     StartNeutralNick = AdNeutralNick;
213
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
241
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
214
    {
242
    {
215
      NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
243
      NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
216
          NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
244
          NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
217
          NeutralAccZ = Aktuell_az;
245
          NeutralAccZ = Aktuell_az;
218
    }
246
    }
219
    else
247
    else
220
    {
248
    {
221
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
249
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
222
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
250
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
223
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
251
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
224
    }
252
    }
225
 
253
 
226
    MesswertNick = 0;
254
    MesswertNick = 0;
227
    MesswertRoll = 0;
255
    MesswertRoll = 0;
228
    MesswertGier = 0;
256
    MesswertGier = 0;
229
    Delay_ms_Mess(100);
257
    Delay_ms_Mess(100);
230
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
258
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
231
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
259
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
232
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
260
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
233
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
261
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
234
    Mess_IntegralNick2 = IntegralNick;
262
    Mess_IntegralNick2 = IntegralNick;
235
    Mess_IntegralRoll2 = IntegralRoll;
263
    Mess_IntegralRoll2 = IntegralRoll;
236
    Mess_Integral_Gier = 0;
264
    Mess_Integral_Gier = 0;
237
    StartLuftdruck = Luftdruck;
265
    StartLuftdruck = Luftdruck;
238
    HoeheD = 0;
266
    HoeheD = 0;
239
    Mess_Integral_Hoch = 0;
267
    Mess_Integral_Hoch = 0;
240
    KompassStartwert = KompassValue;
268
    KompassStartwert = KompassValue;
241
    GPS_Neutral();
269
    GPS_Neutral();
242
    beeptime = 50;
270
    beeptime = 50;
243
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
271
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
244
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
272
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
245
    ExternHoehenValue = 0;
273
    ExternHoehenValue = 0;
246
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
274
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
247
    GierGyroFehler = 0;
275
    GierGyroFehler = 0;
248
    SendVersionToNavi = 1;
276
    SendVersionToNavi = 1;
249
    LED_Init();
277
    LED_Init();
250
    MikroKopterFlags |= FLAG_CALIBRATE;
278
    MikroKopterFlags |= FLAG_CALIBRATE;
251
    FromNaviCtrl_Value.Kalman_K = -1;
279
    FromNaviCtrl_Value.Kalman_K = -1;
252
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
280
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
253
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
281
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
254
    Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110;
282
    Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110;
255
    Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110;
283
    Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110;
256
    Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110;
284
    Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110;
257
    Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110;
285
    Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110;
258
    ServoActive = 1;
286
    ServoActive = 1;
259
    SenderOkay = 100;
287
    SenderOkay = 100;
260
}
288
}
261
 
289
 
262
//############################################################################
290
//############################################################################
263
// Bearbeitet die Messwerte
291
// Bearbeitet die Messwerte
264
void Mittelwert(void)
292
void Mittelwert(void)
265
//############################################################################
293
//############################################################################
266
{
294
{
267
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
295
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
268
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
296
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
269
        signed long winkel_nick, winkel_roll;
297
        signed long winkel_nick, winkel_roll;
270
 
298
 
271
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
299
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
272
//    MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier;
300
//    MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier;
273
    MesswertNick = (signed int) AdWertNickFilter / 8;
301
    MesswertNick = (signed int) AdWertNickFilter / 8;
274
    MesswertRoll = (signed int) AdWertRollFilter / 8;
302
    MesswertRoll = (signed int) AdWertRollFilter / 8;
275
    RohMesswertNick = MesswertNick;
303
    RohMesswertNick = MesswertNick;
276
    RohMesswertRoll = MesswertRoll;
304
    RohMesswertRoll = MesswertRoll;
277
//DebugOut.Analog[21] = MesswertNick;
305
//DebugOut.Analog[21] = MesswertNick;
278
//DebugOut.Analog[22] = MesswertRoll;
306
//DebugOut.Analog[22] = MesswertRoll;
279
//DebugOut.Analog[22] = Mess_Integral_Gier;
307
//DebugOut.Analog[22] = Mess_Integral_Gier;
280
//DebugOut.Analog[21] = MesswertNick;
308
//DebugOut.Analog[21] = MesswertNick;
281
//DebugOut.Analog[22] = MesswertRoll;
309
//DebugOut.Analog[22] = MesswertRoll;
282
 
310
 
283
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
311
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
284
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
312
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
285
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
313
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
286
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
314
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
287
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
315
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
288
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
316
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
289
    NaviAccNick    += AdWertAccNick;
317
    NaviAccNick    += AdWertAccNick;
290
    NaviAccRoll    += AdWertAccRoll;
318
    NaviAccRoll    += AdWertAccRoll;
291
    NaviCntAcc++;
319
    NaviCntAcc++;
292
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
320
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
293
 
321
 
294
//++++++++++++++++++++++++++++++++++++++++++++++++
322
//++++++++++++++++++++++++++++++++++++++++++++++++
295
// ADC einschalten
323
// ADC einschalten
296
    ANALOG_ON;
324
    ANALOG_ON;
297
        AdReady = 0;
325
        AdReady = 0;
298
//++++++++++++++++++++++++++++++++++++++++++++++++
326
//++++++++++++++++++++++++++++++++++++++++++++++++
299
 
327
 
300
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
328
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
301
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
329
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
302
        else winkel_roll = Mess_IntegralRoll;
330
        else winkel_roll = Mess_IntegralRoll;
303
 
331
 
304
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
332
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
305
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
333
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
306
        else winkel_nick = Mess_IntegralNick;
334
        else winkel_nick = Mess_IntegralNick;
307
 
335
 
308
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
336
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
309
   Mess_Integral_Gier += MesswertGier;
337
   Mess_Integral_Gier += MesswertGier;
310
   ErsatzKompass += MesswertGier;
338
   ErsatzKompass += MesswertGier;
311
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
339
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
312
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
340
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
313
         {
341
         {
314
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
342
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
315
            tmpl3 *= Parameter_AchsKopplung2; //65
343
            tmpl3 *= Parameter_AchsKopplung2; //65
316
            tmpl3 /= 4096L;
344
            tmpl3 /= 4096L;
317
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
345
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
318
            tmpl4 *= Parameter_AchsKopplung2; //65
346
            tmpl4 *= Parameter_AchsKopplung2; //65
319
            tmpl4 /= 4096L;
347
            tmpl4 /= 4096L;
320
            KopplungsteilNickRoll = tmpl3;
348
            KopplungsteilNickRoll = tmpl3;
321
            KopplungsteilRollNick = tmpl4;
349
            KopplungsteilRollNick = tmpl4;
322
            tmpl4 -= tmpl3;
350
            tmpl4 -= tmpl3;
323
            ErsatzKompass += tmpl4;
351
            ErsatzKompass += tmpl4;
324
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
352
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
325
 
353
 
326
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
354
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
327
            tmpl *= Parameter_AchsKopplung1;  // 90
355
            tmpl *= Parameter_AchsKopplung1;  // 90
328
            tmpl /= 4096L;
356
            tmpl /= 4096L;
329
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
357
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
330
            tmpl2 *= Parameter_AchsKopplung1;
358
            tmpl2 *= Parameter_AchsKopplung1;
331
            tmpl2 /= 4096L;
359
            tmpl2 /= 4096L;
332
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
360
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
333
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
361
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
334
         }
362
         }
335
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
363
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
336
 
364
 
337
TrimRoll = tmpl - tmpl2 / 100L;
365
TrimRoll = tmpl - tmpl2 / 100L;
338
TrimNick = -tmpl2 + tmpl / 100L;
366
TrimNick = -tmpl2 + tmpl / 100L;
339
 
367
 
340
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
368
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
341
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
369
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
342
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
370
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
343
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
371
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
344
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
372
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
345
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
373
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
346
            if(Mess_IntegralRoll > Umschlag180Roll)
374
            if(Mess_IntegralRoll > Umschlag180Roll)
347
            {
375
            {
348
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
376
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
349
             Mess_IntegralRoll2 = Mess_IntegralRoll;
377
             Mess_IntegralRoll2 = Mess_IntegralRoll;
350
            }
378
            }
351
            if(Mess_IntegralRoll <-Umschlag180Roll)
379
            if(Mess_IntegralRoll <-Umschlag180Roll)
352
            {
380
            {
353
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
381
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
354
             Mess_IntegralRoll2 = Mess_IntegralRoll;
382
             Mess_IntegralRoll2 = Mess_IntegralRoll;
355
            }
383
            }
356
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
384
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
357
            Mess_IntegralNick2 += MesswertNick + TrimNick;
385
            Mess_IntegralNick2 += MesswertNick + TrimNick;
358
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
386
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
359
            if(Mess_IntegralNick > Umschlag180Nick)
387
            if(Mess_IntegralNick > Umschlag180Nick)
360
             {
388
             {
361
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
389
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
362
              Mess_IntegralNick2 = Mess_IntegralNick;
390
              Mess_IntegralNick2 = Mess_IntegralNick;
363
             }
391
             }
364
            if(Mess_IntegralNick <-Umschlag180Nick)
392
            if(Mess_IntegralNick <-Umschlag180Nick)
365
            {
393
            {
366
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
394
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
367
             Mess_IntegralNick2 = Mess_IntegralNick;
395
             Mess_IntegralNick2 = Mess_IntegralNick;
368
            }
396
            }
369
 
397
 
370
    Integral_Gier  = Mess_Integral_Gier;
398
    Integral_Gier  = Mess_Integral_Gier;
371
    IntegralNick = Mess_IntegralNick;
399
    IntegralNick = Mess_IntegralNick;
372
    IntegralRoll = Mess_IntegralRoll;
400
    IntegralRoll = Mess_IntegralRoll;
373
    IntegralNick2 = Mess_IntegralNick2;
401
    IntegralNick2 = Mess_IntegralNick2;
374
    IntegralRoll2 = Mess_IntegralRoll2;
402
    IntegralRoll2 = Mess_IntegralRoll2;
375
 
403
 
376
#define D_LIMIT 128
404
#define D_LIMIT 128
377
 
405
 
378
   MesswertNick = HiResNick / 8;
406
   MesswertNick = HiResNick / 8;
379
   MesswertRoll = HiResRoll / 8;
407
   MesswertRoll = HiResRoll / 8;
380
 
408
 
381
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
409
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
382
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
410
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
383
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
411
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
384
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
412
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
385
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
413
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
386
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
414
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
387
 
415
 
388
  if(Parameter_Gyro_D)
416
  if(Parameter_Gyro_D)
389
  {
417
  {
390
   d2Nick = HiResNick - oldNick;
418
   d2Nick = HiResNick - oldNick;
391
   oldNick = (oldNick + HiResNick)/2;
419
   oldNick = (oldNick + HiResNick)/2;
392
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
420
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
393
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
421
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
394
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
422
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
395
   d2Roll = HiResRoll - oldRoll;
423
   d2Roll = HiResRoll - oldRoll;
396
   oldRoll = (oldRoll + HiResRoll)/2;
424
   oldRoll = (oldRoll + HiResRoll)/2;
397
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
425
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
398
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
426
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
399
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
427
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
400
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
428
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
401
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
429
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
402
  }
430
  }
403
 
431
 
404
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
432
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
405
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
433
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
406
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
434
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
407
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
435
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
408
 
436
 
409
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
437
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
410
  {
438
  {
411
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
439
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
412
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
440
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
413
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
441
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
414
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
442
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
415
  }
443
  }
416
 
444
 
417
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
445
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
418
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
446
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
419
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
447
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
420
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
448
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
421
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
449
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
422
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
450
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
423
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
451
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
424
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
452
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
425
}
453
}
426
 
454
 
427
//############################################################################
455
//############################################################################
428
// Messwerte beim Ermitteln der Nullage
456
// Messwerte beim Ermitteln der Nullage
429
void CalibrierMittelwert(void)
457
void CalibrierMittelwert(void)
430
//############################################################################
458
//############################################################################
431
{
459
{
432
    if(PlatinenVersion == 13) SucheGyroOffset();
460
    if(PlatinenVersion == 13) SucheGyroOffset();
433
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
461
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
434
        ANALOG_OFF;
462
        ANALOG_OFF;
435
        MesswertNick = AdWertNick;
463
        MesswertNick = AdWertNick;
436
        MesswertRoll = AdWertRoll;
464
        MesswertRoll = AdWertRoll;
437
        MesswertGier = AdWertGier;
465
        MesswertGier = AdWertGier;
438
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
466
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
439
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
467
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
440
        Mittelwert_AccHoch = (long)AdWertAccHoch;
468
        Mittelwert_AccHoch = (long)AdWertAccHoch;
441
   // ADC einschalten
469
   // ADC einschalten
442
    ANALOG_ON;
470
    ANALOG_ON;
443
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
471
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
444
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
472
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
445
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
473
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
446
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
474
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
447
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
475
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
448
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
476
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
449
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
477
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
450
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
478
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
451
 
479
 
452
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
480
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
453
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
481
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
454
}
482
}
455
 
483
 
456
//############################################################################
484
//############################################################################
457
// Senden der Motorwerte per I2C-Bus
485
// Senden der Motorwerte per I2C-Bus
458
void SendMotorData(void)
486
void SendMotorData(void)
459
//############################################################################
487
//############################################################################
460
{
488
{
461
 unsigned char i;
489
 unsigned char i;
462
    if(!MotorenEin)
490
    if(!MotorenEin)
463
        {
491
        {
464
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
492
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
465
                 for(i=0;i<MAX_MOTORS;i++)
493
                 for(i=0;i<MAX_MOTORS;i++)
466
                  {
494
                  {
467
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
495
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
468
                   Motor[i] = MotorTest[i];
496
                   Motor[i] = MotorTest[i];
469
                  }
497
                  }
470
          if(PC_MotortestActive) PC_MotortestActive--;
498
          if(PC_MotortestActive) PC_MotortestActive--;
471
        }
499
        }
472
        else MikroKopterFlags |= FLAG_MOTOR_RUN;
500
        else MikroKopterFlags |= FLAG_MOTOR_RUN;
473
 
501
 
474
    DebugOut.Analog[12] = Motor[0];
502
    DebugOut.Analog[12] = Motor[0];
475
    DebugOut.Analog[13] = Motor[1];
503
    DebugOut.Analog[13] = Motor[1];
476
    DebugOut.Analog[14] = Motor[3];
504
    DebugOut.Analog[14] = Motor[3];
477
    DebugOut.Analog[15] = Motor[2];
505
    DebugOut.Analog[15] = Motor[2];
478
 
506
 
479
    //Start I2C Interrupt Mode
507
    //Start I2C Interrupt Mode
480
    twi_state = 0;
508
    twi_state = 0;
481
    motor = 0;
509
    motor = 0;
482
    i2c_start();
510
    i2c_start();
483
}
511
}
484
 
512
 
485
 
513
 
486
 
514
 
487
//############################################################################
515
//############################################################################
488
// Trägt ggf. das Poti als Parameter ein
516
// Trägt ggf. das Poti als Parameter ein
489
void ParameterZuordnung(void)
517
void ParameterZuordnung(void)
490
//############################################################################
518
//############################################################################
491
{
519
{
492
 #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;}
520
 #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;}
493
 #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; }
521
 #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; }
494
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
522
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
495
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
523
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
496
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
524
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
497
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
525
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
498
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
526
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
499
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
527
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
500
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
528
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
501
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255);
529
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255);
502
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
530
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
503
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
531
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
504
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
532
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
505
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
533
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
506
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
534
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
507
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
535
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
508
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
536
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
509
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
537
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
510
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
538
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
511
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
539
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
512
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
540
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
513
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
541
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
514
 CHK_POTI(Parameter_AchsKopplung2,    EE_Parameter.AchsKopplung2,0,255);
542
 CHK_POTI(Parameter_AchsKopplung2,    EE_Parameter.AchsKopplung2,0,255);
515
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255);
543
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255);
516
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
544
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
517
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
545
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
518
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
546
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
519
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
547
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
520
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
548
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
521
 Ki = 10300 / (Parameter_I_Faktor + 1);
549
 Ki = 10300 / (Parameter_I_Faktor + 1);
522
 MAX_GAS = EE_Parameter.Gas_Max;
550
 MAX_GAS = EE_Parameter.Gas_Max;
523
 MIN_GAS = EE_Parameter.Gas_Min;
551
 MIN_GAS = EE_Parameter.Gas_Min;
524
}
552
}
525
 
553
 
526
 
554
 
527
 
555
 
528
//############################################################################
556
//############################################################################
529
//
557
//
530
void MotorRegler(void)
558
void MotorRegler(void)
531
//############################################################################
559
//############################################################################
532
{
560
{
533
         int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int;
561
         int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int;
534
         int GierMischanteil,GasMischanteil;
562
         int GierMischanteil,GasMischanteil;
535
     static long SummeNick=0,SummeRoll=0;
563
     static long SummeNick=0,SummeRoll=0;
536
     static long sollGier = 0,tmp_long,tmp_long2;
564
     static long sollGier = 0,tmp_long,tmp_long2;
537
     static long IntegralFehlerNick = 0;
565
     static long IntegralFehlerNick = 0;
538
     static long IntegralFehlerRoll = 0;
566
     static long IntegralFehlerRoll = 0;
539
         static unsigned int RcLostTimer;
567
         static unsigned int RcLostTimer;
540
         static unsigned char delay_neutral = 0;
568
         static unsigned char delay_neutral = 0;
541
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
569
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
542
     static int hoehenregler = 0;
570
     static int hoehenregler = 0;
543
     static char TimerWerteausgabe = 0;
571
     static char TimerWerteausgabe = 0;
544
     static char NeueKompassRichtungMerken = 0;
572
     static char NeueKompassRichtungMerken = 0;
545
     static long ausgleichNick, ausgleichRoll;
573
     static long ausgleichNick, ausgleichRoll;
546
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
574
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
547
         unsigned char i;
575
         unsigned char i;
548
        Mittelwert();
576
        Mittelwert();
549
 
577
 
550
    GRN_ON;
578
    GRN_ON;
551
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
579
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
552
// Gaswert ermitteln
580
// Gaswert ermitteln
553
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
581
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
554
        GasMischanteil = StickGas;
582
        GasMischanteil = StickGas;
555
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
583
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
556
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
584
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
557
// Empfang schlecht
585
// Empfang schlecht
558
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
586
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
559
   if(SenderOkay < 100)
587
   if(SenderOkay < 100)
560
        {
588
        {
561
        if(!PcZugriff)
589
        if(!PcZugriff)
562
         {
590
         {
563
           if(BeepMuster == 0xffff)
591
           if(BeepMuster == 0xffff)
564
            {
592
            {
565
             beeptime = 15000;
593
             beeptime = 15000;
566
             BeepMuster = 0x0c00;
594
             BeepMuster = 0x0c00;
567
            }
595
            }
568
         }
596
         }
569
        if(RcLostTimer) RcLostTimer--;
597
        if(RcLostTimer) RcLostTimer--;
570
        else
598
        else
571
         {
599
         {
572
          MotorenEin = 0;
600
          MotorenEin = 0;
573
          Notlandung = 0;
601
          Notlandung = 0;
574
         }
602
         }
575
        ROT_ON;
603
        ROT_ON;
576
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
604
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
577
            {
605
            {
578
            GasMischanteil = EE_Parameter.NotGas;
606
            GasMischanteil = EE_Parameter.NotGas;
579
            Notlandung = 1;
607
            Notlandung = 1;
580
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
608
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
581
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
609
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
582
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
610
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
583
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
611
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
584
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
612
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
585
            }
613
            }
586
         else MotorenEin = 0;
614
         else MotorenEin = 0;
587
        }
615
        }
588
        else
616
        else
589
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
617
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
590
// Emfang gut
618
// Emfang gut
591
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
619
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
592
        if(SenderOkay > 140)
620
        if(SenderOkay > 140)
593
            {
621
            {
594
            Notlandung = 0;
622
            Notlandung = 0;
595
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
623
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
596
            if(GasMischanteil > 40 && MotorenEin)
624
            if(GasMischanteil > 40 && MotorenEin)
597
                {
625
                {
598
                if(modell_fliegt < 0xffff) modell_fliegt++;
626
                if(modell_fliegt < 0xffff) modell_fliegt++;
599
                }
627
                }
600
            if((modell_fliegt < 256))
628
            if((modell_fliegt < 256))
601
                {
629
                {
602
                SummeNick = 0;
630
                SummeNick = 0;
603
                SummeRoll = 0;
631
                SummeRoll = 0;
604
                if(modell_fliegt == 250)
632
                if(modell_fliegt == 250)
605
                 {
633
                 {
606
                  NeueKompassRichtungMerken = 1;
634
                  NeueKompassRichtungMerken = 1;
607
                  sollGier = 0;
635
                  sollGier = 0;
608
                  Mess_Integral_Gier = 0;
636
                  Mess_Integral_Gier = 0;
609
//                  Mess_Integral_Gier2 = 0;
637
//                  Mess_Integral_Gier2 = 0;
610
                 }
638
                 }
611
                } else MikroKopterFlags |= FLAG_FLY;
639
                } else MikroKopterFlags |= FLAG_FLY;
612
 
640
 
613
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
641
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
614
                {
642
                {
615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
643
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
616
// auf Nullwerte kalibrieren
644
// auf Nullwerte kalibrieren
617
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
645
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
618
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
646
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
619
                    {
647
                    {
620
                    if(++delay_neutral > 200)  // nicht sofort
648
                    if(++delay_neutral > 200)  // nicht sofort
621
                        {
649
                        {
622
                        GRN_OFF;
650
                        GRN_OFF;
623
                        MotorenEin = 0;
651
                        MotorenEin = 0;
624
                        delay_neutral = 0;
652
                        delay_neutral = 0;
625
                        modell_fliegt = 0;
653
                        modell_fliegt = 0;
626
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
654
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
627
                        {
655
                        {
628
                         unsigned char setting=1;
656
                         unsigned char setting=1;
629
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
657
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
630
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
658
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
631
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
659
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
632
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
660
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
633
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
661
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
634
                         SetActiveParamSetNumber(setting);  // aktiven Datensatz merken
662
                         SetActiveParamSetNumber(setting);  // aktiven Datensatz merken
635
                        }
663
                        }
636
//                        else
664
//                        else
637
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
665
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
638
                          {
666
                          {
639
                           WinkelOut.CalcState = 1;
667
                           WinkelOut.CalcState = 1;
640
                           beeptime = 1000;
668
                           beeptime = 1000;
641
                          }
669
                          }
642
                          else
670
                          else
643
                          {
671
                          {
644
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
672
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
645
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
673
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
646
                            {
674
                            {
647
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
675
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
648
                            }
676
                            }
649
                           SetNeutral();
677
                           SetNeutral();
650
                           Piep(GetActiveParamSetNumber());
678
                           Piep(GetActiveParamSetNumber());
651
                         }
679
                         }
652
                        }
680
                        }
653
                    }
681
                    }
654
                 else
682
                 else
655
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
683
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
656
                    {
684
                    {
657
                    if(++delay_neutral > 200)  // nicht sofort
685
                    if(++delay_neutral > 200)  // nicht sofort
658
                        {
686
                        {
659
                        GRN_OFF;
687
                        GRN_OFF;
660
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
688
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
661
                        MotorenEin = 0;
689
                        MotorenEin = 0;
662
                        delay_neutral = 0;
690
                        delay_neutral = 0;
663
                        modell_fliegt = 0;
691
                        modell_fliegt = 0;
664
                        SetNeutral();
692
                        SetNeutral();
665
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
693
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
666
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
694
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
667
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
695
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
668
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
696
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
669
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
697
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
670
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
698
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
671
                        Piep(GetActiveParamSetNumber());
699
                        Piep(GetActiveParamSetNumber());
672
                        }
700
                        }
673
                    }
701
                    }
674
                 else delay_neutral = 0;
702
                 else delay_neutral = 0;
675
                }
703
                }
676
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
704
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
677
// Gas ist unten
705
// Gas ist unten
678
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
706
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
679
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
707
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
680
                {
708
                {
681
                // Starten
709
                // Starten
682
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
710
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
683
                    {
711
                    {
684
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
712
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
685
// Einschalten
713
// Einschalten
686
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
714
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
687
                    if(++delay_einschalten > 200)
715
                    if(++delay_einschalten > 200)
688
                        {
716
                        {
689
                        delay_einschalten = 200;
717
                        delay_einschalten = 200;
690
                        modell_fliegt = 1;
718
                        modell_fliegt = 1;
691
                        MotorenEin = 1;
719
                        MotorenEin = 1;
692
                        sollGier = 0;
720
                        sollGier = 0;
693
                        Mess_Integral_Gier = 0;
721
                        Mess_Integral_Gier = 0;
694
                        Mess_Integral_Gier2 = 0;
722
                        Mess_Integral_Gier2 = 0;
695
                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
723
                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
696
                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
724
                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
697
                        Mess_IntegralNick2 = IntegralNick;
725
                        Mess_IntegralNick2 = IntegralNick;
698
                        Mess_IntegralRoll2 = IntegralRoll;
726
                        Mess_IntegralRoll2 = IntegralRoll;
699
                        SummeNick = 0;
727
                        SummeNick = 0;
700
                        SummeRoll = 0;
728
                        SummeRoll = 0;
701
                        MikroKopterFlags |= FLAG_START;
729
                        MikroKopterFlags |= FLAG_START;
702
                        }
730
                        }
703
                    }
731
                    }
704
                    else delay_einschalten = 0;
732
                    else delay_einschalten = 0;
705
                //Auf Neutralwerte setzen
733
                //Auf Neutralwerte setzen
706
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
734
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
707
// Auschalten
735
// Auschalten
708
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
736
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
709
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
737
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
710
                    {
738
                    {
711
                    if(++delay_ausschalten > 200)  // nicht sofort
739
                    if(++delay_ausschalten > 200)  // nicht sofort
712
                        {
740
                        {
713
                        MotorenEin = 0;
741
                        MotorenEin = 0;
714
                        delay_ausschalten = 200;
742
                        delay_ausschalten = 200;
715
                        modell_fliegt = 0;
743
                        modell_fliegt = 0;
716
                        }
744
                        }
717
                    }
745
                    }
718
                else delay_ausschalten = 0;
746
                else delay_ausschalten = 0;
719
                }
747
                }
720
            }
748
            }
721
 
749
 
722
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
750
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
723
// neue Werte von der Funke
751
// neue Werte von der Funke
724
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
752
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
725
 
753
 
726
 if(!NewPpmData-- || Notlandung)
754
 if(!NewPpmData-- || Notlandung)
727
  {
755
  {
728
        static int stick_nick,stick_roll;
756
        static int stick_nick,stick_roll;
729
    ParameterZuordnung();
757
    ParameterZuordnung();
730
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
758
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
731
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
759
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
732
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
760
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
733
 
761
 
734
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
762
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
735
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
763
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
736
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
764
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
737
 
765
 
738
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
766
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
739
        if(StickGier > 2) StickGier -= 2;       else
767
        if(StickGier > 2) StickGier -= 2;       else
740
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
768
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
741
 
769
 
742
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
770
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
743
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
771
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
744
    IntegralFaktor = Parameter_Gyro_I;
772
    IntegralFaktor = Parameter_Gyro_I;
745
    GyroFaktorGier     = (Parameter_Gyro_P + 10.0);
773
    GyroFaktorGier     = (Parameter_Gyro_P + 10.0);
746
    IntegralFaktorGier = Parameter_Gyro_I;
774
    IntegralFaktorGier = Parameter_Gyro_I;
747
 
775
 
748
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
776
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
749
//+ Analoge Steuerung per Seriell
777
//+ Analoge Steuerung per Seriell
750
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
778
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
751
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
779
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
752
    {
780
    {
753
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
781
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
754
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
782
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
755
         StickGier += ExternControl.Gier;
783
         StickGier += ExternControl.Gier;
756
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
784
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
757
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
785
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
758
    }
786
    }
759
    if(StickGas < 0) StickGas = 0;
787
    if(StickGas < 0) StickGas = 0;
760
 
788
 
761
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
789
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
762
    if(GyroFaktor < 0) GyroFaktor = 0;
790
    if(GyroFaktor < 0) GyroFaktor = 0;
763
    if(IntegralFaktor < 0) IntegralFaktor = 0;
791
    if(IntegralFaktor < 0) IntegralFaktor = 0;
764
 
792
 
765
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
793
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
766
     {
794
     {
767
      MaxStickNick = abs(StickNick)/STICK_GAIN;
795
      MaxStickNick = abs(StickNick)/STICK_GAIN;
768
      if(MaxStickNick > 100) MaxStickNick = 100;
796
      if(MaxStickNick > 100) MaxStickNick = 100;
769
     }
797
     }
770
     else MaxStickNick--;
798
     else MaxStickNick--;
771
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
799
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
772
     {
800
     {
773
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
801
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
774
      if(MaxStickRoll > 100) MaxStickRoll = 100;
802
      if(MaxStickRoll > 100) MaxStickRoll = 100;
775
     }
803
     }
776
     else MaxStickRoll--;
804
     else MaxStickRoll--;
777
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
805
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
778
 
806
 
779
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
807
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
780
// Looping?
808
// Looping?
781
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
809
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
782
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
810
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
783
  else
811
  else
784
   {
812
   {
785
     {
813
     {
786
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
814
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
787
     }
815
     }
788
   }
816
   }
789
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
817
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
790
   else
818
   else
791
   {
819
   {
792
   if(Looping_Rechts) // Hysterese
820
   if(Looping_Rechts) // Hysterese
793
     {
821
     {
794
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
822
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
795
     }
823
     }
796
   }
824
   }
797
 
825
 
798
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
826
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
799
  else
827
  else
800
   {
828
   {
801
    if(Looping_Oben)  // Hysterese
829
    if(Looping_Oben)  // Hysterese
802
     {
830
     {
803
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
831
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
804
     }
832
     }
805
   }
833
   }
806
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
834
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
807
   else
835
   else
808
   {
836
   {
809
    if(Looping_Unten) // Hysterese
837
    if(Looping_Unten) // Hysterese
810
     {
838
     {
811
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
839
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
812
     }
840
     }
813
   }
841
   }
814
 
842
 
815
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
843
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
816
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
844
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
817
  } // Ende neue Funken-Werte
845
  } // Ende neue Funken-Werte
818
 
846
 
819
  if(Looping_Roll || Looping_Nick)
847
  if(Looping_Roll || Looping_Nick)
820
   {
848
   {
821
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
849
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
822
        TrichterFlug = 1;
850
        TrichterFlug = 1;
823
   }
851
   }
824
 
852
 
825
 
853
 
826
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
854
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
827
// Bei Empfangsausfall im Flug
855
// Bei Empfangsausfall im Flug
828
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
856
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
829
   if(Notlandung)
857
   if(Notlandung)
830
    {
858
    {
831
     StickGier = 0;
859
     StickGier = 0;
832
     StickNick = 0;
860
     StickNick = 0;
833
     StickRoll = 0;
861
     StickRoll = 0;
834
     GyroFaktor     = 90;
862
     GyroFaktor     = 90;
835
     IntegralFaktor = 120;
863
     IntegralFaktor = 120;
836
     GyroFaktorGier     = 90;
864
     GyroFaktorGier     = 90;
837
     IntegralFaktorGier = 120;
865
     IntegralFaktorGier = 120;
838
     Looping_Roll = 0;
866
     Looping_Roll = 0;
839
     Looping_Nick = 0;
867
     Looping_Nick = 0;
840
    }
868
    }
841
 
869
 
842
 
870
 
843
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
871
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
844
// Integrale auf ACC-Signal abgleichen
872
// Integrale auf ACC-Signal abgleichen
845
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
873
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
846
#define ABGLEICH_ANZAHL 256L
874
#define ABGLEICH_ANZAHL 256L
847
 
875
 
848
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
876
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
849
 MittelIntegralRoll  += IntegralRoll;
877
 MittelIntegralRoll  += IntegralRoll;
850
 MittelIntegralNick2 += IntegralNick2;
878
 MittelIntegralNick2 += IntegralNick2;
851
 MittelIntegralRoll2 += IntegralRoll2;
879
 MittelIntegralRoll2 += IntegralRoll2;
852
 
880
 
853
 if(Looping_Nick || Looping_Roll)
881
 if(Looping_Nick || Looping_Roll)
854
  {
882
  {
855
    IntegralAccNick = 0;
883
    IntegralAccNick = 0;
856
    IntegralAccRoll = 0;
884
    IntegralAccRoll = 0;
857
    MittelIntegralNick = 0;
885
    MittelIntegralNick = 0;
858
    MittelIntegralRoll = 0;
886
    MittelIntegralRoll = 0;
859
    MittelIntegralNick2 = 0;
887
    MittelIntegralNick2 = 0;
860
    MittelIntegralRoll2 = 0;
888
    MittelIntegralRoll2 = 0;
861
    Mess_IntegralNick2 = Mess_IntegralNick;
889
    Mess_IntegralNick2 = Mess_IntegralNick;
862
    Mess_IntegralRoll2 = Mess_IntegralRoll;
890
    Mess_IntegralRoll2 = Mess_IntegralRoll;
863
    ZaehlMessungen = 0;
891
    ZaehlMessungen = 0;
864
    LageKorrekturNick = 0;
892
    LageKorrekturNick = 0;
865
    LageKorrekturRoll = 0;
893
    LageKorrekturRoll = 0;
866
  }
894
  }
867
 
895
 
868
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
896
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
869
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
897
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
870
  {
898
  {
871
   long tmp_long, tmp_long2;
899
   long tmp_long, tmp_long2;
872
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
900
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
873
     {
901
     {
874
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
902
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
875
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
903
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
876
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
904
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
877
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
905
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
878
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
906
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
879
      {
907
      {
880
      tmp_long  /= 2;
908
      tmp_long  /= 2;
881
      tmp_long2 /= 2;
909
      tmp_long2 /= 2;
882
      }
910
      }
883
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
911
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
884
      {
912
      {
885
      tmp_long  /= 3;
913
      tmp_long  /= 3;
886
      tmp_long2 /= 3;
914
      tmp_long2 /= 3;
887
      }
915
      }
888
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
916
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
889
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
917
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
890
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
918
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
891
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
919
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
892
     }
920
     }
893
     else
921
     else
894
     {
922
     {
895
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
923
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
896
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
924
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
897
      tmp_long /= 16;
925
      tmp_long /= 16;
898
      tmp_long2 /= 16;
926
      tmp_long2 /= 16;
899
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
927
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
900
      {
928
      {
901
      tmp_long  /= 3;
929
      tmp_long  /= 3;
902
      tmp_long2 /= 3;
930
      tmp_long2 /= 3;
903
      }
931
      }
904
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
932
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
905
      {
933
      {
906
      tmp_long  /= 3;
934
      tmp_long  /= 3;
907
      tmp_long2 /= 3;
935
      tmp_long2 /= 3;
908
      }
936
      }
909
 
937
 
910
#define AUSGLEICH  32
938
#define AUSGLEICH  32
911
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
939
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
912
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
940
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
913
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
941
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
914
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
942
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
915
     }
943
     }
916
 
944
 
917
//if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;}
945
//if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;}
918
   Mess_IntegralNick -= tmp_long;
946
   Mess_IntegralNick -= tmp_long;
919
   Mess_IntegralRoll -= tmp_long2;
947
   Mess_IntegralRoll -= tmp_long2;
920
  }
948
  }
921
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
949
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
922
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
950
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
923
 {
951
 {
924
  static int cnt = 0;
952
  static int cnt = 0;
925
  static char last_n_p,last_n_n,last_r_p,last_r_n;
953
  static char last_n_p,last_n_n,last_r_p,last_r_n;
926
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
954
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
927
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
955
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
928
  {
956
  {
929
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
957
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
930
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
958
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
931
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
959
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
932
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
960
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
933
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
961
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
934
#define MAX_I 0//(Poti2/10)
962
#define MAX_I 0//(Poti2/10)
935
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
963
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
936
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
964
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
937
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
965
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
938
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
966
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
939
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
967
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
940
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
968
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
941
 
969
 
942
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
970
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
943
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
971
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
944
 
972
 
945
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
973
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
946
    {
974
    {
947
     LageKorrekturNick /= 2;
975
     LageKorrekturNick /= 2;
948
     LageKorrekturRoll /= 2;
976
     LageKorrekturRoll /= 2;
949
    }
977
    }
950
 
978
 
951
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
979
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
952
// Gyro-Drift ermitteln
980
// Gyro-Drift ermitteln
953
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
981
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
954
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
982
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
955
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
983
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
956
    tmp_long  = IntegralNick2 - IntegralNick;
984
    tmp_long  = IntegralNick2 - IntegralNick;
957
    tmp_long2 = IntegralRoll2 - IntegralRoll;
985
    tmp_long2 = IntegralRoll2 - IntegralRoll;
958
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
986
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
959
 
987
 
960
    IntegralFehlerNick = tmp_long;
988
    IntegralFehlerNick = tmp_long;
961
    IntegralFehlerRoll = tmp_long2;
989
    IntegralFehlerRoll = tmp_long2;
962
    Mess_IntegralNick2 -= IntegralFehlerNick;
990
    Mess_IntegralNick2 -= IntegralFehlerNick;
963
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
991
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
964
 
992
 
965
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
993
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
966
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
994
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
967
  if(EE_Parameter.Driftkomp)
995
  if(EE_Parameter.Driftkomp)
968
   {
996
   {
969
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
997
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
970
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
998
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
971
   }
999
   }
972
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
1000
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
973
//DebugOut.Analog[24] = GierGyroFehler;
1001
//DebugOut.Analog[24] = GierGyroFehler;
974
    GierGyroFehler = 0;
1002
    GierGyroFehler = 0;
975
 
1003
 
976
 
1004
 
977
/*DebugOut.Analog[17] = IntegralAccNick / 26;
1005
/*DebugOut.Analog[17] = IntegralAccNick / 26;
978
DebugOut.Analog[18] = IntegralAccRoll / 26;
1006
DebugOut.Analog[18] = IntegralAccRoll / 26;
979
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
1007
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
980
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
1008
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
981
*/
1009
*/
982
//DebugOut.Analog[21] = MittelIntegralNick / 26;
1010
//DebugOut.Analog[21] = MittelIntegralNick / 26;
983
//MittelIntegralRoll = MittelIntegralRoll;
1011
//MittelIntegralRoll = MittelIntegralRoll;
984
//DebugOut.Analog[28] = ausgleichNick;
1012
//DebugOut.Analog[28] = ausgleichNick;
985
/*
1013
/*
986
DebugOut.Analog[29] = ausgleichRoll;
1014
DebugOut.Analog[29] = ausgleichRoll;
987
DebugOut.Analog[30] = LageKorrekturRoll * 10;
1015
DebugOut.Analog[30] = LageKorrekturRoll * 10;
988
*/
1016
*/
989
 
1017
 
990
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2) 
1018
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2) 
991
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 
1019
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 
992
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1020
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
993
#define BEWEGUNGS_LIMIT 20000
1021
#define BEWEGUNGS_LIMIT 20000
994
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1022
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
995
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1023
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
996
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1024
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
997
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1025
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
998
        {
1026
        {
999
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1027
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1000
         {
1028
         {
1001
           if(last_n_p)
1029
           if(last_n_p)
1002
           {
1030
           {
1003
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1031
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1004
            ausgleichNick = IntegralFehlerNick / 8;
1032
            ausgleichNick = IntegralFehlerNick / 8;
1005
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1033
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1006
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1034
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1007
           }
1035
           }
1008
           else last_n_p = 1;
1036
           else last_n_p = 1;
1009
         } else  last_n_p = 0;
1037
         } else  last_n_p = 0;
1010
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1038
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1011
         {
1039
         {
1012
           if(last_n_n)
1040
           if(last_n_n)
1013
            {
1041
            {
1014
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1042
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1015
             ausgleichNick = IntegralFehlerNick / 8;
1043
             ausgleichNick = IntegralFehlerNick / 8;
1016
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1044
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1017
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1045
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1018
            }
1046
            }
1019
           else last_n_n = 1;
1047
           else last_n_n = 1;
1020
         } else  last_n_n = 0;
1048
         } else  last_n_n = 0;
1021
        }
1049
        }
1022
        else
1050
        else
1023
        {
1051
        {
1024
         cnt = 0;
1052
         cnt = 0;
1025
         KompassSignalSchlecht = 1000;
1053
         KompassSignalSchlecht = 1000;
1026
        }
1054
        }
1027
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1055
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1028
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1056
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1029
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1057
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1030
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1058
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1031
 
1059
 
1032
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1060
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1033
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1061
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1034
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1062
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1035
        ausgleichRoll = 0;
1063
        ausgleichRoll = 0;
1036
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1064
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1037
        {
1065
        {
1038
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1066
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1039
         {
1067
         {
1040
           if(last_r_p)
1068
           if(last_r_p)
1041
           {
1069
           {
1042
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1070
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1043
            ausgleichRoll = IntegralFehlerRoll / 8;
1071
            ausgleichRoll = IntegralFehlerRoll / 8;
1044
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1072
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1045
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1073
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1046
           }
1074
           }
1047
           else last_r_p = 1;
1075
           else last_r_p = 1;
1048
         } else  last_r_p = 0;
1076
         } else  last_r_p = 0;
1049
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1077
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1050
         {
1078
         {
1051
           if(last_r_n)
1079
           if(last_r_n)
1052
           {
1080
           {
1053
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1081
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1054
            ausgleichRoll = IntegralFehlerRoll / 8;
1082
            ausgleichRoll = IntegralFehlerRoll / 8;
1055
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1083
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1056
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1084
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1057
           }
1085
           }
1058
           else last_r_n = 1;
1086
           else last_r_n = 1;
1059
         } else  last_r_n = 0;
1087
         } else  last_r_n = 0;
1060
        } else
1088
        } else
1061
        {
1089
        {
1062
         cnt = 0;
1090
         cnt = 0;
1063
         KompassSignalSchlecht = 1000;
1091
         KompassSignalSchlecht = 1000;
1064
        }
1092
        }
1065
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1093
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1066
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1094
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1067
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1095
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1068
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1096
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1069
  }
1097
  }
1070
  else
1098
  else
1071
  {
1099
  {
1072
   LageKorrekturRoll = 0;
1100
   LageKorrekturRoll = 0;
1073
   LageKorrekturNick = 0;
1101
   LageKorrekturNick = 0;
1074
   TrichterFlug = 0;
1102
   TrichterFlug = 0;
1075
  }
1103
  }
1076
 
1104
 
1077
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1105
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1078
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1106
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1079
   MittelIntegralNick_Alt = MittelIntegralNick;
1107
   MittelIntegralNick_Alt = MittelIntegralNick;
1080
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1108
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1081
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1109
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1082
    IntegralAccNick = 0;
1110
    IntegralAccNick = 0;
1083
    IntegralAccRoll = 0;
1111
    IntegralAccRoll = 0;
1084
    IntegralAccZ = 0;
1112
    IntegralAccZ = 0;
1085
    MittelIntegralNick = 0;
1113
    MittelIntegralNick = 0;
1086
    MittelIntegralRoll = 0;
1114
    MittelIntegralRoll = 0;
1087
    MittelIntegralNick2 = 0;
1115
    MittelIntegralNick2 = 0;
1088
    MittelIntegralRoll2 = 0;
1116
    MittelIntegralRoll2 = 0;
1089
    ZaehlMessungen = 0;
1117
    ZaehlMessungen = 0;
1090
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1118
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1091
 
1119
 
1092
 
1120
 
1093
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1121
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1094
//  Gieren
1122
//  Gieren
1095
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1123
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1096
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
1124
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
1097
    if(abs(StickGier) > 15) // war 35
1125
    if(abs(StickGier) > 15) // war 35
1098
     {
1126
     {
1099
      KompassSignalSchlecht = 1000;
1127
      KompassSignalSchlecht = 1000;
1100
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1128
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1101
       {
1129
       {
1102
         NeueKompassRichtungMerken = 1;
1130
         NeueKompassRichtungMerken = 1;
1103
        };
1131
        };
1104
     }
1132
     }
1105
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1133
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1106
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1134
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1107
    sollGier = tmp_int;
1135
    sollGier = tmp_int;
1108
    Mess_Integral_Gier -= tmp_int;
1136
    Mess_Integral_Gier -= tmp_int;
1109
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1137
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1110
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1138
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1111
 
1139
 
1112
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1140
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1113
//  Kompass
1141
//  Kompass
1114
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1142
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1115
//DebugOut.Analog[16] = KompassSignalSchlecht;
1143
//DebugOut.Analog[16] = KompassSignalSchlecht;
1116
 
1144
 
1117
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1145
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1118
     {
1146
     {
1119
       int w,v,r,fehler,korrektur;
1147
       int w,v,r,fehler,korrektur;
1120
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1148
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1121
       v = abs(IntegralRoll /512);
1149
       v = abs(IntegralRoll /512);
1122
       if(v > w) w = v; // grösste Neigung ermitteln
1150
       if(v > w) w = v; // grösste Neigung ermitteln
1123
       korrektur = w / 8 + 1;
1151
       korrektur = w / 8 + 1;
1124
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1152
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1125
       if(abs(MesswertGier) > 128)
1153
       if(abs(MesswertGier) > 128)
1126
            {
1154
            {
1127
                 fehler = 0;
1155
                 fehler = 0;
1128
                }
1156
                }
1129
       if(!KompassSignalSchlecht && w < 25)
1157
       if(!KompassSignalSchlecht && w < 25)
1130
        {
1158
        {
1131
        GierGyroFehler += fehler;
1159
        GierGyroFehler += fehler;
1132
        if(NeueKompassRichtungMerken)
1160
        if(NeueKompassRichtungMerken)
1133
         {
1161
         {
1134
          beeptime = 200;
1162
          beeptime = 200;
1135
//         KompassStartwert = KompassValue;
1163
//         KompassStartwert = KompassValue;
1136
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1164
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1137
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1165
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1138
          NeueKompassRichtungMerken = 0;
1166
          NeueKompassRichtungMerken = 0;
1139
         }
1167
         }
1140
        }
1168
        }
1141
       ErsatzKompass += (fehler * 8) / korrektur;
1169
       ErsatzKompass += (fehler * 8) / korrektur;
1142
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1170
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1143
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1171
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1144
       if(w >= 0)
1172
       if(w >= 0)
1145
        {
1173
        {
1146
          if(!KompassSignalSchlecht)
1174
          if(!KompassSignalSchlecht)
1147
          {
1175
          {
1148
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1176
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1149
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1177
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1150
//           r = KompassRichtung;
1178
//           r = KompassRichtung;
1151
           v = (r * w) / v;  // nach Kompass ausrichten
1179
           v = (r * w) / v;  // nach Kompass ausrichten
1152
           w = 3 * Parameter_KompassWirkung;
1180
           w = 3 * Parameter_KompassWirkung;
1153
           if(v > w) v = w; // Begrenzen
1181
           if(v > w) v = w; // Begrenzen
1154
           else
1182
           else
1155
           if(v < -w) v = -w;
1183
           if(v < -w) v = -w;
1156
           Mess_Integral_Gier += v;
1184
           Mess_Integral_Gier += v;
1157
          }
1185
          }
1158
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1186
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1159
        }
1187
        }
1160
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1188
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1161
     }
1189
     }
1162
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1190
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1163
 
1191
 
1164
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1192
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1165
//  Debugwerte zuordnen
1193
//  Debugwerte zuordnen
1166
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1194
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1167
  if(!TimerWerteausgabe--)
1195
  if(!TimerWerteausgabe--)
1168
   {
1196
   {
1169
    TimerWerteausgabe = 24;
1197
    TimerWerteausgabe = 24;
1170
 
1198
 
1171
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
1199
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
1172
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1200
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1173
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1201
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1174
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1202
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1175
    DebugOut.Analog[4] = MesswertGier;
1203
    DebugOut.Analog[4] = MesswertGier;
1176
    DebugOut.Analog[5] = HoehenWert;
1204
    DebugOut.Analog[5] = HoehenWert;
1177
    DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1205
    DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1178
    DebugOut.Analog[8] = KompassValue;
1206
    DebugOut.Analog[8] = KompassValue;
1179
    DebugOut.Analog[9] = UBat;
1207
    DebugOut.Analog[9] = UBat;
1180
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1208
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1181
    DebugOut.Analog[10] = SenderOkay;
1209
    DebugOut.Analog[10] = SenderOkay;
1182
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1210
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1183
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1211
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1184
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1212
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1185
    DebugOut.Analog[19] = WinkelOut.CalcState;
1213
    DebugOut.Analog[19] = WinkelOut.CalcState;
1186
    DebugOut.Analog[20] = ServoValue;
1214
    DebugOut.Analog[20] = ServoValue;
1187
//    DebugOut.Analog[24] = MesswertNick/2;
1215
//    DebugOut.Analog[24] = MesswertNick/2;
1188
//    DebugOut.Analog[25] = MesswertRoll/2;
1216
//    DebugOut.Analog[25] = MesswertRoll/2;
1189
    DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift;
1217
    DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift;
1190
//    DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion;
1218
//    DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion;
1191
//    DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K;
1219
//    DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K;
1192
    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
1220
    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
1193
    DebugOut.Analog[30] = GPS_Nick;
1221
    DebugOut.Analog[30] = GPS_Nick;
1194
    DebugOut.Analog[31] = GPS_Roll;
1222
    DebugOut.Analog[31] = GPS_Roll;
1195
 
1223
 
1196
 
1224
 
1197
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1225
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1198
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1226
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1199
 
1227
 
1200
/*    DebugOut.Analog[16] = motor_rx[0];
1228
/*    DebugOut.Analog[16] = motor_rx[0];
1201
    DebugOut.Analog[17] = motor_rx[1];
1229
    DebugOut.Analog[17] = motor_rx[1];
1202
    DebugOut.Analog[18] = motor_rx[2];
1230
    DebugOut.Analog[18] = motor_rx[2];
1203
    DebugOut.Analog[19] = motor_rx[3];
1231
    DebugOut.Analog[19] = motor_rx[3];
1204
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1232
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1205
    DebugOut.Analog[20] /= 14;
1233
    DebugOut.Analog[20] /= 14;
1206
    DebugOut.Analog[21] = motor_rx[4];
1234
    DebugOut.Analog[21] = motor_rx[4];
1207
    DebugOut.Analog[22] = motor_rx[5];
1235
    DebugOut.Analog[22] = motor_rx[5];
1208
    DebugOut.Analog[23] = motor_rx[6];
1236
    DebugOut.Analog[23] = motor_rx[6];
1209
    DebugOut.Analog[24] = motor_rx[7];
1237
    DebugOut.Analog[24] = motor_rx[7];
1210
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1238
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1211
*/
1239
*/
1212
//    DebugOut.Analog[9] = MesswertNick;
1240
//    DebugOut.Analog[9] = MesswertNick;
1213
//    DebugOut.Analog[9] = SollHoehe;
1241
//    DebugOut.Analog[9] = SollHoehe;
1214
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1242
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1215
//    DebugOut.Analog[11] = KompassStartwert;
1243
//    DebugOut.Analog[11] = KompassStartwert;
1216
//    DebugOut.Analog[10] = Parameter_Gyro_I;
1244
//    DebugOut.Analog[10] = Parameter_Gyro_I;
1217
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;
1245
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;
1218
//    DebugOut.Analog[9] = KompassRichtung;
1246
//    DebugOut.Analog[9] = KompassRichtung;
1219
//    DebugOut.Analog[10] = GasMischanteil;
1247
//    DebugOut.Analog[10] = GasMischanteil;
1220
//    DebugOut.Analog[3] = HoeheD * 32;
1248
//    DebugOut.Analog[3] = HoeheD * 32;
1221
//    DebugOut.Analog[4] = hoehenregler;
1249
//    DebugOut.Analog[4] = hoehenregler;
1222
  }
1250
  }
1223
 
1251
 
1224
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1252
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1225
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1253
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1226
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1254
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1227
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1255
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1228
 
1256
 
1229
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1257
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1230
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1258
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1231
 
1259
 
1232
#define TRIM_MAX 200
1260
#define TRIM_MAX 200
1233
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1261
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1234
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1262
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1235
 
1263
 
1236
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1264
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1237
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1265
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1238
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1266
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1239
 
1267
 
1240
    // Maximalwerte abfangen
1268
    // Maximalwerte abfangen
1241
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1269
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1242
    #define MAX_SENSOR  (4096*4)
1270
    #define MAX_SENSOR  (4096*4)
1243
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1271
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1244
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1272
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1245
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1273
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1246
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1274
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1247
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1275
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1248
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1276
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1249
 
1277
 
1250
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1278
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1251
// all BL-Ctrl connected?
1279
// all BL-Ctrl connected?
1252
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1280
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1253
  if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1281
  if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1254
   {
1282
   {
1255
    modell_fliegt = 1;
1283
    modell_fliegt = 1;
1256
        GasMischanteil = MIN_GAS;
1284
        GasMischanteil = MIN_GAS;
1257
   }
1285
   }
1258
 
1286
 
1259
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1287
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1260
// Höhenregelung
1288
// Höhenregelung
1261
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1289
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1262
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1290
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1263
  GasMischanteil *= STICK_GAIN;
1291
  GasMischanteil *= STICK_GAIN;
1264
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1292
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1265
  {
1293
  {
1266
    int tmp_int;
1294
    int tmp_int;
1267
        static char delay = 100;
1295
        static char delay = 100;
1268
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1296
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1269
    {
1297
    {
1270
      if(Parameter_MaxHoehe < 50)
1298
      if(Parameter_MaxHoehe < 50)
1271
      {
1299
      {
1272
       if(!delay--)
1300
       if(!delay--)
1273
            {
1301
            {
1274
         if((MessLuftdruck > 1000) && OCR0A < 254)
1302
         if((MessLuftdruck > 1000) && OCR0A < 254)
1275
                  {
1303
                  {
1276
                    if(OCR0A < 244)
1304
                    if(OCR0A < 244)
1277
                     {
1305
                     {
1278
                      ExpandBaro -= 10;
1306
                      ExpandBaro -= 10;
1279
                      OCR0A = DruckOffsetSetting - ExpandBaro;
1307
                      OCR0A = DruckOffsetSetting - ExpandBaro;
1280
                         }
1308
                         }
1281
                         else OCR0A = 254;
1309
                         else OCR0A = 254;
1282
                beeptime = 300;
1310
                beeptime = 300;
1283
            delay = 250;
1311
            delay = 250;
1284
                  }
1312
                  }
1285
                  else      
1313
                  else      
1286
         if((MessLuftdruck < 100) && OCR0A > 1)
1314
         if((MessLuftdruck < 100) && OCR0A > 1)
1287
                  {
1315
                  {
1288
                   if(OCR0A > 10)
1316
                   if(OCR0A > 10)
1289
                    {
1317
                    {
1290
                     ExpandBaro += 10;
1318
                     ExpandBaro += 10;
1291
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1319
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1292
                        }
1320
                        }
1293
                         else OCR0A = 1;
1321
                         else OCR0A = 1;
1294
                   beeptime = 300;
1322
                   beeptime = 300;
1295
           delay = 250;
1323
           delay = 250;
1296
                  }
1324
                  }
1297
          else
1325
          else
1298
          {
1326
          {
1299
               SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1327
               SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1300
           HoehenReglerAktiv = 0;
1328
           HoehenReglerAktiv = 0;
1301
                   delay = 1;
1329
                   delay = 1;
1302
                  }
1330
                  }
1303
                }
1331
                }
1304
      }
1332
      }
1305
      else
1333
      else
1306
        {
1334
        {
1307
         HoehenReglerAktiv = 1;
1335
         HoehenReglerAktiv = 1;
1308
                 delay = 200;
1336
                 delay = 200;
1309
                }
1337
                }
1310
    }
1338
    }
1311
    else
1339
    else
1312
    {
1340
    {
1313
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1341
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1314
     HoehenReglerAktiv = 1;
1342
     HoehenReglerAktiv = 1;
1315
    }
1343
    }
1316
 
1344
 
1317
    if(Notlandung) SollHoehe = 0;
1345
    if(Notlandung) SollHoehe = 0;
1318
    h = HoehenWert;
1346
    h = HoehenWert;
1319
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1347
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1320
     {
1348
     {
1321
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1349
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1322
      h = GasMischanteil - h;         // vom Gas abziehen
1350
      h = GasMischanteil - h;         // vom Gas abziehen
1323
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1351
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1324
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1352
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1325
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1353
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1326
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1354
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1327
      h -= tmp_int;
1355
      h -= tmp_int;
1328
      hoehenregler = (hoehenregler*15 + h) / 16;
1356
      hoehenregler = (hoehenregler*15 + h) / 16;
1329
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1357
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1330
       {
1358
       {
1331
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1359
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1332
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1360
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1333
       }
1361
       }
1334
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1362
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1335
      GasMischanteil = hoehenregler;
1363
      GasMischanteil = hoehenregler;
1336
     }
1364
     }
1337
  }
1365
  }
1338
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1366
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1339
 
1367
 
1340
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1368
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1341
// + Mischer und PI-Regler
1369
// + Mischer und PI-Regler
1342
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1370
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1343
  DebugOut.Analog[7] = GasMischanteil;
1371
  DebugOut.Analog[7] = GasMischanteil;
1344
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1372
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1345
// Gier-Anteil
1373
// Gier-Anteil
1346
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1374
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1347
#define MUL_G  1.0
1375
#define MUL_G  1.0
1348
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1376
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1349
// GierMischanteil = 0;
1377
// GierMischanteil = 0;
1350
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1378
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1351
   if(GasMischanteil > MIN_GIERGAS)
1379
   if(GasMischanteil > MIN_GIERGAS)
1352
    {
1380
    {
1353
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1381
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1354
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1382
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1355
    }
1383
    }
1356
    else
1384
    else
1357
    {
1385
    {
1358
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1386
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1359
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1387
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1360
    }
1388
    }
1361
    tmp_int = MAX_GAS*STICK_GAIN;
1389
    tmp_int = MAX_GAS*STICK_GAIN;
1362
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1390
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1363
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1391
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1364
 
1392
 
1365
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1393
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1366
// Nick-Achse
1394
// Nick-Achse
1367
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1395
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1368
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1396
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1369
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1397
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1370
    else  SummeNick += DiffNick; // I-Anteil bei HH
1398
    else  SummeNick += DiffNick; // I-Anteil bei HH
1371
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1399
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1372
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1400
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1373
    pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick
1401
    pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick
1374
    // Motor Vorn
1402
    // Motor Vorn
1375
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1403
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1376
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1404
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1377
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1405
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1378
 
1406
 
1379
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1407
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1380
// Roll-Achse
1408
// Roll-Achse
1381
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1409
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1382
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1410
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1383
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1411
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1384
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1412
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1385
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1413
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1386
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1414
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1387
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1415
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1388
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1416
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1389
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1417
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1390
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1418
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1391
 
1419
 
1392
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1420
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1393
// Universal Mixer
1421
// Universal Mixer
1394
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1422
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1395
 for(i=0; i<MAX_MOTORS; i++)
1423
 for(i=0; i<MAX_MOTORS; i++)
1396
 {
1424
 {
1397
  signed int tmp_int;
1425
  signed int tmp_int;
1398
  if(Mixer.Motor[i][0] > 0)
1426
  if(Mixer.Motor[i][0] > 0)
1399
   {
1427
   {
1400
    tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1428
    tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1401
    tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1429
    tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1402
    tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1430
    tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1403
    tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1431
    tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1404
    tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]);  // Filter
1432
    tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]);  // Filter
1405
        tmp_int = tmp_motorwert[i] / STICK_GAIN;
1433
        tmp_int = tmp_motorwert[i] / STICK_GAIN;
1406
        CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS);
1434
        CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS);
1407
    Motor[i] = tmp_int;
1435
    Motor[i] = tmp_int;
1408
   }
1436
   }
1409
   else Motor[i] = 0;
1437
   else Motor[i] = 0;
1410
 }
1438
 }
1411
/*
1439
/*
1412
if(Poti1 > 20)  Motor1 = 0;
1440
if(Poti1 > 20)  Motor1 = 0;
1413
if(Poti1 > 90)  Motor6 = 0;
1441
if(Poti1 > 90)  Motor6 = 0;
1414
if(Poti1 > 140) Motor2 = 0;
1442
if(Poti1 > 140) Motor2 = 0;
1415
//if(Poti1 > 200) Motor7 = 0;
1443
//if(Poti1 > 200) Motor7 = 0;
1416
*/
1444
*/
1417
}
1445
}
1418
 
1446