Subversion Repositories FlightCtrl

Rev

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

Rev 1698 Rev 1701
1
/*#######################################################################################
1
/*#######################################################################################
2
Flight Control
2
Flight Control
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) Holger Buss, Ingo Busker
5
// + Copyright (c) Holger Buss, Ingo Busker
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
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 oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
27
// + Die Portierung oder Nutzung 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 the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
42
// +   * porting the sources to other systems or using the software on other systems (except 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
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53
// +  POSSIBILITY OF SUCH DAMAGE.
53
// +  POSSIBILITY OF SUCH DAMAGE.
54
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
 
55
 
56
#include "main.h"
56
#include "main.h"
57
#include "mymath.h"
57
#include "mymath.h"
58
#include "isqrt.h"
58
#include "isqrt.h"
59
 
59
 
60
unsigned char h,m,s;
60
unsigned char h,m,s;
61
unsigned int BaroExpandActive = 0;
61
unsigned int BaroExpandActive = 0;
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 AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
64
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
65
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch;
65
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch;
66
unsigned int NeutralAccX=0, NeutralAccY=0;
66
unsigned int NeutralAccX=0, NeutralAccY=0;
67
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
67
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
68
int NeutralAccZ = 0;
68
int NeutralAccZ = 0;
69
unsigned char ControlHeading = 0;// in 2°
69
unsigned char ControlHeading = 0;// in 2°
70
long IntegralNick = 0,IntegralNick2 = 0;
70
long IntegralNick = 0,IntegralNick2 = 0;
71
long IntegralRoll = 0,IntegralRoll2 = 0;
71
long IntegralRoll = 0,IntegralRoll2 = 0;
72
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
72
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
73
long Integral_Gier = 0;
73
long Integral_Gier = 0;
74
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
74
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
75
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
75
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
76
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
76
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
77
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
77
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
78
long SummeNick=0,SummeRoll=0;
78
long SummeNick=0,SummeRoll=0;
79
volatile long Mess_Integral_Hoch = 0;
79
volatile long Mess_Integral_Hoch = 0;
80
int  KompassValue = 0;
80
int  KompassValue = 0;
81
int  KompassStartwert = 0;
81
int  KompassStartwert = 0;
82
int  KompassRichtung = 0;
82
int  KompassRichtung = 0;
83
unsigned int  KompassSignalSchlecht = 500;
83
unsigned int  KompassSignalSchlecht = 500;
84
unsigned char  MAX_GAS,MIN_GAS;
84
unsigned char  MAX_GAS,MIN_GAS;
85
unsigned char HoehenReglerAktiv = 0;
85
unsigned char HoehenReglerAktiv = 0;
86
unsigned char TrichterFlug = 0;
86
unsigned char TrichterFlug = 0;
87
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
87
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
88
long  ErsatzKompass;
88
long  ErsatzKompass;
89
int   ErsatzKompassInGrad; // Kompasswert in Grad
89
int   ErsatzKompassInGrad; // Kompasswert in Grad
90
int   GierGyroFehler = 0;
90
int   GierGyroFehler = 0;
91
char GyroFaktor,GyroFaktorGier;
91
char GyroFaktor,GyroFaktorGier;
92
char IntegralFaktor,IntegralFaktorGier;
92
char IntegralFaktor,IntegralFaktorGier;
93
int  DiffNick,DiffRoll;
93
int  DiffNick,DiffRoll;
94
//int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0;
94
//int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0;
95
unsigned char Poti[9] = {0,0,0,0,0,0,0,0};
95
unsigned char Poti[9] = {0,0,0,0,0,0,0,0};
96
volatile unsigned char SenderOkay = 0;
96
volatile unsigned char SenderOkay = 0;
97
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
97
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
98
char MotorenEin = 0,StartTrigger = 0;
98
char MotorenEin = 0,StartTrigger = 0;
99
long HoehenWert = 0;
99
long HoehenWert = 0;
100
long SollHoehe = 0;
100
long SollHoehe = 0;
101
int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0;
101
int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0;
102
//float Ki =  FAKTOR_I;
102
//float Ki =  FAKTOR_I;
103
int Ki = 10300 / 33;
103
int Ki = 10300 / 33;
104
unsigned char Looping_Nick = 0,Looping_Roll = 0;
104
unsigned char Looping_Nick = 0,Looping_Roll = 0;
105
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
105
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
106
 
106
 
107
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
107
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
108
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
108
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
109
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
109
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
110
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
110
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
111
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
111
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
112
unsigned char Parameter_Hoehe_GPS_Z = 64;        // Wert : 0-250
112
unsigned char Parameter_Hoehe_GPS_Z = 64;        // Wert : 0-250
113
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
113
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
114
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
114
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
115
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
115
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
116
unsigned char Parameter_Gyro_Gier_P = 150;      // Wert : 10-250
116
unsigned char Parameter_Gyro_Gier_P = 150;      // Wert : 10-250
117
unsigned char Parameter_Gyro_Gier_I = 150;      // Wert : 10-250
117
unsigned char Parameter_Gyro_Gier_I = 150;      // Wert : 10-250
118
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
118
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
119
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
119
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
120
unsigned char Parameter_UserParam1 = 0;
120
unsigned char Parameter_UserParam1 = 0;
121
unsigned char Parameter_UserParam2 = 0;
121
unsigned char Parameter_UserParam2 = 0;
122
unsigned char Parameter_UserParam3 = 0;
122
unsigned char Parameter_UserParam3 = 0;
123
unsigned char Parameter_UserParam4 = 0;
123
unsigned char Parameter_UserParam4 = 0;
124
unsigned char Parameter_UserParam5 = 0;
124
unsigned char Parameter_UserParam5 = 0;
125
unsigned char Parameter_UserParam6 = 0;
125
unsigned char Parameter_UserParam6 = 0;
126
unsigned char Parameter_UserParam7 = 0;
126
unsigned char Parameter_UserParam7 = 0;
127
unsigned char Parameter_UserParam8 = 0;
127
unsigned char Parameter_UserParam8 = 0;
128
unsigned char Parameter_ServoNickControl = 100;
128
unsigned char Parameter_ServoNickControl = 100;
129
unsigned char Parameter_ServoRollControl = 100;
129
unsigned char Parameter_ServoRollControl = 100;
130
unsigned char Parameter_LoopGasLimit = 70;
130
unsigned char Parameter_LoopGasLimit = 70;
131
unsigned char Parameter_AchsKopplung1 = 90;
131
unsigned char Parameter_AchsKopplung1 = 90;
132
unsigned char Parameter_AchsKopplung2 = 65;
132
unsigned char Parameter_AchsKopplung2 = 65;
133
unsigned char Parameter_CouplingYawCorrection = 64;
133
unsigned char Parameter_CouplingYawCorrection = 64;
134
//unsigned char Parameter_AchsGegenKopplung1 = 0;
134
//unsigned char Parameter_AchsGegenKopplung1 = 0;
135
unsigned char Parameter_DynamicStability = 100;
135
unsigned char Parameter_DynamicStability = 100;
136
unsigned char Parameter_J16Bitmask;             // for the J16 Output
136
unsigned char Parameter_J16Bitmask;             // for the J16 Output
137
unsigned char Parameter_J16Timing;              // for the J16 Output
137
unsigned char Parameter_J16Timing;              // for the J16 Output
138
unsigned char Parameter_J17Bitmask;             // for the J17 Output
138
unsigned char Parameter_J17Bitmask;             // for the J17 Output
139
unsigned char Parameter_J17Timing;              // for the J17 Output
139
unsigned char Parameter_J17Timing;              // for the J17 Output
140
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
140
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
141
unsigned char Parameter_NaviGpsGain;
141
unsigned char Parameter_NaviGpsGain;
142
unsigned char Parameter_NaviGpsP;
142
unsigned char Parameter_NaviGpsP;
143
unsigned char Parameter_NaviGpsI;
143
unsigned char Parameter_NaviGpsI;
144
unsigned char Parameter_NaviGpsD;
144
unsigned char Parameter_NaviGpsD;
145
unsigned char Parameter_NaviGpsACC;
145
unsigned char Parameter_NaviGpsACC;
146
unsigned char Parameter_NaviOperatingRadius;
146
unsigned char Parameter_NaviOperatingRadius;
147
unsigned char Parameter_NaviWindCorrection;
147
unsigned char Parameter_NaviWindCorrection;
148
unsigned char Parameter_NaviSpeedCompensation;
148
unsigned char Parameter_NaviSpeedCompensation;
149
unsigned char Parameter_ExternalControl;
149
unsigned char Parameter_ExternalControl;
150
unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5;
150
unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5;
151
unsigned char CareFree = 0;
151
unsigned char CareFree = 0;
152
 
152
 
153
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
153
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
154
int MaxStickNick = 0,MaxStickRoll = 0;
154
int MaxStickNick = 0,MaxStickRoll = 0;
155
unsigned int  modell_fliegt = 0;
155
unsigned int  modell_fliegt = 0;
156
volatile unsigned char FCFlags = 0;
156
volatile unsigned char FCFlags = 0;
157
long GIER_GRAD_FAKTOR = 1291;
157
long GIER_GRAD_FAKTOR = 1291;
158
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
158
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
159
signed int tmp_motorwert[MAX_MOTORS];
159
signed int tmp_motorwert[MAX_MOTORS];
160
char VarioCharacter = ' ';
160
char VarioCharacter = ' ';
161
 
161
 
162
#define LIMIT_MIN(value, min) {if(value <= min) value = min;}
162
#define LIMIT_MIN(value, min) {if(value <= min) value = min;}
163
#define LIMIT_MAX(value, max) {if(value >= max) value = max;}
163
#define LIMIT_MAX(value, max) {if(value >= max) value = max;}
164
#define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;}
164
#define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;}
165
 
165
 
166
 
166
 
167
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
167
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168
//  Debugwerte zuordnen
168
//  Debugwerte zuordnen
169
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170
void CopyDebugValues(void)
170
void CopyDebugValues(void)
171
{
171
{
172
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
172
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
173
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
173
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
174
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
174
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
175
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
175
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
176
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
176
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
177
    DebugOut.Analog[5] = HoehenWert/5;
177
    DebugOut.Analog[5] = HoehenWert/5;
178
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);//AdWertAccHoch;// Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
178
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);//AdWertAccHoch;// Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
179
    DebugOut.Analog[8] = KompassValue;
179
    DebugOut.Analog[8] = KompassValue;
180
    DebugOut.Analog[9] = UBat;
180
    DebugOut.Analog[9] = UBat;
181
    DebugOut.Analog[10] = SenderOkay;
181
    DebugOut.Analog[10] = SenderOkay;
182
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
182
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
183
    DebugOut.Analog[20] = ServoNickValue;
183
    DebugOut.Analog[20] = ServoNickValue;
184
    DebugOut.Analog[22] = Capacity.ActualCurrent;
184
    DebugOut.Analog[22] = Capacity.ActualCurrent;
185
    DebugOut.Analog[23] = Capacity.UsedCapacity;
185
    DebugOut.Analog[23] = Capacity.UsedCapacity;
186
 
-
 
187
DebugOut.Analog[24] = AdWertAccHoch;
-
 
188
//    DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ;
186
//    DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ;
189
//    DebugOut.Analog[24] = MesswertNick/2;
-
 
190
//    DebugOut.Analog[25] = MesswertRoll/2;
-
 
191
//    DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift;
-
 
192
//    DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion;
-
 
193
//    DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K;
-
 
194
    //DebugOut.Analog[28] = I2CError;
-
 
195
//    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
187
//    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
196
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
188
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
197
    DebugOut.Analog[30] = GPS_Nick;
189
    DebugOut.Analog[30] = GPS_Nick;
198
    DebugOut.Analog[31] = GPS_Roll;
190
    DebugOut.Analog[31] = GPS_Roll;
199
}
191
}
200
 
192
 
201
void Piep(unsigned char Anzahl, unsigned int dauer)
193
void Piep(unsigned char Anzahl, unsigned int dauer)
202
{
194
{
203
 if(MotorenEin) return; //auf keinen Fall im Flug!
195
 if(MotorenEin) return; //auf keinen Fall im Flug!
204
 while(Anzahl--)
196
 while(Anzahl--)
205
 {
197
 {
206
  beeptime = dauer;
198
  beeptime = dauer;
207
  while(beeptime);
199
  while(beeptime);
208
  Delay_ms(dauer * 2);
200
  Delay_ms(dauer * 2);
209
 }
201
 }
210
}
202
}
211
 
203
 
212
//############################################################################
204
//############################################################################
213
// Messwerte beim Ermitteln der Nullage
205
// Messwerte beim Ermitteln der Nullage
214
void CalibrierMittelwert(void)
206
void CalibrierMittelwert(void)
215
//############################################################################
207
//############################################################################
216
{
208
{
217
    unsigned char i;
209
    unsigned char i;
218
    if(PlatinenVersion == 13) SucheGyroOffset();
210
    if(PlatinenVersion == 13) SucheGyroOffset();
219
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
211
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
220
        ANALOG_OFF;
212
        ANALOG_OFF;
221
        MesswertNick = AdWertNick;
213
        MesswertNick = AdWertNick;
222
        MesswertRoll = AdWertRoll;
214
        MesswertRoll = AdWertRoll;
223
        MesswertGier = AdWertGier;
215
        MesswertGier = AdWertGier;
224
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
216
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
225
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
217
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
226
        Mittelwert_AccHoch = (long)AdWertAccHoch;
218
        Mittelwert_AccHoch = (long)AdWertAccHoch;
227
   // ADC einschalten
219
   // ADC einschalten
228
    ANALOG_ON;
220
    ANALOG_ON;
229
   for(i=0;i<8;i++)
221
   for(i=0;i<8;i++)
230
    {
222
    {
231
     int tmp;
223
     int tmp;
232
         tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110;
224
         tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110;
233
         LIMIT_MIN_MAX(tmp, 0, 255);
225
         LIMIT_MIN_MAX(tmp, 0, 255);
234
     if(Poti[i] > tmp) Poti[i]--;  else  if(Poti[i] < tmp) Poti[i]++;
226
     if(Poti[i] > tmp) Poti[i]--;  else  if(Poti[i] < tmp) Poti[i]++;
235
        }
227
        }
236
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
228
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
237
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
229
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
238
}
230
}
239
 
231
 
240
//############################################################################
232
//############################################################################
241
//  Nullwerte ermitteln
233
//  Nullwerte ermitteln
242
void SetNeutral(unsigned char AccAdjustment)
234
void SetNeutral(unsigned char AccAdjustment)
243
//############################################################################
235
//############################################################################
244
{
236
{
245
        unsigned char i;
237
        unsigned char i;
246
        unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
238
        unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
247
 
239
 
248
    HEF4017R_ON;
240
    HEF4017R_ON;
249
        NeutralAccX = 0;
241
        NeutralAccX = 0;
250
        NeutralAccY = 0;
242
        NeutralAccY = 0;
251
        NeutralAccZ = 0;
243
        NeutralAccZ = 0;
252
 
244
 
253
    AdNeutralNick = 0;
245
    AdNeutralNick = 0;
254
        AdNeutralRoll = 0;
246
        AdNeutralRoll = 0;
255
        AdNeutralGier = 0;
247
        AdNeutralGier = 0;
256
 
248
 
257
    Parameter_AchsKopplung1 = 0;
249
    Parameter_AchsKopplung1 = 0;
258
    Parameter_AchsKopplung2 = 0;
250
    Parameter_AchsKopplung2 = 0;
259
 
251
 
260
    ExpandBaro = 0;
252
    ExpandBaro = 0;
261
 
253
 
262
    CalibrierMittelwert();
254
    CalibrierMittelwert();
263
    Delay_ms_Mess(100);
255
    Delay_ms_Mess(100);
264
 
256
 
265
        CalibrierMittelwert();
257
        CalibrierMittelwert();
266
 
258
 
267
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
259
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
268
     {
260
     {
269
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
261
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
270
     }
262
     }
271
#define NEUTRAL_FILTER 32
263
#define NEUTRAL_FILTER 32
272
    for(i=0; i<NEUTRAL_FILTER; i++)
264
    for(i=0; i<NEUTRAL_FILTER; i++)
273
         {
265
         {
274
          Delay_ms_Mess(10);
266
          Delay_ms_Mess(10);
275
          gier_neutral += AdWertGier;
267
          gier_neutral += AdWertGier;
276
          nick_neutral += AdWertNick;
268
          nick_neutral += AdWertNick;
277
          roll_neutral += AdWertRoll;
269
          roll_neutral += AdWertRoll;
278
         }
270
         }
279
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
271
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
280
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
272
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
281
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
273
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
282
 
274
 
283
     StartNeutralRoll = AdNeutralRoll;
275
     StartNeutralRoll = AdNeutralRoll;
284
     StartNeutralNick = AdNeutralNick;
276
     StartNeutralNick = AdNeutralNick;
285
 
277
 
286
     if(AccAdjustment)
278
     if(AccAdjustment)
287
     {
279
     {
288
            NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
280
            NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
289
            NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
281
            NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
290
            NeutralAccZ = Aktuell_az;
282
            NeutralAccZ = Aktuell_az;
291
 
283
 
292
                // Save ACC neutral settings to eeprom
284
                // Save ACC neutral settings to eeprom
293
                SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX);
285
                SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX);
294
                SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY);
286
                SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY);
295
                SetParamWord(PID_ACC_TOP,  (uint16_t)NeutralAccZ);
287
                SetParamWord(PID_ACC_TOP,  (uint16_t)NeutralAccZ);
296
    }
288
    }
297
    else
289
    else
298
    {
290
    {
299
                // restore from eeprom
291
                // restore from eeprom
300
                NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK);
292
                NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK);
301
                NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL);
293
                NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL);
302
                NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP);
294
                NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP);
303
                // strange settings?
295
                // strange settings?
304
                if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024))
296
                if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024))
305
                {
297
                {
306
                        printf("\n\rACC not calibrated!\r\n");
298
                        printf("\n\rACC not calibrated!\r\n");
307
                        NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
299
                        NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
308
                        NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
300
                        NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
309
                NeutralAccZ = Aktuell_az;
301
                NeutralAccZ = Aktuell_az;
310
                }
302
                }
311
    }
303
    }
312
 
304
 
313
    MesswertNick = 0;
305
    MesswertNick = 0;
314
    MesswertRoll = 0;
306
    MesswertRoll = 0;
315
    MesswertGier = 0;
307
    MesswertGier = 0;
316
    Delay_ms_Mess(100);
308
    Delay_ms_Mess(100);
317
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
309
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
318
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
310
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
319
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
311
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
320
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
312
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
321
    Mess_IntegralNick2 = IntegralNick;
313
    Mess_IntegralNick2 = IntegralNick;
322
    Mess_IntegralRoll2 = IntegralRoll;
314
    Mess_IntegralRoll2 = IntegralRoll;
323
    Mess_Integral_Gier = 0;
315
    Mess_Integral_Gier = 0;
324
    StartLuftdruck = Luftdruck;
316
    StartLuftdruck = Luftdruck;
325
    VarioMeter = 0;
317
    VarioMeter = 0;
326
    Mess_Integral_Hoch = 0;
318
    Mess_Integral_Hoch = 0;
327
    KompassStartwert = KompassValue;
319
    KompassStartwert = KompassValue;
328
    GPS_Neutral();
320
    GPS_Neutral();
329
    beeptime = 50;
321
    beeptime = 50;
330
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
322
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
331
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
323
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
332
    ExternHoehenValue = 0;
324
    ExternHoehenValue = 0;
333
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
325
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
334
    GierGyroFehler = 0;
326
    GierGyroFehler = 0;
335
    SendVersionToNavi = 1;
327
    SendVersionToNavi = 1;
336
    LED_Init();
328
    LED_Init();
337
    FCFlags |= FCFLAG_CALIBRATE;
329
    FCFlags |= FCFLAG_CALIBRATE;
338
    FromNaviCtrl_Value.Kalman_K = -1;
330
    FromNaviCtrl_Value.Kalman_K = -1;
339
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
331
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
340
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
332
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
341
 
333
 
342
   for(i=0;i<8;i++)
334
   for(i=0;i<8;i++)
343
    {
335
    {
344
     Poti[i] =  PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110;
336
     Poti[i] =  PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110;
345
        }
337
        }
346
    SenderOkay = 100;
338
    SenderOkay = 100;
347
    if(ServoActive)
339
    if(ServoActive)
348
         {
340
         {
349
                HEF4017R_ON;
341
                HEF4017R_ON;
350
                DDRD  |=0x80; // enable J7 -> Servo signal
342
                DDRD  |=0x80; // enable J7 -> Servo signal
351
     }
343
     }
352
}
344
}
353
 
345
 
354
//############################################################################
346
//############################################################################
355
// Bearbeitet die Messwerte
347
// Bearbeitet die Messwerte
356
void Mittelwert(void)
348
void Mittelwert(void)
357
//############################################################################
349
//############################################################################
358
{
350
{
359
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
351
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
360
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
352
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
361
        signed long winkel_nick, winkel_roll;
353
        signed long winkel_nick, winkel_roll;
362
    unsigned char i;
354
    unsigned char i;
363
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
355
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
364
    MesswertNick = (signed int) AdWertNickFilter / 8;
356
    MesswertNick = (signed int) AdWertNickFilter / 8;
365
    MesswertRoll = (signed int) AdWertRollFilter / 8;
357
    MesswertRoll = (signed int) AdWertRollFilter / 8;
366
    RohMesswertNick = MesswertNick;
358
    RohMesswertNick = MesswertNick;
367
    RohMesswertRoll = MesswertRoll;
359
    RohMesswertRoll = MesswertRoll;
368
 
360
 
369
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
361
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
370
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
362
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
371
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
363
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
372
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
364
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
373
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
365
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
374
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
366
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
375
    NaviAccNick    += AdWertAccNick;
367
    NaviAccNick    += AdWertAccNick;
376
    NaviAccRoll    += AdWertAccRoll;
368
    NaviAccRoll    += AdWertAccRoll;
377
    NaviCntAcc++;
369
    NaviCntAcc++;
378
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
370
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
379
 
371
 
380
//++++++++++++++++++++++++++++++++++++++++++++++++
372
//++++++++++++++++++++++++++++++++++++++++++++++++
381
// ADC einschalten
373
// ADC einschalten
382
    ANALOG_ON;
374
    ANALOG_ON;
383
        AdReady = 0;
375
        AdReady = 0;
384
//++++++++++++++++++++++++++++++++++++++++++++++++
376
//++++++++++++++++++++++++++++++++++++++++++++++++
385
 
377
 
386
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
378
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
387
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
379
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
388
        else winkel_roll = Mess_IntegralRoll;
380
        else winkel_roll = Mess_IntegralRoll;
389
 
381
 
390
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
382
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
391
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
383
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
392
        else winkel_nick = Mess_IntegralNick;
384
        else winkel_nick = Mess_IntegralNick;
393
 
385
 
394
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
386
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
395
   Mess_Integral_Gier += MesswertGier;
387
   Mess_Integral_Gier += MesswertGier;
396
   ErsatzKompass += MesswertGier;
388
   ErsatzKompass += MesswertGier;
397
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
389
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
398
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
390
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
399
         {
391
         {
400
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
392
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
401
            tmpl3 *= Parameter_AchsKopplung2; //65
393
            tmpl3 *= Parameter_AchsKopplung2; //65
402
            tmpl3 /= 4096L;
394
            tmpl3 /= 4096L;
403
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
395
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
404
            tmpl4 *= Parameter_AchsKopplung2; //65
396
            tmpl4 *= Parameter_AchsKopplung2; //65
405
            tmpl4 /= 4096L;
397
            tmpl4 /= 4096L;
406
            KopplungsteilNickRoll = tmpl3;
398
            KopplungsteilNickRoll = tmpl3;
407
            KopplungsteilRollNick = tmpl4;
399
            KopplungsteilRollNick = tmpl4;
408
            tmpl4 -= tmpl3;
400
            tmpl4 -= tmpl3;
409
            ErsatzKompass += tmpl4;
401
            ErsatzKompass += tmpl4;
410
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
402
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
411
 
403
 
412
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
404
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
413
            tmpl *= Parameter_AchsKopplung1;  // 90
405
            tmpl *= Parameter_AchsKopplung1;  // 90
414
            tmpl /= 4096L;
406
            tmpl /= 4096L;
415
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
407
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
416
            tmpl2 *= Parameter_AchsKopplung1;
408
            tmpl2 *= Parameter_AchsKopplung1;
417
            tmpl2 /= 4096L;
409
            tmpl2 /= 4096L;
418
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
410
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
419
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
411
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
420
         }
412
         }
421
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
413
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
422
                        TrimRoll = tmpl - tmpl2 / 100L;
414
                        TrimRoll = tmpl - tmpl2 / 100L;
423
                        TrimNick = -tmpl2 + tmpl / 100L;
415
                        TrimNick = -tmpl2 + tmpl / 100L;
424
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
416
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
425
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
417
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
426
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
418
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
427
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
419
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
428
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
420
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
429
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
421
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
430
            if(Mess_IntegralRoll > Umschlag180Roll)
422
            if(Mess_IntegralRoll > Umschlag180Roll)
431
            {
423
            {
432
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
424
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
433
             Mess_IntegralRoll2 = Mess_IntegralRoll;
425
             Mess_IntegralRoll2 = Mess_IntegralRoll;
434
            }
426
            }
435
            if(Mess_IntegralRoll <-Umschlag180Roll)
427
            if(Mess_IntegralRoll <-Umschlag180Roll)
436
            {
428
            {
437
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
429
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
438
             Mess_IntegralRoll2 = Mess_IntegralRoll;
430
             Mess_IntegralRoll2 = Mess_IntegralRoll;
439
            }
431
            }
440
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
432
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
441
            Mess_IntegralNick2 += MesswertNick + TrimNick;
433
            Mess_IntegralNick2 += MesswertNick + TrimNick;
442
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
434
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
443
            if(Mess_IntegralNick > Umschlag180Nick)
435
            if(Mess_IntegralNick > Umschlag180Nick)
444
             {
436
             {
445
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
437
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
446
              Mess_IntegralNick2 = Mess_IntegralNick;
438
              Mess_IntegralNick2 = Mess_IntegralNick;
447
             }
439
             }
448
            if(Mess_IntegralNick <-Umschlag180Nick)
440
            if(Mess_IntegralNick <-Umschlag180Nick)
449
            {
441
            {
450
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
442
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
451
             Mess_IntegralNick2 = Mess_IntegralNick;
443
             Mess_IntegralNick2 = Mess_IntegralNick;
452
            }
444
            }
453
 
445
 
454
    Integral_Gier  = Mess_Integral_Gier;
446
    Integral_Gier  = Mess_Integral_Gier;
455
    IntegralNick = Mess_IntegralNick;
447
    IntegralNick = Mess_IntegralNick;
456
    IntegralRoll = Mess_IntegralRoll;
448
    IntegralRoll = Mess_IntegralRoll;
457
    IntegralNick2 = Mess_IntegralNick2;
449
    IntegralNick2 = Mess_IntegralNick2;
458
    IntegralRoll2 = Mess_IntegralRoll2;
450
    IntegralRoll2 = Mess_IntegralRoll2;
459
 
451
 
460
#define D_LIMIT 128
452
#define D_LIMIT 128
461
 
453
 
462
   MesswertNick = HiResNick / 8;
454
   MesswertNick = HiResNick / 8;
463
   MesswertRoll = HiResRoll / 8;
455
   MesswertRoll = HiResRoll / 8;
464
 
456
 
465
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
457
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
466
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
458
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
467
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
459
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
468
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
460
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
469
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
461
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
470
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
462
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
471
 
463
 
472
  if(Parameter_Gyro_D)
464
  if(Parameter_Gyro_D)
473
  {
465
  {
474
   d2Nick = HiResNick - oldNick;
466
   d2Nick = HiResNick - oldNick;
475
   oldNick = (oldNick + HiResNick)/2;
467
   oldNick = (oldNick + HiResNick)/2;
476
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
468
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
477
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
469
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
478
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
470
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
479
   d2Roll = HiResRoll - oldRoll;
471
   d2Roll = HiResRoll - oldRoll;
480
   oldRoll = (oldRoll + HiResRoll)/2;
472
   oldRoll = (oldRoll + HiResRoll)/2;
481
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
473
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
482
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
474
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
483
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
475
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
484
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
476
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
485
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
477
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
486
  }
478
  }
487
 
479
 
488
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
480
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
489
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
481
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
490
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
482
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
491
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
483
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
492
 
484
 
493
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
485
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
494
  {
486
  {
495
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
487
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
496
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
488
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
497
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
489
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
498
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
490
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
499
  }
491
  }
500
  for(i=0;i<8;i++)
492
  for(i=0;i<8;i++)
501
    {
493
    {
502
     int tmp;
494
     int tmp;
503
         tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110;
495
         tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110;
504
         if(tmp > 255) tmp = 255; else if(tmp < 0) tmp = 0;
496
         if(tmp > 255) tmp = 255; else if(tmp < 0) tmp = 0;
505
     if(tmp != Poti[i])
497
     if(tmp != Poti[i])
506
          {
498
          {
507
           Poti[i] += (tmp - Poti[i]) / 8;
499
           Poti[i] += (tmp - Poti[i]) / 8;
508
       if(Poti[i] > tmp) Poti[i]--;
500
       if(Poti[i] > tmp) Poti[i]--;
509
           else Poti[i]++;
501
           else Poti[i]++;
510
          }
502
          }
511
        }
503
        }
512
}
504
}
513
 
505
 
514
//############################################################################
506
//############################################################################
515
// Senden der Motorwerte per I2C-Bus
507
// Senden der Motorwerte per I2C-Bus
516
void SendMotorData(void)
508
void SendMotorData(void)
517
//############################################################################
509
//############################################################################
518
{
510
{
519
 unsigned char i;
511
 unsigned char i;
520
    if(!MotorenEin)
512
    if(!MotorenEin)
521
        {
513
        {
522
         FCFlags &= ~(FCFLAG_MOTOR_RUN | FCFLAG_FLY);
514
         FCFlags &= ~(FCFLAG_MOTOR_RUN | FCFLAG_FLY);
523
                 for(i=0;i<MAX_MOTORS;i++)
515
                 for(i=0;i<MAX_MOTORS;i++)
524
                  {
516
                  {
525
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
517
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
526
                   Motor[i].SetPoint = MotorTest[i];
518
                   Motor[i].SetPoint = MotorTest[i];
527
                   Motor[i].SetPointLowerBits = 0;
519
                   Motor[i].SetPointLowerBits = 0;
528
/*
520
/*
529
                   Motor[i].SetPoint = MotorTest[i] / 4;
521
                   Motor[i].SetPoint = MotorTest[i] / 4;
530
                   Motor[i].SetPointLowerBits = MotorTest[i] % 4;
522
                   Motor[i].SetPointLowerBits = MotorTest[i] % 4;
531
*/
523
*/
532
                  }
