Subversion Repositories FlightCtrl

Rev

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

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