Subversion Repositories FlightCtrl

Rev

Rev 1286 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1286 Rev 1299
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
#include "mymath.c" // MartinR: für Killagreg´s Erweiterung
57
#include "mymath.c" // MartinR: für Killagreg´s Erweiterung
58
#include "mymath.h" // MartinR: für Killagreg´s Erweiterung
58
#include "mymath.h" // MartinR: für Killagreg´s Erweiterung
59
 
59
 
60
unsigned char h,m,s;
60
unsigned char h,m,s;
61
volatile unsigned int I2CTimeout = 100;
61
volatile unsigned int I2CTimeout = 100;
62
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
62
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
63
int TrimNick, TrimRoll;
63
int TrimNick, TrimRoll;
64
int AdNeutralGierBias;
64
int AdNeutralGierBias;
65
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
65
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
66
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
66
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
67
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
67
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
68
//volatile float NeutralAccZ = 0; // MartinR  : so war es
68
//volatile float NeutralAccZ = 0; // MartinR  : so war es
69
volatile int NeutralAccZ = 0; // MartinR geändert
69
volatile int NeutralAccZ = 0; // MartinR geändert
70
 
70
 
71
volatile int NeutralAccZ2 = 0; // MartinR: für HP-Filter 
71
volatile int NeutralAccZ2 = 0; // MartinR: für HP-Filter 
72
signed int h_p,h_d,h_delta,Ziel_d;  // MartinR: P,D Anteil beim eigenen Höhenregler
72
signed int h_p,h_d,h_delta,Ziel_d;  // MartinR: P,D Anteil beim eigenen Höhenregler
73
signed int SchwebeGas; // MartinR: für neuen Höhenregler
73
signed int SchwebeGas; // MartinR: für neuen Höhenregler
74
 
74
 
75
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
75
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
76
long IntegralNick = 0,IntegralNick2 = 0;
76
long IntegralNick = 0,IntegralNick2 = 0;
77
long IntegralRoll = 0,IntegralRoll2 = 0;
77
long IntegralRoll = 0,IntegralRoll2 = 0;
78
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
78
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
79
long Integral_Gier = 0;
79
long Integral_Gier = 0;
80
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
80
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
81
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
81
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
82
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
82
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
83
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
83
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
84
volatile long Mess_Integral_Hoch = 0;
84
volatile long Mess_Integral_Hoch = 0;
85
int  KompassValue = 0;
85
int  KompassValue = 0;
86
int  KompassStartwert = 0;
86
int  KompassStartwert = 0;
87
int  KompassRichtung = 0;
87
int  KompassRichtung = 0;
88
unsigned int  KompassSignalSchlecht = 500;
88
unsigned int  KompassSignalSchlecht = 500;
89
unsigned char  MAX_GAS,MIN_GAS;
89
unsigned char  MAX_GAS,MIN_GAS;
90
unsigned char Notlandung = 0;
90
unsigned char Notlandung = 0;
91
unsigned char HoehenReglerAktiv = 0;
91
unsigned char HoehenReglerAktiv = 0;
92
unsigned char TrichterFlug = 0;
92
unsigned char TrichterFlug = 0;
93
 
93
 
94
unsigned char delay_Hoehenregler = 0; // MartinR: zur Begrenzung der Sinkgeschwindigkeit
94
unsigned char delay_Hoehenregler = 0; // MartinR: zur Begrenzung der Sinkgeschwindigkeit
95
signed int delay_SchwebeGas = 0; // MartinR: zur Begrenzung der Sinkgeschwindigkeit
95
signed int delay_SchwebeGas = 0; // MartinR: zur Begrenzung der Sinkgeschwindigkeit
96
 
96
 
97
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
97
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
98
long  ErsatzKompass;
98
long  ErsatzKompass;
99
int   ErsatzKompassInGrad; // Kompasswert in Grad
99
int   ErsatzKompassInGrad; // Kompasswert in Grad
100
int   GierGyroFehler = 0;
100
int   GierGyroFehler = 0;
101
char GyroFaktor,GyroFaktorGier;
101
char GyroFaktor,GyroFaktorGier;
102
char IntegralFaktor,IntegralFaktorGier;
102
char IntegralFaktor,IntegralFaktorGier;
103
int  DiffNick,DiffRoll;
103
int  DiffNick,DiffRoll;
104
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
104
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
105
volatile unsigned char SenderOkay = 0;
105
volatile unsigned char SenderOkay = 0;
106
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
106
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
107
char MotorenEin = 0;
107
char MotorenEin = 0;
108
//int HoehenWert = 0; //MartinR: so war es
108
//int HoehenWert = 0; //MartinR: so war es
109
long HoehenWert = 0; //MartinR: geändert
109
long HoehenWert = 0; //MartinR: geändert
110
 
110
 
111
long HoehenWertalt = 0; //MartinR: Test
111
long HoehenWertalt = 0; //MartinR: Test
112
unsigned char iHoehe; // MartinR: Zähler für HoeheD
112
unsigned char iHoehe; // MartinR: Zähler für HoeheD
113
signed long HoehenWertSumme = 0; // MartinR: für neuen Höhenregler D-Anteil
113
signed long HoehenWertSumme = 0; // MartinR: für neuen Höhenregler D-Anteil
114
 
114
 
115
//int SollHoehe = 0;//MartinR: so war es
115
//int SollHoehe = 0;//MartinR: so war es
116
long SollHoehe = 0;//MartinR: geändert
116
long SollHoehe = 0;//MartinR: geändert
117
 
117
 
118
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
118
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
119
//float Ki =  FAKTOR_I;
119
//float Ki =  FAKTOR_I;
120
int Ki = 10300 / 33;
120
int Ki = 10300 / 33;
121
 
121
 
122
int KiHH = 10300 / 33; // MartinR : für Ki bei HH über Schalter
122
int KiHH = 10300 / 33; // MartinR : für Ki bei HH über Schalter
123
 
123
 
124
unsigned char Looping_Nick = 0,Looping_Roll = 0;
124
unsigned char Looping_Nick = 0,Looping_Roll = 0;
125
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
125
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
126
 
126
 
127
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
127
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
128
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
128
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
129
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
129
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
130
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
130
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
131
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
131
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
132
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
132
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
133
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
133
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
134
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
134
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
135
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
135
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
136
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
136
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
137
unsigned char Parameter_UserParam1 = 0;
137
unsigned char Parameter_UserParam1 = 0;
138
unsigned char Parameter_UserParam2 = 0;
138
unsigned char Parameter_UserParam2 = 0;
139
unsigned char Parameter_UserParam3 = 0;
139
unsigned char Parameter_UserParam3 = 0;
140
unsigned char Parameter_UserParam4 = 0;
140
unsigned char Parameter_UserParam4 = 0;
141
unsigned char Parameter_UserParam5 = 0;
141
unsigned char Parameter_UserParam5 = 0;
142
unsigned char Parameter_UserParam6 = 0;
142
unsigned char Parameter_UserParam6 = 0;
143
unsigned char Parameter_UserParam7 = 0;
143
unsigned char Parameter_UserParam7 = 0;
144
unsigned char Parameter_UserParam8 = 0;
144
unsigned char Parameter_UserParam8 = 0;
145
unsigned char Parameter_ServoNickControl = 100;
145
unsigned char Parameter_ServoNickControl = 100;
146
unsigned char Parameter_LoopGasLimit = 70;
146
unsigned char Parameter_LoopGasLimit = 70;
147
unsigned char Parameter_AchsKopplung1 = 90;
147
unsigned char Parameter_AchsKopplung1 = 90;
148
unsigned char Parameter_AchsKopplung2 = 65;
148
unsigned char Parameter_AchsKopplung2 = 65;
149
unsigned char Parameter_CouplingYawCorrection = 64;
149
unsigned char Parameter_CouplingYawCorrection = 64;
150
//unsigned char Parameter_AchsGegenKopplung1 = 0;
150
//unsigned char Parameter_AchsGegenKopplung1 = 0;
151
unsigned char Parameter_DynamicStability = 100;
151
unsigned char Parameter_DynamicStability = 100;
152
unsigned char Parameter_J16Bitmask;             // for the J16 Output
152
unsigned char Parameter_J16Bitmask;             // for the J16 Output
153
unsigned char Parameter_J16Timing;              // for the J16 Output
153
unsigned char Parameter_J16Timing;              // for the J16 Output
154
unsigned char Parameter_J17Bitmask;             // for the J17 Output
154
unsigned char Parameter_J17Bitmask;             // for the J17 Output
155
unsigned char Parameter_J17Timing;              // for the J17 Output
155
unsigned char Parameter_J17Timing;              // for the J17 Output
156
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
156
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
157
unsigned char Parameter_NaviGpsGain;
157
unsigned char Parameter_NaviGpsGain;
158
unsigned char Parameter_NaviGpsP;
158
unsigned char Parameter_NaviGpsP;
159
unsigned char Parameter_NaviGpsI;
159
unsigned char Parameter_NaviGpsI;
160
unsigned char Parameter_NaviGpsD;
160
unsigned char Parameter_NaviGpsD;
161
unsigned char Parameter_NaviGpsACC;
161
unsigned char Parameter_NaviGpsACC;
162
unsigned char Parameter_NaviOperatingRadius;
162
unsigned char Parameter_NaviOperatingRadius;
163
unsigned char Parameter_NaviWindCorrection;
163
unsigned char Parameter_NaviWindCorrection;
164
unsigned char Parameter_NaviSpeedCompensation;
164
unsigned char Parameter_NaviSpeedCompensation;
165
unsigned char Parameter_ExternalControl;
165
unsigned char Parameter_ExternalControl;
166
struct mk_param_struct EE_Parameter;
166
struct mk_param_struct EE_Parameter;
167
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
167
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
168
//int MaxStickNick = 0,MaxStickRoll = 0;MartinR: so war es
168
//int MaxStickNick = 0,MaxStickRoll = 0;MartinR: so war es
169
 
169
 
170
int MaxStickNick = 0,MaxStickRoll = 0,stick_nick_neutral = 0,stick_roll_neutral = 0;  // MartinR: stick_.._neutral hinzugefügt
170
int MaxStickNick = 0,MaxStickRoll = 0,stick_nick_neutral = 0,stick_roll_neutral = 0;  // MartinR: stick_.._neutral hinzugefügt
171
 
171
 
172
unsigned int  modell_fliegt = 0;
172
unsigned int  modell_fliegt = 0;
173
volatile unsigned char MikroKopterFlags = 0;
173
volatile unsigned char MikroKopterFlags = 0;
174
long GIER_GRAD_FAKTOR = 1291;
174
long GIER_GRAD_FAKTOR = 1291;
175
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
175
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
176
unsigned char RequiredMotors = 4;
176
unsigned char RequiredMotors = 4;
177
unsigned char Motor[MAX_MOTORS];
177
unsigned char Motor[MAX_MOTORS];
178
signed int tmp_motorwert[MAX_MOTORS];
178
signed int tmp_motorwert[MAX_MOTORS];
179
 
179
 
180
int MotorSmoothing(int neu, int alt)
180
int MotorSmoothing(int neu, int alt)
181
{
181
{
182
 int motor;
182
 int motor;
183
 if(neu > alt) motor = (1*(int)alt + neu) / 2;
183
 if(neu > alt) motor = (1*(int)alt + neu) / 2;
184
 //else   motor = neu - (alt - neu)*1; // MartinR: so war es
184
 //else   motor = neu - (alt - neu)*1; // MartinR: so war es
185
 else   motor = neu; // MartinR: Entsprechend Vorschlag von MartinW geändert
185
 else   motor = neu; // MartinR: Entsprechend Vorschlag von MartinW geändert
186
//if(Poti2 < 20)  return(neu);
186
//if(Poti2 < 20)  return(neu);
187
 return(motor);
187
 return(motor);
188
}
188
}
189
 
189
 
190
 
190
 
191
void Piep(unsigned char Anzahl)
191
void Piep(unsigned char Anzahl)
192
{
192
{
193
 while(Anzahl--)
193
 while(Anzahl--)
194
 {
194
 {
195
  if(MotorenEin) return; //auf keinen Fall im Flug!
195
  if(MotorenEin) return; //auf keinen Fall im Flug!
196
  beeptime = 100;
196
  beeptime = 100;
197
  Delay_ms(250);
197
  Delay_ms(250);
198
 }
198
 }
199
}
199
}
200
 
200
 
201
//############################################################################
201
//############################################################################
202
//  Nullwerte ermitteln
202
//  Nullwerte ermitteln
203
void SetNeutral(void)
203
void SetNeutral(void)
204
//############################################################################
204
//############################################################################
205
{
205
{
206
 unsigned char i;
206
 unsigned char i;
207
 unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
207
 unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
208
    ServoActive = 0; HEF4017R_ON;
208
    ServoActive = 0; HEF4017R_ON;
209
        NeutralAccX = 0;
209
        NeutralAccX = 0;
210
        NeutralAccY = 0;
210
        NeutralAccY = 0;
211
        NeutralAccZ = 0;
211
        NeutralAccZ = 0;
212
        NeutralAccZ2 = 0; // MartinR
212
        NeutralAccZ2 = 0; // MartinR
213
       
213
       
214
    AdNeutralNick = 0;
214
    AdNeutralNick = 0;
215
        AdNeutralRoll = 0;
215
        AdNeutralRoll = 0;
216
        AdNeutralGier = 0;
216
        AdNeutralGier = 0;
217
    AdNeutralGierBias = 0;
217
    AdNeutralGierBias = 0;
218
    Parameter_AchsKopplung1 = 0;
218
    Parameter_AchsKopplung1 = 0;
219
    Parameter_AchsKopplung2 = 0;
219
    Parameter_AchsKopplung2 = 0;
220
    ExpandBaro = 0;
220
    ExpandBaro = 0;
221
    CalibrierMittelwert();
221
    CalibrierMittelwert();
222
    Delay_ms_Mess(100);
222
    Delay_ms_Mess(100);
223
        CalibrierMittelwert();
223
        CalibrierMittelwert();
224
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
224
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
225
     {
225
     {
226
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
226
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
227
     }
227
     }
228
#define NEUTRAL_FILTER 32
228
#define NEUTRAL_FILTER 32
229
    for(i=0; i<NEUTRAL_FILTER; i++)
229
    for(i=0; i<NEUTRAL_FILTER; i++)
230
         {
230
         {
231
          Delay_ms_Mess(10);
231
          Delay_ms_Mess(10);
232
          gier_neutral += AdWertGier;
232
          gier_neutral += AdWertGier;
233
          nick_neutral += AdWertNick;
233
          nick_neutral += AdWertNick;
234
          roll_neutral += AdWertRoll;
234
          roll_neutral += AdWertRoll;
235
         }
235
         }
236
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
236
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
237
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
237
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
238
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
238
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
239
     AdNeutralGierBias = AdNeutralGier;
239
     AdNeutralGierBias = AdNeutralGier;
240
     StartNeutralRoll = AdNeutralRoll;
240
     StartNeutralRoll = AdNeutralRoll;
241
     StartNeutralNick = AdNeutralNick;
241
     StartNeutralNick = AdNeutralNick;
242
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
242
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
243
    {
243
    {
244
      NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
244
      NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
245
          NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
245
          NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
246
          NeutralAccZ = Aktuell_az;
246
          NeutralAccZ = Aktuell_az;
247
          NeutralAccZ2 = NeutralAccZ; // MartinR
247
          NeutralAccZ2 = NeutralAccZ; // MartinR
248
    }
248
    }
249
    else
249
    else
250
    {
250
    {
251
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
251
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
252
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
252
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
253
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
253
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
254
    }
254
    }
255
 
255
 
256
    MesswertNick = 0;
256
    MesswertNick = 0;
257
    MesswertRoll = 0;
257
    MesswertRoll = 0;
258
    MesswertGier = 0;
258
    MesswertGier = 0;
259
    Delay_ms_Mess(100);
259
    Delay_ms_Mess(100);
260
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
260
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
261
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
261
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
262
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
262
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
263
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
263
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
264
    Mess_IntegralNick2 = IntegralNick;
264
    Mess_IntegralNick2 = IntegralNick;
265
    Mess_IntegralRoll2 = IntegralRoll;
265
    Mess_IntegralRoll2 = IntegralRoll;
266
    Mess_Integral_Gier = 0;
266
    Mess_Integral_Gier = 0;
267
    StartLuftdruck = Luftdruck;
267
    StartLuftdruck = Luftdruck;
268
    HoeheD = 0;
268
    HoeheD = 0;
269
    Mess_Integral_Hoch = 0;
269
    Mess_Integral_Hoch = 0;
270
    KompassStartwert = KompassValue;
270
    KompassStartwert = KompassValue;
271
    GPS_Neutral();
271
    GPS_Neutral();
272
    beeptime = 50;
272
    beeptime = 50;
273
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
273
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
274
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
274
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
275
    ExternHoehenValue = 0;
275
    ExternHoehenValue = 0;
276
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
276
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
277
    GierGyroFehler = 0;
277
    GierGyroFehler = 0;
278
    SendVersionToNavi = 1;
278
    SendVersionToNavi = 1;
279
    LED_Init();
279
    LED_Init();
280
    MikroKopterFlags |= FLAG_CALIBRATE;
280
    MikroKopterFlags |= FLAG_CALIBRATE;
281
    FromNaviCtrl_Value.Kalman_K = -1;
281
    FromNaviCtrl_Value.Kalman_K = -1;
282
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
282
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
283
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
283
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
284
    Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110;
284
    Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110;
285
    Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110;
285
    Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110;
286
    Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110;
286
    Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110;
287
    Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110;
287
    Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110;
288
    ServoActive = 1;
288
    ServoActive = 1;
289
    SenderOkay = 100;
289
    SenderOkay = 100;
290
}
290
}
291
 