524
                  }
533
          if(PC_MotortestActive) PC_MotortestActive--;
525
          if(PC_MotortestActive) PC_MotortestActive--;
534
        }
526
        }
535
        else FCFlags |= FCFLAG_MOTOR_RUN;
527
        else FCFlags |= FCFLAG_MOTOR_RUN;
536
 
528
 
537
    DebugOut.Analog[12] = Motor[0].SetPoint;
529
    DebugOut.Analog[12] = Motor[0].SetPoint;
538
    DebugOut.Analog[13] = Motor[1].SetPoint;
530
    DebugOut.Analog[13] = Motor[1].SetPoint;
539
    DebugOut.Analog[14] = Motor[2].SetPoint;
531
    DebugOut.Analog[14] = Motor[2].SetPoint;
540
    DebugOut.Analog[15] = Motor[3].SetPoint;
532
    DebugOut.Analog[15] = Motor[3].SetPoint;
541
 
533
 
542
    //Start I2C Interrupt Mode
534
    //Start I2C Interrupt Mode
543
    motor_write = 0;
535
    motor_write = 0;
544
    I2C_Start(TWI_STATE_MOTOR_TX);
536
    I2C_Start(TWI_STATE_MOTOR_TX);
545
}
537
}
546
 
538
 
547
 
