Subversion Repositories FlightCtrl

Rev

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

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