291
 
292
//############################################################################
292
//############################################################################
293
// Bearbeitet die Messwerte
293
// Bearbeitet die Messwerte
294
void Mittelwert(void)
294
void Mittelwert(void)
295
//############################################################################
295
//############################################################################
296
{
296
{
297
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
297
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
298
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
298
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
299
        static signed int oldNick2, oldRoll2 ; //MartinR : für geänderte d2* Ermittlung
299
        static signed int oldNick2, oldRoll2 ; //MartinR : für geänderte d2* Ermittlung
300
        signed long winkel_nick, winkel_roll;
300
        signed long winkel_nick, winkel_roll;
301
 
301
 
302
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
302
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
303
//    MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier;
303
//    MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier;
304
    MesswertNick = (signed int) AdWertNickFilter / 8;
304
    MesswertNick = (signed int) AdWertNickFilter / 8;
305
    MesswertRoll = (signed int) AdWertRollFilter / 8;
305
    MesswertRoll = (signed int) AdWertRollFilter / 8;
306
    RohMesswertNick = MesswertNick;
306
    RohMesswertNick = MesswertNick;
307
    RohMesswertRoll = MesswertRoll;
307
    RohMesswertRoll = MesswertRoll;
308
//DebugOut.Analog[21] = MesswertNick;
308
//DebugOut.Analog[21] = MesswertNick;
309
//DebugOut.Analog[22] = MesswertRoll;
309
//DebugOut.Analog[22] = MesswertRoll;
310
//DebugOut.Analog[22] = Mess_Integral_Gier;
310
//DebugOut.Analog[22] = Mess_Integral_Gier;
311
//DebugOut.Analog[21] = MesswertNick;
311
//DebugOut.Analog[21] = MesswertNick;
312
//DebugOut.Analog[22] = MesswertRoll;
312
//DebugOut.Analog[22] = MesswertRoll;
313
 
313
 
314
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
314
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
315
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
315
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
316
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
316
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
317
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
317
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
318
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
318
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
319
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
319
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
320
    NaviAccNick    += AdWertAccNick;
320
    NaviAccNick    += AdWertAccNick;
321
    NaviAccRoll    += AdWertAccRoll;
321
    NaviAccRoll    += AdWertAccRoll;
322
    NaviCntAcc++;
322
    NaviCntAcc++;
323
        //IntegralAccZ  += Aktuell_az - NeutralAccZ; // MartinR: so war es
323
        //IntegralAccZ  += Aktuell_az - NeutralAccZ; // MartinR: so war es
324
        IntegralAccZ += AdWertAccHoch;// MartinR: AdWertAccHoch = Aktuell_az - NeutralAccZ; in analog.c
324
        IntegralAccZ += AdWertAccHoch;// MartinR: AdWertAccHoch = Aktuell_az - NeutralAccZ; in analog.c
325
 
325
 
326
//++++++++++++++++++++++++++++++++++++++++++++++++
326
//++++++++++++++++++++++++++++++++++++++++++++++++
327
// ADC einschalten
327
// ADC einschalten
328
        //ANALOG_ON; // MartinR : so war es
328
        //ANALOG_ON; // MartinR : so war es
329
        // ANALOG_START; // MartinR verschoben zu timer0
329
        // ANALOG_START; // MartinR verschoben zu timer0
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
 
345
 
346
if((EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) || (Parameter_UserParam1 > 140)) IntegralFaktor = 0;  // MartinR: zusätzlich
346
if((EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) || (Parameter_UserParam1 > 140)) IntegralFaktor = 0;  // MartinR: zusätzlich
347
 
347
 
348
          //if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))  // MartinR : so war es
348
          //if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))  // MartinR : so war es
349
          if(!Looping_Nick && !Looping_Roll && IntegralFaktor && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) // MartinR: zusätzlich "&& IntegralFaktor"
349
          if(!Looping_Nick && !Looping_Roll && IntegralFaktor && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) // MartinR: zusätzlich "&& IntegralFaktor"
350
         {
350
         {
351
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
351
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
352
            tmpl3 *= Parameter_AchsKopplung2; //65
352
            tmpl3 *= Parameter_AchsKopplung2; //65
353
            tmpl3 /= 4096L;
353
            tmpl3 /= 4096L;
354
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
354
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
355
            tmpl4 *= Parameter_AchsKopplung2; //65
355
            tmpl4 *= Parameter_AchsKopplung2; //65
356
            tmpl4 /= 4096L;
356
            tmpl4 /= 4096L;
357
            KopplungsteilNickRoll = tmpl3;
357
            KopplungsteilNickRoll = tmpl3;
358
            KopplungsteilRollNick = tmpl4;
358
            KopplungsteilRollNick = tmpl4;
359
            tmpl4 -= tmpl3;
359
            tmpl4 -= tmpl3;
360
            ErsatzKompass += tmpl4;
360
            ErsatzKompass += tmpl4;
361
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
361
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
362
 
362
 
363
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
363
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
364
            tmpl *= Parameter_AchsKopplung1;  // 90
364
            tmpl *= Parameter_AchsKopplung1;  // 90
365
            tmpl /= 4096L;
365
            tmpl /= 4096L;
366
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
366
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
367
            tmpl2 *= Parameter_AchsKopplung1;
367
            tmpl2 *= Parameter_AchsKopplung1;
368
            tmpl2 /= 4096L;
368
            tmpl2 /= 4096L;
369
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
369
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
370
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
370
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
371
         }
371
         }
372
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
372
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
373
 
373
 
374
TrimRoll = tmpl - tmpl2 / 100L;
374
TrimRoll = tmpl - tmpl2 / 100L;
375
TrimNick = -tmpl2 + tmpl / 100L;
375
TrimNick = -tmpl2 + tmpl / 100L;
376
 
376
 
377
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
377
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
378
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
378
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
379
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
379
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
380
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
380
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
381
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
381
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
382
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
382
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
383
            if(Mess_IntegralRoll > Umschlag180Roll)
383
            if(Mess_IntegralRoll > Umschlag180Roll)
384
            {
384
            {
385
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
385
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
386
             Mess_IntegralRoll2 = Mess_IntegralRoll;
386
             Mess_IntegralRoll2 = Mess_IntegralRoll;
387
            }
387
            }
388
            if(Mess_IntegralRoll <-Umschlag180Roll)
388
            if(Mess_IntegralRoll <-Umschlag180Roll)
389
            {
389
            {
390
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
390
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
391
             Mess_IntegralRoll2 = Mess_IntegralRoll;
391
             Mess_IntegralRoll2 = Mess_IntegralRoll;
392
            }
392
            }
393
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
393
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
394
            Mess_IntegralNick2 += MesswertNick + TrimNick;
394
            Mess_IntegralNick2 += MesswertNick + TrimNick;
395
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
395
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
396
            if(Mess_IntegralNick > Umschlag180Nick)
396
            if(Mess_IntegralNick > Umschlag180Nick)
397
             {
397
             {
398
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
398
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
399
              Mess_IntegralNick2 = Mess_IntegralNick;
399
              Mess_IntegralNick2 = Mess_IntegralNick;
400
             }
400
             }
401
            if(Mess_IntegralNick <-Umschlag180Nick)
401
            if(Mess_IntegralNick <-Umschlag180Nick)
402
            {
402
            {
403
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
403
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
404
             Mess_IntegralNick2 = Mess_IntegralNick;
404
             Mess_IntegralNick2 = Mess_IntegralNick;
405
            }
405
            }
406
 
406
 
407
    Integral_Gier  = Mess_Integral_Gier;
407
    Integral_Gier  = Mess_Integral_Gier;
408
    IntegralNick = Mess_IntegralNick;
408
    IntegralNick = Mess_IntegralNick;
409
    IntegralRoll = Mess_IntegralRoll;
409
    IntegralRoll = Mess_IntegralRoll;
410
    IntegralNick2 = Mess_IntegralNick2;
410
    IntegralNick2 = Mess_IntegralNick2;
411
    IntegralRoll2 = Mess_IntegralRoll2;
411
    IntegralRoll2 = Mess_IntegralRoll2;
412
 
412
 
413
#define D_LIMIT 128
413
#define D_LIMIT 128
414
 
414
 
415
   //MesswertNick = HiResNick / 8;// MartinR : so war es
415
   //MesswertNick = HiResNick / 8;// MartinR : so war es
416
   //MesswertRoll = HiResRoll / 8;// MartinR : so war es
416
   //MesswertRoll = HiResRoll / 8;// MartinR : so war es
417
   MesswertNick = AdWertNickFilter / 8;// MartinR : anstelle HiResNick : AdWertNickFilter
417
   MesswertNick = AdWertNickFilter / 8;// MartinR : anstelle HiResNick : AdWertNickFilter
418
   MesswertRoll = AdWertRollFilter / 8;// MartinR : ist im vergleich zu HiRes.. eimal mehr gemittelt
418
   MesswertRoll = AdWertRollFilter / 8;// MartinR : ist im vergleich zu HiRes.. eimal mehr gemittelt
419
 
419
 
420
 
420
 
421
 // MartinR : so war es Anfang
421
 // MartinR : so war es Anfang
422
        /*
422
        /*
423
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
423
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
424
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
424
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
425
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
425
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
426
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
426
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
427
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
427
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
428
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
428
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
429
   
429
   
430
   // MartinR : FC 1.0: Sprung von 500 auf 2000 !! FC-ME: Sprung von 1000 auf 2000
430
   // MartinR : FC 1.0: Sprung von 500 auf 2000 !! FC-ME: Sprung von 1000 auf 2000
431
        */
431
        */
432
        // MartinR : so war es Ende
432
        // MartinR : so war es Ende
433
       
433
       
434
         // MartinR : Neu Anfang
434
         // MartinR : Neu Anfang
435
        if(PlatinenVersion == 10)  
435
        if(PlatinenVersion == 10)  
436
        {
436
        {
437
        if(AdWertNick > 1010) MesswertNick = +600;  
437
        if(AdWertNick > 1010) MesswertNick = +600;  
438
        if(AdWertNick > 1017) MesswertNick = +800;
438
        if(AdWertNick > 1017) MesswertNick = +800;
439
        if(AdWertNick < 15)   MesswertNick = -600;  
439
        if(AdWertNick < 15)   MesswertNick = -600;  
440
        if(AdWertNick <  7)   MesswertNick = -800;
440
        if(AdWertNick <  7)   MesswertNick = -800;
441
        if(AdWertRoll > 1010) MesswertRoll = +600;  
441
        if(AdWertRoll > 1010) MesswertRoll = +600;  
442
        if(AdWertRoll > 1017) MesswertRoll = +800;
442
        if(AdWertRoll > 1017) MesswertRoll = +800;
443
        if(AdWertRoll < 15)   MesswertRoll = -600;  
443
        if(AdWertRoll < 15)   MesswertRoll = -600;  
444
        if(AdWertRoll <  7)   MesswertRoll = -800;
444
        if(AdWertRoll <  7)   MesswertRoll = -800;
445
        }
445
        }
446
        else  
446
        else  
447
        {  
447
        {  
448
        if(AdWertNick > 2000) MesswertNick = +1200;  
448
        if(AdWertNick > 2000) MesswertNick = +1200;  
449
        if(AdWertNick > 2015) MesswertNick = +1600;
449
        if(AdWertNick > 2015) MesswertNick = +1600;
450
        if(AdWertNick < 15)   MesswertNick = -1200;  
450
        if(AdWertNick < 15)   MesswertNick = -1200;  
451
        if(AdWertNick <  7)   MesswertNick = -1600;
451
        if(AdWertNick <  7)   MesswertNick = -1600;
452
        if(AdWertRoll > 2000) MesswertRoll = +1200;  
452
        if(AdWertRoll > 2000) MesswertRoll = +1200;  
453
        if(AdWertRoll > 2015) MesswertRoll = +1600;
453
        if(AdWertRoll > 2015) MesswertRoll = +1600;
454
        if(AdWertRoll < 15)   MesswertRoll = -1200;  
454
        if(AdWertRoll < 15)   MesswertRoll = -1200;  
455
        if(AdWertRoll <  7)   MesswertRoll = -1600;
455
        if(AdWertRoll <  7)   MesswertRoll = -1600;
456
        }
456
        }
457
 // MartinR : Neu Ende
457
 // MartinR : Neu Ende
458
 
458
 
459
  if(Parameter_Gyro_D)
459
  if(Parameter_Gyro_D)
460
  {
460
  {
461
  /* MartinR: so war es Anfang
461
  /* MartinR: so war es Anfang
462
 
462
 
463
   d2Nick = HiResNick - oldNick;
463
   d2Nick = HiResNick - oldNick;
464
   oldNick = (oldNick + HiResNick)/2;
464
   oldNick = (oldNick + HiResNick)/2;
465
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
465
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
466
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
466
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
467
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
467
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
468
   d2Roll = HiResRoll - oldRoll;
468
   d2Roll = HiResRoll - oldRoll;
469
   oldRoll = (oldRoll + HiResRoll)/2;
469
   oldRoll = (oldRoll + HiResRoll)/2;
470
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
470
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
471
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
471
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
472
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
472
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
473
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
473
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
474
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
474
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
475
   
475
   
476
   */ //MartinR: so war es Ende
476
   */ //MartinR: so war es Ende
477
   
477
   
478
   // MartinR :neu Anfang
478
   // MartinR :neu Anfang
479
   d2Nick = MesswertNick - oldNick2;
479
   d2Nick = MesswertNick - oldNick2;
480
   oldNick2 = oldNick;
480
   oldNick2 = oldNick;
481
   oldNick = MesswertNick;
481
   oldNick = MesswertNick;
482
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
482
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
483
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
483
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
484
   if(d2Nick > 0) d2Nick --;
484
   if(d2Nick > 0) d2Nick --;
485
   if(d2Nick < 0) d2Nick ++;
485
   if(d2Nick < 0) d2Nick ++;
486
   
486
   
487
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
487
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
488
   
488
   
489
   d2Roll = MesswertRoll - oldRoll2;
489
   d2Roll = MesswertRoll - oldRoll2;
490
   oldRoll2 = oldRoll;
490
   oldRoll2 = oldRoll;
491
   oldRoll = MesswertRoll;
491
   oldRoll = MesswertRoll;
492
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
492
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
493
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;  
493
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;  
494
   if(d2Roll > 0) d2Roll --;
494
   if(d2Roll > 0) d2Roll --;
495
   if(d2Roll < 0) d2Roll ++;
495
   if(d2Roll < 0) d2Roll ++;
496
   
496
   
497
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
497
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
498
   // MartinR :neu Ende
498
   // MartinR :neu Ende
499
   
499
   
500
  }
500
  }
501
 
501
 
502
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
502
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
503
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
503
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
504
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
504
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
505
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
505
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
506
 
506
 
507
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
507
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
508
  {
508
  {
509
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
509
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
510
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
510
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
511
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
511
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
512
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
512
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
513
  }
513
  }
514
 
514
 
515
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
515
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
516
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
516
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
517
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
517
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
518
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
518
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
519
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
519
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
520
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
520
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
521
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
521
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
522
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
522
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
523
}
523
}
524
 