539
 
548
 
540
 
549
//############################################################################
541
//############################################################################
550
// Trägt ggf. das Poti als Parameter ein
542
// Trägt ggf. das Poti als Parameter ein
551
void ParameterZuordnung(void)
543
void ParameterZuordnung(void)
552
//############################################################################
544
//############################################################################
553
{
545
{
554
 unsigned char tmp;
546
 unsigned char tmp;
555
 #define CHK_POTI(b,a) {if(a < 248) b = a; else b = Poti[255 - a];}
547
 #define CHK_POTI(b,a) {if(a < 248) b = a; else b = Poti[255 - a];}
556
 #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max);}
548
 #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max);}
557
 
549
 
558
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
550
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
559
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
551
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
560
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
552
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
561
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
553
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
562
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
554
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
563
 CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3);
555
 CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3);
564
 CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4);
556
 CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4);
565
 CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5);
557
 CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5);
566
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe);
558
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe);
567
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe);
559
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe);
568
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung);
560
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung);
569
 CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z);
561
 CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z);
570
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung);
562
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung);
571
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I);
563
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I);
572
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D);
564
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D);
573
 CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P);
565
 CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P);
574
 CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I);
566
 CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I);
575
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor);
567
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor);
576
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1);
568
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1);
577
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2);
569
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2);
578
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3);
570
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3);
579
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4);
571
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4);
580
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5);
572
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5);
581
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6);
573
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6);
582
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7);
574
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7);
583
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8);
575
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8);
584
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl);
576
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl);
585
 CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl);
577
 CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl);
586
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit);
578
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit);
587
 CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1);
579
 CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1);
588
 CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2);
580
 CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2);
589
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection);
581
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection);
590
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
582
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
591
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability);
583
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability);
592
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl);
584
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl);
593
 Ki = 10300 / (Parameter_I_Faktor + 1);
585
 Ki = 10300 / (Parameter_I_Faktor + 1);
594
 MAX_GAS = EE_Parameter.Gas_Max;
586
 MAX_GAS = EE_Parameter.Gas_Max;
595
 MIN_GAS = EE_Parameter.Gas_Min;
587
 MIN_GAS = EE_Parameter.Gas_Min;
596
 
588
 
597
 tmp = EE_Parameter.OrientationModeControl;
589
 tmp = EE_Parameter.OrientationModeControl;
598
 if(tmp > 50)
590
 if(tmp > 50)
599
   {
591
   {
600
#ifdef SWITCH_LEARNS_CAREFREE
592
#ifdef SWITCH_LEARNS_CAREFREE
601
    if(!CareFree) ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2;
593
    if(!CareFree) ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2;
602
#endif
594
#endif
603
        CareFree = 1;
595
        CareFree = 1;
604
    if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0;
596
    if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0;
605
   }
597
   }
606
   else CareFree = 0;
598
   else CareFree = 0;
607
 
599
 
608
 if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert
600
 if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert
609
        {
601
        {
610
         beeptime = 15000;
602
         beeptime = 15000;
611
         BeepMuster = 0xA400;
603
         BeepMuster = 0xA400;
612
         CareFree = 0;
604
         CareFree = 0;
613
    }
605
    }
614
 if(CareFree) {if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;}
606
 if(CareFree) {if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;}
615
}
607
}
616
 
608
 