524
 
525
//############################################################################
525
//############################################################################
526
// Messwerte beim Ermitteln der Nullage
526
// Messwerte beim Ermitteln der Nullage
527
void CalibrierMittelwert(void)
527
void CalibrierMittelwert(void)
528
//############################################################################
528
//############################################################################
529
{
529
{
530
    if(PlatinenVersion == 13) SucheGyroOffset();
530
    if(PlatinenVersion == 13) SucheGyroOffset();
531
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
531
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
532
        ANALOG_OFF;
532
        ANALOG_OFF;
533
        MesswertNick = AdWertNick;
533
        MesswertNick = AdWertNick;
534
        MesswertRoll = AdWertRoll;
534
        MesswertRoll = AdWertRoll;
535
        MesswertGier = AdWertGier;
535
        MesswertGier = AdWertGier;
536
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
536
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
537
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
537
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
538
        Mittelwert_AccHoch = (long)AdWertAccHoch;
538
        Mittelwert_AccHoch = (long)AdWertAccHoch;
539
   // ADC einschalten
539
   // ADC einschalten
540
    ANALOG_ON;
540
    ANALOG_ON;
541
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
541
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
542
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
542
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
543
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
543
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
544
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
544
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
545
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
545
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
546
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
546
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
547
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
547
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
548
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
548
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
549
 
549
 
550
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
550
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
551
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
551
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
552
}
552
}
553
 
553
 
554
//############################################################################
554
//############################################################################
555
// Senden der Motorwerte per I2C-Bus
555
// Senden der Motorwerte per I2C-Bus
556
void SendMotorData(void)
556
void SendMotorData(void)
557
//############################################################################
557
//############################################################################
558
{
558
{
559
 unsigned char i;
559
 unsigned char i;
560
    if(!MotorenEin)
560
    if(!MotorenEin)
561
        {
561
        {
562
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
562
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
563
                 for(i=0;i<MAX_MOTORS;i++)
563
                 for(i=0;i<MAX_MOTORS;i++)
564
                  {
564
                  {
565
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
565
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
566
                   Motor[i] = MotorTest[i];
566
                   Motor[i] = MotorTest[i];
567
                  }
567
                  }
568
          if(PC_MotortestActive) PC_MotortestActive--;
568
          if(PC_MotortestActive) PC_MotortestActive--;
569
        }
569
        }
570
        else MikroKopterFlags |= FLAG_MOTOR_RUN;
570
        else MikroKopterFlags |= FLAG_MOTOR_RUN;
571
 
571
 
572
    DebugOut.Analog[12] = Motor[0];
572
    DebugOut.Analog[12] = Motor[0];
573
    DebugOut.Analog[13] = Motor[1];
573
    DebugOut.Analog[13] = Motor[1];
574
    DebugOut.Analog[14] = Motor[3];
574
    DebugOut.Analog[14] = Motor[3];
575
    DebugOut.Analog[15] = Motor[2];
575
    DebugOut.Analog[15] = Motor[2];
576
 
576
 
577
    //Start I2C Interrupt Mode
577
    //Start I2C Interrupt Mode
578
    twi_state = 0;
578
    twi_state = 0;
579
    motor = 0;
579
    motor = 0;
580
    i2c_start();
580
    i2c_start();
581
}
581
}
582
 
582
 
583
 
583
 
584
 
584
 
585
//############################################################################
585
//############################################################################
586
// Trägt ggf. das Poti als Parameter ein
586
// Trägt ggf. das Poti als Parameter ein
587
void ParameterZuordnung(void)
587
void ParameterZuordnung(void)
588
//############################################################################
588
//############################################################################
589
{
589
{
590
 #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;}
590
 #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;}
591
 #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; }
591
 #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; }
592
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
592
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
593
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
593
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
594
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
594
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
595
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
595
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
596
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
596
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
597
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
597
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
598
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
598
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
599
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255);
599
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255);
600
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
600
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
601
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
601
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
602
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
602
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
603
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
603
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
604
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
604
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
605
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
605
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
606
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
606
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
607
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
607
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
608
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
608
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
609
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
609
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
610
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
610
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
611
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
611
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
612
 CHK_POTI(Parameter_AchsKopplung2,    EE_Parameter.AchsKopplung2,0,255);
612
 CHK_POTI(Parameter_AchsKopplung2,    EE_Parameter.AchsKopplung2,0,255);
613
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255);
613
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255);
614
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
614
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
615
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
615
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
616
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
616
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
617
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
617
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
618
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
618
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
619
 Ki = 10300 / (Parameter_I_Faktor + 1);
619
 Ki = 10300 / (Parameter_I_Faktor + 1);
620
 
620
 
621
 if(Parameter_UserParam1 > 140) KiHH = 10300 / (Parameter_UserParam2 + 1); else  KiHH = Ki; // MartinR : für HH über Schalter
621
 if(Parameter_UserParam1 > 140) KiHH = 10300 / (Parameter_UserParam2 + 1); else  KiHH = Ki; // MartinR : für HH über Schalter
622
 Parameter_NaviGpsModeControl = EE_Parameter.NaviGpsModeControl; //MartinR: Standard: EE_Parameter.NaviGpsModeControl wird übertragen
622
 Parameter_NaviGpsModeControl = EE_Parameter.NaviGpsModeControl; //MartinR: Standard: EE_Parameter.NaviGpsModeControl wird übertragen
623
 if(!IntegralFaktor) Parameter_NaviGpsModeControl= 0; // MartinR: wenn HH dann GPS auf free- Mode 
623
 if(!IntegralFaktor) Parameter_NaviGpsModeControl= 0; // MartinR: wenn HH dann GPS auf free- Mode 
624
  // 0 = AID; 100 = free; 200 = coming home //so war es 
624
  // 0 = AID; 100 = free; 200 = coming home //so war es 
625
  // 0 = free; 100 = AID; 200 = coming home //neu 
625
  // 0 = free; 100 = AID; 200 = coming home //neu 
626
 
626
 
627
 
627
 
628
 MAX_GAS = EE_Parameter.Gas_Max;
628
 MAX_GAS = EE_Parameter.Gas_Max;
629
 MIN_GAS = EE_Parameter.Gas_Min;
629
 MIN_GAS = EE_Parameter.Gas_Min;
630
}
630
}
631
 
631
 
632
 
632
 
633
 
633
 
634
//############################################################################
634
//############################################################################
635
//
635
//
636
void MotorRegler(void)
636
void MotorRegler(void)
637
//############################################################################
637
//############################################################################
638
{
638
{
639
         int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int;
639
         int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int;
640
         int GierMischanteil,GasMischanteil;
640
         int GierMischanteil,GasMischanteil;
641
     static long SummeNick=0,SummeRoll=0;
641
     static long SummeNick=0,SummeRoll=0;
642
         
642
         
643
         static long SummeNickHH=0,SummeRollHH=0; // MartinR: Für ACC-HH Umschaltung
643
         static long SummeNickHH=0,SummeRollHH=0; // MartinR: Für ACC-HH Umschaltung
644
         
644
         
645
     static long sollGier = 0,tmp_long,tmp_long2;
645
     static long sollGier = 0,tmp_long,tmp_long2;
646
     static long IntegralFehlerNick = 0;
646
     static long IntegralFehlerNick = 0;
647
     static long IntegralFehlerRoll = 0;
647
     static long IntegralFehlerRoll = 0;
648
         static unsigned int RcLostTimer;
648
         static unsigned int RcLostTimer;
649
         static unsigned char delay_neutral = 0;
649
         static unsigned char delay_neutral = 0;
650
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
650
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
651
     static int hoehenregler = 0;
651
     static int hoehenregler = 0;
652
     static char TimerWerteausgabe = 0;
652
     static char TimerWerteausgabe = 0;
653
     static char NeueKompassRichtungMerken = 0;
653
     static char NeueKompassRichtungMerken = 0;
654
     static long ausgleichNick, ausgleichRoll;
654
     static long ausgleichNick, ausgleichRoll;
655
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
655
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
656
         unsigned char i;
656
         unsigned char i;
657
        Mittelwert();
657
        Mittelwert();
658
 
658
 
659
    GRN_ON;
659
    GRN_ON;
660
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
660
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
661
// Gaswert ermitteln
661
// Gaswert ermitteln
662
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
662
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
663
        GasMischanteil = StickGas;
663
        GasMischanteil = StickGas;
664
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
664
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
665
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
665
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
666
// Empfang schlecht
666
// Empfang schlecht
667
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
667
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
668
   if(SenderOkay < 100)
668
   if(SenderOkay < 100)
669
        {
669
        {
670
        if(!PcZugriff)
670
        if(!PcZugriff)
671
         {
671
         {
672
           if(BeepMuster == 0xffff)
672
           if(BeepMuster == 0xffff)
673
            {
673
            {
674
             beeptime = 15000;
674
             beeptime = 15000;
675
             BeepMuster = 0x0c00;
675
             BeepMuster = 0x0c00;
676
            }
676
            }
677
         }
677
         }
678
        if(RcLostTimer) RcLostTimer--;
678
        if(RcLostTimer) RcLostTimer--;
679
        else
679
        else
680
         {
680
         {
681
          MotorenEin = 0;
681
          MotorenEin = 0;
682
          Notlandung = 0;
682
          Notlandung = 0;
683
         }
683
         }
684
        ROT_ON;
684
        ROT_ON;
685
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
685
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
686
            {
686
            {
687
            GasMischanteil = EE_Parameter.NotGas;
687
            GasMischanteil = EE_Parameter.NotGas;
688
            Notlandung = 1;
688
            Notlandung = 1;
689
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
689
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
690
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
690
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
691
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
691
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
692
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
692
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
693
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
693
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
694
            }
694
            }
695
         else MotorenEin = 0;
695
         else MotorenEin = 0;
696
        }
696
        }
697
        else
697
        else
698
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
698
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
699
// Emfang gut
699
// Emfang gut
700
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
700
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
701
        if(SenderOkay > 140)
701
        if(SenderOkay > 140)
702
            {
702
            {
703
            Notlandung = 0;
703
            Notlandung = 0;
704
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
704
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
705
            if(GasMischanteil > 40 && MotorenEin)
705
            if(GasMischanteil > 40 && MotorenEin)
706
                {
706
                {
707
                if(modell_fliegt < 0xffff) modell_fliegt++;
707
                if(modell_fliegt < 0xffff) modell_fliegt++;
708
                }
708
                }
709
            if((modell_fliegt < 256))
709
            if((modell_fliegt < 256))
710
                {
710
                {
711
                SummeNick = 0;
711
                SummeNick = 0;
712
                SummeRoll = 0;
712
                SummeRoll = 0;
713
                if(modell_fliegt == 250)
713
                if(modell_fliegt == 250)
714
                 {
714
                 {
715
                  NeueKompassRichtungMerken = 1;
715
                  NeueKompassRichtungMerken = 1;
716
                  sollGier = 0;
716
                  sollGier = 0;
717
                  Mess_Integral_Gier = 0;
717
                  Mess_Integral_Gier = 0;
718
//                  Mess_Integral_Gier2 = 0;
718
//                  Mess_Integral_Gier2 = 0;
719
                 }
719
                 }
720
                } else MikroKopterFlags |= FLAG_FLY;
720
                } else MikroKopterFlags |= FLAG_FLY;
721
 
721
 
722
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
722
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
723
                {
723
                {
724
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
724
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
725
// auf Nullwerte kalibrieren
725
// auf Nullwerte kalibrieren
726
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
726
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
727
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
727
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
728
                    {
728
                    {
729
                    if(++delay_neutral > 200)  // nicht sofort
729
                    if(++delay_neutral > 200)  // nicht sofort
730
                        {
730
                        {
731
                        GRN_OFF;
731
                        GRN_OFF;
732
                        MotorenEin = 0;
732
                        MotorenEin = 0;
733
                        delay_neutral = 0;
733
                        delay_neutral = 0;
734
                        modell_fliegt = 0;
734
                        modell_fliegt = 0;
735
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
735
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
736
                        {
736
                        {
737
                         unsigned char setting=1;
737
                         unsigned char setting=1;
738
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
738
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
739
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
739
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
740
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
740
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
741
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
741
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
742
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
742
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
743
                         SetActiveParamSetNumber(setting);  // aktiven Datensatz merken
743
                         SetActiveParamSetNumber(setting);  // aktiven Datensatz merken
744
                        }
744
                        }
745
//                        else
745
//                        else
746
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
746
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
747
                          {
747
                          {
748
                           WinkelOut.CalcState = 1;
748
                           WinkelOut.CalcState = 1;
749
                           beeptime = 1000;
749
                           beeptime = 1000;
750
                          }
750
                          }
751
                          else
751
                          else
752
                          {
752
                          {
753
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
753
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
754
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
754
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
755
                            {
755
                            {
756
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
756
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
757
                            }
757
                            }
758
                           SetNeutral();
758
                           SetNeutral();
759
                           Piep(GetActiveParamSetNumber());
759
                           Piep(GetActiveParamSetNumber());
760
                         }
760
                         }
761
                        }
761
                        }
762
                    }
762
                    }
763
                 else
763
                 else
764
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
764
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
765
                    {
765
                    {
766
                    if(++delay_neutral > 200)  // nicht sofort
766
                    if(++delay_neutral > 200)  // nicht sofort
767
                        {
767
                        {
768
                        GRN_OFF;
768
                        GRN_OFF;
769
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
769
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
770
                        MotorenEin = 0;
770
                        MotorenEin = 0;
771
                        delay_neutral = 0;
771
                        delay_neutral = 0;
772
                        modell_fliegt = 0;
772
                        modell_fliegt = 0;
773
                        SetNeutral();
773
                        SetNeutral();
774
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
774
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
775
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
775
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
776
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
776
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
777
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
777
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
778
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
778
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
779
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
779
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
780
                        Piep(GetActiveParamSetNumber());
780
                        Piep(GetActiveParamSetNumber());
781
                        }
781
                        }
782
                    }
782
                    }
783
                 else delay_neutral = 0;
783
                 else delay_neutral = 0;
784
                }
784
                }
785
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
785
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
786
// Gas ist unten
786
// Gas ist unten
787
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
787
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
788
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
788
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
789
                {
789
                {
790
                // Starten
790
                // Starten
791
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
791
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
792
                    {
792
                    {
793
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
793
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
794
// Einschalten
794
// Einschalten
795
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
795
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
796
                    if(++delay_einschalten > 200)
796
                    if(++delay_einschalten > 200)
797
                        {
797
                        {
798
                        delay_einschalten = 200;
798
                        delay_einschalten = 200;
799
                        modell_fliegt = 1;
799
                        modell_fliegt = 1;
800
                        MotorenEin = 1;
800
                        MotorenEin = 1;
801
                        sollGier = 0;
801
                        sollGier = 0;
802
                        Mess_Integral_Gier = 0;
802
                        Mess_Integral_Gier = 0;
803
                        Mess_Integral_Gier2 = 0;
803
                        Mess_Integral_Gier2 = 0;
804
                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
804
                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
805
                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
805
                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
806
                        Mess_IntegralNick2 = IntegralNick;
806
                        Mess_IntegralNick2 = IntegralNick;
807
                        Mess_IntegralRoll2 = IntegralRoll;
807
                        Mess_IntegralRoll2 = IntegralRoll;
808
                        SummeNick = 0;
808
                        SummeNick = 0;
809
                        SummeRoll = 0;
809
                        SummeRoll = 0;
810
                                                SchwebeGas = 0; // MartinR: für neuen Höhenregler
810
                                                SchwebeGas = 0; // MartinR: für neuen Höhenregler
811
                        MikroKopterFlags |= FLAG_START;
811
                        MikroKopterFlags |= FLAG_START;
812
                        }
812
                        }
813
                    }
813
                    }
814
                    else delay_einschalten = 0;
814
                    else delay_einschalten = 0;
815
                //Auf Neutralwerte setzen
815
                //Auf Neutralwerte setzen
816
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
816
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
817
// Auschalten
817
// Auschalten
818
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
818
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
819
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
819
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
820
                    {
820
                    {
821
                    if(++delay_ausschalten > 200)  // nicht sofort
821
                    if(++delay_ausschalten > 200)  // nicht sofort
822
                        {
822
                        {
823
                        MotorenEin = 0;
823
                        MotorenEin = 0;
824
                        delay_ausschalten = 200;
824
                        delay_ausschalten = 200;
825
                        modell_fliegt = 0;
825
                        modell_fliegt = 0;
826
                        }
826
                        }
827
                    }
827
                    }
828
                else delay_ausschalten = 0;
828
                else delay_ausschalten = 0;
829
                }
829
                }
830
            }
830
            }
831
 
831
 
832
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
832
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
833
// neue Werte von der Funke
833
// neue Werte von der Funke
834
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
834
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
835
 
835
 
836
 if(!NewPpmData-- || Notlandung)
836
 if(!NewPpmData-- || Notlandung)
837
  {
837
  {
838
        static int stick_nick,stick_roll;
838
        static int stick_nick,stick_roll;
839
    ParameterZuordnung();
839
    ParameterZuordnung();
840
       
840
       
841
        // MartinR: original:   
841
        // MartinR: original:   
842
        /*
842
        /*
843
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
843
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
844
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
844
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
845
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
845
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
846
 
846
 
847
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
847
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
848
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
848
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
849
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
849
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
850
       
850
       
851
        */
851
        */
852
        // MartinR: geändert Anfang
852
        // MartinR: geändert Anfang
853
        if(Parameter_UserParam1 > 140)  // MartinR: zweiter Stick_P Wert nur, wenn HH über Schalter aktiv ist
853
        if(Parameter_UserParam1 > 140)  // MartinR: zweiter Stick_P Wert nur, wenn HH über Schalter aktiv ist
854
                {
854
                {
855
                stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * Parameter_UserParam3 - stick_nick_neutral) / 4;
855
                stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * Parameter_UserParam3 - stick_nick_neutral) / 4;
856
                stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * Parameter_UserParam3 - stick_roll_neutral) / 4 ;
856
                stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * Parameter_UserParam3 - stick_roll_neutral) / 4 ;
857
                }
857
                }