617
//############################################################################
609
//############################################################################
618
//
610
//
619
void MotorRegler(void)
611
void MotorRegler(void)
620
//############################################################################
612
//############################################################################
621
{
613
{
622
         int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2;
614
         int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2;
623
         int GierMischanteil,GasMischanteil;
615
         int GierMischanteil,GasMischanteil;
624
     static long sollGier = 0,tmp_long,tmp_long2;
616
     static long sollGier = 0,tmp_long,tmp_long2;
625
     static long IntegralFehlerNick = 0;
617
     static long IntegralFehlerNick = 0;
626
     static long IntegralFehlerRoll = 0;
618
     static long IntegralFehlerRoll = 0;
627
         static unsigned int RcLostTimer;
619
         static unsigned int RcLostTimer;
628
         static unsigned char delay_neutral = 0;
620
         static unsigned char delay_neutral = 0;
629
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
621
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
630
         static unsigned char calibration_done = 0;
622
         static unsigned char calibration_done = 0;
631
     static char NeueKompassRichtungMerken = 0;
623
     static char NeueKompassRichtungMerken = 0;
632
     static long ausgleichNick, ausgleichRoll;
624
     static long ausgleichNick, ausgleichRoll;
633
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
625
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
634
         unsigned char i;
626
         unsigned char i;
635
        Mittelwert();
627
        Mittelwert();
636
    GRN_ON;
628
    GRN_ON;
637
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
629
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
638
// Gaswert ermitteln
630
// Gaswert ermitteln
639
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
631
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
640
        GasMischanteil = StickGas;
632
        GasMischanteil = StickGas;
641
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
633
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
642
 
634
 
643
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
635
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
644
// Empfang schlecht
636
// Empfang schlecht
645
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
637
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
646
   if(SenderOkay < 100)
638
   if(SenderOkay < 100)
647
        {
639
        {
648
        if(RcLostTimer) RcLostTimer--;
640
        if(RcLostTimer) RcLostTimer--;
649
        else
641
        else
650
         {
642
         {
651
          MotorenEin = 0;
643
          MotorenEin = 0;
652
          FCFlags &= ~FCFLAG_NOTLANDUNG;
644
          FCFlags &= ~FCFLAG_NOTLANDUNG;
653
         }
645
         }
654
        ROT_ON;
646
        ROT_ON;
655
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
647
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
656
            {
648
            {
657
            GasMischanteil = EE_Parameter.NotGas;
649
            GasMischanteil = EE_Parameter.NotGas;
658
            FCFlags |= FCFLAG_NOTLANDUNG;
650
            FCFlags |= FCFLAG_NOTLANDUNG;
659
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
651
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
660
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
652
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
661
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
653
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
662
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
654
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
663
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
655
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
664
            }
656
            }
665
         else MotorenEin = 0;
657
         else MotorenEin = 0;
666
        }
658
        }
667
        else
659
        else
668
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
660
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
669
// Emfang gut
661
// Emfang gut
670
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
662
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
671
        if(SenderOkay > 140)
663
        if(SenderOkay > 140)
672
            {
664
            {
673
                        FCFlags &= ~FCFLAG_NOTLANDUNG;
665
                        FCFlags &= ~FCFLAG_NOTLANDUNG;
674
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
666
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
675
            if(GasMischanteil > 40 && MotorenEin)
667
            if(GasMischanteil > 40 && MotorenEin)
676
                {
668
                {
677
                if(modell_fliegt < 0xffff) modell_fliegt++;
669
                if(modell_fliegt < 0xffff) modell_fliegt++;
678
                }
670
                }
679
            if((modell_fliegt < 256))
671
            if((modell_fliegt < 256))
680
                {
672
                {
681
                SummeNick = 0;
673
                SummeNick = 0;
682
                SummeRoll = 0;
674
                SummeRoll = 0;
683
                sollGier = 0;
675
                sollGier = 0;
684
                Mess_Integral_Gier = 0;
676
                Mess_Integral_Gier = 0;
685
                if(modell_fliegt == 250)
677
                if(modell_fliegt == 250)
686
                 {
678
                 {
687
                  NeueKompassRichtungMerken = 1;
679
                  NeueKompassRichtungMerken = 1;
688
//                  Mess_Integral_Gier2 = 0;
680
//                  Mess_Integral_Gier2 = 0;
689
                 }
681
                 }
690
                } else FCFlags |= FCFLAG_FLY;
682
                } else FCFlags |= FCFLAG_FLY;
691
 
683
 
692
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
684
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
693
                {
685
                {
694
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
686
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
695
// auf Nullwerte kalibrieren
687
// auf Nullwerte kalibrieren
696
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
688
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
697
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
689
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
698
                    {
690
                    {
699
                    if(++delay_neutral > 200)  // nicht sofort
691
                    if(++delay_neutral > 200)  // nicht sofort
700
                        {
692
                        {
701
                        GRN_OFF;
693
                        GRN_OFF;
702
                        MotorenEin = 0;
694
                        MotorenEin = 0;
703
                        delay_neutral = 0;
695
                        delay_neutral = 0;
704
                        modell_fliegt = 0;
696
                        modell_fliegt = 0;
705
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
697
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
706
                        {
698
                        {
707
                         unsigned char setting=1;
699
                         unsigned char setting=1;
708
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
700
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
709
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
701
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
710
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
702
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
711
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
703
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
712
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
704
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
713
                         SetActiveParamSet(setting);  // aktiven Datensatz merken
705
                         SetActiveParamSet(setting);  // aktiven Datensatz merken
714
                        }
706
                        }
715
//                        else
707
//                        else
716
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
708
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
717
                          {
709
                          {
718
                           WinkelOut.CalcState = 1;
710
                           WinkelOut.CalcState = 1;
719
                           beeptime = 1000;
711
                           beeptime = 1000;
720
                          }
712
                          }
721
                          else
713
                          else
722
                          {
714
                          {
723
                               ParamSet_ReadFromEEProm(GetActiveParamSet());
715
                               ParamSet_ReadFromEEProm(GetActiveParamSet());
724
                               LipoDetection(0);
716
                               LipoDetection(0);
725
                                                   LIBFC_ReceiverInit(EE_Parameter.Receiver);
717
                                                   LIBFC_ReceiverInit(EE_Parameter.Receiver);
726
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
718
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
727
                            {
719
                            {
728
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
720
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
729
                            }
721
                            }
730
                                                   ServoActive = 0;
722
                                                   ServoActive = 0;
731
                           SetNeutral(0);
723
                           SetNeutral(0);
732
                           calibration_done = 1;
724
                           calibration_done = 1;
733
                                                   ServoActive = 1;
725
                                                   ServoActive = 1;
734
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
726
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
735
                           Piep(GetActiveParamSet(),120);
727
                           Piep(GetActiveParamSet(),120);
736
                         }
728
                         }
737
                        }
729
                        }
738
                    }
730
                    }
739
                 else
731
                 else
740
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
732
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
741
                    {
733
                    {
742
                    if(++delay_neutral > 200)  // nicht sofort
734
                    if(++delay_neutral > 200)  // nicht sofort
743
                        {
735
                        {
744
                        GRN_OFF;
736
                        GRN_OFF;
745
                        MotorenEin = 0;
737
                        MotorenEin = 0;
746
                        delay_neutral = 0;
738
                        delay_neutral = 0;
747
                        modell_fliegt = 0;
739
                        modell_fliegt = 0;
748
                        SetNeutral(1);
740
                        SetNeutral(1);
749
                        calibration_done = 1;
741
                        calibration_done = 1;
750
                        Piep(GetActiveParamSet(),120);
742
                        Piep(GetActiveParamSet(),120);
751
                        }
743
                        }
752
                    }
744
                    }
753
                 else delay_neutral = 0;
745
                 else delay_neutral = 0;
754
                }
746
                }
755
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
747
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
756
// Gas ist unten
748
// Gas ist unten
757
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
749
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
758
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
750
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
759
                {
751
                {
760
                                        // Motoren Starten
752
                                        // Motoren Starten
761
                                        if(!MotorenEin)
753
                                        if(!MotorenEin)
762
                        {
754
                        {
763
                                                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
755
                                                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
764
                                                {
756
                                                {
765
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
757
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
766
// Einschalten
758
// Einschalten
767
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
759
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
768
                                                        if(++delay_einschalten > 200)
760
                                                        if(++delay_einschalten > 200)
769
                                                        {
761
                                                        {
770
                                                                delay_einschalten = 0;
762
                                                                delay_einschalten = 0;
771
                                                                if(calibration_done)
763
                                                                if(calibration_done)
772
                                                                {
764
                                                                {
773
                                                                        modell_fliegt = 1;
765
                                                                        modell_fliegt = 1;
774
                                                                        MotorenEin = 1;
766
                                                                        MotorenEin = 1;
775
                                                                        sollGier = 0;
767
                                                                        sollGier = 0;
776
                                                                        Mess_Integral_Gier = 0;
768
                                                                        Mess_Integral_Gier = 0;
777
                                                                        Mess_Integral_Gier2 = 0;
769
                                                                        Mess_Integral_Gier2 = 0;
778
                                                                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
770
                                                                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
779
                                                                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
771
                                                                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
780
                                                                        Mess_IntegralNick2 = IntegralNick;
772
                                                                        Mess_IntegralNick2 = IntegralNick;
781
                                                                        Mess_IntegralRoll2 = IntegralRoll;
773
                                                                        Mess_IntegralRoll2 = IntegralRoll;
782
                                                                        SummeNick = 0;
774
                                                                        SummeNick = 0;
783
                                                                        SummeRoll = 0;
775
                                                                        SummeRoll = 0;
784
                                                                        FCFlags |= FCFLAG_START;
776
                                                                        FCFlags |= FCFLAG_START;
785
                                                                        ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2;
777
                                                                        ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2;
786
                                                                }
778
                                                                }
787
                                                                else
779
                                                                else
788
                                                                {
780
                                                                {
789
                                                                        beeptime = 1500; // indicate missing calibration
781
                                                                        beeptime = 1500; // indicate missing calibration
790
                                                                }
782
                                                                }
791
                                                        }
783
                                                        }
792
                                                }
784
                                                }
793
                                                else delay_einschalten = 0;
785
                                                else delay_einschalten = 0;
794
                                        }
786
                                        }
795
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
787
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
796
// Auschalten
788
// Auschalten
797
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
789
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
798
                                        else // only if motors are running
790
                                        else // only if motors are running
799
                                        {
791
                                        {
800
                                                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
792
                                                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
801
                                                {
793
                                                {
802
                                                        if(++delay_ausschalten > 200)  // nicht sofort
794
                                                        if(++delay_ausschalten > 200)  // nicht sofort
803
                                                        {
795
                                                        {
804
                                                                MotorenEin = 0;
796
                                                                MotorenEin = 0;
805
                                                                delay_ausschalten = 0;
797
                                                                delay_ausschalten = 0;
806
                                                                modell_fliegt = 0;
798
                                                                modell_fliegt = 0;
807
                                                        }
799
                                                        }
808
                                                }
800
                                                }
809
                                                else delay_ausschalten = 0;
801
                                                else delay_ausschalten = 0;
810
                                        }
802
                                        }
811
                }
803
                }
812
            }
804
            }
813
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
805
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
814
// neue Werte von der Funke
806
// neue Werte von der Funke
815
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
807
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
816
 
808
 
817
 if(!NewPpmData-- || (FCFlags & FCFLAG_NOTLANDUNG))
809
 if(!NewPpmData-- || (FCFlags & FCFLAG_NOTLANDUNG))
818
  {
810
  {
819
        static int stick_nick,stick_roll;
811
        static int stick_nick,stick_roll;
820
    ParameterZuordnung();
812
    ParameterZuordnung();
821
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
813
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
822
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
814
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
823
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
815
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
824
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
816
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
825
 
817
 
826
 
818
 
827
signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8};
819
signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8};
828
 
820
 
829
if(CareFree)
821
if(CareFree)
830
 {
822
 {
831
    signed int nick, roll;
823
    signed int nick, roll;
832
        nick = stick_nick / 4;
824
        nick = stick_nick / 4;
833
        roll = stick_roll / 4;
825
        roll = stick_roll / 4;
834
    StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4);
826
    StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4);
835
    StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4);
827
    StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4);
836
 }
828
 }
837
 else
829
 else
838
 {
830
 {
839
        FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6];
831
        FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6];
840
        FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle];
832
        FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle];
841
    StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8;
833
    StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8;
842
    StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8;
834
    StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8;
843
 }
835
 }
844
 
836
 
845
 
837
 
846
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
838
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
847
        if(StickGier > 2) StickGier -= 2;       else
839
        if(StickGier > 2) StickGier -= 2;       else
848
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
840
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
849
 
841
 
850
    StickNick -= (GPS_Nick + GPS_Nick2);
842
    StickNick -= (GPS_Nick + GPS_Nick2);
851
    StickRoll -= (GPS_Roll + GPS_Roll2);
843
    StickRoll -= (GPS_Roll + GPS_Roll2);
852
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
844
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
853
 
845
 
854
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
846
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
855
    IntegralFaktor = Parameter_Gyro_I;
847
    IntegralFaktor = Parameter_Gyro_I;
856
    GyroFaktorGier     = (Parameter_Gyro_Gier_P + 10.0);
848
    GyroFaktorGier     = (Parameter_Gyro_Gier_P + 10.0);
857
    IntegralFaktorGier = Parameter_Gyro_Gier_I;
849
    IntegralFaktorGier = Parameter_Gyro_Gier_I;
858
 
850
 
859
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
851
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
860
//+ Analoge Steuerung per Seriell
852
//+ Analoge Steuerung per Seriell
861
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
853
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
862
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
854
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
863
    {
855
    {
864
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
856
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
865
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
857
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
866
         StickGier += ExternControl.Gier;
858
         StickGier += ExternControl.Gier;
867
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
859
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
868
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
860
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
869
    }
861
    }
870
    if(StickGas < 0) StickGas = 0;
862
    if(StickGas < 0) StickGas = 0;
871
 
863
 
872
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
864
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
873
    //if(GyroFaktor < 0) GyroFaktor = 0;
865
    //if(GyroFaktor < 0) GyroFaktor = 0;
874
    //if(IntegralFaktor < 0) IntegralFaktor = 0;
866
    //if(IntegralFaktor < 0) IntegralFaktor = 0;
875
 
867
 
876
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
868
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
877
     {
869
     {
878
      MaxStickNick = abs(StickNick)/STICK_GAIN;
870
      MaxStickNick = abs(StickNick)/STICK_GAIN;
879
      if(MaxStickNick > 100) MaxStickNick = 100;
871
      if(MaxStickNick > 100) MaxStickNick = 100;
880
     }
872
     }
881
     else MaxStickNick--;
873
     else MaxStickNick--;
882
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
874
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
883
     {
875
     {
884
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
876
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
885
      if(MaxStickRoll > 100) MaxStickRoll = 100;
877
      if(MaxStickRoll > 100) MaxStickRoll = 100;
886
     }
878
     }
887
     else MaxStickRoll--;
879
     else MaxStickRoll--;
888
    if(FCFlags & FCFLAG_NOTLANDUNG)  {MaxStickNick = 0; MaxStickRoll = 0;}
880
    if(FCFlags & FCFLAG_NOTLANDUNG)  {MaxStickNick = 0; MaxStickRoll = 0;}
889
 
881
 
890
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
882
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
891
// Looping?
883
// Looping?
892
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
884
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
893
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
885
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
894
  else
886
  else
895
   {
887
   {
896
     {
888
     {
897
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
889
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
898
     }
890
     }
899
   }
891
   }
900
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
892
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
901
   else
893
   else
902
   {
894
   {
903
   if(Looping_Rechts) // Hysterese
895
   if(Looping_Rechts) // Hysterese
904
     {
896
     {
905
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
897
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
906
     }
898
     }
907
   }
899
   }
908
 
900
 
909
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
901
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
910
  else
902
  else
911
   {
903
   {
912
    if(Looping_Oben)  // Hysterese
904
    if(Looping_Oben)  // Hysterese
913
     {
905
     {
914
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
906
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
915
     }
907
     }
916
   }
908
   }