858
               
858
               
859
         else
859
         else
860
               
860
                {
861
                stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
861
                stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
862
                stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
862
                stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
863
               
863
                }
864
       
864
       
865
         if(IntegralFaktor)  
865
         if(IntegralFaktor)  
866
                {
866
                {
867
                stick_nick_neutral = stick_nick; //  beim Umschalten auf HH wird derletzte Stickwert als Neutralposition verwendet, MartinR
867
                stick_nick_neutral = stick_nick; //  beim Umschalten auf HH wird derletzte Stickwert als Neutralposition verwendet, MartinR
868
                stick_roll_neutral = stick_roll; //  beim Umschalten auf HH wird derletzte Stickwert als Neutralposition verwendet, MartinR
868
                stick_roll_neutral = stick_roll; //  beim Umschalten auf HH wird derletzte Stickwert als Neutralposition verwendet, MartinR
869
                stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
869
                stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
870
                stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
870
                stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
871
               
871
               
872
                StickNick = stick_nick - (GPS_Nick + GPS_Nick2); // MartinR: GPS nur im ACC-Mode wirksam
872
                StickNick = stick_nick - (GPS_Nick + GPS_Nick2); // MartinR: GPS nur im ACC-Mode wirksam
873
                StickRoll = stick_roll - (GPS_Roll + GPS_Roll2); // MartinR: GPS nur im ACC-Mode wirksam
873
                StickRoll = stick_roll - (GPS_Roll + GPS_Roll2); // MartinR: GPS nur im ACC-Mode wirksam
874
                }
874
                }
875
        else            // wenn HH , MartinR
875
        else            // wenn HH , MartinR
876
                {
876
                {
877
                stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; // MartinR: eventuell vor if verschieben
877
                stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; // MartinR: eventuell vor if verschieben
878
                stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; // MartinR: eventuell vor if verschieben
878
                stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; // MartinR: eventuell vor if verschieben
879
                StickNick = stick_nick; // MartinR: GPS nur im ACC-Mode wirksam
879
                StickNick = stick_nick; // MartinR: GPS nur im ACC-Mode wirksam
880
                StickRoll = stick_roll; // MartinR: GPS nur im ACC-Mode wirksam
880
                StickRoll = stick_roll; // MartinR: GPS nur im ACC-Mode wirksam
881
                }
881
                }
882
               
882
               
883
// MartinR: geändert Ende
883
// MartinR: geändert Ende
884
 
884
 
885
 
885
 
886
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
886
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
887
        if(StickGier > 2) StickGier -= 2;       else
887
        if(StickGier > 2) StickGier -= 2;       else
888
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
888
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
889
 
889
 
890
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
890
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
891
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
891
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
892
    IntegralFaktor = Parameter_Gyro_I;
892
    IntegralFaktor = Parameter_Gyro_I;
893
    GyroFaktorGier     = (Parameter_Gyro_P + 10.0);
893
    GyroFaktorGier     = (Parameter_Gyro_P + 10.0);
894
    IntegralFaktorGier = Parameter_Gyro_I;
894
    IntegralFaktorGier = Parameter_Gyro_I;
895
 
895
 
896
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
896
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
897
//+ Analoge Steuerung per Seriell
897
//+ Analoge Steuerung per Seriell
898
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
898
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
899
// MartinR: ToDo: eventuell die Kombination HH und Steuerung per Seriell nicht zulassen??
899
// MartinR: ToDo: eventuell die Kombination HH und Steuerung per Seriell nicht zulassen??
900
 
900
 
901
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
901
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
902
    {
902
    {
903
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
903
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
904
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
904
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
905
         StickGier += ExternControl.Gier;
905
         StickGier += ExternControl.Gier;
906
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
906
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
907
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
907
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
908
    }
908
    }
909
    if(StickGas < 0) StickGas = 0;
909
    if(StickGas < 0) StickGas = 0;
910
 
910
 
911
        //if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0; // MartinR: Original
911
        //if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0; // MartinR: Original
912
        if((EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) || (Parameter_UserParam1 > 140)) IntegralFaktor = 0;  // MartinR
912
        if((EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) || (Parameter_UserParam1 > 140)) IntegralFaktor = 0;  // MartinR
913
       
913
       
914
    if(GyroFaktor < 0) GyroFaktor = 0;
914
    if(GyroFaktor < 0) GyroFaktor = 0;
915
    if(IntegralFaktor < 0) IntegralFaktor = 0;
915
    if(IntegralFaktor < 0) IntegralFaktor = 0;
916
 
916
 
917
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
917
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
918
     {
918
     {
919
      MaxStickNick = abs(StickNick)/STICK_GAIN;
919
      MaxStickNick = abs(StickNick)/STICK_GAIN;
920
      if(MaxStickNick > 100) MaxStickNick = 100;
920
      if(MaxStickNick > 100) MaxStickNick = 100;
921
     }
921
     }
922
     else MaxStickNick--;
922
     else MaxStickNick--;
923
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
923
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
924
     {
924
     {
925
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
925
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
926
      if(MaxStickRoll > 100) MaxStickRoll = 100;
926
      if(MaxStickRoll > 100) MaxStickRoll = 100;
927
     }
927
     }
928
     else MaxStickRoll--;
928
     else MaxStickRoll--;
929
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
929
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
930
 
930
 
931
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
931
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
932
// Looping?
932
// Looping?
933
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
933
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
934
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
934
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
935
  else
935
  else
936
   {
936
   {
937
     {
937
     {
938
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
938
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
939
     }
939
     }
940
   }
940
   }
941
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
941
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
942
   else
942
   else
943
   {
943
   {
944
   if(Looping_Rechts) // Hysterese
944
   if(Looping_Rechts) // Hysterese
945
     {
945
     {
946
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
946
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
947
     }
947
     }
948
   }
948
   }
949
 
949
 
950
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
950
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
951
  else
951
  else
952
   {
952
   {
953
    if(Looping_Oben)  // Hysterese
953
    if(Looping_Oben)  // Hysterese
954
     {
954
     {
955
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
955
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
956
     }
956
     }
957
   }
957
   }
958
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
958
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
959
   else
959
   else
960
   {
960
   {
961
    if(Looping_Unten) // Hysterese
961
    if(Looping_Unten) // Hysterese
962
     {
962
     {
963
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
963
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
964
     }
964
     }
965
   }
965
   }
966
 
966
 
967
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
967
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
968
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
968
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
969
  } // Ende neue Funken-Werte
969
  } // Ende neue Funken-Werte
970
 
970
 
971
  if(Looping_Roll || Looping_Nick)
971
  if(Looping_Roll || Looping_Nick)
972
   {
972
   {
973
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
973
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
974
        TrichterFlug = 1;
974
        TrichterFlug = 1;
975
   }
975
   }
976
 
976
 
977
 
977
 
978
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
978
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
979
// Bei Empfangsausfall im Flug
979
// Bei Empfangsausfall im Flug
980
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
980
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
981
   if(Notlandung)
981
   if(Notlandung)
982
    {
982
    {
983
     StickGier = 0;
983
     StickGier = 0;
984
     StickNick = 0;
984
     StickNick = 0;
985
     StickRoll = 0;
985
     StickRoll = 0;
986
     GyroFaktor     = 90;
986
     GyroFaktor     = 90;
987
     IntegralFaktor = 120;
987
     IntegralFaktor = 120;
988
     GyroFaktorGier     = 90;
988
     GyroFaktorGier     = 90;
989
     IntegralFaktorGier = 120;
989
     IntegralFaktorGier = 120;
990
     Looping_Roll = 0;
990
     Looping_Roll = 0;
991
     Looping_Nick = 0;
991
     Looping_Nick = 0;
992
    }
992
    }
993
 
993
 
994
 
994
 
995
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
995
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
996
// Integrale auf ACC-Signal abgleichen
996
// Integrale auf ACC-Signal abgleichen
997
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
997
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
998
#define ABGLEICH_ANZAHL 256L
998
#define ABGLEICH_ANZAHL 256L
999
 
999
 
1000
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
1000
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
1001
 MittelIntegralRoll  += IntegralRoll;
1001
 MittelIntegralRoll  += IntegralRoll;
1002
 MittelIntegralNick2 += IntegralNick2;
1002
 MittelIntegralNick2 += IntegralNick2;
1003
 MittelIntegralRoll2 += IntegralRoll2;
1003
 MittelIntegralRoll2 += IntegralRoll2;
1004
 
1004
 
1005
 //if(Looping_Nick || Looping_Roll) // MartinR: so war es
1005
 //if(Looping_Nick || Looping_Roll) // MartinR: so war es
1006
 if(Looping_Nick || Looping_Roll || !IntegralFaktor)  // MartinR: "|| !IntegralFaktor" hinzugefügt
1006
 if(Looping_Nick || Looping_Roll || !IntegralFaktor)  // MartinR: "|| !IntegralFaktor" hinzugefügt
1007
  {
1007
  {
1008
    IntegralAccNick = 0;
1008
    IntegralAccNick = 0;
1009
    IntegralAccRoll = 0;
1009
    IntegralAccRoll = 0;
1010
    MittelIntegralNick = 0;
1010
    MittelIntegralNick = 0;
1011
    MittelIntegralRoll = 0;
1011
    MittelIntegralRoll = 0;
1012
    MittelIntegralNick2 = 0;
1012
    MittelIntegralNick2 = 0;
1013
    MittelIntegralRoll2 = 0;
1013
    MittelIntegralRoll2 = 0;
1014
       
1014
       
1015
        IntegralNick = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0
1015
        IntegralNick = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0
1016
    IntegralRoll = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0 
1016
    IntegralRoll = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0 
1017
    Mess_IntegralNick = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0    
1017
    Mess_IntegralNick = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0    
1018
    Mess_IntegralRoll = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0    
1018
    Mess_IntegralRoll = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0    
1019
    Mess_Integral_Gier = 0;     // MartinR: im HH-Modus alle unbenutzten Integratoren = 0       
1019
    Mess_Integral_Gier = 0;     // MartinR: im HH-Modus alle unbenutzten Integratoren = 0       
1020
    Mess_Integral_Gier2 = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0
1020
    Mess_Integral_Gier2 = 0; // MartinR: im HH-Modus alle unbenutzten Integratoren = 0
1021
       
1021
       
1022
    Mess_IntegralNick2 = Mess_IntegralNick;
1022
    Mess_IntegralNick2 = Mess_IntegralNick;
1023
    Mess_IntegralRoll2 = Mess_IntegralRoll;
1023
    Mess_IntegralRoll2 = Mess_IntegralRoll;
1024
    ZaehlMessungen = 0;
1024
    ZaehlMessungen = 0;
1025
    LageKorrekturNick = 0;
1025
    LageKorrekturNick = 0;
1026
    LageKorrekturRoll = 0;
1026
    LageKorrekturRoll = 0;
1027
  }
1027
  }
1028
 
1028
 