917
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
909
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
918
   else
910
   else
919
   {
911
   {
920
    if(Looping_Unten) // Hysterese
912
    if(Looping_Unten) // Hysterese
921
     {
913
     {
922
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
914
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
923
     }
915
     }
924
   }
916
   }
925
 
917
 
926
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
918
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
927
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
919
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
928
  } // Ende neue Funken-Werte
920
  } // Ende neue Funken-Werte
929
 
921
 
930
  if(Looping_Roll || Looping_Nick)
922
  if(Looping_Roll || Looping_Nick)
931
   {
923
   {
932
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
924
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
933
        TrichterFlug = 1;
925
        TrichterFlug = 1;
934
   }
926
   }
935
 
927
 
936
 
928
 
937
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
929
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
938
// Bei Empfangsausfall im Flug
930
// Bei Empfangsausfall im Flug
939
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
931
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
940
   if(FCFlags & FCFLAG_NOTLANDUNG)
932
   if(FCFlags & FCFLAG_NOTLANDUNG)
941
    {
933
    {
942
     StickGier = 0;
934
     StickGier = 0;
943
     StickNick = 0;
935
     StickNick = 0;
944
     StickRoll = 0;
936
     StickRoll = 0;
945
     GyroFaktor     = 90;
937
     GyroFaktor     = 90;
946
     IntegralFaktor = 120;
938
     IntegralFaktor = 120;
947
     GyroFaktorGier     = 90;
939
     GyroFaktorGier     = 90;
948
     IntegralFaktorGier = 120;
940
     IntegralFaktorGier = 120;
949
     Looping_Roll = 0;
941
     Looping_Roll = 0;
950
     Looping_Nick = 0;
942
     Looping_Nick = 0;
951
    }
943
    }
952
 
944
 
953
 
945
 
954
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
946
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
955
// Integrale auf ACC-Signal abgleichen
947
// Integrale auf ACC-Signal abgleichen
956
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
948
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
957
#define ABGLEICH_ANZAHL 256L
949
#define ABGLEICH_ANZAHL 256L
958
 
950
 
959
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
951
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
960
 MittelIntegralRoll  += IntegralRoll;
952
 MittelIntegralRoll  += IntegralRoll;
961
 MittelIntegralNick2 += IntegralNick2;
953
 MittelIntegralNick2 += IntegralNick2;
962
 MittelIntegralRoll2 += IntegralRoll2;
954
 MittelIntegralRoll2 += IntegralRoll2;
963
 
955
 
964
 if(Looping_Nick || Looping_Roll)
956
 if(Looping_Nick || Looping_Roll)
965
  {
957
  {
966
    IntegralAccNick = 0;
958
    IntegralAccNick = 0;
967
    IntegralAccRoll = 0;
959
    IntegralAccRoll = 0;
968
    MittelIntegralNick = 0;
960
    MittelIntegralNick = 0;
969
    MittelIntegralRoll = 0;
961
    MittelIntegralRoll = 0;
970
    MittelIntegralNick2 = 0;
962
    MittelIntegralNick2 = 0;
971
    MittelIntegralRoll2 = 0;
963
    MittelIntegralRoll2 = 0;
972
    Mess_IntegralNick2 = Mess_IntegralNick;
964
    Mess_IntegralNick2 = Mess_IntegralNick;
973
    Mess_IntegralRoll2 = Mess_IntegralRoll;
965
    Mess_IntegralRoll2 = Mess_IntegralRoll;
974
    ZaehlMessungen = 0;
966
    ZaehlMessungen = 0;
975
    LageKorrekturNick = 0;
967
    LageKorrekturNick = 0;
976
    LageKorrekturRoll = 0;
968
    LageKorrekturRoll = 0;
977
  }
969
  }
978
 
970
 
979
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
971
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
980
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
972
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
981
  {
973
  {
982
   long tmp_long, tmp_long2;
974
   long tmp_long, tmp_long2;
983
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
975
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
984
     {
976
     {
985
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
977
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
986
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
978
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
987
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
979
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
988
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
980
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
989
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
981
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
990
      {
982
      {
991
      tmp_long  /= 2;
983
      tmp_long  /= 2;
992
      tmp_long2 /= 2;
984
      tmp_long2 /= 2;
993
      }
985
      }
994
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
986
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
995
      {
987
      {
996
      tmp_long  /= 3;
988
      tmp_long  /= 3;
997
      tmp_long2 /= 3;
989
      tmp_long2 /= 3;
998
      }
990
      }
999
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
991
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1000
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
992
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1001
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
993
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1002
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
994
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1003
     }
995
     }
1004
     else
996
     else
1005
     {
997
     {
1006
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
998
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1007
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
999
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
1008
      tmp_long /= 16;
1000
      tmp_long /= 16;
1009
      tmp_long2 /= 16;
1001
      tmp_long2 /= 16;
1010
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
1002
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
1011
      {
1003
      {
1012
      tmp_long  /= 3;
1004
      tmp_long  /= 3;
1013
      tmp_long2 /= 3;
1005
      tmp_long2 /= 3;
1014
      }
1006
      }
1015
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1007
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1016
      {
1008
      {
1017
      tmp_long  /= 3;
1009
      tmp_long  /= 3;
1018
      tmp_long2 /= 3;
1010
      tmp_long2 /= 3;
1019
      }
1011
      }
1020
 
1012
 
1021
#define AUSGLEICH  32
1013
#define AUSGLEICH  32
1022
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
1014
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
1023
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
1015
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
1024
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
1016
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
1025
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
1017
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
1026
     }
1018
     }
1027
 
-
 
1028
//if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;}
1019
 
1029
   Mess_IntegralNick -= tmp_long;
1020
   Mess_IntegralNick -= tmp_long;
1030
   Mess_IntegralRoll -= tmp_long2;
1021
   Mess_IntegralRoll -= tmp_long2;
1031
  }
1022
  }
1032
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1023
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1033
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
1024
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
1034
 {
1025
 {
1035
  static int cnt = 0;
1026
  static int cnt = 0;
1036
  static char last_n_p,last_n_n,last_r_p,last_r_n;
1027
  static char last_n_p,last_n_n,last_r_p,last_r_n;
1037
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
1028
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
1038
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
1029
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
1039
  {
1030
  {
1040
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
1031
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
1041
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
1032
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
1042
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
1033
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
1043
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
1034
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
1044
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
1035
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
1045
#define MAX_I 0//(Poti2/10)
1036
#define MAX_I 0//(Poti2/10)
1046
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
1037
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
1047
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
1038
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
1048
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
1039
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
1049
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
1040
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
1050
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
1041
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
1051
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
1042
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
1052
 
1043
 
1053
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
1044
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
1054
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
1045
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
1055
 
1046
 
1056
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
1047
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
1057
    {
1048
    {
1058
     LageKorrekturNick /= 2;
1049
     LageKorrekturNick /= 2;
1059
     LageKorrekturRoll /= 2;
1050
     LageKorrekturRoll /= 2;
1060
    }
1051
    }
1061
 
1052
 
1062
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1053
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1063
// Gyro-Drift ermitteln
1054
// Gyro-Drift ermitteln
1064
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1055
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1065
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
1056
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
1066
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
1057
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
1067
    tmp_long  = IntegralNick2 - IntegralNick;
1058
    tmp_long  = IntegralNick2 - IntegralNick;
1068
    tmp_long2 = IntegralRoll2 - IntegralRoll;
1059
    tmp_long2 = IntegralRoll2 - IntegralRoll;
1069
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
1060
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
1070
 
1061
 
1071
    IntegralFehlerNick = tmp_long;
1062
    IntegralFehlerNick = tmp_long;
1072
    IntegralFehlerRoll = tmp_long2;
1063
    IntegralFehlerRoll = tmp_long2;
1073
    Mess_IntegralNick2 -= IntegralFehlerNick;
1064
    Mess_IntegralNick2 -= IntegralFehlerNick;
1074
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
1065
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
1075
 
1066
 
1076
  if(EE_Parameter.Driftkomp)
1067
  if(EE_Parameter.Driftkomp)
1077
   {
1068
   {
1078
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; }
1069
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; }
1079
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; }
1070
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; }
1080
   }
1071
   }
1081
    GierGyroFehler = 0;
1072
    GierGyroFehler = 0;
1082
 
1073
 
1083
 
1074
 
1084
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2)
1075
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2)
1085
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4
1076
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4
1086
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1077
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1087
#define BEWEGUNGS_LIMIT 20000
1078
#define BEWEGUNGS_LIMIT 20000
1088
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1079
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1089
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1080
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1090
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1081
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1091
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1082
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1092
        {
1083
        {
1093
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1084
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1094
         {
1085
         {
1095
           if(last_n_p)
1086
           if(last_n_p)
1096
           {
1087
           {
1097
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1088
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1098
            ausgleichNick = IntegralFehlerNick / 8;
1089
            ausgleichNick = IntegralFehlerNick / 8;
1099
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1090
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1100
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1091
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1101
           }
1092
           }
1102
           else last_n_p = 1;
1093
           else last_n_p = 1;
1103
         } else  last_n_p = 0;
1094
         } else  last_n_p = 0;
1104
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1095
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1105
         {
1096
         {
1106
           if(last_n_n)
1097
           if(last_n_n)
1107
            {
1098
            {
1108
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1099
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1109
             ausgleichNick = IntegralFehlerNick / 8;
1100
             ausgleichNick = IntegralFehlerNick / 8;
1110
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1101
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1111
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1102
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1112
            }
1103
            }
1113
           else last_n_n = 1;
1104
           else last_n_n = 1;
1114
         } else  last_n_n = 0;
1105
         } else  last_n_n = 0;
1115
        }
1106
        }
1116
        else
1107
        else
1117
        {
1108
        {
1118
         cnt = 0;
1109
         cnt = 0;
1119
         KompassSignalSchlecht = 1000;
1110
         KompassSignalSchlecht = 1000;
1120
        }
1111
        }
1121
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1112
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1122
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1113
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1123
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1114
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1124
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1115
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1125
 
1116
 
1126
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1117
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1127
        cnt = 1;// + labs(IntegralFehlerRoll) / 4096;
1118
        cnt = 1;// + labs(IntegralFehlerRoll) / 4096;
1128
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1119
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1129
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1120
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1130
        {
1121
        {
1131
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1122
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1132
         {
1123
         {
1133
           if(last_r_p)
1124
           if(last_r_p)
1134
           {
1125
           {
1135
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1126
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1136
            ausgleichRoll = IntegralFehlerRoll / 8;
1127
            ausgleichRoll = IntegralFehlerRoll / 8;
1137
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1128
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1138
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1129
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1139
           }
1130
           }
1140
           else last_r_p = 1;
1131
           else last_r_p = 1;
1141
         } else  last_r_p = 0;
1132
         } else  last_r_p = 0;
1142
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1133
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1143
         {
1134
         {
1144
           if(last_r_n)
1135
           if(last_r_n)
1145
           {
1136
           {
1146
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1137
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1147
            ausgleichRoll = IntegralFehlerRoll / 8;
1138
            ausgleichRoll = IntegralFehlerRoll / 8;
1148
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1139
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1149
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1140
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1150
           }
1141
           }
1151
           else last_r_n = 1;
1142
           else last_r_n = 1;
1152
         } else  last_r_n = 0;
1143
         } else  last_r_n = 0;
1153
        } else
1144
        } else
1154
        {
1145
        {
1155
         cnt = 0;
1146
         cnt = 0;
1156
         KompassSignalSchlecht = 1000;
1147
         KompassSignalSchlecht = 1000;
1157
        }
1148
        }
1158
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1149
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1159
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1150
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1160
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1151
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1161
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1152
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1162
  }
1153
  }
1163
  else
1154
  else
1164
  {
1155
  {
1165
   LageKorrekturRoll = 0;
1156
   LageKorrekturRoll = 0;
1166
   LageKorrekturNick = 0;
1157
   LageKorrekturNick = 0;
1167
   TrichterFlug = 0;
1158
   TrichterFlug = 0;
1168
  }
1159
  }
1169
 
1160
 
1170
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1161
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1171
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1162
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1172
   MittelIntegralNick_Alt = MittelIntegralNick;
1163
   MittelIntegralNick_Alt = MittelIntegralNick;
1173
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1164
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1174
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1165
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1175
    IntegralAccNick = 0;
1166
    IntegralAccNick = 0;
1176
    IntegralAccRoll = 0;
1167
    IntegralAccRoll = 0;
1177
    IntegralAccZ = 0;
1168
    IntegralAccZ = 0;
1178
    MittelIntegralNick = 0;
1169
    MittelIntegralNick = 0;
1179
    MittelIntegralRoll = 0;
1170
    MittelIntegralRoll = 0;
1180
    MittelIntegralNick2 = 0;
1171
    MittelIntegralNick2 = 0;
1181
    MittelIntegralRoll2 = 0;
1172
    MittelIntegralRoll2 = 0;
1182
    ZaehlMessungen = 0;
1173
    ZaehlMessungen = 0;
1183
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1174
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1184
 
1175
 
1185
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1176
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1186
//  Gieren
1177
//  Gieren
1187
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1178
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1188
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
-
 
1189
    if(abs(StickGier) > 15) // war 35
1179
    if(abs(StickGier) > 15) // war 35
1190
     {
1180
     {
1191
      KompassSignalSchlecht = 1000;
1181
      KompassSignalSchlecht = 1000;
1192
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1182
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1193
       {
1183
       {
1194
         NeueKompassRichtungMerken = 1;
1184
         NeueKompassRichtungMerken = 1;
1195
        };
1185
        };
1196
     }
1186
     }
1197
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1187
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1198
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1188
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1199
    sollGier = tmp_int;
1189
    sollGier = tmp_int;
1200
    Mess_Integral_Gier -= tmp_int;
1190
    Mess_Integral_Gier -= tmp_int;
1201
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1191
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1202
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1192
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1203
 
1193
 
1204
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1194
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1205
//  Kompass
1195
//  Kompass
1206
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1196
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1207
//DebugOut.Analog[18] = KompassSignalSchlecht;
-
 
1208
 
-
 
1209
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1197
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1210
     {
1198
     {
1211
       int w,v,r,fehler,korrektur;
1199
       int w,v,r,fehler,korrektur;
1212
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1200
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1213
       v = abs(IntegralRoll /512);
1201
       v = abs(IntegralRoll /512);
1214
       if(v > w) w = v; // grösste Neigung ermitteln
1202
       if(v > w) w = v; // grösste Neigung ermitteln
1215
       korrektur = w / 8 + 2;
1203
       korrektur = w / 8 + 2;
1216
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1204
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1217
           //fehler += MesswertGier / 12;
1205
           //fehler += MesswertGier / 12;
1218
 
1206
 
1219
       if(!KompassSignalSchlecht && w < 25)
1207
       if(!KompassSignalSchlecht && w < 25)
1220
        {
1208
        {
1221
        GierGyroFehler += fehler;
1209
        GierGyroFehler += fehler;
1222
        if(NeueKompassRichtungMerken)
1210
        if(NeueKompassRichtungMerken)
1223
         {
1211
         {
1224
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1212
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1225
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1213
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1226
          NeueKompassRichtungMerken = 0;
1214
          NeueKompassRichtungMerken = 0;
1227
         }
1215
         }
1228
        }
1216
        }
1229
//DebugOut.Analog[16] = fehler;
-
 
1230
//DebugOut.Analog[17] = korrektur;
-
 
1231
       ErsatzKompass += (fehler * 16) / korrektur;
1217
       ErsatzKompass += (fehler * 16) / korrektur;
1232
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1218
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1233
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1219
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1234
       if(w >= 0)
1220
       if(w >= 0)
1235
        {
1221
        {
1236
          if(!KompassSignalSchlecht)
1222
          if(!KompassSignalSchlecht)
1237
          {
1223
          {
1238
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1224
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1239
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1225
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1240
//           r = KompassRichtung;
-
 
1241
           v = (r * w) / v;  // nach Kompass ausrichten
1226
           v = (r * w) / v;  // nach Kompass ausrichten
1242
           w = 3 * Parameter_KompassWirkung;
1227
           w = 3 * Parameter_KompassWirkung;
1243
           if(v > w) v = w; // Begrenzen
1228
           if(v > w) v = w; // Begrenzen
1244
           else
1229
           else
1245
           if(v < -w) v = -w;
1230
           if(v < -w) v = -w;
1246
           Mess_Integral_Gier += v;
1231
           Mess_Integral_Gier += v;
1247
          }
1232
          }
1248
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1233
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1249
        }
1234
        }
1250
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1235
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1251
     }
1236
     }
1252
 
1237
 
1253
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1238
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1254
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1239
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1255
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1240
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1256
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1241
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1257
 
1242
 
1258
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1243
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1259
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1244
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1260
 
1245
 
1261
#define TRIM_MAX 200
1246
#define TRIM_MAX 200
1262
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1247
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1263
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1248
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1264
 
1249
 
1265
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1250
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1266
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1251
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1267
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1252
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1268
 
1253
 
1269
    // Maximalwerte abfangen
1254
    // Maximalwerte abfangen
1270
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1255
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1271
    #define MAX_SENSOR  (4096)
1256
    #define MAX_SENSOR  (4096)
1272
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1257
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1273
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1258
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1274
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1259
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1275
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1260
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1276
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1261
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1277
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1262
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1278
 
1263
 
1279
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1264
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1280
// Höhenregelung
1265
// Höhenregelung
1281
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1266
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1282
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1267
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1283
  if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen
1268
  if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen
1284
  GasMischanteil *= STICK_GAIN;
1269
  GasMischanteil *= STICK_GAIN;
1285
        // if height control is activated
1270
        // if height control is activated
1286
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick))  // Höhenregelung
1271
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick))  // Höhenregelung
1287
        {
1272
        {
1288
                #define HOVER_GAS_AVERAGE 16384L                // 16384 * 2ms = 32s averaging
1273
                #define HOVER_GAS_AVERAGE 16384L                // 16384 * 2ms = 32s averaging
1289
                #define HC_GAS_AVERAGE 4                        // 4 * 2ms= 8ms averaging
1274
                #define HC_GAS_AVERAGE 4                        // 4 * 2ms= 8ms averaging
1290
 
1275
 
1291
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1276
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1292
#define OPA_OFFSET_STEP 15
1277
#define OPA_OFFSET_STEP 15
1293
#else
1278
#else
1294
#define OPA_OFFSET_STEP 10
1279
#define OPA_OFFSET_STEP 10
1295
#endif
1280
#endif
1296
                int HCGas, HeightDeviation = 0,GasReduction = 0;
1281
                int HCGas, HeightDeviation = 0,GasReduction = 0;
1297
                static int HeightTrimming = 0;  // rate for change of height setpoint
1282
                static int HeightTrimming = 0;  // rate for change of height setpoint
1298
                static int FilterHCGas = 0;
1283
                static int FilterHCGas = 0;
1299
                static int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023;
1284
                static int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023;
1300
                static unsigned long HoverGasFilter = 0;
1285
                static unsigned long HoverGasFilter = 0;
1301
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
1286
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
1302
            int CosAttitude;    // for projection of hoover gas
1287
            int CosAttitude;    // for projection of hoover gas
1303
 
1288
 
1304
                // get the current hooverpoint
1289
                // get the current hooverpoint
1305
                DebugOut.Analog[21] = HoverGas;
1290
                DebugOut.Analog[21] = HoverGas;
1306
 
1291
 
1307
        // Expand the measurement
1292
        // Expand the measurement
1308
                // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs
1293
                // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs
1309
          if(!BaroExpandActive)
1294
          if(!BaroExpandActive)
1310
                   {
1295
                   {
1311
                        if(MessLuftdruck > 920)
1296
                        if(MessLuftdruck > 920)
1312
                        {   // increase offset
1297
                        {   // increase offset
1313
             if(OCR0A < (255 - OPA_OFFSET_STEP))
1298
             if(OCR0A < (255 - OPA_OFFSET_STEP))
1314
                           {
1299
                           {
1315
                                ExpandBaro -= 1;
1300
                                ExpandBaro -= 1;
1316
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down
1301
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down
1317
                                beeptime = 300;
1302
                                beeptime = 300;
1318
                                BaroExpandActive = 350;
1303
                                BaroExpandActive = 350;
1319
                           }
1304
                           }
1320
                           else
1305
                           else
1321
                           {
1306
                           {
1322
                            BaroAtLowerLimit = 1;
1307
                            BaroAtLowerLimit = 1;
1323
               }
1308
               }
1324
                        }
1309
                        }
1325
                        // measurement of air pressure close to lower limit and
1310
                        // measurement of air pressure close to lower limit and
1326
                        else
1311
                        else
1327
                        if(MessLuftdruck < 100)
1312
                        if(MessLuftdruck < 100)
1328
                        {   // decrease offset
1313
                        {   // decrease offset
1329
                          if(OCR0A > OPA_OFFSET_STEP)
1314
                          if(OCR0A > OPA_OFFSET_STEP)
1330
                           {
1315
                           {
1331
                                ExpandBaro += 1;
1316
                                ExpandBaro += 1;
1332
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up
1317
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up
1333
                                beeptime = 300;
1318
                                beeptime = 300;
1334
                                BaroExpandActive = 350;
1319
                                BaroExpandActive = 350;
1335
                           }
1320
                           }
1336
                           else
1321
                           else
1337
                           {
1322
                           {
1338
                            BaroAtUpperLimit = 1;
1323
                            BaroAtUpperLimit = 1;
1339
               }
1324
               }
1340
                        }
1325
                        }
1341
                        else
1326
                        else
1342
                        {
1327
                        {
1343
                            BaroAtUpperLimit = 0;
1328
                            BaroAtUpperLimit = 0;
1344
                                BaroAtLowerLimit = 0;
1329
                                BaroAtLowerLimit = 0;
1345
                        }
1330
                        }
1346
                   }
1331
                   }
1347
                   else // delay, because of expanding the Baro-Range
1332
                   else // delay, because of expanding the Baro-Range
1348
                   {
1333
                   {
1349
                    // now clear the D-values
1334
                    // now clear the D-values
1350
                          SummenHoehe = HoehenWert * SM_FILTER;
1335
                          SummenHoehe = HoehenWert * SM_FILTER;
1351
                          VarioMeter = 0;
1336
                          VarioMeter = 0;
1352
                          BaroExpandActive--;
1337
                          BaroExpandActive--;
1353
                   }
1338
                   }
1354
 
1339
 
1355
                // if height control is activated by an rc channel
1340
                // if height control is activated by an rc channel
1356
        if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1341
        if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1357
                {       // check if parameter is less than activation threshold
1342
                {       // check if parameter is less than activation threshold
1358
                        if(Parameter_MaxHoehe < 50) // for 3 or 2-state switch height control is disabled in lowest position
1343
                        if(Parameter_MaxHoehe < 50) // for 3 or 2-state switch height control is disabled in lowest position
1359
                        {   //height control not active
1344
                        {   //height control not active
1360
                                if(!delay--)
1345
                                if(!delay--)
1361
                                {
1346
                                {
1362
                                        HoehenReglerAktiv = 0; // disable height control
1347
                                        HoehenReglerAktiv = 0; // disable height control
1363
                                        SollHoehe = HoehenWert;  // update SetPoint with current reading
1348
                                        SollHoehe = HoehenWert;  // update SetPoint with current reading
1364
                                        delay = 1;
1349
                                        delay = 1;
1365
                                }
1350
                                }
1366
                        }
1351
                        }
1367
                        else
1352
                        else
1368
                        {       //height control is activated
1353
                        {       //height control is activated
1369
                                HoehenReglerAktiv = 1; // enable height control
1354
                                HoehenReglerAktiv = 1; // enable height control
1370
                                delay = 200;
1355
                                delay = 200;
1371
                        }
1356
                        }
1372
                }
1357
                }
1373
                else // no switchable height control
1358
                else // no switchable height control
1374
                {
1359
                {
1375
                        SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung;
1360
                        SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung;
1376
                        HoehenReglerAktiv = 1;
1361
                        HoehenReglerAktiv = 1;
1377
                }
1362
                }
1378
 
1363
 
1379
                // calculate cos of nick and roll angle used for projection of the vertical hoover gas
1364
                // calculate cos of nick and roll angle used for projection of the vertical hoover gas
1380
                tmp_int  = (int)(IntegralNick/GIER_GRAD_FAKTOR);  // nick angle in deg
1365
                tmp_int  = (int)(IntegralNick/GIER_GRAD_FAKTOR);  // nick angle in deg
1381
                tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR);  // roll angle in deg
1366
                tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR);  // roll angle in deg
1382
                CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg
1367
                CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg
1383
                LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle
1368
                LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle
1384
                CosAttitude = c_cos_8192(CosAttitude);  // cos of actual attitude
1369
                CosAttitude = c_cos_8192(CosAttitude);  // cos of actual attitude
1385
                VarioCharacter = ' ';
1370
                VarioCharacter = ' ';
1386
                if(HoehenReglerAktiv && !(FCFlags & FCFLAG_NOTLANDUNG))
1371
                if(HoehenReglerAktiv && !(FCFlags & FCFLAG_NOTLANDUNG))