1029
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1029
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1030
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin) && IntegralFaktor) // MartinR: "&& IntegralFaktor" hinzugefügt 
1030
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin) && IntegralFaktor) // MartinR: "&& IntegralFaktor" hinzugefügt 
1031
  {
1031
  {
1032
   long tmp_long, tmp_long2;
1032
   long tmp_long, tmp_long2;
1033
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
1033
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
1034
     {
1034
     {
1035
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1035
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1036
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
1036
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
1037
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1037
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1038
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1038
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1039
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
1039
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
1040
      {
1040
      {
1041
      tmp_long  /= 2;
1041
      tmp_long  /= 2;
1042
      tmp_long2 /= 2;
1042
      tmp_long2 /= 2;
1043
      }
1043
      }
1044
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1044
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1045
      {
1045
      {
1046
      tmp_long  /= 3;
1046
      tmp_long  /= 3;
1047
      tmp_long2 /= 3;
1047
      tmp_long2 /= 3;
1048
      }
1048
      }
1049
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1049
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1050
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1050
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1051
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1051
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1052
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1052
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1053
     }
1053
     }
1054
     else
1054
     else
1055
     {
1055
     {
1056
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1056
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1057
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
1057
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
1058
      tmp_long /= 16;
1058
      tmp_long /= 16;
1059
      tmp_long2 /= 16;
1059
      tmp_long2 /= 16;
1060
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
1060
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
1061
      {
1061
      {
1062
      tmp_long  /= 3;
1062
      tmp_long  /= 3;
1063
      tmp_long2 /= 3;
1063
      tmp_long2 /= 3;
1064
      }
1064
      }
1065
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1065
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1066
      {
1066
      {
1067
      tmp_long  /= 3;
1067
      tmp_long  /= 3;
1068
      tmp_long2 /= 3;
1068
      tmp_long2 /= 3;
1069
      }
1069
      }
1070
 
1070
 
1071
#define AUSGLEICH  32
1071
#define AUSGLEICH  32
1072
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
1072
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
1073
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
1073
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
1074
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
1074
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
1075
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
1075
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
1076
     }
1076
     }
1077
 
1077
 
1078
//if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;}
1078
//if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;}
1079
   Mess_IntegralNick -= tmp_long;
1079
   Mess_IntegralNick -= tmp_long;
1080
   Mess_IntegralRoll -= tmp_long2;
1080
   Mess_IntegralRoll -= tmp_long2;
1081
  }
1081
  }
1082
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1082
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1083
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
1083
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
1084
 {
1084
 {
1085
  static int cnt = 0;
1085
  static int cnt = 0;
1086
  static char last_n_p,last_n_n,last_r_p,last_r_n;
1086
  static char last_n_p,last_n_n,last_r_p,last_r_n;
1087
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
1087
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
1088
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp && IntegralFaktor) // MartinR: "&& IntegralFaktor" hinzugefügt
1088
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp && IntegralFaktor) // MartinR: "&& IntegralFaktor" hinzugefügt
1089
  {
1089
  {
1090
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
1090
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
1091
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
1091
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
1092
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
1092
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
1093
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
1093
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
1094
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
1094
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
1095
#define MAX_I 0//(Poti2/10)
1095
#define MAX_I 0//(Poti2/10)
1096
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
1096
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
1097
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
1097
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
1098
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
1098
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
1099
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
1099
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
1100
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
1100
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
1101
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
1101
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
1102
 
1102
 
1103
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
1103
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
1104
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
1104
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
1105
 
1105
 
1106
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
1106
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
1107
    {
1107
    {
1108
     LageKorrekturNick /= 2;
1108
     LageKorrekturNick /= 2;
1109
     LageKorrekturRoll /= 2;
1109
     LageKorrekturRoll /= 2;
1110
    }
1110
    }
1111
 
1111
 
1112
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1112
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1113
// Gyro-Drift ermitteln
1113
// Gyro-Drift ermitteln
1114
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1114
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1115
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
1115
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
1116
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
1116
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
1117
    tmp_long  = IntegralNick2 - IntegralNick;
1117
    tmp_long  = IntegralNick2 - IntegralNick;
1118
    tmp_long2 = IntegralRoll2 - IntegralRoll;
1118
    tmp_long2 = IntegralRoll2 - IntegralRoll;
1119
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
1119
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
1120
 
1120
 
1121
    IntegralFehlerNick = tmp_long;
1121
    IntegralFehlerNick = tmp_long;
1122
    IntegralFehlerRoll = tmp_long2;
1122
    IntegralFehlerRoll = tmp_long2;
1123
    Mess_IntegralNick2 -= IntegralFehlerNick;
1123
    Mess_IntegralNick2 -= IntegralFehlerNick;
1124
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
1124
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
1125
 
1125
 
1126
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
1126
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
1127
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
1127
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
1128
  if(EE_Parameter.Driftkomp)
1128
  if(EE_Parameter.Driftkomp)
1129
   {
1129
   {
1130
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
1130
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
1131
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
1131
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
1132
   }
1132
   }
1133
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
1133
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
1134
//DebugOut.Analog[24] = GierGyroFehler;
1134
//DebugOut.Analog[24] = GierGyroFehler;
1135
    GierGyroFehler = 0;
1135
    GierGyroFehler = 0;
1136
 
1136
 
1137
 
1137
 
1138
/*DebugOut.Analog[17] = IntegralAccNick / 26;
1138
/*DebugOut.Analog[17] = IntegralAccNick / 26;
1139
DebugOut.Analog[18] = IntegralAccRoll / 26;
1139
DebugOut.Analog[18] = IntegralAccRoll / 26;
1140
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
1140
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
1141
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
1141
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
1142
*/
1142
*/
1143
//DebugOut.Analog[21] = MittelIntegralNick / 26;
1143
//DebugOut.Analog[21] = MittelIntegralNick / 26;
1144
//MittelIntegralRoll = MittelIntegralRoll;
1144
//MittelIntegralRoll = MittelIntegralRoll;
1145
//DebugOut.Analog[28] = ausgleichNick;
1145
//DebugOut.Analog[28] = ausgleichNick;
1146
/*
1146
/*
1147
DebugOut.Analog[29] = ausgleichRoll;
1147
DebugOut.Analog[29] = ausgleichRoll;
1148
DebugOut.Analog[30] = LageKorrekturRoll * 10;
1148
DebugOut.Analog[30] = LageKorrekturRoll * 10;
1149
*/
1149
*/
1150
 
1150
 
1151
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2) 
1151
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2) 
1152
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 
1152
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 
1153
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1153
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1154
#define BEWEGUNGS_LIMIT 20000
1154
#define BEWEGUNGS_LIMIT 20000
1155
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1155
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1156
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1156
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1157
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1157
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1158
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1158
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1159
        {
1159
        {
1160
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1160
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1161
         {
1161
         {
1162
           if(last_n_p)
1162
           if(last_n_p)
1163
           {
1163
           {
1164
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1164
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1165
            ausgleichNick = IntegralFehlerNick / 8;
1165
            ausgleichNick = IntegralFehlerNick / 8;
1166
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1166
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1167
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1167
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1168
           }
1168
           }
1169
           else last_n_p = 1;
1169
           else last_n_p = 1;
1170
         } else  last_n_p = 0;
1170
         } else  last_n_p = 0;
1171
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1171
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1172
         {
1172
         {
1173
           if(last_n_n)
1173
           if(last_n_n)
1174
            {
1174
            {
1175
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1175
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1176
             ausgleichNick = IntegralFehlerNick / 8;
1176
             ausgleichNick = IntegralFehlerNick / 8;
1177
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1177
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1178
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1178
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1179
            }
1179
            }
1180
           else last_n_n = 1;
1180
           else last_n_n = 1;
1181
         } else  last_n_n = 0;
1181
         } else  last_n_n = 0;
1182
        }
1182
        }
1183
        else
1183
        else
1184
        {
1184
        {
1185
         cnt = 0;
1185
         cnt = 0;
1186
         KompassSignalSchlecht = 1000;
1186
         KompassSignalSchlecht = 1000;
1187
        }
1187
        }
1188
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1188
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1189
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1189
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1190
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1190
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1191
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1191
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1192
 
1192
 
1193
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1193
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1194
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1194
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1195
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1195
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1196
        ausgleichRoll = 0;
1196
        ausgleichRoll = 0;
1197
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1197
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1198
        {
1198
        {
1199
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1199
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1200
         {
1200
         {
1201
           if(last_r_p)
1201
           if(last_r_p)
1202
           {
1202
           {
1203
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1203
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1204
            ausgleichRoll = IntegralFehlerRoll / 8;
1204
            ausgleichRoll = IntegralFehlerRoll / 8;
1205
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1205
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1206
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1206
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1207
           }
1207
           }
1208
           else last_r_p = 1;
1208
           else last_r_p = 1;
1209
         } else  last_r_p = 0;
1209
         } else  last_r_p = 0;
1210
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1210
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1211
         {
1211
         {
1212
           if(last_r_n)
1212
           if(last_r_n)
1213
           {
1213
           {
1214
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1214
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1215
            ausgleichRoll = IntegralFehlerRoll / 8;
1215
            ausgleichRoll = IntegralFehlerRoll / 8;
1216
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1216
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1217
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1217
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1218
           }
1218
           }
1219
           else last_r_n = 1;
1219
           else last_r_n = 1;
1220
         } else  last_r_n = 0;
1220
         } else  last_r_n = 0;
1221
        } else
1221
        } else
1222
        {
1222
        {
1223
         cnt = 0;
1223
         cnt = 0;
1224
         KompassSignalSchlecht = 1000;
1224
         KompassSignalSchlecht = 1000;
1225
        }
1225
        }
1226
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1226
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1227
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1227
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1228
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1228
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1229
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1229
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1230
  }
1230
  }
1231
  else
1231
  else
1232
  {
1232
  {
1233
   LageKorrekturRoll = 0;
1233
   LageKorrekturRoll = 0;
1234
   LageKorrekturNick = 0;
1234
   LageKorrekturNick = 0;
1235
   TrichterFlug = 0;
1235
   TrichterFlug = 0;
1236
  }
1236
  }
1237
 
1237
 
1238
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1238
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1239
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1239
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1240
   MittelIntegralNick_Alt = MittelIntegralNick;
1240
   MittelIntegralNick_Alt = MittelIntegralNick;
1241
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1241
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1242
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1242
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1243
    IntegralAccNick = 0;
1243
    IntegralAccNick = 0;
1244
    IntegralAccRoll = 0;
1244
    IntegralAccRoll = 0;
1245
    IntegralAccZ = 0;
1245
    IntegralAccZ = 0;
1246
    MittelIntegralNick = 0;
1246
    MittelIntegralNick = 0;
1247
    MittelIntegralRoll = 0;
1247
    MittelIntegralRoll = 0;
1248
    MittelIntegralNick2 = 0;
1248
    MittelIntegralNick2 = 0;
1249
    MittelIntegralRoll2 = 0;
1249
    MittelIntegralRoll2 = 0;
1250
    ZaehlMessungen = 0;
1250
    ZaehlMessungen = 0;
1251
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1251
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1252
 
1252
 
1253
 
1253
 
1254
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1254
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1255
//  Gieren
1255
//  Gieren
1256
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1256
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1257
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
1257
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
1258
    if(abs(StickGier) > 15) // war 35
1258
    if(abs(StickGier) > 15) // war 35
1259
     {
1259
     {
1260
      KompassSignalSchlecht = 1000;
1260
      KompassSignalSchlecht = 1000;
1261
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1261
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1262
       {
1262
       {
1263
         NeueKompassRichtungMerken = 1;
1263
         NeueKompassRichtungMerken = 1;
1264
        };
1264
        };
1265
     }
1265
     }
1266
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1266
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1267
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1267
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1268
    sollGier = tmp_int;
1268
    sollGier = tmp_int;
1269
    Mess_Integral_Gier -= tmp_int;
1269
    Mess_Integral_Gier -= tmp_int;
1270
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1270
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1271
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1271
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1272
 
1272
 
1273
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1273
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1274
//  Kompass
1274
//  Kompass
1275
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1275
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1276
//DebugOut.Analog[16] = KompassSignalSchlecht;
1276
//DebugOut.Analog[16] = KompassSignalSchlecht;
1277
 
1277
 
1278
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1278
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1279
     {
1279
     {
1280
       int w,v,r,fehler,korrektur;
1280
       int w,v,r,fehler,korrektur;
1281
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1281
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1282
       v = abs(IntegralRoll /512);
1282
       v = abs(IntegralRoll /512);
1283
       if(v > w) w = v; // grösste Neigung ermitteln
1283
       if(v > w) w = v; // grösste Neigung ermitteln
1284
       korrektur = w / 8 + 1;
1284
       korrektur = w / 8 + 1;
1285
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1285
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1286
       if(abs(MesswertGier) > 128)
1286
       if(abs(MesswertGier) > 128)
1287
            {
1287
            {
1288
                 fehler = 0;
1288
                 fehler = 0;
1289
                }
1289
                }
1290
       if(!KompassSignalSchlecht && w < 25)
1290
       if(!KompassSignalSchlecht && w < 25)
1291
        {
1291
        {
1292
        GierGyroFehler += fehler;
1292
        GierGyroFehler += fehler;
1293
        if(NeueKompassRichtungMerken)
1293
        if(NeueKompassRichtungMerken)
1294
         {
1294
         {
1295
          beeptime = 200;
1295
          beeptime = 200;
1296
//         KompassStartwert = KompassValue;
1296
//         KompassStartwert = KompassValue;
1297
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1297
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1298
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1298
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1299
          NeueKompassRichtungMerken = 0;
1299
          NeueKompassRichtungMerken = 0;
1300
         }
1300
         }
1301
        }
1301
        }
1302
       ErsatzKompass += (fehler * 8) / korrektur;
1302
       ErsatzKompass += (fehler * 8) / korrektur;
1303
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1303
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1304
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1304
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1305
       if(w >= 0)
1305
       if(w >= 0)
1306
        {
1306
        {
1307
          if(!KompassSignalSchlecht)
1307
          if(!KompassSignalSchlecht)
1308
          {
1308
          {
1309
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1309
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1310
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1310
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1311
//           r = KompassRichtung;
1311
//           r = KompassRichtung;
1312
           v = (r * w) / v;  // nach Kompass ausrichten
1312
           v = (r * w) / v;  // nach Kompass ausrichten
1313
           w = 3 * Parameter_KompassWirkung;
1313
           w = 3 * Parameter_KompassWirkung;
1314
           if(v > w) v = w; // Begrenzen
1314
           if(v > w) v = w; // Begrenzen
1315
           else
1315
           else
1316
           if(v < -w) v = -w;
1316
           if(v < -w) v = -w;
1317
           Mess_Integral_Gier += v;
1317
           Mess_Integral_Gier += v;
1318
          }
1318
          }
1319
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1319
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1320
        }
1320
        }
1321
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1321
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1322
     }
1322
     }
1323
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1323
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1324
 
1324
 
1325
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1325
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1326
//  Debugwerte zuordnen
1326
//  Debugwerte zuordnen
1327
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1327
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1328
  if(!TimerWerteausgabe--)
1328
  if(!TimerWerteausgabe--)