1387
                {
1372
                {
1388
                        #define HEIGHT_TRIM_UP          0x01
1373
                        #define HEIGHT_TRIM_UP          0x01
1389
                        #define HEIGHT_TRIM_DOWN        0x02
1374
                        #define HEIGHT_TRIM_DOWN        0x02
1390
                        static unsigned char HeightTrimmingFlag = 0x00;
1375
                        static unsigned char HeightTrimmingFlag = 0x00;
1391
 
1376
 
1392
                        #define HEIGHT_CONTROL_STICKTHRESHOLD 15
1377
                        #define HEIGHT_CONTROL_STICKTHRESHOLD 15
1393
                // Holger original version
1378
                // Holger original version
1394
                // start of height control algorithm
1379
                // start of height control algorithm
1395
                // the height control is only an attenuation of the actual gas stick.
1380
                // the height control is only an attenuation of the actual gas stick.
1396
                // I.e. it will work only if the gas stick is higher than the hover gas
1381
                // I.e. it will work only if the gas stick is higher than the hover gas
1397
                // and the hover height will be allways larger than height setpoint.
1382
                // and the hover height will be allways larger than height setpoint.
1398
        if((EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) || !(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER))  // Regler wird über Schalter gesteuert)
1383
        if((EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) || !(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER))  // Regler wird über Schalter gesteuert)
1399
              {  // old version
1384
              {  // old version
1400
                        HCGas = GasMischanteil; // take current stick gas as neutral point for the height control
1385
                        HCGas = GasMischanteil; // take current stick gas as neutral point for the height control
1401
                        HeightTrimming = 0;
1386
                        HeightTrimming = 0;
1402
          }
1387
          }
1403
                  else
1388
                  else
1404
                  {
1389
                  {
1405
                // alternative height control
1390
                // alternative height control
1406
                // PD-Control with respect to hoover point
1391
                // PD-Control with respect to hoover point
1407
                // the thrust loss out of horizontal attitude is compensated
1392
                // the thrust loss out of horizontal attitude is compensated
1408
                // the setpoint will be fine adjusted with the gas stick position
1393
                // the setpoint will be fine adjusted with the gas stick position
1409
                        if(FCFlags & FCFLAG_FLY) // trim setpoint only when flying
1394
                        if(FCFlags & FCFLAG_FLY) // trim setpoint only when flying
1410
                        {   // gas stick is above hoover point
1395
                        {   // gas stick is above hoover point
1411
                                if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit)
1396
                                if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit)
1412
                                {
1397
                                {
1413
                                        if(HeightTrimmingFlag & HEIGHT_TRIM_DOWN)
1398
                                        if(HeightTrimmingFlag & HEIGHT_TRIM_DOWN)
1414
                                        {
1399
                                        {
1415
                                                HeightTrimmingFlag &= ~HEIGHT_TRIM_DOWN;
1400
                                                HeightTrimmingFlag &= ~HEIGHT_TRIM_DOWN;
1416
                                                SollHoehe = HoehenWert; // update setpoint to current heigth
1401
                                                SollHoehe = HoehenWert; // update setpoint to current heigth
1417
                                        }
1402
                                        }
1418
                                        HeightTrimmingFlag |= HEIGHT_TRIM_UP;
1403
                                        HeightTrimmingFlag |= HEIGHT_TRIM_UP;
1419
                                        HeightTrimming += abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD));
1404
                                        HeightTrimming += abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD));
1420
                                        VarioCharacter = '+';
1405
                                        VarioCharacter = '+';
1421
                                } // gas stick is below hoover point
1406
                                } // gas stick is below hoover point
1422
                                else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit )
1407
                                else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit )
1423
                                {
1408
                                {
1424
                                        if(HeightTrimmingFlag & HEIGHT_TRIM_UP)
1409
                                        if(HeightTrimmingFlag & HEIGHT_TRIM_UP)
1425
                                        {
1410
                                        {
1426
                                                HeightTrimmingFlag &= ~HEIGHT_TRIM_UP;
1411
                                                HeightTrimmingFlag &= ~HEIGHT_TRIM_UP;
1427
                                                SollHoehe = HoehenWert; // update setpoint to current heigth
1412
                                                SollHoehe = HoehenWert; // update setpoint to current heigth
1428
                                        }
1413
                                        }
1429
                                        HeightTrimmingFlag |= HEIGHT_TRIM_DOWN;
1414
                                        HeightTrimmingFlag |= HEIGHT_TRIM_DOWN;
1430
                                        HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1415
                                        HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1431
                                        VarioCharacter = '-';
1416
                                        VarioCharacter = '-';
1432
                                }
1417
                                }
1433
                                else // Gas Stick in Hover Range
1418
                                else // Gas Stick in Hover Range
1434
                                {
1419
                                {
1435
                                        if(HeightTrimmingFlag & (HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN))
1420
                                        if(HeightTrimmingFlag & (HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN))
1436
                                        {
1421
                                        {
1437
                                                HeightTrimmingFlag &= ~(HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN);
1422
                                                HeightTrimmingFlag &= ~(HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN);
1438
                                                HeightTrimming = 0;
1423
                                                HeightTrimming = 0;
1439
                                                SollHoehe = HoehenWert; // update setpoint to current height
1424
                                                SollHoehe = HoehenWert; // update setpoint to current height
1440
                                                if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500;
1425
                                                if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500;
1441
                                                if(!StartTrigger && HoehenWert > 50)
1426
                                                if(!StartTrigger && HoehenWert > 50)
1442
                                                {
1427
                                                {
1443
                                                 StartTrigger = 1;
1428
                                                 StartTrigger = 1;
1444
                                                }
1429
                                                }
1445
                                        }
1430
                                        }
1446
                                        VarioCharacter = '=';
1431
                                        VarioCharacter = '=';
1447
                                }
1432
                                }
1448
                                // Trim height set point
1433
                                // Trim height set point
1449
                                if(abs(HeightTrimming) > 512)
1434
                                if(abs(HeightTrimming) > 512)
1450
                                {
1435
                                {
1451
                                        SollHoehe += (HeightTrimming * EE_Parameter.Hoehe_Verstaerkung)/(5 * 512 / 2); // move setpoint
1436
                                        SollHoehe += (HeightTrimming * EE_Parameter.Hoehe_Verstaerkung)/(5 * 512 / 2); // move setpoint
1452
                                        HeightTrimming = 0;
1437
                                        HeightTrimming = 0;
1453
                    LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied
1438
                    LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied
1454
                                        if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 75;
1439
                                        if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 75;
1455
                                        //update hoover gas stick value when setpoint is shifted
1440
                                        //update hoover gas stick value when setpoint is shifted
1456
                       if(!EE_Parameter.Hoehe_StickNeutralPoint)
1441
                       if(!EE_Parameter.Hoehe_StickNeutralPoint)
1457
                       {
1442
                       {
1458
                           StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value
1443
                           StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value
1459
                           StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1444
                           StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1460
                           if(StickGasHover < 70) StickGasHover = 70;
1445
                           if(StickGasHover < 70) StickGasHover = 70;
1461
                           else if(StickGasHover > 150) StickGasHover = 150;
1446
                           else if(StickGasHover > 150) StickGasHover = 150;
1462
                       }
1447
                       }
1463
                                }
1448
                                }
1464
              if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active
1449
              if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active
1465
                        } //if FCFlags & MKFCFLAG_FLY
1450
                        } //if FCFlags & MKFCFLAG_FLY
1466
                        else
1451
                        else
1467
                        {
1452
                        {
1468
                         SollHoehe = HoehenWert - 400;
1453
                         SollHoehe = HoehenWert - 400;
1469
                         if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1454
                         if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1470
                         else StickGasHover = 120;
1455
                         else StickGasHover = 120;
1471
                         HoverGas = GasMischanteil;
1456
                         HoverGas = GasMischanteil;
1472
                         }
1457
                         }
1473
                        HCGas = HoverGas;      // take hover gas (neutral point)
1458
                        HCGas = HoverGas;      // take hover gas (neutral point)
1474
                   }
1459
                   }
1475
         if(HoehenWert > SollHoehe || !(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT))
1460
         if(HoehenWert > SollHoehe || !(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT))
1476
                 {
1461
                 {
1477
                        // from this point the Heigth Control Algorithm is identical for both versions
1462
                        // from this point the Heigth Control Algorithm is identical for both versions
1478
                        if(BaroExpandActive) // baro range expanding active
1463
                        if(BaroExpandActive) // baro range expanding active
1479
                        {
1464
                        {
1480
                                HCGas = HoverGas; // hover while expanding baro adc range
1465
                                HCGas = HoverGas; // hover while expanding baro adc range
1481
                                HeightDeviation = 0;
1466
                                HeightDeviation = 0;
1482
                        } // EOF // baro range expanding active
1467
                        } // EOF // baro range expanding active
1483
                        else // valid data from air pressure sensor
1468
                        else // valid data from air pressure sensor
1484
                        {
1469
                        {
1485
                                // ------------------------- P-Part ----------------------------
1470
                                // ------------------------- P-Part ----------------------------
1486
                                tmp_long = (HoehenWert - SollHoehe); // positive when too high
1471
                                tmp_long = (HoehenWert - SollHoehe); // positive when too high
1487
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1472
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1488
                                HeightDeviation = (int)(tmp_long); // positive when too high
1473
                                HeightDeviation = (int)(tmp_long); // positive when too high
1489
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1474
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1490
                                LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense
1475
                                LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense
1491
DebugOut.Analog[25] = tmp_long;
-
 
1492
                                GasReduction = tmp_long;
1476
                                GasReduction = tmp_long;
1493
                                // ------------------------- D-Part 1: Vario Meter ----------------------------
1477
                                // ------------------------- D-Part 1: Vario Meter ----------------------------
1494
                                tmp_int = VarioMeter / 8;
1478
                                tmp_int = VarioMeter / 8;
1495
                                LIMIT_MIN_MAX(tmp_int, -127, 128);     
1479
                                LIMIT_MIN_MAX(tmp_int, -127, 128);     
1496
DebugOut.Analog[18] = tmp_int;
-
 
1497
//                              tmp_int2 = tmp_int/4;
-
 
1498
//                              LIMIT_MAX(tmp_int2, 64); 
-
 
1499
//                              if(tmp_int > 0) tmp_int = tmp_int + (tmp_int2 * tmp_int2);
-
 
1500
//                              else             tmp_int = tmp_int - (tmp_int2 * tmp_int2);
-
 
1501
 
-
 
1502
if(!HeightTrimmingFlag)
1480
                                if(!HeightTrimmingFlag)
1503
                                {
1481
                                {
1504
                                 tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter
1482
                                 tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter
1505
                                 LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN);
1483
                                 LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN);
1506
                                }
1484
                                }
1507
                                 
1485
                                else
1508
else                    {
1486
                                {
1509
                                 tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 16L; // weniger D zum Höhe ändern
1487
                                 tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 16L; // weniger D zum Höhe ändern
1510
                                 LIMIT_MIN_MAX(tmp_int,-16 * STICK_GAIN, 16 * STICK_GAIN);
1488
                                 LIMIT_MIN_MAX(tmp_int,-16 * STICK_GAIN, 16 * STICK_GAIN);
1511
                                }
1489
                                }
1512
 
-
 
1513
DebugOut.Analog[19] = tmp_int;
-
 
1514
                                GasReduction += tmp_int;
1490
                                GasReduction += tmp_int;
1515
                        } // EOF no baro range expanding
1491
                        } // EOF no baro range expanding
1516
                        // ------------------------ D-Part 2: ACC-Z Integral  ------------------------
1492
                        // ------------------------ D-Part 2: ACC-Z Integral  ------------------------
1517
            if(Parameter_Hoehe_ACC_Wirkung)
1493
            if(Parameter_Hoehe_ACC_Wirkung)
1518
                         {
1494
                         {
1519
                          tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN);
1495
                          tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN);
1520
                          LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN);
1496
                          LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN);
1521
                          GasReduction += tmp_long;
1497
                          GasReduction += tmp_long;
1522
                         }
1498
                         }
1523
                        // ------------------------ D-Part 3: GpsZ  ----------------------------------
1499
                        // ------------------------ D-Part 3: GpsZ  ----------------------------------
1524
                        tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L;
1500
                        tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L;
1525
            LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN);
1501
            LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN);
1526
                        GasReduction += tmp_int;
1502
                        GasReduction += tmp_int;
-
 
1503
            GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value
1527
 
-
 
1528
//DebugOut.Analog[16] = GasReduction;
-
 
1529
GasReduction = (long)((long)GasReduction * HoverGas) / 512;
1504
 
1530
//GasReduction = (long)((long)GasReduction * Poti3) / 64;
-
 
1531
DebugOut.Analog[17] = GasReduction;
-
 
1532
 
1505
                        // ------------------------                  ----------------------------------
1533
HCGas -= GasReduction;
-
 
1534
 
1506
                        HCGas -= GasReduction;
1535
                        // limit deviation from hoover point within the target region
1507
                        // limit deviation from hoover point within the target region