1329
   {
1329
   {
1330
    TimerWerteausgabe = 24;
1330
    TimerWerteausgabe = 24;
1331
 
1331
 
1332
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
1332
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
1333
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1333
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1334
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1334
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1335
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1335
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1336
    DebugOut.Analog[4] = MesswertGier;
1336
    DebugOut.Analog[4] = MesswertGier;
1337
    DebugOut.Analog[5] = HoehenWert;
1337
    DebugOut.Analog[5] = HoehenWert;
1338
    DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1338
    DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1339
    DebugOut.Analog[8] = KompassValue;
1339
    DebugOut.Analog[8] = KompassValue;
1340
    DebugOut.Analog[9] = UBat;
1340
    DebugOut.Analog[9] = UBat;
1341
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1341
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1342
    DebugOut.Analog[10] = SenderOkay;
1342
    DebugOut.Analog[10] = SenderOkay;
1343
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1343
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1344
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1344
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1345
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1345
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1346
    DebugOut.Analog[19] = WinkelOut.CalcState;
1346
    DebugOut.Analog[19] = WinkelOut.CalcState;
1347
        //DebugOut.Analog[20] = ServoValue; // MartinR: DebugOut.Analog[20] wird in timer0.c ausgegeben!!
1347
        //DebugOut.Analog[20] = ServoValue; // MartinR: DebugOut.Analog[20] wird in timer0.c ausgegeben!!
1348
//    DebugOut.Analog[24] = MesswertNick/2;
1348
//    DebugOut.Analog[24] = MesswertNick/2;
1349
//    DebugOut.Analog[25] = MesswertRoll/2;
1349
//    DebugOut.Analog[25] = MesswertRoll/2;
1350
    DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift;
1350
    DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift;
1351
//    DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion;
1351
//    DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion;
1352
//    DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K;
1352
//    DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K;
1353
    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
1353
    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
1354
    DebugOut.Analog[30] = GPS_Nick;
1354
    DebugOut.Analog[30] = GPS_Nick;
1355
    DebugOut.Analog[31] = GPS_Roll;
1355
    DebugOut.Analog[31] = GPS_Roll;
1356
 
1356
 
1357
 
1357
 
1358
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1358
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1359
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1359
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1360
 
1360
 
1361
/*    DebugOut.Analog[16] = motor_rx[0];
1361
/*    DebugOut.Analog[16] = motor_rx[0];
1362
    DebugOut.Analog[17] = motor_rx[1];
1362
    DebugOut.Analog[17] = motor_rx[1];
1363
    DebugOut.Analog[18] = motor_rx[2];
1363
    DebugOut.Analog[18] = motor_rx[2];
1364
    DebugOut.Analog[19] = motor_rx[3];
1364
    DebugOut.Analog[19] = motor_rx[3];
1365
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1365
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1366
    DebugOut.Analog[20] /= 14;
1366
    DebugOut.Analog[20] /= 14;
1367
    DebugOut.Analog[21] = motor_rx[4];
1367
    DebugOut.Analog[21] = motor_rx[4];
1368
    DebugOut.Analog[22] = motor_rx[5];
1368
    DebugOut.Analog[22] = motor_rx[5];
1369
    DebugOut.Analog[23] = motor_rx[6];
1369
    DebugOut.Analog[23] = motor_rx[6];
1370
    DebugOut.Analog[24] = motor_rx[7];
1370
    DebugOut.Analog[24] = motor_rx[7];
1371
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1371
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1372
*/
1372
*/
1373
//    DebugOut.Analog[9] = MesswertNick;
1373
//    DebugOut.Analog[9] = MesswertNick;
1374
//    DebugOut.Analog[9] = SollHoehe;
1374
//    DebugOut.Analog[9] = SollHoehe;
1375
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1375
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1376
//    DebugOut.Analog[11] = KompassStartwert;
1376
//    DebugOut.Analog[11] = KompassStartwert;
1377
//    DebugOut.Analog[10] = Parameter_Gyro_I;
1377
//    DebugOut.Analog[10] = Parameter_Gyro_I;
1378
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;
1378
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;
1379
//    DebugOut.Analog[9] = KompassRichtung;
1379
//    DebugOut.Analog[9] = KompassRichtung;
1380
//    DebugOut.Analog[10] = GasMischanteil;
1380
//    DebugOut.Analog[10] = GasMischanteil;
1381
//    DebugOut.Analog[3] = HoeheD * 32;
1381
//    DebugOut.Analog[3] = HoeheD * 32;
1382
//    DebugOut.Analog[4] = hoehenregler;
1382
//    DebugOut.Analog[4] = hoehenregler;
1383
  }
1383
  }
1384
 
1384
 
1385
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1385
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1386
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1386
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1387
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1387
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1388
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1388
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1389
 
1389
 
1390
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1390
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1391
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1391
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1392
 
1392
 
1393
#define TRIM_MAX 200
1393
#define TRIM_MAX 200
1394
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1394
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1395
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1395
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1396
 
1396
 
1397
  if(!IntegralFaktor) // MartinR : hinzugefügt
1397
  if(!IntegralFaktor) // MartinR : hinzugefügt
1398
        {
1398
        {
1399
        MesswertNick = (long) ((long)MesswertNick * GyroFaktor) / (256L / STICK_GAIN)  ; // MartinR : hinzugefügt
1399
        MesswertNick = (long) ((long)MesswertNick * GyroFaktor) / (256L / STICK_GAIN)  ; // MartinR : hinzugefügt
1400
        MesswertRoll = (long) ((long)MesswertRoll * GyroFaktor) / (256L / STICK_GAIN) ;  // MartinR : hinzugefügt
1400
        MesswertRoll = (long) ((long)MesswertRoll * GyroFaktor) / (256L / STICK_GAIN) ;  // MartinR : hinzugefügt
1401
        }
1401
        }
1402
        else // MartinR so war es
1402
        else // MartinR so war es
1403
        {
1403
        {
1404
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1404
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1405
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1405
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1406
        }
1406
        }
1407
 
1407
 
1408
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1408
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1409
 
1409
 
1410
    // Maximalwerte abfangen
1410
    // Maximalwerte abfangen
1411
        // MartinR : Prüfen ob Unterscheidung nach Platinenversion erforderlich?
1411
        // MartinR : Prüfen ob Unterscheidung nach Platinenversion erforderlich?
1412
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1412
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1413
    #define MAX_SENSOR  (4096*4)
1413
    #define MAX_SENSOR  (4096*4)
1414
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1414
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1415
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1415
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1416
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1416
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1417
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1417
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1418
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1418
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1419
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1419
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1420
 
1420
 
1421
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1421
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1422
// all BL-Ctrl connected?
1422
// all BL-Ctrl connected?
1423
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1423
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1424
  if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1424
  if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1425
   {
1425
   {
1426
    modell_fliegt = 1;
1426
    modell_fliegt = 1;
1427
        GasMischanteil = MIN_GAS;
1427
        GasMischanteil = MIN_GAS;
1428
   }
1428
   }
1429
 
1429
 
1430
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1430
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1431
// Höhenregelung
1431
// Höhenregelung
1432
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1432
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1433
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1433
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1434
  GasMischanteil *= STICK_GAIN;
1434
  GasMischanteil *= STICK_GAIN;
1435
 
1435
 
1436
// MartinR : so war es:
1436
// MartinR : so war es:
1437
/*  
1437
/*  
1438
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1438
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1439
  {
1439
  {
1440
    int tmp_int;
1440
    int tmp_int;
1441
        static char delay = 100;
1441
        static char delay = 100;
1442
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1442
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1443
    {
1443
    {
1444
      if(Parameter_MaxHoehe < 50)
1444
      if(Parameter_MaxHoehe < 50)
1445
      {
1445
      {
1446
       if(!delay--)
1446
       if(!delay--)
1447
            {
1447
            {
1448
         if((MessLuftdruck > 1000) && OCR0A < 254)
1448
         if((MessLuftdruck > 1000) && OCR0A < 254)
1449
                  {
1449
                  {
1450
                    if(OCR0A < 244)
1450
                    if(OCR0A < 244)
1451
                     {
1451
                     {
1452
                      ExpandBaro -= 10;
1452
                      ExpandBaro -= 10;
1453
                      OCR0A = DruckOffsetSetting - ExpandBaro;
1453
                      OCR0A = DruckOffsetSetting - ExpandBaro;
1454
                         }
1454
                         }
1455
                         else OCR0A = 254;
1455
                         else OCR0A = 254;
1456
                beeptime = 300;
1456
                beeptime = 300;
1457
            delay = 250;
1457
            delay = 250;
1458
                  }
1458
                  }
1459
                  else      
1459
                  else      
1460
         if((MessLuftdruck < 100) && OCR0A > 1)
1460
         if((MessLuftdruck < 100) && OCR0A > 1)
1461
                  {
1461
                  {
1462
                   if(OCR0A > 10)
1462
                   if(OCR0A > 10)
1463
                    {
1463
                    {
1464
                     ExpandBaro += 10;
1464
                     ExpandBaro += 10;
1465
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1465
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1466
                        }
1466
                        }
1467
                         else OCR0A = 1;
1467
                         else OCR0A = 1;
1468
                   beeptime = 300;
1468
                   beeptime = 300;
1469
           delay = 250;
1469
           delay = 250;
1470
                  }
1470
                  }
1471
          else
1471
          else
1472
          {
1472
          {
1473
               SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1473
               SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1474
           HoehenReglerAktiv = 0;
1474
           HoehenReglerAktiv = 0;
1475
                   delay = 1;
1475
                   delay = 1;
1476
                  }
1476
                  }
1477
                }
1477
                }
1478
      }
1478
      }
1479
      else
1479
      else
1480
        {
1480
        {
1481
         HoehenReglerAktiv = 1;
1481
         HoehenReglerAktiv = 1;
1482
                 delay = 200;
1482
                 delay = 200;
1483
                }
1483
                }
1484
    }
1484
    }
1485
    else
1485
    else
1486
    {
1486
    {
1487
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1487
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1488
     HoehenReglerAktiv = 1;
1488
     HoehenReglerAktiv = 1;
1489
    }
1489
    }
1490
 
1490
 
1491
    if(Notlandung) SollHoehe = 0;
1491
    if(Notlandung) SollHoehe = 0;
1492
    h = HoehenWert;
1492
    h = HoehenWert;
1493
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1493
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1494
     {
1494
     {
1495
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1495
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1496
      h = GasMischanteil - h;         // vom Gas abziehen
1496
      h = GasMischanteil - h;         // vom Gas abziehen
1497
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1497
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1498
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1498
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1499
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1499
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1500
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1500
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1501
      h -= tmp_int;
1501
      h -= tmp_int;
1502
      hoehenregler = (hoehenregler*15 + h) / 16;
1502
      hoehenregler = (hoehenregler*15 + h) / 16;
1503
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1503
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1504
       {
1504
       {
1505
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1505
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1506
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1506
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1507
       }
1507
       }
1508
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1508
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1509
      GasMischanteil = hoehenregler;
1509
      GasMischanteil = hoehenregler;
1510
     }
1510
     }
1511
  }
1511
  }
1512
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1512
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1513
  */
1513
  */
1514
 
1514
 
1515
  // MartinR: Neuer Höhenregler von MartinR: Anfang
1515
  // MartinR: Neuer Höhenregler von MartinR: Anfang
1516
 
1516
 