1536
                        if(!HeightTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero
1508
                        if(!HeightTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero
1537
                        {
1509
                        {
1538
                         signed int tmp,min,max;
1510
                         signed int tmp,min,max;
1539
              if(abs(HeightDeviation) < 60)
1511
              if(abs(HeightDeviation) < 60)
1540
                           {
1512
                           {
1541
                            LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point
1513
                            LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point
1542
                           }   
1514
                           }   
1543
                          else
1515
                          else
1544
                           {
1516
                           {
1545
                            tmp = (abs(HeightDeviation) - 60)/32;
1517
                            tmp = (abs(HeightDeviation) - 60)/32;
1546
                                if(tmp > 15) tmp = 15;
1518
                                if(tmp > 15) tmp = 15;
1547
                                if(HeightDeviation > 0)
1519
                                if(HeightDeviation > 0)
1548
                                 {
1520
                                 {
1549
                                  min = (HoverGasMin * (16 - tmp)) / 16;  
1521
                                  min = (HoverGasMin * (16 - tmp)) / 16;  
1550
                              LIMIT_MIN_MAX(HCGas, min, HoverGasMax); // limit gas around the hoover point
1522
                              LIMIT_MIN_MAX(HCGas, min, HoverGasMax); // limit gas around the hoover point
1551
                                 }
1523
                                 }
1552
                                else
1524
                                else
1553
                                {
1525
                                {
1554
                                 max = (HoverGasMax * (tmp + 16)) / 16;
1526
                                 max = (HoverGasMax * (tmp + 16)) / 16;
1555
                              LIMIT_MIN_MAX(HCGas, HoverGasMin, max); // limit gas around the hoover point
1527
                              LIMIT_MIN_MAX(HCGas, HoverGasMin, max); // limit gas around the hoover point
1556
                                }
1528
                                }
1557
                           }
1529
                           }
1558
                        }
1530
                        }
1559
                        // strech control output by inverse attitude projection 1/cos
1531
                        // strech control output by inverse attitude projection 1/cos
1560
            // + 1/cos(angle)  ++++++++++++++++++++++++++
1532
            // + 1/cos(angle)  ++++++++++++++++++++++++++
1561
                        tmp_long2 = (int32_t)HCGas;
1533
                        tmp_long2 = (int32_t)HCGas;
1562
                        tmp_long2 *= 8192L;
1534
                        tmp_long2 *= 8192L;
1563
                        tmp_long2 /= CosAttitude;
1535
                        tmp_long2 /= CosAttitude;
1564
                        HCGas = (int16_t)tmp_long2;
1536
                        HCGas = (int16_t)tmp_long2;
1565
                        // update height control gas averaging
1537
                        // update height control gas averaging
1566
                        FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE;
1538
                        FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE;
1567
                        // limit height control gas pd-control output
1539
                        // limit height control gas pd-control output
1568
                        LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN);
1540
                        LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN);
1569
                        // set GasMischanteil to HeightControlGasFilter
1541
                        // set GasMischanteil to HeightControlGasFilter
1570
            if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT)
1542
            if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT)
1571
                        {  // old version
1543
                        {  // old version
1572
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1544
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1573
                        }
1545
                        }
1574
                        GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4;
1546
                        GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4;
1575
                  }
1547
                  }
1576
                }// EOF height control active
1548
                }// EOF height control active
1577
                else // HC not active
1549
                else // HC not active
1578
                {
1550
                {
1579
                        //update hoover gas stick value when HC is not active
1551
                        //update hoover gas stick value when HC is not active
1580
                        if(!EE_Parameter.Hoehe_StickNeutralPoint)
1552
                        if(!EE_Parameter.Hoehe_StickNeutralPoint)
1581
                        {
1553
                        {
1582
                                StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value
1554
                                StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value
1583
                                StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1555
                                StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1584
                        }
1556
                        }
1585
                        else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1557
                        else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1586
            LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down
1558
            LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down
1587
                        FilterHCGas = GasMischanteil;
1559
                        FilterHCGas = GasMischanteil;
1588
                }
1560
                }
1589
 
1561
 
1590
                // Hover gas estimation by averaging gas control output on small z-velocities
1562
                // Hover gas estimation by averaging gas control output on small z-velocities
1591
                // this is done only if height contol option is selected in global config and aircraft is flying
1563
                // this is done only if height contol option is selected in global config and aircraft is flying
1592
                if((FCFlags & FCFLAG_FLY))// && !(FCFlags & FCFLAG_NOTLANDUNG))
1564
                if((FCFlags & FCFLAG_FLY))// && !(FCFlags & FCFLAG_NOTLANDUNG))
1593
                {
1565
                {
1594
                        if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation
1566
                        if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation
1595
                        if(StartTrigger == 1) StartTrigger = 2;
1567
                        if(StartTrigger == 1) StartTrigger = 2;
1596
                                tmp_long2 = (int32_t)GasMischanteil; // take current thrust
1568
                                tmp_long2 = (int32_t)GasMischanteil; // take current thrust
1597
                                tmp_long2 *= CosAttitude;            // apply attitude projection
1569
                                tmp_long2 *= CosAttitude;            // apply attitude projection
1598
                                tmp_long2 /= 8192;
1570
                                tmp_long2 /= 8192;
1599
                                // average vertical projected thrust
1571
                                // average vertical projected thrust
1600
                            if(modell_fliegt < 4000) // the first 8 seconds
1572
                            if(modell_fliegt < 4000) // the first 8 seconds
1601
                                {   // reduce the time constant of averaging by factor of 4 to get much faster a stable value
1573
                                {   // reduce the time constant of averaging by factor of 4 to get much faster a stable value
1602
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L);
1574
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L);
1603
                                        HoverGasFilter += 16L * tmp_long2;
1575
                                        HoverGasFilter += 16L * tmp_long2;
1604
                                }
1576
                                }
1605
                if(modell_fliegt < 8000) // the first 16 seconds
1577
                if(modell_fliegt < 8000) // the first 16 seconds
1606
                                {   // reduce the time constant of averaging by factor of 2 to get much faster a stable value
1578
                                {   // reduce the time constant of averaging by factor of 2 to get much faster a stable value
1607
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L);
1579
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L);
1608
                                        HoverGasFilter += 4L * tmp_long2;
1580
                                        HoverGasFilter += 4L * tmp_long2;
1609
                                }
1581
                                }
1610
                          else //later
1582
                          else //later
1611
                          if(abs(VarioMeter) < 100) // only on small vertical speed
1583
                          if(abs(VarioMeter) < 100) // only on small vertical speed
1612
                                {
1584
                                {
1613
                                        HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE;
1585
                                        HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE;
1614
                                        HoverGasFilter += tmp_long2;
1586
                                        HoverGasFilter += tmp_long2;
1615
                                }
1587
                                }
1616
                                HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE);
1588
                                HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE);
1617
                                if(EE_Parameter.Hoehe_HoverBand)
1589
                                if(EE_Parameter.Hoehe_HoverBand)
1618
                                {
1590
                                {
1619
                                        int16_t band;
1591
                                        int16_t band;
1620
                                        band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range
1592
                                        band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range
1621
                                        HoverGasMin = HoverGas - band;
1593
                                        HoverGasMin = HoverGas - band;
1622
                                        HoverGasMax = HoverGas + band;
1594
                                        HoverGasMax = HoverGas + band;
1623
                                }
1595
                                }
1624
                                else
1596
                                else
1625
                                {       // no limit
1597
                                {       // no limit
1626
                                        HoverGasMin = 0;
1598
                                        HoverGasMin = 0;
1627
                                        HoverGasMax = 1023;
1599
                                        HoverGasMax = 1023;
1628
                                }
1600
                                }
1629
                }
1601
                }
1630
                 else
1602
                 else
1631
                  {
1603
                  {
1632
                   StartTrigger = 0;
1604
                   StartTrigger = 0;
1633
                   HoverGasFilter = 0;
1605
                   HoverGasFilter = 0;
1634
                   HoverGas = 0;
1606
                   HoverGas = 0;
1635
                  }
1607
                  }
1636
        }// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL
1608
        }// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL
1637
DebugOut.Analog[16] = StartTrigger;
-
 
1638
        // limit gas to parameter setting
1609
        // limit gas to parameter setting
1639
  LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN);
1610
  LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN);
1640
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1611
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1641
 
1612
 
1642
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1613
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1643
// all BL-Ctrl connected?
1614
// all BL-Ctrl connected?
1644
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1615
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1645
  if(MissingMotor || Capacity.MinOfMaxPWM != 255)
1616
  if(MissingMotor || Capacity.MinOfMaxPWM != 255)
1646
  if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1617
  if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1647
   {
1618
   {
1648
    modell_fliegt = 1;
1619
    modell_fliegt = 1;
1649
        GasMischanteil = (MIN_GAS + 10) * STICK_GAIN;
1620
        GasMischanteil = (MIN_GAS + 10) * STICK_GAIN;
1650
   }
1621
   }
1651
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1622
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1652
// + Mischer und PI-Regler
1623
// + Mischer und PI-Regler
1653
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1624
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1654
  DebugOut.Analog[7] = GasMischanteil;
1625
  DebugOut.Analog[7] = GasMischanteil;
1655
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1626
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1656
// Gier-Anteil
1627
// Gier-Anteil
1657
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1628
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1658
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1629
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1659
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1630
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1660
   if(GasMischanteil > MIN_GIERGAS)
1631
   if(GasMischanteil > MIN_GIERGAS)
1661
    {
1632
    {
1662
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1633
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1663
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1634
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1664
    }
1635
    }
1665
    else
1636
    else
1666
    {
1637
    {
1667
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1638
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1668
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1639
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1669
    }
1640
    }
1670
    tmp_int = MAX_GAS*STICK_GAIN;
1641
    tmp_int = MAX_GAS*STICK_GAIN;
1671
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1642
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1672
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1643
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1673
 
1644
 
1674
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1645
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1675
// Nick-Achse
1646
// Nick-Achse
1676
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1647
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1677
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1648
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1678
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1649
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1679
    else  SummeNick += DiffNick; // I-Anteil bei HH
1650
    else  SummeNick += DiffNick; // I-Anteil bei HH
1680
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1651
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1681
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1652
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1682
        pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8 + SummeNick / Ki; // PI-Regler für Nick
1653
        pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8 + SummeNick / Ki; // PI-Regler für Nick
1683
    // Motor Vorn
1654
    // Motor Vorn
1684
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1655
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1685
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1656
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1686
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1657
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1687
 
1658
 
1688
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1659
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1689
// Roll-Achse
1660
// Roll-Achse
1690
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1661
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1691
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1662
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1692
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1663
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1693
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1664
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1694
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1665
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1695
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1666
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1696
    pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8 + SummeRoll / Ki;   // PI-Regler für Roll
1667
    pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8 + SummeRoll / Ki;   // PI-Regler für Roll
1697
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1668
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1698
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1669
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1699
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1670
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1700
 
1671
 
1701
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1672
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1702
// Universal Mixer
1673
// Universal Mixer
1703
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1674
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1704
        for(i=0; i<MAX_MOTORS; i++)
1675
        for(i=0; i<MAX_MOTORS; i++)
1705
        {
1676
        {
1706
                signed int tmp_int;
1677
                signed int tmp_int;
1707
                if(Mixer.Motor[i][0] > 0)
1678
                if(Mixer.Motor[i][0] > 0)
1708
                {
1679
                {
1709
                        // Gas
1680
                        // Gas
1710
                        if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1681
                        if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1711
                        // Nick
1682
                        // Nick
1712
                        if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick;
1683
                        if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick;
1713
                        else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick;
1684
                        else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick;
1714
                        else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1685
                        else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1715
            // Roll
1686
            // Roll
1716
                        if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll;
1687
                        if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll;
1717
                        else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll;
1688
                        else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll;
1718
                        else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1689
                        else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1719
            // Gier
1690
            // Gier
1720
                        if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil;
1691
                        if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil;
1721
                        else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil;
1692
                        else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil;
1722
                        else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1693
                        else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1723
 
-
 
1724
//if(Parameter_UserParam4 < 50)
-
 
1725
 {
1694
 
1726
                        if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2;      // MotorSmoothing
1695
                        if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2;      // MotorSmoothing
1727
                        else tmp_int = 2 * tmp_int - tmp_motorwert[i];                                                              // MotorSmoothing
-
 
1728
 }
1696
                        else tmp_int = 2 * tmp_int - tmp_motorwert[i];                                                              // MotorSmoothing
1729
 
1697
 
1730
                        LIMIT_MIN_MAX(tmp_int,MIN_GAS * 4,MAX_GAS * 4);
1698
                        LIMIT_MIN_MAX(tmp_int,MIN_GAS * 4,MAX_GAS * 4);
1731
                        Motor[i].SetPoint = tmp_int / 4;
1699
                        Motor[i].SetPoint = tmp_int / 4;
1732
                        Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total)
1700
                        Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total)
1733
            tmp_motorwert[i] = tmp_int;
1701
            tmp_motorwert[i] = tmp_int;
1734
                }
1702
                }
1735
                else
1703
                else
1736
                {
1704
                {
1737
                        Motor[i].SetPoint = 0;
1705
                        Motor[i].SetPoint = 0;
1738
                        Motor[i].SetPointLowerBits = 0;
1706
                        Motor[i].SetPointLowerBits = 0;
1739
                }
1707
                }
1740
        }
1708
        }
1741
}
1709
}
1742
 
1710