1517
   if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1517
   if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1518
  {
1518
  {
1519
    int tmp_int;
1519
    int tmp_int;
1520
        static char delay = 100;
1520
        static char delay = 100;
1521
  // Definitionen Vorschlag Killagreg Anfang
1521
  // Definitionen Vorschlag Killagreg Anfang
1522
  #define HOOVER_GAS_AVERAGE 4192 // 4192 * 2ms = 8.2s averaging 
1522
  #define HOOVER_GAS_AVERAGE 4192 // 4192 * 2ms = 8.2s averaging 
1523
  #define HEIGHT_CONTROL_GAS_AVERAGE 16
1523
  #define HEIGHT_CONTROL_GAS_AVERAGE 16
1524
        int16_t CosNick, CosRoll;
1524
        int16_t CosNick, CosRoll;
1525
        //int16_t HeightControlGas; // MartinR: Schwebegas
1525
        //int16_t HeightControlGas; // MartinR: Schwebegas
1526
        //static int16_t FilterHeightControlGas = 0; // MartinR: SchwebegasFilter
1526
        //static int16_t FilterHeightControlGas = 0; // MartinR: SchwebegasFilter
1527
        static uint32_t HooverGasEstimation = 0;
1527
        static uint32_t HooverGasEstimation = 0;
1528
        //static uint8_t delay = 100;
1528
        //static uint8_t delay = 100;
1529
       
1529
       
1530
        int32_t tmp_long3;
1530
        int32_t tmp_long3;
1531
 // Ende Definitionen Vorschlag Killagreg
1531
 // Ende Definitionen Vorschlag Killagreg
1532
       
1532
       
1533
        // calculate cos of nick and roll angle used for projection of the vertical hoover gas  // Vorschlag von Killagerg:
1533
        // calculate cos of nick and roll angle used for projection of the vertical hoover gas  // Vorschlag von Killagerg:
1534
        CosNick = IntegralNick/GIER_GRAD_FAKTOR; // nick angle in deg // =IntegralNick/GIER_GRAD_FAKTOR
1534
        CosNick = IntegralNick/GIER_GRAD_FAKTOR; // nick angle in deg // =IntegralNick/GIER_GRAD_FAKTOR
1535
        CHECK_MIN_MAX(CosNick, -60, 60); // limit nick angle 
1535
        CHECK_MIN_MAX(CosNick, -60, 60); // limit nick angle 
1536
        CosNick = c_cos_8192(CosNick);
1536
        CosNick = c_cos_8192(CosNick);
1537
        CosRoll = IntegralRoll/GIER_GRAD_FAKTOR; // roll angle in deg 
1537
        CosRoll = IntegralRoll/GIER_GRAD_FAKTOR; // roll angle in deg 
1538
        CHECK_MIN_MAX(CosRoll, -60, 60); // limit roll angle 
1538
        CHECK_MIN_MAX(CosRoll, -60, 60); // limit roll angle 
1539
        CosRoll = c_cos_8192(CosRoll);
1539
        CosRoll = c_cos_8192(CosRoll);
1540
 
1540
 
1541
 
1541
 
1542
// Neigungskorrektur ACCHoch:      
1542
// Neigungskorrektur ACCHoch:      
1543
          tmp_long3 = (int32_t) (NeutralAccZ-(Parameter_UserParam6*4)); // take current thrust 
1543
          tmp_long3 = (int32_t) (NeutralAccZ-(Parameter_UserParam6*4)); // take current thrust 
1544
          tmp_long3 *= CosNick; // apply nick projection 
1544
          tmp_long3 *= CosNick; // apply nick projection 
1545
          tmp_long3 /= 8192; tmp_long3 *= CosRoll; // apply roll projection 
1545
          tmp_long3 /= 8192; tmp_long3 *= CosRoll; // apply roll projection 
1546
          tmp_long3 /= 8129; // average vertical projected thrust 
1546
          tmp_long3 /= 8129; // average vertical projected thrust 
1547
         
1547
         
1548
        //Mess_Integral_Hoch += AdWertAccHoch;      // Integrieren // MartinR: zu Höhenregler in fc.c verschoben
1548
        //Mess_Integral_Hoch += AdWertAccHoch;      // Integrieren // MartinR: zu Höhenregler in fc.c verschoben
1549
        //Mess_Integral_Hoch += tmp_long3; // Integrieren // MartinR: mit Neigungskorrektur // Test
1549
        //Mess_Integral_Hoch += tmp_long3; // Integrieren // MartinR: mit Neigungskorrektur // Test
1550
       
1550
       
1551
        tmp_int = (int16_t) (AdWertAccHoch + NeutralAccZ - tmp_long3 - (Parameter_UserParam6*4));
1551
        tmp_int = (int16_t) (AdWertAccHoch + NeutralAccZ - tmp_long3 - (Parameter_UserParam6*4));
1552
        if (tmp_int < 0) tmp_int ++ ; // MartinR: Digitalisierungsrauschen abmindern
1552
        if (tmp_int < 0) tmp_int ++ ; // MartinR: Digitalisierungsrauschen abmindern
1553
        if (tmp_int > 0) tmp_int -- ; // MartinR: entspricht - 1 Bit
1553
        if (tmp_int > 0) tmp_int -- ; // MartinR: entspricht - 1 Bit
1554
       
1554
       
1555
        Mess_Integral_Hoch += tmp_int; // Integrieren // MartinR: mit Neigungskorrektur
1555
        Mess_Integral_Hoch += tmp_int; // Integrieren // MartinR: mit Neigungskorrektur
1556
        Mess_Integral_Hoch -= Mess_Integral_Hoch / 256; // dämfen // MartinR: zu Höhenregler in fc.c verschoben
1556
        Mess_Integral_Hoch -= Mess_Integral_Hoch / 256; // dämfen // MartinR: zu Höhenregler in fc.c verschoben
1557
        CHECK_MIN_MAX(Mess_Integral_Hoch, -16000, 16000); // limit 
1557
        CHECK_MIN_MAX(Mess_Integral_Hoch, -16000, 16000); // limit 
1558
 
1558
 
1559
 
1559
 
1560
        // MartinR: Änderungen HoheD und D-Anteil Höhenregler (h_d) Anfang :
1560
        // MartinR: Änderungen HoheD und D-Anteil Höhenregler (h_d) Anfang :
1561
                HoehenWertSumme += HoehenWert ;
1561
                HoehenWertSumme += HoehenWert ;
1562
                //if (++ iHoehe >= 40) // MartinR: Wartezeit um auch kleine Änderungsgeschwindigkeiten erkennen zu können
1562
                //if (++ iHoehe >= 40) // MartinR: Wartezeit um auch kleine Änderungsgeschwindigkeiten erkennen zu können
1563
                if (++ iHoehe >= Parameter_UserParam5) // MartinR: Wartezeit einstellbar
1563
                if (++ iHoehe >= Parameter_UserParam5) // MartinR: Wartezeit einstellbar
1564
                {
1564
                {
1565
                 HoehenWertSumme = HoehenWertSumme / iHoehe ; // MartinR: Mittelwert während der Wartezeit
1565
                 HoehenWertSumme = HoehenWertSumme / iHoehe ; // MartinR: Mittelwert während der Wartezeit
1566
                 HoeheD = (int) Parameter_Luftdruck_D * (HoehenWert - HoehenWertalt) ;
1566
                 HoeheD = (int) Parameter_Luftdruck_D * (HoehenWert - HoehenWertalt) ;
1567
                 if (HoeheD < 0) HoeheD += Parameter_Luftdruck_D ; // MartinR: Digitalisierungsrauschen abmindern
1567
                 if (HoeheD < 0) HoeheD += Parameter_Luftdruck_D ; // MartinR: Digitalisierungsrauschen abmindern
1568
                 if (HoeheD > 0) HoeheD -= Parameter_Luftdruck_D ; // MartinR: entspricht - 1 Bit vom Höhenwert
1568
                 if (HoeheD > 0) HoeheD -= Parameter_Luftdruck_D ; // MartinR: entspricht - 1 Bit vom Höhenwert
1569
                 
1569
                 
1570
                 iHoehe = 0 ;
1570
                 iHoehe = 0 ;
1571
                 HoehenWertalt = HoehenWertSumme ;
1571
                 HoehenWertalt = HoehenWertSumme ;
1572
                 HoehenWertSumme = 0 ;
1572
                 HoehenWertSumme = 0 ;
1573
                }      
1573
                }      
1574
                // D-Anteil berechnen:
1574
                // D-Anteil berechnen:
1575
                h_d = (int) (HoeheD)/(64/STICK_GAIN);    // D-Anteil (8*8=64)
1575
                h_d = (int) (HoeheD)/(64/STICK_GAIN);    // D-Anteil (8*8=64)
1576
                // ACC-D-Anteil
1576
                // ACC-D-Anteil
1577
                tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1577
                tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1578
                if(tmp_int > 50*STICK_GAIN) tmp_int = 50*STICK_GAIN;
1578
                if(tmp_int > 50*STICK_GAIN) tmp_int = 50*STICK_GAIN;
1579
                else if(tmp_int < -(50*STICK_GAIN)) tmp_int = -(50*STICK_GAIN);
1579
                else if(tmp_int < -(50*STICK_GAIN)) tmp_int = -(50*STICK_GAIN);
1580
                h_d += tmp_int; // positiver D-Anteil bedeutet Steigen
1580
                h_d += tmp_int; // positiver D-Anteil bedeutet Steigen
1581
               
1581
               
1582
        // MartinR: Änderungen HoheD und D-Anteil Höhenregler (h_d) Ende
1582
        // MartinR: Änderungen HoheD und D-Anteil Höhenregler (h_d) Ende
1583
 
1583
 
1584
   
1584
   
1585
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1585
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1586
    {
1586
    {
1587
      //if(Parameter_MaxHoehe < 50)  // MartinR :so war es
1587
      //if(Parameter_MaxHoehe < 50)  // MartinR :so war es
1588
         
1588
         
1589
         
1589
         
1590
            if(Parameter_MaxHoehe < 50  || (Parameter_UserParam1 > 140) )   // MartinR: Schalter aus oder HH über UsererParam1 an
1590
            if(Parameter_MaxHoehe < 50  || (Parameter_UserParam1 > 140) )   // MartinR: Schalter aus oder HH über UsererParam1 an
1591
      {
1591
      {
1592
          // Höhenregler nicht aktiv
1592
          // Höhenregler nicht aktiv
1593
           if(!delay--)
1593
           if(!delay--)
1594
            {
1594
            {
1595
                 #define OPA_OFFSET_STEP 10
1595
                 #define OPA_OFFSET_STEP 10
1596
         if((MessLuftdruck > 1000) && (OCR0A < (255 - OPA_OFFSET_STEP)) )
1596
         if((MessLuftdruck > 1000) && (OCR0A < (255 - OPA_OFFSET_STEP)) )
1597
                  {
1597
                  {
1598
                    ExpandBaro -= 1;
1598
                    ExpandBaro -= 1;
1599
                    OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro;
1599
                    OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro;
1600
                beeptime = 300;
1600
                beeptime = 300;
1601
            delay = 250;
1601
            delay = 250;
1602
                  }
1602
                  }
1603
                  else if((MessLuftdruck < 100) && (OCR0A > OPA_OFFSET_STEP))
1603
                  else if((MessLuftdruck < 100) && (OCR0A > OPA_OFFSET_STEP))
1604
                  {
1604
                  {
1605
                    ExpandBaro += 1;
1605
                    ExpandBaro += 1;
1606
                    OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro;
1606
                    OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro;
1607
                    beeptime = 300;
1607
                    beeptime = 300;
1608
            delay = 250;
1608
            delay = 250;
1609
                  }
1609
                  }
1610
                  else      
1610
                  else      
1611
         if((MessLuftdruck < 100) && OCR0A > 1)
1611
         if((MessLuftdruck < 100) && OCR0A > 1)
1612
                  {
1612
                  {
1613
                   if(OCR0A > 10)
1613
                   if(OCR0A > 10)
1614
                    {
1614
                    {
1615
                     ExpandBaro += 10;
1615
                     ExpandBaro += 10;
1616
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1616
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1617
                        }
1617
                        }
1618
                         else OCR0A = 1;
1618
                         else OCR0A = 1;
1619
                   beeptime = 300;
1619
                   beeptime = 300;
1620
           delay = 250;
1620
           delay = 250;
1621
                  }
1621
                  }
1622
          else
1622
          else
1623
          {    
1623
          {    
1624
               //SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters // MartinR : so war es
1624
               //SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters // MartinR : so war es
1625
                   SollHoehe = HoehenWert; // MartinR : geändert
1625
                   SollHoehe = HoehenWert; // MartinR : geändert
1626
           HoehenReglerAktiv = 0;
1626
           HoehenReglerAktiv = 0;
1627
                   delay = 1;
1627
                   delay = 1;
1628
                  }
1628
                  }
1629
                }
1629
                }
1630
                SollHoehe = HoehenWert;  // MartinR: SollHoehe wird nachgeführt bis HoehenreglerAktiv = 1
1630
                SollHoehe = HoehenWert;  // MartinR: SollHoehe wird nachgeführt bis HoehenreglerAktiv = 1
1631
                //SchwebeGas = GasMischanteil;  // MartinR: SchwebeGas wird nachgeführt bis HoehenreglerAktiv = 1 
1631
                //SchwebeGas = GasMischanteil;  // MartinR: SchwebeGas wird nachgeführt bis HoehenreglerAktiv = 1 
1632
                // Deaktiv wegen HooverGasEstimation/HOOVER_GAS_AVERAGE
1632
                // Deaktiv wegen HooverGasEstimation/HOOVER_GAS_AVERAGE
1633
               
1633
               
1634
                HoehenReglerAktiv = 0; // MartinR: zur Sicherheit
1634
                HoehenReglerAktiv = 0; // MartinR: zur Sicherheit
1635
      }
1635
      }
1636
      else // Schalter an und kein HH über Schalter
1636
      else // Schalter an und kein HH über Schalter
1637
        {
1637
        {
1638
         HoehenReglerAktiv = 1;
1638
         HoehenReglerAktiv = 1;
1639
                 // Schwebegas ist der letzte GasMischanteil vor dem Aktivieren der Höhenregelung
1639
                 // Schwebegas ist der letzte GasMischanteil vor dem Aktivieren der Höhenregelung
1640
                 delay = 200;
1640
                 delay = 200;
1641
                }
1641
                }
1642
    }
1642
    }
1643
    else // Sollhöhe über Poti
1643
    else // Sollhöhe über Poti
1644
    {
1644
    {
1645
     //SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20; // MartinR : so war es
1645
     //SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20; // MartinR : so war es
1646
         //HoehenReglerAktiv = 1; // MartinR : so war es
1646
         //HoehenReglerAktiv = 1; // MartinR : so war es
1647
         if(Parameter_UserParam1 > 140) // HH über Schalter: Höhenregler abgeschaltet, Nachführen von Parametern 
1647
         if(Parameter_UserParam1 > 140) // HH über Schalter: Höhenregler abgeschaltet, Nachführen von Parametern 
1648
         {
1648
         {
1649
           SollHoehe = HoehenWert;  // SollHoehe wird nachgeführt bis HoehenreglerAktiv = 1
1649
           SollHoehe = HoehenWert;  // SollHoehe wird nachgeführt bis HoehenreglerAktiv = 1
1650
       HoehenReglerAktiv = 0;
1650
       HoehenReglerAktiv = 0;
1651
         }
1651
         }
1652
         else  // Höhenregler mit Sollhöhe über Poti aktiv
1652
         else  // Höhenregler mit Sollhöhe über Poti aktiv
1653
         {
1653
         {
1654
          // SchwebeGas = GasMischanteil;  // SchwebeGas zunächst = Gasmischanteil bis bessere Lösung
1654
          // SchwebeGas = GasMischanteil;  // SchwebeGas zunächst = Gasmischanteil bis bessere Lösung
1655
          // Deaktiv wegen HooverGasEstimation/HOOVER_GAS_AVERAGE
1655
          // Deaktiv wegen HooverGasEstimation/HOOVER_GAS_AVERAGE
1656
      HoehenReglerAktiv = 1;
1656
      HoehenReglerAktiv = 1;
1657
          // MartinR: Versuch Höhenregler zu verlangsamen.  Steig- / Sinkrate im MK-Tool über UserParam4 einstellbar
1657
          // MartinR: Versuch Höhenregler zu verlangsamen.  Steig- / Sinkrate im MK-Tool über UserParam4 einstellbar
1658
                if (((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20 > SollHoehe)
1658
                if (((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20 > SollHoehe)
1659
                {
1659
                {
1660
                        if(++delay_Hoehenregler > (Parameter_UserParam4 / 4))
1660
                        if(++delay_Hoehenregler > (Parameter_UserParam4 / 4))
1661
                        {
1661
                        {
1662
                        delay_Hoehenregler = 0;
1662
                        delay_Hoehenregler = 0;
1663
                        SollHoehe ++ ; //MartinR: Höhenänderung begrenzen.
1663
                        SollHoehe ++ ; //MartinR: Höhenänderung begrenzen.
1664
                        }
1664
                        }
1665
                }
1665
                }
1666
                else
1666
                else
1667
                {
1667
                {
1668
                        if (((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20 < SollHoehe)
1668
                        if (((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20 < SollHoehe)
1669
                        {
1669
                        {
1670
                                if(++delay_Hoehenregler > (Parameter_UserParam4 / 4))
1670
                                if(++delay_Hoehenregler > (Parameter_UserParam4 / 4))
1671
                                {
1671
                                {
1672
                                delay_Hoehenregler = 0;
1672
                                delay_Hoehenregler = 0;
1673
                                SollHoehe -- ; //MartinR: Höhenänderung begrenzen.
1673
                                SollHoehe -- ; //MartinR: Höhenänderung begrenzen.
1674
                                }
1674
                                }
1675
                        }
1675
                        }
1676
                }
1676
                }
1677
         }
1677
         }
1678
    }
1678
    }
1679
 
1679
 
1680
    if(Notlandung) SollHoehe = 0;
1680
    if(Notlandung) SollHoehe = 0;
1681
       
1681
       
1682
         if(HoehenReglerAktiv && !(Parameter_UserParam1 > 140))      // kein HH
1682
         if(HoehenReglerAktiv && !(Parameter_UserParam1 > 140))      // kein HH
1683
        {
1683
        {
1684
          h_delta = (int) SollHoehe - (int) HoehenWert; // positiver Wert: MK ist unterhalb der Sollhöhe
1684
          h_delta = (int) SollHoehe - (int) HoehenWert; // positiver Wert: MK ist unterhalb der Sollhöhe
1685
         
1685
         
1686
          h_p = (h_delta * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1686
          h_p = (h_delta * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1687
         
1687
         
1688
         
1688
         
1689
          /* an Anfang Höhenregler verschoben, da h_d für Schwebegas- Abschätzung verwendet wird
1689
          /* an Anfang Höhenregler verschoben, da h_d für Schwebegas- Abschätzung verwendet wird
1690
      h_d = (int) (HoeheD)/(64/STICK_GAIN);    // D-Anteil (8*8=64)
1690
      h_d = (int) (HoeheD)/(64/STICK_GAIN);    // D-Anteil (8*8=64)
1691
          // ACC-D-Anteil
1691
          // ACC-D-Anteil
1692
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1692
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1693
      if(tmp_int > 50*STICK_GAIN) tmp_int = 50*STICK_GAIN;
1693
      if(tmp_int > 50*STICK_GAIN) tmp_int = 50*STICK_GAIN;
1694
      else if(tmp_int < -(50*STICK_GAIN)) tmp_int = -(50*STICK_GAIN);
1694
      else if(tmp_int < -(50*STICK_GAIN)) tmp_int = -(50*STICK_GAIN);
1695
      h_d += tmp_int; // positiver D-Anteil bedeutet Steigen
1695
      h_d += tmp_int; // positiver D-Anteil bedeutet Steigen
1696
          */
1696
          */
1697
         
1697
         
1698
         
1698
         
1699
          //if(HooverGasEstimation == 0) HeightControlGas = GasMixFraction; // take stick gas // MartinR: SchwebeGas = GasMischanteil;
1699
          //if(HooverGasEstimation == 0) HeightControlGas = GasMixFraction; // take stick gas // MartinR: SchwebeGas = GasMischanteil;
1700
          if(HooverGasEstimation == 0) SchwebeGas = GasMischanteil;
1700
          if(HooverGasEstimation == 0) SchwebeGas = GasMischanteil;
1701
          else SchwebeGas = (int16_t)(HooverGasEstimation/HOOVER_GAS_AVERAGE); // take hoover point 
1701
          else SchwebeGas = (int16_t)(HooverGasEstimation/HOOVER_GAS_AVERAGE); // take hoover point 
1702
          // MartinR: SchwebeGas = HooverGasEstimation/HOOVER_GAS_AVERAGE 
1702
          // MartinR: SchwebeGas = HooverGasEstimation/HOOVER_GAS_AVERAGE 
1703
         
1703
         
1704
          h = SchwebeGas + h_p - h_d ;
1704
          h = SchwebeGas + h_p - h_d ;
1705
         
1705
         
1706
          // strech by actual attitude projection // Neigungskorrektur
1706
          // strech by actual attitude projection // Neigungskorrektur
1707
          tmp_long3 = (int32_t)h;   // MartinR: HeightControlGas = h
1707
          tmp_long3 = (int32_t)h;   // MartinR: HeightControlGas = h
1708
          tmp_long3 *= 8192; tmp_long3 /= CosNick;
1708
          tmp_long3 *= 8192; tmp_long3 /= CosNick;
1709
          tmp_long3 *= 8192; tmp_long3 /= CosRoll;
1709
          tmp_long3 *= 8192; tmp_long3 /= CosRoll;
1710
          h = (int16_t)tmp_long3;
1710
          h = (int16_t)tmp_long3;
1711
         
1711
         
1712
          hoehenregler = (hoehenregler*7 + h) / 8;
1712
          hoehenregler = (hoehenregler*7 + h) / 8;
1713
         
1713
         
1714
          if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1714
          if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1715
      {
1715
      {
1716
        if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1716
        if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1717
        if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1717
        if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1718
      }  
1718
      }  
1719
          if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1719
          if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1720
          //else hoehenregler += (GasMischanteil-hoehenregler)/16  ; // um die Höhe noch leicht mit Gas korrigieren zu können
1720
          //else hoehenregler += (GasMischanteil-hoehenregler)/16  ; // um die Höhe noch leicht mit Gas korrigieren zu können
1721
          //if(SchwebeGas < 20)  SchwebeGas = 20; // nicht unter 20
1721
          //if(SchwebeGas < 20)  SchwebeGas = 20; // nicht unter 20
1722
         
1722
         
1723
          GasMischanteil = hoehenregler;
1723
          GasMischanteil = hoehenregler;
1724
        }
1724
        }
1725
        else  // Integratoren auf Null halten
1725
        else  // Integratoren auf Null halten
1726
        {
1726
        {
1727
        Mess_Integral_Hoch = 0;
1727
        Mess_Integral_Hoch = 0;
1728
        hoehenregler = GasMischanteil;
1728
        hoehenregler = GasMischanteil;
1729
        // h_p = 0 ;
1729
        // h_p = 0 ;
1730
        // h_d = 0 ;
1730
        // h_d = 0 ;
1731
        }      
1731
        }      
1732
        // Hoover gas estimation by averaging gas control output on small z-velocities 
1732
        // Hoover gas estimation by averaging gas control output on small z-velocities 
1733
        // this is done only if height contol option is selected in global config and aircraft is flying 
1733
        // this is done only if height contol option is selected in global config and aircraft is flying 
1734
        if(MikroKopterFlags & FLAG_FLY) //MikroKopterFlags  FLAG_FLY
1734
        if(MikroKopterFlags & FLAG_FLY) //MikroKopterFlags  FLAG_FLY
1735
        {
1735
        {
1736
         if(HooverGasEstimation == 0) HooverGasEstimation = HOOVER_GAS_AVERAGE * (uint32_t)GasMischanteil; // init estimation 
1736
         if(HooverGasEstimation == 0) HooverGasEstimation = HOOVER_GAS_AVERAGE * (uint32_t)GasMischanteil; // init estimation 
1737
         // HOOVER_GAS_AVERAGE= 4192
1737
         // HOOVER_GAS_AVERAGE= 4192
1738
         if(abs(h_d) < 8)
1738
         if(abs(h_d) < 8)
1739
          {
1739
          {
1740
           tmp_long3 = (int32_t)GasMischanteil; // take current thrust 
1740
           tmp_long3 = (int32_t)GasMischanteil; // take current thrust 
1741
           tmp_long3 *= CosNick; // apply nick projection 
1741
           tmp_long3 *= CosNick; // apply nick projection 
1742
           tmp_long3 /= 8192; tmp_long3 *= CosRoll; // apply roll projection 
1742
           tmp_long3 /= 8192; tmp_long3 *= CosRoll; // apply roll projection 
1743
           tmp_long3 /= 8129; // average vertical projected thrust 
1743
           tmp_long3 /= 8129; // average vertical projected thrust 
1744
           HooverGasEstimation -= HooverGasEstimation/HOOVER_GAS_AVERAGE;
1744
           HooverGasEstimation -= HooverGasEstimation/HOOVER_GAS_AVERAGE;
1745
           HooverGasEstimation += tmp_long3;  
1745
           HooverGasEstimation += tmp_long3;  
1746
          }
1746
          }
1747
        }
1747
        }
1748
       
1748
       
1749
        DebugOut.Analog[16] = HooverGasEstimation/HOOVER_GAS_AVERAGE;
1749
        DebugOut.Analog[16] = HooverGasEstimation/HOOVER_GAS_AVERAGE;
1750
        //DebugOut.Analog[16] = Mess_Integral_Hoch;
1750
        //DebugOut.Analog[16] = Mess_Integral_Hoch;
1751
        DebugOut.Analog[17] = h_d;
1751
        DebugOut.Analog[17] = h_d;
1752
 
1752
 
1753
  } // EOF: EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG  
1753
  } // EOF: EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG  
1754
 
1754
 
1755
 
1755
 
1756
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1756
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1757
 
1757
 
1758
 // MartinR: Ende neuer Höhenregler 
1758
 // MartinR: Ende neuer Höhenregler 
1759
 
1759
 
1760
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1760
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1761
// + Mischer und PI-Regler
1761
// + Mischer und PI-Regler
1762
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1762
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1763
  DebugOut.Analog[7] = GasMischanteil;
1763
  DebugOut.Analog[7] = GasMischanteil;
1764
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1764
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1765
// Gier-Anteil
1765
// Gier-Anteil
1766
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1766
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1767
#define MUL_G  1.0
1767
#define MUL_G  1.0
1768
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1768
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1769
// GierMischanteil = 0;
1769
// GierMischanteil = 0;
1770
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1770
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1771
   if(GasMischanteil > MIN_GIERGAS)
1771
   if(GasMischanteil > MIN_GIERGAS)
1772
    {
1772
    {
1773
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1773
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1774
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1774
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1775
    }
1775
    }
1776
    else
1776
    else
1777
    {
1777
    {
1778
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1778
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1779
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1779
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1780
    }
1780
    }
1781
    tmp_int = MAX_GAS*STICK_GAIN;
1781
    tmp_int = MAX_GAS*STICK_GAIN;
1782
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1782
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1783
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1783
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1784
 
1784
 
1785
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1785
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1786
// Nick-Achse
1786
// Nick-Achse
1787
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1787
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1788
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1788
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1789
       
1789
       
1790
        // MartinR : so war es Anfang
1790
        // MartinR : so war es Anfang
1791
        /*
1791
        /*
1792
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1792
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1793
    else  SummeNick += DiffNick; // I-Anteil bei HH
1793
    else  SummeNick += DiffNick; // I-Anteil bei HH
1794
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1794
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1795
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1795
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1796
    pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick
1796
    pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick
1797
    // Motor Vorn
1797
    // Motor Vorn
1798
        */
1798
        */
1799
        // MartinR : so war es Ende
1799
        // MartinR : so war es Ende
1800
        // MartinR : geändert Anfang
1800
        // MartinR : geändert Anfang
1801
       
1801
       
1802
        if(IntegralFaktor) // MartinR : ACC-Mode
1802
        if(IntegralFaktor) // MartinR : ACC-Mode
1803
         {
1803
         {
1804
          SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1804
          SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1805
          if(SummeNick >  (STICK_GAIN * 8000L)) SummeNick =  (STICK_GAIN * 8000L); // MartinR : von 16000 auf 8000, da überlauf
1805
          if(SummeNick >  (STICK_GAIN * 8000L)) SummeNick =  (STICK_GAIN * 8000L); // MartinR : von 16000 auf 8000, da überlauf
1806
      if(SummeNick < -(8000L * STICK_GAIN)) SummeNick = -(8000L * STICK_GAIN); // MartinR : von 16000 auf 8000, da überlauf
1806
      if(SummeNick < -(8000L * STICK_GAIN)) SummeNick = -(8000L * STICK_GAIN); // MartinR : von 16000 auf 8000, da überlauf
1807
          pd_ergebnis_nick = DiffNick + (SummeNick / Ki);
1807
          pd_ergebnis_nick = DiffNick + (SummeNick / Ki);
1808
          SummeNickHH = 0 ;
1808
          SummeNickHH = 0 ;
1809
         }
1809
         }
1810
    else // MartinR : HH-Mode
1810
    else // MartinR : HH-Mode
1811
         {
1811
         {
1812
          SummeNickHH += DiffNick; // I-Anteil bei HH
1812
          SummeNickHH += DiffNick; // I-Anteil bei HH
1813
      if(SummeNickHH >  (STICK_GAIN * 8000L)) SummeNickHH =  (STICK_GAIN * 8000L); // MartinR : von 16000 auf 8000, da überlauf
1813
      if(SummeNickHH >  (STICK_GAIN * 8000L)) SummeNickHH =  (STICK_GAIN * 8000L); // MartinR : von 16000 auf 8000, da überlauf
1814
      if(SummeNickHH < -(8000L * STICK_GAIN)) SummeNickHH = -(8000L * STICK_GAIN); // MartinR : von 16000 auf 8000, da überlauf
1814
      if(SummeNickHH < -(8000L * STICK_GAIN)) SummeNickHH = -(8000L * STICK_GAIN); // MartinR : von 16000 auf 8000, da überlauf
1815
          pd_ergebnis_nick = DiffNick + SummeNickHH / KiHH; // MartinR: PI-Regler für Nick bei HH
1815
          pd_ergebnis_nick = DiffNick + SummeNickHH / KiHH; // MartinR: PI-Regler für Nick bei HH
1816
          SummeNick = 0;
1816
          SummeNick = 0;
1817
     } 
1817
     } 
1818
       
1818
       
1819
        // MartinR : geändert Ende
1819
        // MartinR : geändert Ende
1820
       
1820
       
1821
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1821
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1822
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1822
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1823
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1823
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1824
 
1824
 
1825
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1825
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1826
// Roll-Achse
1826
// Roll-Achse
1827
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1827
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1828
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1828
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1829
       
1829
       
1830
        // MartinR : so war es Anfang
1830
        // MartinR : so war es Anfang
1831
        /*
1831
        /*
1832
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1832
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1833
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1833
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1834
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1834
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1835
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1835
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1836
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1836
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1837
        */
1837
        */
1838
        // MartinR : so war es Ende
1838
        // MartinR : so war es Ende
1839
        // MartinR : geändert Anfang
1839
        // MartinR : geändert Anfang
1840
       
1840
       
1841
        if(IntegralFaktor) // MartinR : ACC-Mode
1841
        if(IntegralFaktor) // MartinR : ACC-Mode
1842
         {
1842
         {
1843
         SummeRoll += IntegralRollMalFaktor - StickRoll;
1843
         SummeRoll += IntegralRollMalFaktor - StickRoll;
1844
         if(SummeRoll >  (STICK_GAIN * 8000L)) SummeRoll =  (STICK_GAIN * 8000L);// MartinR : von 16000 auf 8000, da überlauf
1844
         if(SummeRoll >  (STICK_GAIN * 8000L)) SummeRoll =  (STICK_GAIN * 8000L);// MartinR : von 16000 auf 8000, da überlauf
1845
     if(SummeRoll < -(8000L * STICK_GAIN)) SummeRoll = -(8000L * STICK_GAIN);// MartinR : von 16000 auf 8000, da überlauf
1845
     if(SummeRoll < -(8000L * STICK_GAIN)) SummeRoll = -(8000L * STICK_GAIN);// MartinR : von 16000 auf 8000, da überlauf
1846
         tmp_int = SummeRoll / Ki;
1846
         tmp_int = SummeRoll / Ki;
1847
         pd_ergebnis_roll = DiffRoll + tmp_int;         // MartinR: PI-Regler im ACC-Mode
1847
         pd_ergebnis_roll = DiffRoll + tmp_int;         // MartinR: PI-Regler im ACC-Mode
1848
         //SummeRollHH = (IntegralRollMalFaktor + tmp_int - stick_roll_neutral + (TrimRoll * STICK_GAIN / 2)) * KiHH;// MartinR: Startwert von SummeRollHH bei Umschaltung auf HH
1848
         //SummeRollHH = (IntegralRollMalFaktor + tmp_int - stick_roll_neutral + (TrimRoll * STICK_GAIN / 2)) * KiHH;// MartinR: Startwert von SummeRollHH bei Umschaltung auf HH
1849
         // MartinR: Hintergrund: pd_ergebnis_xx soll sich beim Umschalten nicht ändern!
1849
         // MartinR: Hintergrund: pd_ergebnis_xx soll sich beim Umschalten nicht ändern!
1850
         SummeRollHH = 0;
1850
         SummeRollHH = 0;
1851
         }
1851
         }
1852
    else // MartinR : HH-Mode
1852
    else // MartinR : HH-Mode
1853
         {               
1853
         {               
1854
          SummeRollHH += DiffRoll;  // I-Anteil bei HH
1854
          SummeRollHH += DiffRoll;  // I-Anteil bei HH
1855
      if(SummeRollHH >  (STICK_GAIN * 8000L)) SummeRollHH =  (STICK_GAIN * 8000L);// MartinR : von 16000 auf 8000, da überlauf
1855
      if(SummeRollHH >  (STICK_GAIN * 8000L)) SummeRollHH =  (STICK_GAIN * 8000L);// MartinR : von 16000 auf 8000, da überlauf
1856
      if(SummeRollHH < -(8000L * STICK_GAIN)) SummeRollHH = -(8000L * STICK_GAIN);// MartinR : von 16000 auf 8000, da überlauf
1856
      if(SummeRollHH < -(8000L * STICK_GAIN)) SummeRollHH = -(8000L * STICK_GAIN);// MartinR : von 16000 auf 8000, da überlauf
1857
          pd_ergebnis_roll = DiffRoll + SummeRollHH / KiHH;     // MartinR: PI-Regler für Roll bei HH
1857
          pd_ergebnis_roll = DiffRoll + SummeRollHH / KiHH;     // MartinR: PI-Regler für Roll bei HH
1858
          SummeRoll = 0;
1858
          SummeRoll = 0;
1859
         }
1859
         }
1860
       
1860
       
1861
        // MartinR : geändert Ende
1861
        // MartinR : geändert Ende
1862
 
1862
 
1863
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1863
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1864
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1864
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1865
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1865
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1866
 
1866
 
1867
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1867
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1868
// Universal Mixer
1868
// Universal Mixer
1869
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1869
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1870
 for(i=0; i<MAX_MOTORS; i++)
1870
 for(i=0; i<MAX_MOTORS; i++)
1871
 {
1871
 {
1872
  signed int tmp_int;
1872
  signed int tmp_int;
1873
  if(Mixer.Motor[i][0] > 0)
1873
  if(Mixer.Motor[i][0] > 0)
1874
   {
1874
   {
1875
    tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1875
    tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1876
    tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1876
    tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1877
    tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1877
    tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1878
    tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1878
    tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1879
    tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]);  // Filter
1879
    tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]);  // Filter
1880
        tmp_int = tmp_motorwert[i] / STICK_GAIN;
1880
        tmp_int = tmp_motorwert[i] / STICK_GAIN;
1881
        CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS);
1881
        CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS);
1882
    Motor[i] = tmp_int;
1882
    Motor[i] = tmp_int;
1883
   }
1883
   }
1884
   else Motor[i] = 0;
1884
   else Motor[i] = 0;
1885
 }
1885
 }
1886
/*
1886
/*
1887
if(Poti1 > 20)  Motor1 = 0;
1887
if(Poti1 > 20)  Motor1 = 0;
1888
if(Poti1 > 90)  Motor6 = 0;
1888
if(Poti1 > 90)  Motor6 = 0;
1889
if(Poti1 > 140) Motor2 = 0;
1889
if(Poti1 > 140) Motor2 = 0;
1890
//if(Poti1 > 200) Motor7 = 0;
1890
//if(Poti1 > 200) Motor7 = 0;
1891
*/
1891
*/
1892
}
1892
}
1893
 
1893