Subversion Repositories FlightCtrl

Rev

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

Rev 2344 Rev 2345
1
/*#######################################################################################
1
/*#######################################################################################
2
Flight Control
2
Flight Control
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
 
56
 
57
#include "main.h"
57
#include "main.h"
58
#include "mymath.h"
58
#include "mymath.h"
59
#include "isqrt.h"
59
#include "isqrt.h"
60
 
60
 
61
unsigned char h,m,s;
61
unsigned char h,m,s;
62
unsigned int BaroExpandActive = 0;
62
unsigned int BaroExpandActive = 0;
63
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
63
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
64
int TrimNick, TrimRoll;
64
int TrimNick, TrimRoll;
65
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
65
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
66
int Mittelwert_AccNick, Mittelwert_AccRoll;
66
int Mittelwert_AccNick, Mittelwert_AccRoll;
67
unsigned int NeutralAccX=0, NeutralAccY=0;
67
unsigned int NeutralAccX=0, NeutralAccY=0;
68
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
68
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
69
int NeutralAccZ = 0;
69
int NeutralAccZ = 0;
70
signed char NeutralAccZfine = 0;
70
signed char NeutralAccZfine = 0;
71
unsigned char ControlHeading = 0;// in 2°
71
unsigned char ControlHeading = 0;// in 2°
72
long IntegralNick = 0,IntegralNick2 = 0;
72
long IntegralNick = 0,IntegralNick2 = 0;
73
long IntegralRoll = 0,IntegralRoll2 = 0;
73
long IntegralRoll = 0,IntegralRoll2 = 0;
74
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
74
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
75
long Integral_Gier = 0;
75
long Integral_Gier = 0;
76
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
76
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
77
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
77
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
78
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
78
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
79
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
79
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
80
long SummeNick=0,SummeRoll=0;
80
long SummeNick=0,SummeRoll=0;
81
volatile long Mess_Integral_Hoch = 0;
81
volatile long Mess_Integral_Hoch = 0;
82
int  KompassValue = -1;
82
int  KompassValue = -1;
83
int  KompassSollWert = 0;
83
int  KompassSollWert = 0;
84
//int  KompassRichtung = 0;
84
//int  KompassRichtung = 0;
85
char CalculateCompassTimer = 100;
85
char CalculateCompassTimer = 100;
86
unsigned char KompassFusion = 32;
86
unsigned char KompassFusion = 32;
87
unsigned int  KompassSignalSchlecht = 50;
87
unsigned int  KompassSignalSchlecht = 50;
88
unsigned char  MAX_GAS,MIN_GAS;
88
unsigned char  MAX_GAS,MIN_GAS;
89
unsigned char HoehenReglerAktiv = 0;
89
unsigned char HoehenReglerAktiv = 0;
90
unsigned char TrichterFlug = 0;
90
unsigned char TrichterFlug = 0;
91
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
91
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
92
long  ErsatzKompass;
92
long  ErsatzKompass;
93
int   ErsatzKompassInGrad; // Kompasswert in Grad
93
int   ErsatzKompassInGrad; // Kompasswert in Grad
94
int   GierGyroFehler = 0;
94
int   GierGyroFehler = 0;
95
char GyroFaktor,GyroFaktorGier;
95
char GyroFaktor,GyroFaktorGier;
96
char IntegralFaktor,IntegralFaktorGier;
96
char IntegralFaktor,IntegralFaktorGier;
97
int  DiffNick,DiffRoll;
97
int  DiffNick,DiffRoll;
98
int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023;
98
int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023;
99
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
99
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
100
//int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0;
100
//int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0;
101
unsigned char Poti[9] = {0,0,0,0,0,0,0,0};
101
unsigned char Poti[9] = {0,0,0,0,0,0,0,0};
102
volatile unsigned char SenderOkay = 0;
102
volatile unsigned char SenderOkay = 0;
103
char MotorenEin = 0,StartTrigger = 0;
103
char MotorenEin = 0,StartTrigger = 0;
104
long HoehenWert = 0;
104
long HoehenWert = 0;
105
long SollHoehe = 0;
105
long SollHoehe = 0;
106
signed int AltitudeSetpointTrimming = 0;
106
signed int AltitudeSetpointTrimming = 0;
107
long FromNC_AltitudeSetpoint = 0;
107
long FromNC_AltitudeSetpoint = 0;
108
unsigned char FromNC_AltitudeSpeed = 0;
108
unsigned char FromNC_AltitudeSpeed = 0;
109
unsigned char carefree_old = 50; // to make the Beep when switching
109
unsigned char carefree_old = 50; // to make the Beep when switching
110
signed char WaypointTrimming = 0;
110
signed char WaypointTrimming = 0;
111
int CompassGierSetpoint = 0;
111
int CompassGierSetpoint = 0;
112
unsigned char CalibrationDone = 0;
112
unsigned char CalibrationDone = 0;
113
char NeueKompassRichtungMerken = 0;
113
char NeueKompassRichtungMerken = 0;
114
int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0;
114
int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0;
115
//float Ki =  FAKTOR_I;
115
//float Ki =  FAKTOR_I;
116
int Ki = 10300 / 33;
116
int Ki = 10300 / 33;
117
unsigned char Looping_Nick = 0,Looping_Roll = 0;
117
unsigned char Looping_Nick = 0,Looping_Roll = 0;
118
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
118
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
119
 
119
 
120
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
120
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
121
unsigned char Parameter_HoehenSchalter = 0;      // Wert : 0-250
121
unsigned char Parameter_HoehenSchalter = 0;      // Wert : 0-250
122
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
122
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
123
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
123
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
124
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
124
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
125
unsigned char Parameter_Hoehe_GPS_Z = 64;        // Wert : 0-250
125
unsigned char Parameter_Hoehe_GPS_Z = 64;        // Wert : 0-250
126
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
126
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
127
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
127
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
128
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
128
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
129
unsigned char Parameter_Gyro_Gier_P = 150;      // Wert : 10-250
129
unsigned char Parameter_Gyro_Gier_P = 150;      // Wert : 10-250
130
unsigned char Parameter_Gyro_Gier_I = 150;      // Wert : 10-250
130
unsigned char Parameter_Gyro_Gier_I = 150;      // Wert : 10-250
131
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
131
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
132
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
132
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
133
unsigned char Parameter_UserParam1 = 0;
133
unsigned char Parameter_UserParam1 = 0;
134
unsigned char Parameter_UserParam2 = 0;
134
unsigned char Parameter_UserParam2 = 0;
135
unsigned char Parameter_UserParam3 = 0;
135
unsigned char Parameter_UserParam3 = 0;
136
unsigned char Parameter_UserParam4 = 0;
136
unsigned char Parameter_UserParam4 = 0;
137
unsigned char Parameter_UserParam5 = 0;
137
unsigned char Parameter_UserParam5 = 0;
138
unsigned char Parameter_UserParam6 = 0;
138
unsigned char Parameter_UserParam6 = 0;
139
unsigned char Parameter_UserParam7 = 0;
139
unsigned char Parameter_UserParam7 = 0;
140
unsigned char Parameter_UserParam8 = 0;
140
unsigned char Parameter_UserParam8 = 0;
141
unsigned char Parameter_ServoNickControl = 100;
141
unsigned char Parameter_ServoNickControl = 100;
142
unsigned char Parameter_ServoRollControl = 100;
142
unsigned char Parameter_ServoRollControl = 100;
143
unsigned char Parameter_ServoNickComp = 50;
143
unsigned char Parameter_ServoNickComp = 50;
144
unsigned char Parameter_ServoRollComp = 85;
144
unsigned char Parameter_ServoRollComp = 85;
145
unsigned char Parameter_LoopGasLimit = 70;
145
unsigned char Parameter_LoopGasLimit = 70;
146
unsigned char Parameter_AchsKopplung1 = 90;
146
unsigned char Parameter_AchsKopplung1 = 90;
147
unsigned char Parameter_AchsKopplung2 = 65;
147
unsigned char Parameter_AchsKopplung2 = 65;
148
unsigned char Parameter_CouplingYawCorrection = 64;
148
unsigned char Parameter_CouplingYawCorrection = 64;
149
//unsigned char Parameter_AchsGegenKopplung1 = 0;
149
//unsigned char Parameter_AchsGegenKopplung1 = 0;
150
unsigned char Parameter_DynamicStability = 100;
150
unsigned char Parameter_DynamicStability = 100;
151
unsigned char Parameter_J16Bitmask;             // for the J16 Output
151
unsigned char Parameter_J16Bitmask;             // for the J16 Output
152
unsigned char Parameter_J16Timing;              // for the J16 Output
152
unsigned char Parameter_J16Timing;              // for the J16 Output
153
unsigned char Parameter_J17Bitmask;             // for the J17 Output
153
unsigned char Parameter_J17Bitmask;             // for the J17 Output
154
unsigned char Parameter_J17Timing;              // for the J17 Output
154
unsigned char Parameter_J17Timing;              // for the J17 Output
155
unsigned char Parameter_NaviGpsGain;
155
unsigned char Parameter_NaviGpsGain;
156
unsigned char Parameter_NaviGpsP;
156
unsigned char Parameter_NaviGpsP;
157
unsigned char Parameter_NaviGpsI;
157
unsigned char Parameter_NaviGpsI;
158
unsigned char Parameter_NaviGpsD;
158
unsigned char Parameter_NaviGpsD;
159
unsigned char Parameter_NaviGpsA;
159
unsigned char Parameter_NaviGpsA;
160
unsigned char Parameter_NaviOperatingRadius;
160
unsigned char Parameter_NaviOperatingRadius;
161
unsigned char Parameter_NaviWindCorrection;
161
unsigned char Parameter_NaviWindCorrection;
162
unsigned char Parameter_NaviSpeedCompensation;
162
unsigned char Parameter_NaviSpeedCompensation;
163
unsigned char Parameter_ExternalControl;
163
unsigned char Parameter_ExternalControl;
164
unsigned char Parameter_GlobalConfig;
164
unsigned char Parameter_GlobalConfig;
165
unsigned char Parameter_ExtraConfig;
165
unsigned char Parameter_ExtraConfig;
166
unsigned char Parameter_MaximumAltitude;
166
unsigned char Parameter_MaximumAltitude;
167
unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5;
167
unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5;
168
unsigned char CareFree = 0;
168
unsigned char CareFree = 0;
169
const 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}; // 15° steps
169
const 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}; // 15° steps
170
 
170
 
171
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
171
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
172
int MaxStickNick = 0,MaxStickRoll = 0;
172
int MaxStickNick = 0,MaxStickRoll = 0;
173
unsigned int  modell_fliegt = 0;
173
unsigned int  modell_fliegt = 0;
174
volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0;
174
volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0;
175
long GIER_GRAD_FAKTOR = 1291;
175
long GIER_GRAD_FAKTOR = 1291;
176
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
176
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
177
signed int tmp_motorwert[MAX_MOTORS];
177
signed int tmp_motorwert[MAX_MOTORS];
178
char VarioCharacter = ' ';
178
char VarioCharacter = ' ';
179
unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing
179
unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing
180
unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while
180
unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while
181
signed int Variance = 0;
181
signed int Variance = 0;
182
signed int CosAttitude; // for projection of hoover gas
182
signed int CosAttitude; // for projection of hoover gas
183
unsigned char ACC_AltitudeControl = 0;
183
unsigned char ACC_AltitudeControl = 0;
184
 
184
 
185
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
185
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
186
//  Debugwerte zuordnen
186
//  Debugwerte zuordnen
187
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
188
void CopyDebugValues(void)
188
void CopyDebugValues(void)
189
{
189
{
190
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
190
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
191
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
191
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
192
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
192
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
193
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
193
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
194
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
194
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
195
    DebugOut.Analog[5] = HoehenWert/10;
195
    DebugOut.Analog[5] = HoehenWert/10;
196
    DebugOut.Analog[6] = Aktuell_az;//AdWertAccHoch;//(Mess_Integral_Hoch / 512);
196
    DebugOut.Analog[6] = Aktuell_az;//AdWertAccHoch;//(Mess_Integral_Hoch / 512);
197
    DebugOut.Analog[8] = KompassValue;
197
    DebugOut.Analog[8] = KompassValue;
198
    DebugOut.Analog[9] = UBat;
198
    DebugOut.Analog[9] = UBat;
199
    DebugOut.Analog[10] = SenderOkay;
199
    DebugOut.Analog[10] = SenderOkay;
200
    DebugOut.Analog[11] = ErsatzKompassInGrad;
200
    DebugOut.Analog[11] = ErsatzKompassInGrad;
201
    DebugOut.Analog[12] = Motor[0].SetPoint;
201
    DebugOut.Analog[12] = Motor[0].SetPoint;
202
    DebugOut.Analog[13] = Motor[1].SetPoint;
202
    DebugOut.Analog[13] = Motor[1].SetPoint;
203
    DebugOut.Analog[14] = Motor[2].SetPoint;
203
    DebugOut.Analog[14] = Motor[2].SetPoint;
204
    DebugOut.Analog[15] = Motor[3].SetPoint;
204
    DebugOut.Analog[15] = Motor[3].SetPoint;
205
    DebugOut.Analog[20] = ServoNickValue;
205
    DebugOut.Analog[20] = ServoNickValue;
206
        DebugOut.Analog[21] = HoverGas;
206
        DebugOut.Analog[21] = HoverGas;
207
    DebugOut.Analog[22] = Capacity.ActualCurrent;
207
    DebugOut.Analog[22] = Capacity.ActualCurrent;
208
    DebugOut.Analog[23] = Capacity.UsedCapacity;
208
    DebugOut.Analog[23] = Capacity.UsedCapacity;
209
        DebugOut.Analog[24] = SollHoehe/10;    
209
        DebugOut.Analog[24] = SollHoehe/10;    
210
    DebugOut.Analog[27] = KompassSollWert;
210
    DebugOut.Analog[27] = KompassSollWert;
211
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
211
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
212
    DebugOut.Analog[30] = GPS_Nick;
212
    DebugOut.Analog[30] = GPS_Nick;
213
    DebugOut.Analog[31] = GPS_Roll;
213
    DebugOut.Analog[31] = GPS_Roll;
214
    if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe;
214
    if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe;
215
//DebugOut.Analog[16] = Variance;
215
//DebugOut.Analog[16] = Variance;
216
//DebugOut.Analog[17] = VarioMeter;
216
//DebugOut.Analog[17] = VarioMeter;
217
//DebugOut.Analog[18] = HoehenWertF;            
217
//DebugOut.Analog[18] = HoehenWertF;            
218
//DebugOut.Analog[25] = Parameter_Hoehe_P;
218
//DebugOut.Analog[25] = Parameter_Hoehe_P;
219
//DebugOut.Analog[26] = Parameter_Luftdruck_D;
219
//DebugOut.Analog[26] = Parameter_Luftdruck_D;
220
}
220
}
221
 
221
 
222
 
222
 
223
void Piep(unsigned char Anzahl, unsigned int dauer)
223
void Piep(unsigned char Anzahl, unsigned int dauer)
224
{
224
{
225
 unsigned int wait = 0;
225
 unsigned int wait = 0;
226
 if(MotorenEin) return; //auf keinen Fall im Flug!
226
 if(MotorenEin) return; //auf keinen Fall im Flug!
227
GRN_OFF;
227
GRN_OFF;
228
 while(Anzahl--)
228
 while(Anzahl--)
229
 {
229
 {
230
  beeptime = dauer;
230
  beeptime = dauer;
231
  wait = dauer;
231
  wait = dauer;
232
  while(beeptime || wait)
232
  while(beeptime || wait)
233
   {
233
   {
234
    if(UpdateMotor)
234
    if(UpdateMotor)
235
         {
235
         {
236
          UpdateMotor = 0;
236
          UpdateMotor = 0;
237
          if(!beeptime) wait--;
237
          if(!beeptime) wait--;
238
          LIBFC_Polling();
238
          LIBFC_Polling();
239
         };
239
         };
240
   }
240
   }
241
 }
241
 }
242
GRN_ON;
242
GRN_ON;
243
}
243
}
244
 
244
 
245
//############################################################################
245
//############################################################################
246
// Messwerte beim Ermitteln der Nullage
246
// Messwerte beim Ermitteln der Nullage
247
void CalibrierMittelwert(void)
247
void CalibrierMittelwert(void)
248
//############################################################################
248
//############################################################################
249
{
249
{
250
    unsigned char i;
250
    unsigned char i;
251
    if(PlatinenVersion == 13) SucheGyroOffset();
251
    if(PlatinenVersion == 13) SucheGyroOffset();
252
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
252
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
253
        ANALOG_OFF;
253
        ANALOG_OFF;
254
        MesswertNick = AdWertNick;
254
        MesswertNick = AdWertNick;
255
        MesswertRoll = AdWertRoll;
255
        MesswertRoll = AdWertRoll;
256
        MesswertGier = AdWertGier;
256
        MesswertGier = AdWertGier;
257
        Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick;
257
        Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick;
258
        Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll;
258
        Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll;
259
   // ADC einschalten
259
   // ADC einschalten
260
    ANALOG_ON;
260
    ANALOG_ON;
261
   for(i=0;i<8;i++)
261
   for(i=0;i<8;i++)
262
    {
262
    {
263
     int tmp;
263
     int tmp;
264
         tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127;
264
         tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127;
265
         LIMIT_MIN_MAX(tmp, 0, 255);
265
         LIMIT_MIN_MAX(tmp, 0, 255);
266
     if(Poti[i] > tmp) Poti[i]--;  else  if(Poti[i] < tmp) Poti[i]++;
266
     if(Poti[i] > tmp) Poti[i]--;  else  if(Poti[i] < tmp) Poti[i]++;
267
        }
267
        }
268
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
268
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
269
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
269
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
270
}
270
}
271
 
271
 
272
//############################################################################
272
//############################################################################
273
//  Nullwerte ermitteln
273
//  Nullwerte ermitteln
274
//  Parameter: 0 -> after switch on (ignore ACC-Z fault)
274
//  Parameter: 0 -> after switch on (ignore ACC-Z fault)
275
//  Parameter: 1 -> before Start
275
//  Parameter: 1 -> before Start
276
//  Parameter: 2 -> calibrate and store ACC
276
//  Parameter: 2 -> calibrate and store ACC
277
unsigned char SetNeutral(unsigned char AdjustmentMode)  // retuns: "sucess"
277
unsigned char SetNeutral(unsigned char AdjustmentMode)  // retuns: "sucess"
278
//############################################################################
278
//############################################################################
279
{
279
{
280
        unsigned char i, sucess = 1;
280
        unsigned char i, sucess = 1;
281
        unsigned int gier_neutral = 0, nick_neutral = 0, roll_neutral = 0, acc_z_neutral = 0;
281
        unsigned int gier_neutral = 0, nick_neutral = 0, roll_neutral = 0, acc_z_neutral = 0;
282
    VersionInfo.HardwareError[0] = 0;
282
    VersionInfo.HardwareError[0] = 0;
283
//    HEF4017Reset_ON;
283
//    HEF4017Reset_ON;
284
        NeutralAccX = 0;
284
        NeutralAccX = 0;
285
        NeutralAccY = 0;
285
        NeutralAccY = 0;
286
        NeutralAccZ = 0;
286
        NeutralAccZ = 0;
287
        NeutralAccZfine = 0;
287
        NeutralAccZfine = 0;
288
 
288
 
289
    AdNeutralNick = 0;
289
    AdNeutralNick = 0;
290
        AdNeutralRoll = 0;
290
        AdNeutralRoll = 0;
291
        AdNeutralGier = 0;
291
        AdNeutralGier = 0;
292
 
292
 
293
    Parameter_AchsKopplung1 = 0;
293
    Parameter_AchsKopplung1 = 0;
294
    Parameter_AchsKopplung2 = 0;
294
    Parameter_AchsKopplung2 = 0;
295
 
295
 
296
    ExpandBaro = 0;
296
    ExpandBaro = 0;
297
 
297
 
298
    CalibrierMittelwert();
298
    CalibrierMittelwert();
299
    Delay_ms_Mess(100);
299
    Delay_ms_Mess(100);
300
 
300
 
301
        CalibrierMittelwert();
301
        CalibrierMittelwert();
302
 
302
 
303
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
303
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
304
     {
304
     {
305
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
305
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
306
     }
306
     }
307
#define NEUTRAL_FILTER 32
307
#define NEUTRAL_FILTER 32
308
    for(i=0; i<NEUTRAL_FILTER; i++)
308
    for(i=0; i<NEUTRAL_FILTER; i++)
309
         {
309
         {
310
          Delay_ms_Mess(10);
310
          Delay_ms_Mess(10);
311
          gier_neutral += AdWertGier;
311
          gier_neutral += AdWertGier;
312
          nick_neutral += AdWertNick;
312
          nick_neutral += AdWertNick;
313
          roll_neutral += AdWertRoll;
313
          roll_neutral += AdWertRoll;
314
          acc_z_neutral += Aktuell_az;
314
          acc_z_neutral += Aktuell_az;
315
         }
315
         }
316
     AdNeutralNick = (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
316
     AdNeutralNick = (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
317
         AdNeutralRoll = (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
317
         AdNeutralRoll = (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
318
         AdNeutralGier = (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
318
         AdNeutralGier = (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
319
     NeutralAccZ = (acc_z_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
319
     NeutralAccZ = (acc_z_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
320
 
320
 
321
     StartNeutralRoll = AdNeutralRoll;
321
     StartNeutralRoll = AdNeutralRoll;
322
     StartNeutralNick = AdNeutralNick;
322
     StartNeutralNick = AdNeutralNick;
323
 
323
 
324
     if(AdjustmentMode == 2)
324
     if(AdjustmentMode == 2)
325
     {
325
     {
326
            NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
326
            NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
327
            NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
327
            NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
328
                // Save ACC neutral settings to eeprom
328
                // Save ACC neutral settings to eeprom
329
                SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX);
329
                SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX);
330
                SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY);
330
                SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY);
331
                SetParamWord(PID_ACC_TOP,  (uint16_t)NeutralAccZ);
331
                SetParamWord(PID_ACC_TOP,  (uint16_t)NeutralAccZ);
332
    }
332
    }
333
    else
333
    else
334
    {
334
    {
335
                // restore from eeprom
335
                // restore from eeprom
336
                NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK);
336
                NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK);
337
                NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL);
337
                NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL);
338
                // strange settings?
338
                // strange settings?
339
                if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048)/* || ((unsigned int) NeutralAccZ > 1024)*/)
339
                if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048)/* || ((unsigned int) NeutralAccZ > 1024)*/)
340
                {
340
                {
341
                        printf("\n\rACC not calibrated!\r\n");
341
                        printf("\n\rACC not calibrated!\r\n");
342
                        NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
342
                        NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
343
                        NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
343
                        NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
344
                        sucess = 0;
344
                        sucess = 0;
345
                }
345
                }
346
    }
346
    }
347
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
347
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
348
        MesswertNick = 0;
348
        MesswertNick = 0;
349
    MesswertRoll = 0;
349
    MesswertRoll = 0;
350
    MesswertGier = 0;
350
    MesswertGier = 0;
351
    Delay_ms_Mess(100);
351
    Delay_ms_Mess(100);
352
    Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick;
352
    Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick;
353
    Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll;
353
    Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll;
354
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
354
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
355
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
355
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
356
    Mess_IntegralNick = IntegralNick;
356
    Mess_IntegralNick = IntegralNick;
357
    Mess_IntegralRoll = IntegralRoll;
357
    Mess_IntegralRoll = IntegralRoll;
358
    Mess_Integral_Gier = 0;
358
    Mess_Integral_Gier = 0;
359
    StartLuftdruck = Luftdruck;
359
    StartLuftdruck = Luftdruck;
360
    VarioMeter = 0;
360
    VarioMeter = 0;
361
        SummenHoehe = 0;    Mess_Integral_Hoch = 0;
361
        SummenHoehe = 0;    Mess_Integral_Hoch = 0;
362
    KompassSollWert = KompassValue;
362
    KompassSollWert = KompassValue;
363
        KompassSignalSchlecht = 100;
363
        KompassSignalSchlecht = 100;
364
    beeptime = 50;
364
    beeptime = 50;
365
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
365
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
366
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
366
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
367
    ExternHoehenValue = 0;
367
    ExternHoehenValue = 0;
368
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
368
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
369
    GierGyroFehler = 0;
369
    GierGyroFehler = 0;
370
    LED_Init();
370
    LED_Init();
371
    FC_StatusFlags |= FC_STATUS_CALIBRATE;
371
    FC_StatusFlags |= FC_STATUS_CALIBRATE;
372
    FromNaviCtrl_Value.Kalman_K = -1;
372
    FromNaviCtrl_Value.Kalman_K = -1;
373
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
373
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
374
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
374
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
375
   for(i=0;i<8;i++)
375
   for(i=0;i<8;i++)
376
    {
376
    {
377
     Poti[i] =  PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127;
377
     Poti[i] =  PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127;
378
        }
378
        }
379
    SenderOkay = 100;
379
    SenderOkay = 100;
380
    if(ServoActive)
380
    if(ServoActive)
381
         {
381
         {
382
                DDRD  |=0x80; // enable J7 -> Servo signal
382
                DDRD  |=0x80; // enable J7 -> Servo signal
383
     }
383
     }
384
         else
384
         else
385
         {
385
         {
386
//      if(EE_Parameter.ServoCompInvert & SERVO_NICK_INV) NickServoValue = ((128 + 60) * 4 * 16); // neutral position = upper 1/4
386
//      if(EE_Parameter.ServoCompInvert & SERVO_NICK_INV) NickServoValue = ((128 + 60) * 4 * 16); // neutral position = upper 1/4
387
//        else    
387
//        else    
388
          NickServoValue = ((128 - 60) * 4 * 16); // neutral position = lower 1/4
388
          NickServoValue = ((128 - 60) * 4 * 16); // neutral position = lower 1/4
389
         }
389
         }
390
 
390
 
391
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
391
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
392
    signed int tilt1, tilt2;
392
    signed int tilt1, tilt2;
393
                tilt1 = (int)(IntegralNick/GIER_GRAD_FAKTOR);  // nick angle in deg
393
                tilt1 = (int)(IntegralNick/GIER_GRAD_FAKTOR);  // nick angle in deg
394
                tilt2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR);  // roll angle in deg
394
                tilt2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR);  // roll angle in deg
395
                tilt1 = (int16_t)ihypot(tilt1,tilt2);                   // tilt angle over all 
395
                tilt1 = (int16_t)ihypot(tilt1,tilt2);                   // tilt angle over all 
396
                CosAttitude = c_cos_8192(tilt1);                               
396
                CosAttitude = c_cos_8192(tilt1);                               
397
                NeutralAccZ = (long)((long) (NeutralAccZ - 512) * 8192 + 4096) / CosAttitude + 512;
397
                NeutralAccZ = (long)((long) (NeutralAccZ - 512) * 8192 + 4096) / CosAttitude + 512;
398
                if(tilt1 > 20) sucess = 0; // calibration must be within 20° Tilt angle 
398
                if(tilt1 > 20) sucess = 0; // calibration must be within 20° Tilt angle 
399
                if(AdjustmentMode != 0 && ACC_AltitudeControl) if((NeutralAccZ < 682 - 25) || (NeutralAccZ > 682 + 25)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; sucess = 0;};
399
                if(AdjustmentMode != 0 && ACC_AltitudeControl) if((NeutralAccZ < 682 - 25) || (NeutralAccZ > 682 + 25)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; sucess = 0;};
400
#else
400
#else
401
        NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP);
401
        NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP);
402
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
402
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
403
#endif
403
#endif
404
 
404
 
405
        if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; };
405
        if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; };
406
        if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; };
406
        if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; };
407
        if((AdNeutralGier < 150 * 2)  || (AdNeutralGier > 850 * 2))  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; };
407
        if((AdNeutralGier < 150 * 2)  || (AdNeutralGier > 850 * 2))  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; };
408
        if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; };
408
        if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; };
409
        if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; };
409
        if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; };
410
        if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; };
410
        if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; };
411
    if(VersionInfo.HardwareError[0]) sucess = 0;
411
    if(VersionInfo.HardwareError[0]) sucess = 0;
412
    carefree_old = 70;
412
    carefree_old = 70;
413
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
413
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
414
        LIBFC_HoTT_Clear();
414
        LIBFC_HoTT_Clear();
415
        ACC_AltitudeFusion(2); // initalisation
415
        ACC_AltitudeFusion(2); // initalisation
416
#endif
416
#endif
417
 return(sucess);
417
 return(sucess);
418
}
418
}
419
 
419
 
420
 
420
 
421
//############################################################################
421
//############################################################################
422
// Bearbeitet die Messwerte
422
// Bearbeitet die Messwerte
423
void Mittelwert(void)
423
void Mittelwert(void)
424
//############################################################################
424
//############################################################################
425
{
425
{
426
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
426
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
427
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
427
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
428
        signed long winkel_nick, winkel_roll;
428
        signed long winkel_nick, winkel_roll;
429
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
429
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
430
    MesswertNick = (signed int) AdWertNickFilter / 8;
430
    MesswertNick = (signed int) AdWertNickFilter / 8;
431
    MesswertRoll = (signed int) AdWertRollFilter / 8;
431
    MesswertRoll = (signed int) AdWertRollFilter / 8;
432
    RohMesswertNick = MesswertNick;
432
    RohMesswertNick = MesswertNick;
433
    RohMesswertRoll = MesswertRoll;
433
    RohMesswertRoll = MesswertRoll;
434
 
434
 
435
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
435
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
436
        Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L;
436
        Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L;
437
        Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L;
437
        Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L;
438
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
438
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
439
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
439
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
440
    NaviAccNick    += AdWertAccNick;
440
    NaviAccNick    += AdWertAccNick;
441
    NaviAccRoll    += AdWertAccRoll;
441
    NaviAccRoll    += AdWertAccRoll;
442
    NaviCntAcc++;
442
    NaviCntAcc++;
443
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
443
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
444
 
444
 
445
//++++++++++++++++++++++++++++++++++++++++++++++++
445
//++++++++++++++++++++++++++++++++++++++++++++++++
446
// ADC einschalten
446
// ADC einschalten
447
    ANALOG_ON;
447
    ANALOG_ON;
448
        AdReady = 0;
448
        AdReady = 0;
449
//++++++++++++++++++++++++++++++++++++++++++++++++
449
//++++++++++++++++++++++++++++++++++++++++++++++++
450
 
450
 
451
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
451
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
452
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
452
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
453
        else winkel_roll = Mess_IntegralRoll;
453
        else winkel_roll = Mess_IntegralRoll;
454
 
454
 
455
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
455
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
456
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
456
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
457
        else winkel_nick = Mess_IntegralNick;
457
        else winkel_nick = Mess_IntegralNick;
458
 
458
 
459
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
459
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
460
   Mess_Integral_Gier += MesswertGier;
460
   Mess_Integral_Gier += MesswertGier;
461
   ErsatzKompass += MesswertGier;
461
   ErsatzKompass += MesswertGier;
462
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
462
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
463
      if(!Looping_Nick && !Looping_Roll && (Parameter_GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
463
      if(!Looping_Nick && !Looping_Roll && (Parameter_GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
464
         {
464
         {
465
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
465
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
466
            tmpl3 *= Parameter_AchsKopplung2; //65
466
            tmpl3 *= Parameter_AchsKopplung2; //65
467
            tmpl3 /= 4096L;
467
            tmpl3 /= 4096L;
468
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
468
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
469
            tmpl4 *= Parameter_AchsKopplung2; //65
469
            tmpl4 *= Parameter_AchsKopplung2; //65
470
            tmpl4 /= 4096L;
470
            tmpl4 /= 4096L;
471
            KopplungsteilNickRoll = tmpl3;
471
            KopplungsteilNickRoll = tmpl3;
472
            KopplungsteilRollNick = tmpl4;
472
            KopplungsteilRollNick = tmpl4;
473
            tmpl4 -= tmpl3;
473
            tmpl4 -= tmpl3;
474
            ErsatzKompass += tmpl4;
474
            ErsatzKompass += tmpl4;
475
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
475
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
476
 
476
 
477
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
477
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
478
            tmpl *= Parameter_AchsKopplung1;  // 90
478
            tmpl *= Parameter_AchsKopplung1;  // 90
479
            tmpl /= 4096L;
479
            tmpl /= 4096L;
480
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
480
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
481
            tmpl2 *= Parameter_AchsKopplung1;
481
            tmpl2 *= Parameter_AchsKopplung1;
482
            tmpl2 /= 4096L;
482
            tmpl2 /= 4096L;
483
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
483
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
484
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
484
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
485
         }
485
         }
486
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
486
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
487
                        TrimRoll = tmpl - tmpl2 / 100L;
487
                        TrimRoll = tmpl - tmpl2 / 100L;
488
                        TrimNick = -tmpl2 + tmpl / 100L;
488
                        TrimNick = -tmpl2 + tmpl / 100L;
489
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
489
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
490
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
490
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
491
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
491
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
492
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
492
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
493
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
493
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
494
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
494
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
495
            if(Mess_IntegralRoll > Umschlag180Roll)
495
            if(Mess_IntegralRoll > Umschlag180Roll)
496
            {
496
            {
497
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
497
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
498
             Mess_IntegralRoll2 = Mess_IntegralRoll;
498
             Mess_IntegralRoll2 = Mess_IntegralRoll;
499
            }
499
            }
500
            if(Mess_IntegralRoll <-Umschlag180Roll)
500
            if(Mess_IntegralRoll <-Umschlag180Roll)
501
            {
501
            {
502
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
502
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
503
             Mess_IntegralRoll2 = Mess_IntegralRoll;
503
             Mess_IntegralRoll2 = Mess_IntegralRoll;
504
            }
504
            }
505
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
505
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
506
            Mess_IntegralNick2 += MesswertNick + TrimNick;
506
            Mess_IntegralNick2 += MesswertNick + TrimNick;
507
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
507
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
508
            if(Mess_IntegralNick > Umschlag180Nick)
508
            if(Mess_IntegralNick > Umschlag180Nick)
509
             {
509
             {
510
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
510
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
511
              Mess_IntegralNick2 = Mess_IntegralNick;
511
              Mess_IntegralNick2 = Mess_IntegralNick;
512
             }
512
             }
513
            if(Mess_IntegralNick <-Umschlag180Nick)
513
            if(Mess_IntegralNick <-Umschlag180Nick)
514
            {
514
            {
515
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
515
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
516
             Mess_IntegralNick2 = Mess_IntegralNick;
516
             Mess_IntegralNick2 = Mess_IntegralNick;
517
            }
517
            }
518
 
518
 
519
    Integral_Gier  = Mess_Integral_Gier;
519
    Integral_Gier  = Mess_Integral_Gier;
520
    IntegralNick = Mess_IntegralNick;
520
    IntegralNick = Mess_IntegralNick;
521
    IntegralRoll = Mess_IntegralRoll;
521
    IntegralRoll = Mess_IntegralRoll;
522
    IntegralNick2 = Mess_IntegralNick2;
522
    IntegralNick2 = Mess_IntegralNick2;
523
    IntegralRoll2 = Mess_IntegralRoll2;
523
    IntegralRoll2 = Mess_IntegralRoll2;
524
 
524
 
525
#define D_LIMIT 128
525
#define D_LIMIT 128
526
 
526
 
527
   MesswertNick = HiResNick / 8;
527
   MesswertNick = HiResNick / 8;
528
   MesswertRoll = HiResRoll / 8;
528
   MesswertRoll = HiResRoll / 8;
529
 
529
 
530
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
530
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
531
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
531
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
532
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
532
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
533
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
533
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
534
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
534
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
535
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
535
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
536
 
536
 
537
  if(Parameter_Gyro_D)
537
  if(Parameter_Gyro_D)
538
  {
538
  {
539
   d2Nick = HiResNick - oldNick;
539
   d2Nick = HiResNick - oldNick;
540
   oldNick = (oldNick + HiResNick)/2;
540
   oldNick = (oldNick + HiResNick)/2;
541
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
541
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
542
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
542
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
543
 
543
 
544
   d2Roll = HiResRoll - oldRoll;
544
   d2Roll = HiResRoll - oldRoll;
545
   oldRoll = (oldRoll + HiResRoll)/2;
545
   oldRoll = (oldRoll + HiResRoll)/2;
546
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
546
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
547
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
547
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
548
 
548
 
549
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
549
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
550
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
550
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
551
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
551
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
552
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
552
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
553
  }
553
  }
554
 
554
 
555
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
555
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
556
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
556
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
557
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
557
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
558
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
558
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
559
 
559
 
560
  if(Parameter_GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
560
  if(Parameter_GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
561
  {
561
  {
562
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
562
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
563
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
563
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
564
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
564
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
565
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
565
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
566
  }
566
  }
567
}
567
}
568
 
568
 
569
//############################################################################
569
//############################################################################
570
// Senden der Motorwerte per I2C-Bus
570
// Senden der Motorwerte per I2C-Bus
571
void SendMotorData(void)
571
void SendMotorData(void)
572
//############################################################################
572
//############################################################################
573
{
573
{
574
 unsigned char i;
574
 unsigned char i;
575
    if(!MotorenEin)
575
    if(!MotorenEin)
576
        {
576
        {
577
         FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY);
577
         FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY);
578
                 FC_StatusFlags2 &= ~FC_STATUS2_WAIT_FOR_TAKEOFF;
578
                 FC_StatusFlags2 &= ~FC_STATUS2_WAIT_FOR_TAKEOFF;
579
                 for(i=0;i<MAX_MOTORS;i++)
579
                 for(i=0;i<MAX_MOTORS;i++)
580
                  {
580
                  {
581
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
581
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
582
                   Motor[i].SetPoint = MotorTest[i];
582
                   Motor[i].SetPoint = MotorTest[i];
583
                   Motor[i].SetPointLowerBits = 0;
583
                   Motor[i].SetPointLowerBits = 0;
584
/*
584
/*
585
 Motor[i].SetPoint = MotorTest[i] / 4;            // testing the high resolution
585
 Motor[i].SetPoint = MotorTest[i] / 4;            // testing the high resolution
586
 Motor[i].SetPointLowerBits = MotorTest[i] % 4;
586
 Motor[i].SetPointLowerBits = MotorTest[i] % 4;
587
*/
587
*/
588
                  }
588
                  }
589
          if(PC_MotortestActive) PC_MotortestActive--;
589
          if(PC_MotortestActive) PC_MotortestActive--;
590
        }
590
        }
591
        else FC_StatusFlags |= FC_STATUS_MOTOR_RUN;
591
        else FC_StatusFlags |= FC_STATUS_MOTOR_RUN;
592
 
592
 
593
    if(I2C_TransferActive)
593
    if(I2C_TransferActive)
594
         {
594
         {
595
          I2C_TransferActive = 0; // enable for the next time
595
          I2C_TransferActive = 0; // enable for the next time
596
         }
596
         }
597
        else
597
        else
598
    {
598
    {
599
     motor_write = 0;
599
     motor_write = 0;
600
     I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode
600
     I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode
601
        }
601
        }
602
}
602
}
603
 
603
 
604
unsigned char GetChannelValue(unsigned char ch) // gives the unsigned value of the channel
604
unsigned char GetChannelValue(unsigned char ch) // gives the unsigned value of the channel
605
{
605
{
606
 int tmp2;
606
 int tmp2;
607
 if(ch == 0) return(0);
607
 if(ch == 0) return(0);
608
 tmp2 = PPM_in[ch] + 127;
608
 tmp2 = PPM_in[ch] + 127;
609
 if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0;
609
 if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0;
610
 return(tmp2);   
610
 return(tmp2);   
611
}
611
}
612
 
612
 
613
//############################################################################
613
//############################################################################
614
// Trägt ggf. das Poti als Parameter ein
614
// Trägt ggf. das Poti als Parameter ein
615
void ParameterZuordnung(void)
615
void ParameterZuordnung(void)
616
//############################################################################
616
//############################################################################
617
{
617
{
618
 unsigned char tmp,i;
618
 unsigned char tmp,i;
619
  for(i=0;i<8;i++)
619
  for(i=0;i<8;i++)
620
    {
620
    {
621
     int tmp2;
621
     int tmp2;
622
         tmp = EE_Parameter.Kanalbelegung[K_POTI1 + i];
622
         tmp = EE_Parameter.Kanalbelegung[K_POTI1 + i];
623
         tmp2 = PPM_in[tmp] + 127;
623
         tmp2 = PPM_in[tmp] + 127;
624
         if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0;
624
         if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0;
625
 
625
 
626
         if(tmp == 25) Poti[i] = tmp2; // 25 = WaypointEvent channel -> no filter
626
         if(tmp == 25) Poti[i] = tmp2; // 25 = WaypointEvent channel -> no filter
627
         else
627
         else
628
     if(tmp2 != Poti[i])
628
     if(tmp2 != Poti[i])
629
          {
629
          {
630
           Poti[i] += (tmp2 - Poti[i]) / 4;
630
           Poti[i] += (tmp2 - Poti[i]) / 4;
631
       if(Poti[i] > tmp2) Poti[i]--;
631
       if(Poti[i] > tmp2) Poti[i]--;
632
           else Poti[i]++;
632
           else Poti[i]++;
633
          }
633
          }
634
        }
634
        }
635
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
635
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
636
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
636
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
637
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
637
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
638
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,5,255);
638
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,5,255);
639
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,5,255);
639
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,5,255);
640
 
640
 
641
 if(EE_Parameter.Servo3 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;}       // Out1 (J16)
641
 if(EE_Parameter.Servo3 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;}       // Out1 (J16)
642
 else if(EE_Parameter.Servo3 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;}
642
 else if(EE_Parameter.Servo3 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;}
643
 else CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3);
643
 else CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3);
644
 
644
 
645
 if(EE_Parameter.Servo4 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;}
645
 if(EE_Parameter.Servo4 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;}
646
 else if(EE_Parameter.Servo4 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;}  // Out2 (J17)
646
 else if(EE_Parameter.Servo4 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;}  // Out2 (J17)
647
 else CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4);
647
 else CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4);
648
 CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5);
648
 CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5);
649
 Parameter_HoehenSchalter = GetChannelValue(EE_Parameter.HoeheChannel);
649
 Parameter_HoehenSchalter = GetChannelValue(EE_Parameter.HoeheChannel);
650
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung);
650
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung);
651
 CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z);
651
 CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z);
652
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung);
652
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung);
653
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I);
653
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I);
654
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D);
654
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D);
655
 CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P);
655
 CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P);
656
 CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I);
656
 CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I);
657
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor);
657
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor);
658
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1);
658
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1);
659
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2);
659
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2);
660
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3);
660
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3);
661
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4);
661
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4);
662
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5);
662
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5);
663
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6);
663
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6);
664
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7);
664
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7);
665
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8);
665
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8);
666
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl);
666
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl);
667
 CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl);
667
 CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl);
668
 CHK_POTI(Parameter_ServoNickComp,EE_Parameter.ServoNickComp);
668
 CHK_POTI(Parameter_ServoNickComp,EE_Parameter.ServoNickComp);
669
 CHK_POTI(Parameter_ServoRollComp,EE_Parameter.ServoRollComp);
669
 CHK_POTI(Parameter_ServoRollComp,EE_Parameter.ServoRollComp);
670
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit);
670
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit);
671
 CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1);
671
 CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1);
672
 CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2);
672
 CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2);
673
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection);
673
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection);
674
 CHK_POTI(Parameter_MaximumAltitude,EE_Parameter.MaxAltitude);
674
 CHK_POTI(Parameter_MaximumAltitude,EE_Parameter.MaxAltitude);
675
 if((NC_To_FC_MaxAltitude && NC_To_FC_MaxAltitude < Parameter_MaximumAltitude) || Parameter_MaximumAltitude == 0) Parameter_MaximumAltitude = NC_To_FC_MaxAltitude;
675
 if((NC_To_FC_MaxAltitude && NC_To_FC_MaxAltitude < Parameter_MaximumAltitude) || Parameter_MaximumAltitude == 0) Parameter_MaximumAltitude = NC_To_FC_MaxAltitude;
676
 Parameter_GlobalConfig = EE_Parameter.GlobalConfig;
676
 Parameter_GlobalConfig = EE_Parameter.GlobalConfig;
677
 Parameter_ExtraConfig = EE_Parameter.ExtraConfig;
677
 Parameter_ExtraConfig = EE_Parameter.ExtraConfig;
678
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
678
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
679
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability);
679
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability);
680
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl);
680
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl);
681
 Ki = 10300 / (Parameter_I_Faktor + 1);
681
 Ki = 10300 / (Parameter_I_Faktor + 1);
682
 MAX_GAS = EE_Parameter.Gas_Max;
682
 MAX_GAS = EE_Parameter.Gas_Max;
683
 MIN_GAS = EE_Parameter.Gas_Min;
683
 MIN_GAS = EE_Parameter.Gas_Min;
684
 
684
 
685
 if(EE_Parameter.CareFreeChannel)
685
 if(EE_Parameter.CareFreeChannel)
686
   {
686
   {
687
        CareFree = 1;
687
        CareFree = 1;
688
        if(PPM_in[EE_Parameter.CareFreeChannel] < -64) CareFree = 0;
688
        if(PPM_in[EE_Parameter.CareFreeChannel] < -64) CareFree = 0;
689
//    if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; 
689
//    if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; 
690
    if(carefree_old != CareFree)
690
    if(carefree_old != CareFree)
691
    {
691
    {
692
      if(carefree_old < 3)
692
      if(carefree_old < 3)
693
           {
693
           {
694
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
694
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
695
                if(CareFree) { beeptime = 1500;  if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; }
695
                if(CareFree) { beeptime = 1500;  if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; }
696
            else { beeptime = 200;  if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; }
696
            else { beeptime = 200;  if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; }
697
#else
697
#else
698
                if(CareFree) beeptime = 1500;
698
                if(CareFree) beeptime = 1500;
699
            else beeptime = 200;
699
            else beeptime = 200;
700
#endif
700
#endif
701
                NeueKompassRichtungMerken = 5;
701
                NeueKompassRichtungMerken = 5;
702
        carefree_old = CareFree;
702
        carefree_old = CareFree;
703
           } else carefree_old--;
703
           } else carefree_old--;
704
        }  
704
        }  
705
        if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= FC_ERROR0_CAREFREE; //else VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE;
705
        if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= FC_ERROR0_CAREFREE; //else VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE;
706
   }
706
   }
707
   else
707
   else
708
   {
708
   {
709
    CareFree = 0;
709
    CareFree = 0;
710
        carefree_old = 10;
710
        carefree_old = 10;
711
   }   
711
   }   
712
 
712
 
713
 if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert
713
 if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert
714
        {
714
        {
715
         beeptime = 15000;
715
         beeptime = 15000;
716
         BeepMuster = 0xA400;
716
         BeepMuster = 0xA400;
717
         CareFree = 0;
717
         CareFree = 0;
718
    }
718
    }
719
 if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; /*if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;*/} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE;
719
 if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; /*if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;*/} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE;
720
}
720
}
721
 
721
 
722
//############################################################################
722
//############################################################################
723
//
723
//
724
void MotorRegler(void)
724
void MotorRegler(void)
725
//############################################################################
725
//############################################################################
726
{
726
{
727
         int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2;
727
         int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2;
728
         int GierMischanteil,GasMischanteil;
728
         int GierMischanteil,GasMischanteil;
729
     static long sollGier = 0,tmp_long,tmp_long2;
729
     static long sollGier = 0,tmp_long,tmp_long2;
730
     static long IntegralFehlerNick = 0;
730
     static long IntegralFehlerNick = 0;
731
     static long IntegralFehlerRoll = 0;
731
     static long IntegralFehlerRoll = 0;
732
         static unsigned int RcLostTimer;
732
         static unsigned int RcLostTimer;
733
         static unsigned char delay_neutral = 0;
733
         static unsigned char delay_neutral = 0;
734
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
734
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
735
         static signed char move_safety_switch = 0;
735
         static signed char move_safety_switch = 0;
736
     static long ausgleichNick, ausgleichRoll;
736
     static long ausgleichNick, ausgleichRoll;
737
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
737
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
738
         unsigned char i;
738
         unsigned char i;
739
        Mittelwert();
739
        Mittelwert();
740
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
740
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
741
// Gaswert ermitteln
741
// Gaswert ermitteln
742
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
742
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
743
  if(!(FC_StatusFlags & (FC_STATUS_EMERGENCY_LANDING | FC_STATUS2_RC_FAILSAVE_ACTIVE)))
743
  if(!(FC_StatusFlags & (FC_STATUS_EMERGENCY_LANDING | FC_STATUS2_RC_FAILSAVE_ACTIVE)))
744
   {
744
   {
745
        if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE)
745
        if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE)
746
        {
746
        {
747
     if(HoverGas && HoverGas < 150 * STICK_GAIN)
747
     if(HoverGas && HoverGas < 150 * STICK_GAIN)
748
           {
748
           {
749
                HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas
749
                HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas
750
           }
750
           }
751
      else HooverGasEmergencyPercent = 45;  // default if the Hoovergas was could not calculated yet
751
      else HooverGasEmergencyPercent = 45;  // default if the Hoovergas was could not calculated yet
752
    } else HooverGasEmergencyPercent = EE_Parameter.NotGas;
752
    } else HooverGasEmergencyPercent = EE_Parameter.NotGas;
753
   }
753
   }
754
   if(GasIsZeroCnt == 30000)  // in that case we have RC-Lost, but the MK is probably landed
754
   if(GasIsZeroCnt == 30000)  // in that case we have RC-Lost, but the MK is probably landed
755
    {
755
    {
756
         StickGas = 0; // Hold Gas down in that case 
756
         StickGas = 0; // Hold Gas down in that case 
757
         HooverGasEmergencyPercent = MIN_GAS;
757
         HooverGasEmergencyPercent = MIN_GAS;
758
        }
758
        }
759
        GasMischanteil = StickGas;
759
        GasMischanteil = StickGas;
760
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
760
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
761
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
761
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
762
// Empfang schlecht
762
// Empfang schlecht
763
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
763
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
764
   if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE))
764
   if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE))
765
        {
765
        {
766
        if(RcLostTimer) RcLostTimer--;
766
        if(RcLostTimer) RcLostTimer--;
767
        else
767
        else
768
         {
768
         {
769
          MotorenEin = 0;
769
          MotorenEin = 0;
770
                  modell_fliegt = 0;
770
                  modell_fliegt = 0;
771
          FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY);
771
          FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY);
772
         }
772
         }
773
        ROT_ON;
773
        ROT_ON;
774
        if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100)  // wahrscheinlich in der Luft --> langsam absenken
774
        if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100)  // wahrscheinlich in der Luft --> langsam absenken
775
            {
775
            {
776
            GasMischanteil = HooverGasEmergencyPercent;
776
            GasMischanteil = HooverGasEmergencyPercent;
777
            FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING;
777
            FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING;
778
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
778
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
779
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
779
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
780
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
780
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
781
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
781
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
782
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
782
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
783
            }
783
            }
784
         else
784
         else
785
                    {
785
                    {
786
                          MotorenEin = 0;
786
                          MotorenEin = 0;
787
                        }  
787
                        }  
788
        }
788
        }
789
        else
789
        else
790
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
790
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
791
// Emfang gut
791
// Emfang gut
792
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
792
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
793
        if(SenderOkay > 140)
793
        if(SenderOkay > 140)
794
            {
794
            {
795
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
795
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
796
                     static unsigned int trigger = 0;
796
                     static unsigned int trigger = 1000;
797
                         static unsigned char old_switch = 100;
797
                         static unsigned char old_switch = 100;
798
                        if(EE_Parameter.StartLandChannel && EE_Parameter.LandingSpeed)
798
                        if(EE_Parameter.StartLandChannel && EE_Parameter.LandingSpeed)
799
                        {
799
                        {
800
                                if(PPM_in[EE_Parameter.StartLandChannel] > 50)
800
                                if(PPM_in[EE_Parameter.StartLandChannel] > 50)
801
                                {
801
                                {
802
                                 if(old_switch == 50) if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) { FC_StatusFlags2 |= FC_STATUS2_AUTO_STARTING; SpeakHoTT = SPEAK_RISING;}
802
                                 if(old_switch == 50) if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) { FC_StatusFlags2 |= FC_STATUS2_AUTO_STARTING; SpeakHoTT = SPEAK_RISING;}
803
                                 FC_StatusFlags2 &= ~FC_STATUS2_AUTO_LANDING;
803
                                 FC_StatusFlags2 &= ~FC_STATUS2_AUTO_LANDING;
804
                                 old_switch = 150;
804
                                 old_switch = 150;
805
                                }
805
                                }
806
                                else
806
                                else
807
                                if(PPM_in[EE_Parameter.StartLandChannel] < -50)
807
                                if(PPM_in[EE_Parameter.StartLandChannel] < -50)
808
                                {
808
                                {
809
                                 if(old_switch == 150) { FC_StatusFlags2 |= FC_STATUS2_AUTO_LANDING; SpeakHoTT = SPEAK_SINKING;}
809
                                 if(old_switch == 150) { FC_StatusFlags2 |= FC_STATUS2_AUTO_LANDING; SpeakHoTT = SPEAK_SINKING;}
810
                                 FC_StatusFlags2 &= ~FC_STATUS2_AUTO_STARTING;
810
                                 FC_StatusFlags2 &= ~FC_STATUS2_AUTO_STARTING;
811
                                 old_switch = 50;
811
                                 old_switch = 50;
812
                                }
812
                                }
813
                                else
813
                                else
814
                                {
814
                                {
815
                                 FC_StatusFlags2 &= ~(FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING);
815
                                 FC_StatusFlags2 &= ~(FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING);
816
                                }
816
                                }
817
                        }
817
                        }
818
#endif
818
#endif
819
                        FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING;
819
                        FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING;
820
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
820
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
821
            if(GasMischanteil > 40 && MotorenEin)
821
            if(GasMischanteil > 40 && MotorenEin)
822
                {
822
                {
823
                if(modell_fliegt < 0xffff) modell_fliegt++;
823
                if(modell_fliegt < 0xffff) modell_fliegt++;
824
                }
824
                }
825
            if((modell_fliegt < 256))
825
            if((modell_fliegt < 256))
826
             {
826
             {
827
                SummeNick = 0;
827
                SummeNick = 0;
828
                SummeRoll = 0;
828
                SummeRoll = 0;
829
                sollGier = 0;
829
                sollGier = 0;
830
                Mess_Integral_Gier = 0;
830
                Mess_Integral_Gier = 0;
831
                                FC_StatusFlags2 |= FC_STATUS2_WAIT_FOR_TAKEOFF;
831
                                FC_StatusFlags2 |= FC_STATUS2_WAIT_FOR_TAKEOFF;
832
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
832
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
833
                                old_switch = 100;
833
                                old_switch = 100;
834
#endif
834
#endif
835
             }
835
             }
836
                        else
836
                        else
837
                         {
837
                         {
838
               FC_StatusFlags |= FC_STATUS_FLY;
838
               FC_StatusFlags |= FC_STATUS_FLY;
839
                           if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF)
839
                           if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF)
840
                           {
840
                           {
841
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
841
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
842
                                if((NC_To_FC_Flags & NC_TO_FC_AUTOSTART || FC_StatusFlags2 & FC_STATUS2_AUTO_STARTING) && (VarioCharacter == '=') && ACC_AltitudeControl)
842
                                if((NC_To_FC_Flags & NC_TO_FC_AUTOSTART || FC_StatusFlags2 & FC_STATUS2_AUTO_STARTING) && (VarioCharacter == '=') && ACC_AltitudeControl)
843
                                {
843
                                {
844
                                   FromNC_AltitudeSpeed = 80;
844
                                   FromNC_AltitudeSpeed = 80;
845
                                   FromNC_AltitudeSetpoint = 500;
845
                                   FromNC_AltitudeSetpoint = 500;
846
                                   SollHoehe = 500;
846
                                   SollHoehe = 500;
847
                                   trigger = 1000;
847
                                   trigger = 1000;
848
                                   if(NC_To_FC_Flags & NC_TO_FC_AUTOSTART) SpeakHoTT = SPEAK_NEXT_WP;
848
                                   if(NC_To_FC_Flags & NC_TO_FC_AUTOSTART) SpeakHoTT = SPEAK_NEXT_WP;
849
/*                                 if(StartTrigger != 2)
849
/*                                 if(StartTrigger != 2)
850
                                                {
850
                                                {
851
                                                 StartTrigger = 1;
851
                                                 StartTrigger = 1;
852
                                                 if(HoverGas < STICK_GAIN * 35) HoverGas = STICK_GAIN * 35;
852
                                                 if(HoverGas < STICK_GAIN * 35) HoverGas = STICK_GAIN * 35;
853
                                                }
853
                                                }
854
*/
854
*/
855
                            }
855
                            }
856
//                              else FC_StatusFlags2 &= ~(FC_STATUS2_AUTO_STARTING);
856
//                              else FC_StatusFlags2 &= ~(FC_STATUS2_AUTO_STARTING);
857
#endif
857
#endif
858
                            if(HoehenWertF > 150 || HoehenWert < -350 || !(Parameter_GlobalConfig & CFG_HOEHENREGELUNG))
858
                            if(HoehenWertF > 150 || HoehenWert < -350 || !(Parameter_GlobalConfig & CFG_HOEHENREGELUNG))
859
                                 {
859
                                 {
860
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
860
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
861
                                  trigger = 1000;
861
                                  trigger = 1000;
862
if(FC_StatusFlags2 & FC_STATUS2_AUTO_STARTING) { FromNC_AltitudeSpeed = 0; SollHoehe = 300;/*HoehenWertF + 100;*/}
862
if(FC_StatusFlags2 & FC_STATUS2_AUTO_STARTING) { FromNC_AltitudeSpeed = 0; SollHoehe = 300;/*HoehenWertF + 100;*/}
863
else SpeakHoTT = SPEAK_RISING;
863
else SpeakHoTT = SPEAK_RISING;
864
#endif
864
#endif
865
                                  FC_StatusFlags2 &= ~(FC_STATUS2_WAIT_FOR_TAKEOFF | FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING);
865
                                  FC_StatusFlags2 &= ~(FC_STATUS2_WAIT_FOR_TAKEOFF | FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING);
866
                                 }
866
                                 }
867
                SummeNick = 0;
867
                SummeNick = 0;
868
                SummeRoll = 0;
868
                SummeRoll = 0;
869
                Mess_Integral_Gier = 0;
869
                Mess_Integral_Gier = 0;
870
//                              sollGier = 0;
870
//                              sollGier = 0;
871
                                if(modell_fliegt > 1000) modell_fliegt = 1000;  // for the Hooverpoint-Estimation
871
                                if(modell_fliegt > 1000) modell_fliegt = 1000;  // for the Hooverpoint-Estimation
872
                           }
872
                           }
873
                                else  // Flying mode
873
                                else  // Flying mode
874
                                {
874
                                {
875
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
875
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
876
                                if((FC_StatusFlags2 & FC_STATUS2_AUTO_LANDING) && (VarioCharacter == 'v' || VarioCharacter == '=') && ACC_AltitudeControl)
876
                                if((FC_StatusFlags2 & FC_STATUS2_AUTO_LANDING) && (VarioCharacter == 'v' || VarioCharacter == '=') && ACC_AltitudeControl)
877
                                {
877
                                {
878
                                   FromNC_AltitudeSpeed = EE_Parameter.LandingSpeed;
878
                                   FromNC_AltitudeSpeed = EE_Parameter.LandingSpeed;
879
                                   FromNC_AltitudeSetpoint = -20000;
879
                                   FromNC_AltitudeSetpoint = -20000;
880
                            }
880
                            }
881
                                 if(trigger < 1000)
881
                                 if(trigger < 1000)
882
                                        {
882
                                        {
883
                                                trigger++;
883
                                                trigger++;
884
                                                SummeNick = 0;
884
                                                SummeNick = 0;
885
                                                SummeRoll = 0;
885
                                                SummeRoll = 0;
886
                                                Mess_Integral_Gier = 0;
886
                                                Mess_Integral_Gier = 0;
887
                                                SollHoehe = HoehenWertF - 300;
887
                                                SollHoehe = HoehenWertF - 300;
-
 
888
                                                if(trigger == 1000 && FC_StatusFlags2 & FC_STATUS2_AUTO_LANDING && VarioCharacter != '+')
-
 
889
                                                 {
-
 
890
                                                   FC_StatusFlags2 &= ~FC_STATUS2_AUTO_LANDING;
-
 
891
                                                   FC_StatusFlags2 |= FC_STATUS2_WAIT_FOR_TAKEOFF;  // go back into starting state
-
 
892
                                             } 
888
                                        }
893
                                        }
889
                                 else
894
                                 else
890
                                 if(ACC_AltitudeControl && (VarioCharacter == 'v' || VarioCharacter == '-') && HoehenWert < 1000 /*&& FromNC_AltitudeSetpoint < 0*/)
895
                                 if(ACC_AltitudeControl && (VarioCharacter == 'v' || VarioCharacter == '-') && HoehenWert < 1000 /*&& FromNC_AltitudeSetpoint < 0*/)
891
                                  {
896
                                  {
-
 
897
                                        if(Aktuell_az > 940)
-
 
898
                                         {
-
 
899
                                          trigger = 0;
892
                                        if(Aktuell_az > 940) { trigger = 0; SpeakHoTT = SPEAK_LANDING; };
900
                                          SpeakHoTT = SPEAK_LANDING;
-
 
901
                                         };
893
                                  }
902
                                  }
894
#endif
903
#endif
895
               }
904
               }
896
                          }  // end of: modell_fliegt > 256                        
905
                          }  // end of: modell_fliegt > 256                        
897
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
906
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
898
                {
907
                {
899
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
908
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
900
// auf Nullwerte kalibrieren
909
// auf Nullwerte kalibrieren
901
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
910
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
902
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
911
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
903
                    {
912
                    {
904
                    if(++delay_neutral > 200)  // nicht sofort
913
                    if(++delay_neutral > 200)  // nicht sofort
905
                        {
914
                        {
906
                        delay_neutral = 0;
915
                        delay_neutral = 0;
907
                        modell_fliegt = 0;
916
                        modell_fliegt = 0;
908
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
917
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
909
                        {
918
                        {
910
                         unsigned char setting=1;
919
                         unsigned char setting=1;
911
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
920
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
912
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
921
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
913
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
922
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
914
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
923
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
915
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
924
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
916
                         SetActiveParamSet(setting);  // aktiven Datensatz merken
925
                         SetActiveParamSet(setting);  // aktiven Datensatz merken
917
                        }
926
                        }
918
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
927
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
919
                          {
928
                          {
920
                           WinkelOut.CalcState = 1;
929
                           WinkelOut.CalcState = 1;
921
                                                   CalibrationDone = 0;
930
                                                   CalibrationDone = 0;
922
                           beeptime = 1000;
931
                           beeptime = 1000;
923
                          }
932
                          }
924
                          else
933
                          else
925
                          {
934
                          {
926
                               ParamSet_ReadFromEEProm(ActiveParamSet);
935
                               ParamSet_ReadFromEEProm(ActiveParamSet);
927
                               LipoDetection(0);
936
                               LipoDetection(0);
928
                                                   LIBFC_ReceiverInit(EE_Parameter.Receiver);
937
                                                   LIBFC_ReceiverInit(EE_Parameter.Receiver);
929
                           if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
938
                           if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
930
                            {
939
                            {
931
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
940
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
932
                            }
941
                            }
933
//                                                 ServoActive = 0;
942
//                                                 ServoActive = 0;
934
                           CalibrationDone = SetNeutral(1);
943
                           CalibrationDone = SetNeutral(1);
935
                                                   ServoActive = 1;
944
                                                   ServoActive = 1;
936
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
945
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
937
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
946
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
938
                                                   if(VersionInfo.HardwareError[0]) SpeakHoTT = SPEAK_ERR_SENSOR;
947
                                                   if(VersionInfo.HardwareError[0]) SpeakHoTT = SPEAK_ERR_SENSOR;
939
                                                   else
948
                                                   else
940
                                                   if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION;
949
                                                   if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION;
941
                                                   else SpeakHoTT = SPEAK_CALIBRATE;
950
                                                   else SpeakHoTT = SPEAK_CALIBRATE;
942
                                                   ShowSettingName = 20; // for HoTT & Jeti (muss eine gerade Zahl sein)
951
                                                   ShowSettingNameTime = 5; // for HoTT & Jeti 
943
#endif
952
#endif
944
                           Piep(ActiveParamSet,120);
953
                           Piep(ActiveParamSet,120);
945
                         }
954
                         }
946
                        }
955
                        }
947
                    }
956
                    }
948
                 else
957
                 else
949
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
958
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
950
                    {
959
                    {
951
                    if(++delay_neutral > 200)  // nicht sofort
960
                    if(++delay_neutral > 200)  // nicht sofort
952
                        {
961
                        {
953
                        MotorenEin = 0;
962
                        MotorenEin = 0;
954
                        delay_neutral = 0;
963
                        delay_neutral = 0;
955
                        modell_fliegt = 0;
964
                        modell_fliegt = 0;
956
                        CalibrationDone = SetNeutral(2); // store ACC values into EEPROM
965
                        CalibrationDone = SetNeutral(2); // store ACC values into EEPROM
957
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
966
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
958
                                                   if(VersionInfo.HardwareError[0]) SpeakHoTT = SPEAK_ERR_SENSOR;
967
                                                   if(VersionInfo.HardwareError[0]) SpeakHoTT = SPEAK_ERR_SENSOR;
959
                                                   else
968
                                                   else
960
                                                   if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION;
969
                                                   if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION;
961
                                                   else SpeakHoTT = SPEAK_CALIBRATE;
970
                                                   else SpeakHoTT = SPEAK_CALIBRATE;
962
#endif
971
#endif
963
                        Piep(ActiveParamSet,120);
972
                        Piep(ActiveParamSet,120);
964
                        }
973
                        }
965
                    }
974
                    }
966
                 else delay_neutral = 0;
975
                 else delay_neutral = 0;
967
                }
976
                }
968
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
977
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
969
// Gas ist unten
978
// Gas ist unten
970
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
979
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
971
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < -100)
980
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < -100)
972
                {
981
                {
973
                                        if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100;
982
                                        if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100;
974
                                        else
983
                                        else
975
                                        if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100;
984
                                        if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100;
976
                                        // Motoren Starten
985
                                        // Motoren Starten
977
                                        if(!MotorenEin)
986
                                        if(!MotorenEin)
978
                        {
987
                        {
979
                                                if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -100) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0)))
988
                                                if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -100) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0)))
980
                                                || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100)))
989
                                                || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100)))
981
                                                {
990
                                                {
982
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
991
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
983
// Einschalten
992
// Einschalten
984
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
993
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
985
                                                        if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START;
994
                                                        if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START;
986
                                                        StartLuftdruck = Luftdruck;
995
                                                        StartLuftdruck = Luftdruck;
987
                                                        HoehenWertF = 0;
996
                                                        HoehenWertF = 0;
988
                                                        HoehenWert = 0;
997
                                                        HoehenWert = 0;
989
                                                        SummenHoehe = 0;
998
                                                        SummenHoehe = 0;
990
if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0) delay_einschalten = 0;
999
if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0) delay_einschalten = 0;
991
                                                        if(++delay_einschalten > 253)
1000
                                                        if(++delay_einschalten > 253)
992
                                                        {
1001
                                                        {
993
                                                                delay_einschalten = 0;
1002
                                                                delay_einschalten = 0;
994
                                                                if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode)
1003
                                                                if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode)
995
                                                                {
1004
                                                                {
996
                                                                        modell_fliegt = 1;
1005
                                                                        modell_fliegt = 1;
997
                                                                        MotorenEin = 1;
1006
                                                                        MotorenEin = 1;
998
                                                                        sollGier = 0;
1007
                                                                        sollGier = 0;
999
                                                                        Mess_Integral_Gier = 0;
1008
                                                                        Mess_Integral_Gier = 0;
1000
                                                                        Mess_Integral_Gier2 = 0;
1009
                                                                        Mess_Integral_Gier2 = 0;
1001
                                                                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
1010
                                                                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
1002
                                                                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
1011
                                                                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
1003
                                                                        Mess_IntegralNick2 = IntegralNick;
1012
                                                                        Mess_IntegralNick2 = IntegralNick;
1004
                                                                        Mess_IntegralRoll2 = IntegralRoll;
1013
                                                                        Mess_IntegralRoll2 = IntegralRoll;
1005
                                                                        SummeNick = 0;
1014
                                                                        SummeNick = 0;
1006
                                                                        SummeRoll = 0;
1015
                                                                        SummeRoll = 0;
1007
//                                                                      ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2;
1016
//                                                                      ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2;
1008
                                                                        NeueKompassRichtungMerken = 100; // 2 sekunden
1017
                                                                        NeueKompassRichtungMerken = 100; // 2 sekunden
1009
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1018
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1010
                                                                        SpeakHoTT = SPEAK_STARTING;
1019
                                                                        SpeakHoTT = SPEAK_STARTING;
1011
#endif
1020
#endif
1012
                                                                }
1021
                                                                }
1013
                                                                else
1022
                                                                else
1014
                                                                {
1023
                                                                {
1015
                                                                        beeptime = 1500; // indicate missing calibration
1024
                                                                        beeptime = 1500; // indicate missing calibration
1016
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1025
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1017
                                                                        if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION;
1026
                                                                        if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION;
1018
#endif
1027
#endif
1019
                                                                }
1028
                                                                }
1020
                                                        }
1029
                                                        }
1021
                                                }
1030
                                                }
1022
                                                else delay_einschalten = 0;
1031
                                                else delay_einschalten = 0;
1023
                                        }
1032
                                        }
1024
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1033
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1025
// Auschalten
1034
// Auschalten
1026
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1035
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1027
                                        else // only if motors are running
1036
                                        else // only if motors are running
1028
                                        {
1037
                                        {
1029
//                                              if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0))
1038
//                                              if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0))
1030
                                                if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 100) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0)))
1039
                                                if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 100) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0)))
1031
                                                || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100)))
1040
                                                || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100)))
1032
                                                {
1041
                                                {
1033
if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0)
1042
if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0)
1034
 {
1043
 {
1035
  delay_ausschalten = 0;
1044
  delay_ausschalten = 0;
1036
 }
1045
 }
1037
else
1046
else
1038
 {
1047
 {
1039
  SummeNick = 0;
1048
  SummeNick = 0;
1040
  SummeRoll = 0;
1049
  SummeRoll = 0;
1041
  StickNick = 0;
1050
  StickNick = 0;
1042
  StickRoll = 0;
1051
  StickRoll = 0;
1043
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1052
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1044
  SpeakHoTT = SPEAK_MK_OFF;
1053
  SpeakHoTT = SPEAK_MK_OFF;
1045
#endif
1054
#endif
1046
 }
1055
 }
1047
                                                        if(++delay_ausschalten > 250)  // nicht sofort
1056
                                                        if(++delay_ausschalten > 250)  // nicht sofort
1048
                                                        {
1057
                                                        {
1049
                                                                MotorenEin = 0;
1058
                                                                MotorenEin = 0;
1050
                                                                delay_ausschalten = 0;
1059
                                                                delay_ausschalten = 0;
1051
                                                                modell_fliegt = 0;
1060
                                                                modell_fliegt = 0;
1052
FC_StatusFlags2 &= ~(FC_STATUS2_WAIT_FOR_TAKEOFF | FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING);
1061
FC_StatusFlags2 &= ~(FC_STATUS2_WAIT_FOR_TAKEOFF | FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING);
1053
                                                        }
1062
                                                        }
1054
                                                }
1063
                                                }
1055
                                                else delay_ausschalten = 0;
1064
                                                else delay_ausschalten = 0;
1056
                                        }
1065
                                        }
1057
                  if(GasIsZeroCnt < 1000) GasIsZeroCnt++;
1066
                  if(GasIsZeroCnt < 1000) GasIsZeroCnt++;
1058
                                }
1067
                                }
1059
                                else // gas not at minimum
1068
                                else // gas not at minimum
1060
                                {
1069
                                {
1061
                                  move_safety_switch = 0;
1070
                                  move_safety_switch = 0;
1062
                                  GasIsZeroCnt = 0;
1071
                                  GasIsZeroCnt = 0;
1063
                                }  
1072
                                }  
1064
            }
1073
            }
1065
                        else  // Empfang zwischen 100 und 140 -> schlecht
1074
                        else  // Empfang zwischen 100 und 140 -> schlecht
1066
                        {
1075
                        {
1067
                        if(GasIsZeroCnt >= 750)  // gas-stick was down for 1.5 seconds before RC-Lost
1076
                        if(GasIsZeroCnt >= 750)  // gas-stick was down for 1.5 seconds before RC-Lost
1068
                         {
1077
                         {
1069
                           if((GPSInfo.HomeDistance < 40 * 10) && (HoehenWert < 15 * 100))  // and we are at the starting point -> maybe landed? 
1078
                           if((GPSInfo.HomeDistance < 40 * 10) && (HoehenWert < 15 * 100))  // and we are at the starting point -> maybe landed? 
1070
                                {
1079
                                {
1071
                                 GasIsZeroCnt = 30000;
1080
                                 GasIsZeroCnt = 30000;
1072
                                 if(modell_fliegt > 1001) modell_fliegt = 1001;
1081
                                 if(modell_fliegt > 1001) modell_fliegt = 1001;
1073
                                }        
1082
                                }        
1074
                         }
1083
                         }
1075
                        }
1084
                        }
1076
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1085
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1077
// neue Werte von der Funke
1086
// neue Werte von der Funke
1078
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1087
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1079
 
1088
 
1080
 if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING))
1089
 if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING))
1081
  {
1090
  {
1082
        static int stick_nick,stick_roll;
1091
        static int stick_nick,stick_roll;
1083
        unsigned char stick_p;
1092
        unsigned char stick_p;
1084
    ParameterZuordnung();
1093
    ParameterZuordnung();
1085
        stick_p = EE_Parameter.Stick_P;
1094
        stick_p = EE_Parameter.Stick_P;
1086
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4;
1095
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4;
1087
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
1096
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
1088
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4;
1097
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4;
1089
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
1098
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
1090
 
1099
 
1091
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1100
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1092
// CareFree und freie Wahl der vorderen Richtung
1101
// CareFree und freie Wahl der vorderen Richtung
1093
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1102
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1094
        if(CareFree)
1103
        if(CareFree)
1095
        {
1104
        {
1096
                signed int nick, roll;
1105
                signed int nick, roll;
1097
                nick = stick_nick / 4;
1106
                nick = stick_nick / 4;
1098
                roll = stick_roll / 4;
1107
                roll = stick_roll / 4;
1099
                StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4);
1108
                StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4);
1100
                StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4);
1109
                StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4);
1101
        }
1110
        }
1102
        else
1111
        else
1103
        {
1112
        {
1104
                FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6];
1113
                FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6];
1105
                FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle];
1114
                FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle];
1106
                StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8;
1115
                StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8;
1107
                StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8;
1116
                StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8;
1108
        }
1117
        }
1109
 
1118
 
1110
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
1119
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
1111
        if(StickGier > 4) StickGier -= 4;       else
1120
        if(StickGier > 4) StickGier -= 4;       else
1112
        if(StickGier < -4) StickGier += 4; else StickGier = 0;
1121
        if(StickGier < -4) StickGier += 4; else StickGier = 0;
1113
 
1122
 
1114
    if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger
1123
    if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger
1115
         {
1124
         {
1116
          StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16;
1125
          StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16;
1117
          StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16;
1126
          StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16;
1118
         }
1127
         }
1119
 
1128
 
1120
    StickNick -= GPS_Nick;
1129
    StickNick -= GPS_Nick;
1121
    StickRoll -= GPS_Roll;
1130
    StickRoll -= GPS_Roll;
1122
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127;
1131
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127;
1123
 
1132
 
1124
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
1133
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
1125
    IntegralFaktor = Parameter_Gyro_I;
1134
    IntegralFaktor = Parameter_Gyro_I;
1126
    GyroFaktorGier     = (Parameter_Gyro_Gier_P + 10.0);
1135
    GyroFaktorGier     = (Parameter_Gyro_Gier_P + 10.0);
1127
    IntegralFaktorGier = Parameter_Gyro_Gier_I;
1136
    IntegralFaktorGier = Parameter_Gyro_Gier_I;
1128
 
1137
 
1129
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1138
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1130
//+ Analoge Steuerung per Seriell
1139
//+ Analoge Steuerung per Seriell
1131
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1140
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1132
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
1141
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
1133
    {
1142
    {
1134
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
1143
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
1135
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
1144
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
1136
         StickGier += ExternControl.Gier;
1145
         StickGier += ExternControl.Gier;
1137
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
1146
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
1138
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
1147
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
1139
    }
1148
    }
1140
    if(StickGas < 0) StickGas = 0;
1149
    if(StickGas < 0) StickGas = 0;
1141
 
1150
 
1142
    if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
1151
    if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
1143
 
1152
 
1144
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
1153
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
1145
     {
1154
     {
1146
      MaxStickNick = abs(StickNick)/STICK_GAIN;
1155
      MaxStickNick = abs(StickNick)/STICK_GAIN;
1147
      if(MaxStickNick > 100) MaxStickNick = 100;
1156
      if(MaxStickNick > 100) MaxStickNick = 100;
1148
     }
1157
     }
1149
     else MaxStickNick--;
1158
     else MaxStickNick--;
1150
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
1159
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
1151
     {
1160
     {
1152
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
1161
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
1153
      if(MaxStickRoll > 100) MaxStickRoll = 100;
1162
      if(MaxStickRoll > 100) MaxStickRoll = 100;
1154
     }
1163
     }
1155
     else MaxStickRoll--;
1164
     else MaxStickRoll--;
1156
    if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)  {MaxStickNick = 0; MaxStickRoll = 0;}
1165
    if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)  {MaxStickNick = 0; MaxStickRoll = 0;}
1157
 
1166
 
1158
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1167
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1159
// Looping?
1168
// Looping?
1160
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1169
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1161
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
1170
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
1162
  else
1171
  else
1163
   {
1172
   {
1164
     {
1173
     {
1165
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
1174
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
1166
     }
1175
     }
1167
   }
1176
   }
1168
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
1177
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
1169
   else
1178
   else
1170
   {
1179
   {
1171
   if(Looping_Rechts) // Hysterese
1180
   if(Looping_Rechts) // Hysterese
1172
     {
1181
     {
1173
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
1182
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
1174
     }
1183
     }
1175
   }
1184
   }
1176
 
1185
 
1177
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
1186
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
1178
  else
1187
  else
1179
   {
1188
   {
1180
    if(Looping_Oben)  // Hysterese
1189
    if(Looping_Oben)  // Hysterese
1181
     {
1190
     {
1182
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
1191
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
1183
     }
1192
     }
1184
   }
1193
   }
1185
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
1194
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
1186
   else
1195
   else
1187
   {
1196
   {
1188
    if(Looping_Unten) // Hysterese
1197
    if(Looping_Unten) // Hysterese
1189
     {
1198
     {
1190
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
1199
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
1191
     }
1200
     }
1192
   }
1201
   }
1193
 
1202
 
1194
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
1203
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
1195
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
1204
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
1196
  } // Ende neue Funken-Werte
1205
  } // Ende neue Funken-Werte
1197
 
1206
 
1198
  if(Looping_Roll || Looping_Nick)
1207
  if(Looping_Roll || Looping_Nick)
1199
   {
1208
   {
1200
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
1209
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
1201
        TrichterFlug = 1;
1210
        TrichterFlug = 1;
1202
   }
1211
   }
1203
 
1212
 
1204
 
1213
 
1205
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1214
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1206
// Bei Empfangsausfall im Flug
1215
// Bei Empfangsausfall im Flug
1207
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1216
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1208
   if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)
1217
   if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)
1209
   {
1218
   {
1210
    StickNick = -GPS_Nick;
1219
    StickNick = -GPS_Nick;
1211
    StickRoll = -GPS_Roll;
1220
    StickRoll = -GPS_Roll;
1212
        StickGas = StickGasHover;
1221
        StickGas = StickGasHover;
1213
        Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER);
1222
        Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER);
1214
        Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV;
1223
        Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV;
1215
        Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP);
1224
        Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP);
1216
        Parameter_HoehenSchalter = 200; // switch on
1225
        Parameter_HoehenSchalter = 200; // switch on
1217
   }
1226
   }
1218
   else
1227
   else
1219
   if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)
1228
   if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)
1220
    {
1229
    {
1221
     StickGier = 0;
1230
     StickGier = 0;
1222
     StickNick = 0;
1231
     StickNick = 0;
1223
     StickRoll = 0;
1232
     StickRoll = 0;
1224
     GyroFaktor     = 90;
1233
     GyroFaktor     = 90;
1225
     IntegralFaktor = 120;
1234
     IntegralFaktor = 120;
1226
     GyroFaktorGier     = 90;
1235
     GyroFaktorGier     = 90;
1227
     IntegralFaktorGier = 120;
1236
     IntegralFaktorGier = 120;
1228
     Looping_Roll = 0;
1237
     Looping_Roll = 0;
1229
     Looping_Nick = 0;
1238
     Looping_Nick = 0;
1230
    }
1239
    }
1231
 
1240
 
1232
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1241
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1233
// Integrale auf ACC-Signal abgleichen
1242
// Integrale auf ACC-Signal abgleichen
1234
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1243
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1235
#define ABGLEICH_ANZAHL 256L
1244
#define ABGLEICH_ANZAHL 256L
1236
 
1245
 
1237
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
1246
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
1238
 MittelIntegralRoll  += IntegralRoll;
1247
 MittelIntegralRoll  += IntegralRoll;
1239
 MittelIntegralNick2 += IntegralNick2;
1248
 MittelIntegralNick2 += IntegralNick2;
1240
 MittelIntegralRoll2 += IntegralRoll2;
1249
 MittelIntegralRoll2 += IntegralRoll2;
1241
 
1250
 
1242
 if(Looping_Nick || Looping_Roll)
1251
 if(Looping_Nick || Looping_Roll)
1243
  {
1252
  {
1244
    IntegralAccNick = 0;
1253
    IntegralAccNick = 0;
1245
    IntegralAccRoll = 0;
1254
    IntegralAccRoll = 0;
1246
    MittelIntegralNick = 0;
1255
    MittelIntegralNick = 0;
1247
    MittelIntegralRoll = 0;
1256
    MittelIntegralRoll = 0;
1248
    MittelIntegralNick2 = 0;
1257
    MittelIntegralNick2 = 0;
1249
    MittelIntegralRoll2 = 0;
1258
    MittelIntegralRoll2 = 0;
1250
    Mess_IntegralNick2 = Mess_IntegralNick;
1259
    Mess_IntegralNick2 = Mess_IntegralNick;
1251
    Mess_IntegralRoll2 = Mess_IntegralRoll;
1260
    Mess_IntegralRoll2 = Mess_IntegralRoll;
1252
    ZaehlMessungen = 0;
1261
    ZaehlMessungen = 0;
1253
    LageKorrekturNick = 0;
1262
    LageKorrekturNick = 0;
1254
    LageKorrekturRoll = 0;
1263
    LageKorrekturRoll = 0;
1255
  }
1264
  }
1256
 
1265
 
1257
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1266
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1258
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
1267
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
1259
  {
1268
  {
1260
   long tmp_long, tmp_long2;
1269
   long tmp_long, tmp_long2;
1261
   if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/)
1270
   if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/)
1262
     {
1271
     {
1263
                tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN));
1272
                tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN));
1264
                tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR));
1273
                tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR));
1265
                tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1274
                tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1266
                tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1275
                tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
1267
                if((MaxStickNick > 64) || (MaxStickRoll > 64))
1276
                if((MaxStickNick > 64) || (MaxStickRoll > 64))
1268
                {
1277
                {
1269
                tmp_long  /= 2;
1278
                tmp_long  /= 2;
1270
                tmp_long2 /= 2;
1279
                tmp_long2 /= 2;
1271
                }
1280
                }
1272
                if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1281
                if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1273
                if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1282
                if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1274
                if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1283
                if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1275
                if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1284
                if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1276
     }
1285
     }
1277
     else
1286
     else
1278
     {
1287
     {
1279
                tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1288
                tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
1280
                tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
1289
                tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
1281
                tmp_long /= 16;
1290
                tmp_long /= 16;
1282
                tmp_long2 /= 16;
1291
                tmp_long2 /= 16;
1283
                if((MaxStickNick > 64) || (MaxStickRoll > 64))
1292
                if((MaxStickNick > 64) || (MaxStickRoll > 64))
1284
                {
1293
                {
1285
                tmp_long  /= 3;
1294
                tmp_long  /= 3;
1286
                tmp_long2 /= 3;
1295
                tmp_long2 /= 3;
1287
                }
1296
                }
1288
                if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1297
                if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
1289
                {
1298
                {
1290
                tmp_long  /= 3;
1299
                tmp_long  /= 3;
1291
                tmp_long2 /= 3;
1300
                tmp_long2 /= 3;
1292
                }
1301
                }
1293
                KompassFusion = 25;
1302
                KompassFusion = 25;
1294
#define AUSGLEICH  32
1303
#define AUSGLEICH  32
1295
                if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
1304
                if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
1296
                if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
1305
                if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
1297
                if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
1306
                if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
1298
                if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
1307
                if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
1299
     }
1308
     }
1300
 
1309
 
1301
   Mess_IntegralNick -= tmp_long;
1310
   Mess_IntegralNick -= tmp_long;
1302
   Mess_IntegralRoll -= tmp_long2;
1311
   Mess_IntegralRoll -= tmp_long2;
1303
  }
1312
  }
1304
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1313
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1305
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
1314
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
1306
 {
1315
 {
1307
  static int cnt = 0;
1316
  static int cnt = 0;
1308
  static char last_n_p,last_n_n,last_r_p,last_r_n;
1317
  static char last_n_p,last_n_n,last_r_p,last_r_n;
1309
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
1318
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
1310
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
1319
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
1311
  {
1320
  {
1312
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
1321
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
1313
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
1322
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
1314
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
1323
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
1315
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
1324
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
1316
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
1325
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
1317
#define MAX_I 0
1326
#define MAX_I 0
1318
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
1327
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
1319
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
1328
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
1320
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
1329
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
1321
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
1330
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
1322
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
1331
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
1323
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
1332
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
1324
 
1333
 
1325
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
1334
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
1326
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
1335
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
1327
 
1336
 
1328
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
1337
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
1329
    {
1338
    {
1330
     LageKorrekturNick /= 2;
1339
     LageKorrekturNick /= 2;
1331
     LageKorrekturRoll /= 2;
1340
     LageKorrekturRoll /= 2;
1332
    }
1341
    }
1333
 
1342
 
1334
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1343
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1335
// Gyro-Drift ermitteln
1344
// Gyro-Drift ermitteln
1336
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1345
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1337
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
1346
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
1338
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
1347
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
1339
    tmp_long  = IntegralNick2 - IntegralNick;
1348
    tmp_long  = IntegralNick2 - IntegralNick;
1340
    tmp_long2 = IntegralRoll2 - IntegralRoll;
1349
    tmp_long2 = IntegralRoll2 - IntegralRoll;
1341
 
1350
 
1342
    IntegralFehlerNick = tmp_long;
1351
    IntegralFehlerNick = tmp_long;
1343
    IntegralFehlerRoll = tmp_long2;
1352
    IntegralFehlerRoll = tmp_long2;
1344
    Mess_IntegralNick2 -= IntegralFehlerNick;
1353
    Mess_IntegralNick2 -= IntegralFehlerNick;
1345
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
1354
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
1346
 
1355
 
1347
  if(EE_Parameter.Driftkomp)
1356
  if(EE_Parameter.Driftkomp)
1348
   {
1357
   {
1349
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; }
1358
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; }
1350
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; }
1359
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; }
1351
   }
1360
   }
1352
    GierGyroFehler = 0;
1361
    GierGyroFehler = 0;
1353
 
1362
 
1354
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2)
1363
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2)
1355
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4
1364
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4
1356
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1365
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1357
#define BEWEGUNGS_LIMIT 20000
1366
#define BEWEGUNGS_LIMIT 20000
1358
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1367
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1359
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1368
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1360
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1369
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1361
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1370
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1362
        {
1371
        {
1363
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1372
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1364
         {
1373
         {
1365
           if(last_n_p)
1374
           if(last_n_p)
1366
           {
1375
           {
1367
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1376
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1368
            ausgleichNick = IntegralFehlerNick / 8;
1377
            ausgleichNick = IntegralFehlerNick / 8;
1369
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1378
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1370
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1379
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1371
           }
1380
           }
1372
           else last_n_p = 1;
1381
           else last_n_p = 1;
1373
         } else  last_n_p = 0;
1382
         } else  last_n_p = 0;
1374
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1383
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1375
         {
1384
         {
1376
           if(last_n_n)
1385
           if(last_n_n)
1377
            {
1386
            {
1378
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1387
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1379
             ausgleichNick = IntegralFehlerNick / 8;
1388
             ausgleichNick = IntegralFehlerNick / 8;
1380
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1389
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1381
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1390
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1382
            }
1391
            }
1383
           else last_n_n = 1;
1392
           else last_n_n = 1;
1384
         } else  last_n_n = 0;
1393
         } else  last_n_n = 0;
1385
        }
1394
        }
1386
        else
1395
        else
1387
        {
1396
        {
1388
         cnt = 0;
1397
         cnt = 0;
1389
         KompassSignalSchlecht = 100;
1398
         KompassSignalSchlecht = 100;
1390
        }
1399
        }
1391
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1400
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1392
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1401
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1393
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1402
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1394
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1403
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1395
 
1404
 
1396
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1405
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1397
        cnt = 1;// + labs(IntegralFehlerRoll) / 4096;
1406
        cnt = 1;// + labs(IntegralFehlerRoll) / 4096;
1398
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1407
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1399
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1408
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1400
        {
1409
        {
1401
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1410
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1402
         {
1411
         {
1403
           if(last_r_p)
1412
           if(last_r_p)
1404
           {
1413
           {
1405
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1414
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1406
            ausgleichRoll = IntegralFehlerRoll / 8;
1415
            ausgleichRoll = IntegralFehlerRoll / 8;
1407
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1416
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1408
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1417
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1409
           }
1418
           }
1410
           else last_r_p = 1;
1419
           else last_r_p = 1;
1411
         } else  last_r_p = 0;
1420
         } else  last_r_p = 0;
1412
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1421
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1413
         {
1422
         {
1414
           if(last_r_n)
1423
           if(last_r_n)
1415
           {
1424
           {
1416
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1425
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1417
            ausgleichRoll = IntegralFehlerRoll / 8;
1426
            ausgleichRoll = IntegralFehlerRoll / 8;
1418
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1427
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1419
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1428
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1420
           }
1429
           }
1421
           else last_r_n = 1;
1430
           else last_r_n = 1;
1422
         } else  last_r_n = 0;
1431
         } else  last_r_n = 0;
1423
        } else
1432
        } else
1424
        {
1433
        {
1425
         cnt = 0;
1434
         cnt = 0;
1426
         KompassSignalSchlecht = 100;
1435
         KompassSignalSchlecht = 100;
1427
        }
1436
        }
1428
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1437
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1429
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1438
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1430
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1439
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1431
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1440
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1432
  }
1441
  }
1433
  else
1442
  else
1434
  {
1443
  {
1435
   LageKorrekturRoll = 0;
1444
   LageKorrekturRoll = 0;
1436
   LageKorrekturNick = 0;
1445
   LageKorrekturNick = 0;
1437
   TrichterFlug = 0;
1446
   TrichterFlug = 0;
1438
  }
1447
  }
1439
 
1448
 
1440
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1449
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1441
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1450
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1442
   MittelIntegralNick_Alt = MittelIntegralNick;
1451
   MittelIntegralNick_Alt = MittelIntegralNick;
1443
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1452
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1444
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1453
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1445
    IntegralAccNick = 0;
1454
    IntegralAccNick = 0;
1446
    IntegralAccRoll = 0;
1455
    IntegralAccRoll = 0;
1447
    IntegralAccZ = 0;
1456
    IntegralAccZ = 0;
1448
    MittelIntegralNick = 0;
1457
    MittelIntegralNick = 0;
1449
    MittelIntegralRoll = 0;
1458
    MittelIntegralRoll = 0;
1450
    MittelIntegralNick2 = 0;
1459
    MittelIntegralNick2 = 0;
1451
    MittelIntegralRoll2 = 0;
1460
    MittelIntegralRoll2 = 0;
1452
    ZaehlMessungen = 0;
1461
    ZaehlMessungen = 0;
1453
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1462
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1454
 
1463
 
1455
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1464
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1456
//  Gieren
1465
//  Gieren
1457
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1466
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1458
    if(abs(StickGier) > 3) // war 15
1467
    if(abs(StickGier) > 3) // war 15
1459
     {
1468
     {
1460
//      KompassSignalSchlecht = 1000;
1469
//      KompassSignalSchlecht = 1000;
1461
      if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX))
1470
      if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX))
1462
       {
1471
       {
1463
         NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen
1472
         NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen
1464
        };
1473
        };
1465
     }
1474
     }
1466
    tmp_int  = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1475
    tmp_int  = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1467
    tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4;
1476
    tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4;
1468
        if(GasIsZeroCnt > 512) tmp_int = 0; // disable Yawing when Gas-Stick is to Zero
1477
        if(GasIsZeroCnt > 512) tmp_int = 0; // disable Yawing when Gas-Stick is to Zero
1469
        tmp_int += CompassGierSetpoint;
1478
        tmp_int += CompassGierSetpoint;
1470
    sollGier = tmp_int;
1479
    sollGier = tmp_int;
1471
    Mess_Integral_Gier -= tmp_int;
1480
    Mess_Integral_Gier -= tmp_int;
1472
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1481
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1473
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1482
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1474
 
1483
 
1475
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1484
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1476
//  Kompass
1485
//  Kompass
1477
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1486
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1478
    if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV))
1487
    if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV))
1479
     {
1488
     {
1480
      if(CalculateCompassTimer-- == 1)
1489
      if(CalculateCompassTimer-- == 1)
1481
          {
1490
          {
1482
       int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt
1491
       int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt
1483
       CalculateCompassTimer = 13; // falls keine Navi-Daten
1492
       CalculateCompassTimer = 13; // falls keine Navi-Daten
1484
           // max. Korrekturwert schätzen
1493
           // max. Korrekturwert schätzen
1485
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1494
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1486
       v = abs(IntegralRoll /512);
1495
       v = abs(IntegralRoll /512);
1487
       if(v > w) w = v; // grösste Neigung ermitteln
1496
       if(v > w) w = v; // grösste Neigung ermitteln
1488
//       korrektur = w / 4 + 1;
1497
//       korrektur = w / 4 + 1;
1489
           korrektur = w / 8 + 2;
1498
           korrektur = w / 8 + 2;
1490
           ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR;
1499
           ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR;
1491
           // Kompassfehlerwert bestimmen   
1500
           // Kompassfehlerwert bestimmen   
1492
           fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180;
1501
           fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180;
1493
           // GIER_GRAD_FAKTOR ist ca. 1200
1502
           // GIER_GRAD_FAKTOR ist ca. 1200
1494
           // Kompasswert einloggen
1503
           // Kompasswert einloggen
1495
       if(KompassSignalSchlecht) KompassSignalSchlecht--;
1504
       if(KompassSignalSchlecht) KompassSignalSchlecht--;
1496
           else
1505
           else
1497
       if(w < 25)
1506
       if(w < 25)
1498
        {
1507
        {
1499
        GierGyroFehler += fehler;
1508
        GierGyroFehler += fehler;
1500
        if(NeueKompassRichtungMerken)
1509
        if(NeueKompassRichtungMerken)
1501
         {
1510
         {
1502
          if(--NeueKompassRichtungMerken == 0)
1511
          if(--NeueKompassRichtungMerken == 0)
1503
                   {
1512
                   {
1504
            KompassSollWert = ErsatzKompassInGrad;
1513
            KompassSollWert = ErsatzKompassInGrad;
1505
                   }   
1514
                   }   
1506
         }
1515
         }
1507
        }
1516
        }
1508
       // Kompass fusionieren
1517
       // Kompass fusionieren
1509
       if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur;
1518
       if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur;
1510
       // MK Gieren
1519
       // MK Gieren
1511
           if(!NeueKompassRichtungMerken)
1520
           if(!NeueKompassRichtungMerken)
1512
       {
1521
       {
1513
           r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180;
1522
           r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180;
1514
           v = r * (Parameter_KompassWirkung/2);  // nach Kompass ausrichten
1523
           v = r * (Parameter_KompassWirkung/2);  // nach Kompass ausrichten
1515
                   CompassGierSetpoint = v / 16;
1524
                   CompassGierSetpoint = v / 16;
1516
       }
1525
       }
1517
      else CompassGierSetpoint = 0;
1526
      else CompassGierSetpoint = 0;
1518
      } // CalculateCompassTimer
1527
      } // CalculateCompassTimer
1519
     }
1528
     }
1520
         else CompassGierSetpoint = 0;
1529
         else CompassGierSetpoint = 0;
1521
 
1530
 
1522
//DebugOut.Analog[16] = KompassFusion;
1531
//DebugOut.Analog[16] = KompassFusion;
1523
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1532
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1524
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1533
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1525
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1534
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1526
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1535
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1527
 
1536
 
1528
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1537
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1529
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1538
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1530
 
1539
 
1531
#define TRIM_MAX 200
1540
#define TRIM_MAX 200
1532
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1541
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1533
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1542
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1534
 
1543
 
1535
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1544
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1536
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1545
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1537
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1546
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1538
 
1547
 
1539
    // Maximalwerte abfangen
1548
    // Maximalwerte abfangen
1540
    #define MAX_SENSOR  (4096)
1549
    #define MAX_SENSOR  (4096)
1541
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1550
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1542
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1551
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1543
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1552
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1544
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1553
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1545
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1554
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1546
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1555
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1547
 
1556
 
1548
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1557
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1549
// Höhenregelung
1558
// Höhenregelung
1550
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1559
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1551
  if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen
1560
  if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen
1552
  GasMischanteil *= STICK_GAIN;
1561
  GasMischanteil *= STICK_GAIN;
1553
        // if height control is activated
1562
        // if height control is activated
1554
 if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick) && !(VersionInfo.HardwareError[0] & 0x7F))  // Höhenregelung
1563
 if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick) && !(VersionInfo.HardwareError[0] & 0x7F))  // Höhenregelung
1555
        {
1564
        {
1556
                #define HOVER_GAS_AVERAGE 16384L                // 16384 * 2ms = 32s averaging
1565
                #define HOVER_GAS_AVERAGE 16384L                // 16384 * 2ms = 32s averaging
1557
                #define HC_GAS_AVERAGE 4                        // 4 * 2ms= 8ms averaging
1566
                #define HC_GAS_AVERAGE 4                        // 4 * 2ms= 8ms averaging
1558
 
1567
 
1559
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1568
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1560
#define OPA_OFFSET_STEP 15
1569
#define OPA_OFFSET_STEP 15
1561
#else
1570
#else
1562
#define OPA_OFFSET_STEP 10
1571
#define OPA_OFFSET_STEP 10
1563
#endif
1572
#endif
1564
                int HCGas, GasReduction = 0;
1573
                int HCGas, GasReduction = 0;
1565
                static int HeightTrimming = 0;  // rate for change of height setpoint
1574
                static int HeightTrimming = 0;  // rate for change of height setpoint
1566
                static int HeightDeviation = 0, FilterHCGas = 0;
1575
                static int HeightDeviation = 0, FilterHCGas = 0;
1567
                static unsigned long HoverGasFilter = 0;
1576
                static unsigned long HoverGasFilter = 0;
1568
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
1577
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
1569
 
1578
 
1570
 
1579
 
1571
        // Expand the measurement
1580
        // Expand the measurement
1572
                // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs
1581
                // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs
1573
          if(!BaroExpandActive)
1582
          if(!BaroExpandActive)
1574
                   {
1583
                   {
1575
                        if(MessLuftdruck > 920)
1584
                        if(MessLuftdruck > 920)
1576
                        {   // increase offset
1585
                        {   // increase offset
1577
             if(OCR0A < (255 - OPA_OFFSET_STEP))
1586
             if(OCR0A < (255 - OPA_OFFSET_STEP))
1578
                           {
1587
                           {
1579
                                ExpandBaro -= 1;
1588
                                ExpandBaro -= 1;
1580
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down
1589
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down
1581
                                beeptime = 300;
1590
                                beeptime = 300;
1582
                                BaroExpandActive = 350;
1591
                                BaroExpandActive = 350;
1583
                           }
1592
                           }
1584
                           else
1593
                           else
1585
                           {
1594
                           {
1586
                            BaroAtLowerLimit = 1;
1595
                            BaroAtLowerLimit = 1;
1587
               }
1596
               }
1588
                        }
1597
                        }
1589
                        // measurement of air pressure close to lower limit and
1598
                        // measurement of air pressure close to lower limit and
1590
                        else
1599
                        else
1591
                        if(MessLuftdruck < 100)
1600
                        if(MessLuftdruck < 100)
1592
                        {   // decrease offset
1601
                        {   // decrease offset
1593
                          if(OCR0A > OPA_OFFSET_STEP)
1602
                          if(OCR0A > OPA_OFFSET_STEP)
1594
                           {
1603
                           {
1595
                                ExpandBaro += 1;
1604
                                ExpandBaro += 1;
1596
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up
1605
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up
1597
                                beeptime = 300;
1606
                                beeptime = 300;
1598
                                BaroExpandActive = 350;
1607
                                BaroExpandActive = 350;
1599
                           }
1608
                           }
1600
                           else
1609
                           else
1601
                           {
1610
                           {
1602
                            BaroAtUpperLimit = 1;
1611
                            BaroAtUpperLimit = 1;
1603
               }
1612
               }
1604
                        }
1613
                        }
1605
                        else
1614
                        else
1606
                        {
1615
                        {
1607
                            BaroAtUpperLimit = 0;
1616
                            BaroAtUpperLimit = 0;
1608
                                BaroAtLowerLimit = 0;
1617
                                BaroAtLowerLimit = 0;
1609
                        }
1618
                        }
1610
                   }
1619
                   }
1611
                   else // delay, because of expanding the Baro-Range
1620
                   else // delay, because of expanding the Baro-Range
1612
                   {
1621
                   {
1613
                    // now clear the D-values
1622
                    // now clear the D-values
1614
                          VarioMeter = 0;
1623
                          VarioMeter = 0;
1615
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1624
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1616
                          if(ACC_AltitudeControl) ACC_AltitudeFusion(1); // init
1625
                          if(ACC_AltitudeControl) ACC_AltitudeFusion(1); // init
1617
                          else SummenHoehe = HoehenWert * SM_FILTER;
1626
                          else SummenHoehe = HoehenWert * SM_FILTER;
1618
#else 
1627
#else 
1619
              SummenHoehe = HoehenWert * SM_FILTER;
1628
              SummenHoehe = HoehenWert * SM_FILTER;
1620
#endif
1629
#endif
1621
                          BaroExpandActive--;
1630
                          BaroExpandActive--;
1622
                   }
1631
                   }
1623
                // if height control is activated by an rc channel
1632
                // if height control is activated by an rc channel
1624
        if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1633
        if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1625
                {       // check if parameter is less than activation threshold
1634
                {       // check if parameter is less than activation threshold
1626
                        if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position
1635
                        if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position
1627
                        {   //height control not active
1636
                        {   //height control not active
1628
                                if(!delay--)
1637
                                if(!delay--)
1629
                                {
1638
                                {
1630
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1639
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1631
                                    if(!SpeakHoTT && HoehenReglerAktiv)  SpeakHoTT = SPEAK_ALTITUDE_OFF;
1640
                                    if(!SpeakHoTT && HoehenReglerAktiv)  SpeakHoTT = SPEAK_ALTITUDE_OFF;
1632
#endif
1641
#endif
1633
                                        HoehenReglerAktiv = 0; // disable height control
1642
                                        HoehenReglerAktiv = 0; // disable height control
1634
                                        SollHoehe = HoehenWert;  // update SetPoint with current reading
1643
                                        SollHoehe = HoehenWert;  // update SetPoint with current reading
1635
                                        delay = 1;
1644
                                        delay = 1;
1636
                                }
1645
                                }
1637
                        }
1646
                        }
1638
                        else
1647
                        else
1639
                        if(Parameter_HoehenSchalter > 70)
1648
                        if(Parameter_HoehenSchalter > 70)
1640
                        {       //height control is activated
1649
                        {       //height control is activated
1641
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1650
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1642
                            if(!SpeakHoTT && !HoehenReglerAktiv)  SpeakHoTT = SPEAK_ALTITUDE_ON;
1651
                            if(!SpeakHoTT && !HoehenReglerAktiv)  SpeakHoTT = SPEAK_ALTITUDE_ON;
1643
#endif
1652
#endif
1644
                                delay = 200;
1653
                                delay = 200;
1645
                                HoehenReglerAktiv = 1; // enable height control
1654
                                HoehenReglerAktiv = 1; // enable height control
1646
                        }
1655
                        }
1647
                }
1656
                }
1648
                else // no switchable height control
1657
                else // no switchable height control
1649
                {
1658
                {
1650
                        SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung;
1659
                        SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung;
1651
                        HoehenReglerAktiv = 1;
1660
                        HoehenReglerAktiv = 1;
1652
                }
1661
                }
1653
                // calculate cos of nick and roll angle used for projection of the vertical hoover gas
1662
                // calculate cos of nick and roll angle used for projection of the vertical hoover gas
1654
                tmp_int  = (int)(IntegralNick/GIER_GRAD_FAKTOR);  // nick angle in deg
1663
                tmp_int  = (int)(IntegralNick/GIER_GRAD_FAKTOR);  // nick angle in deg
1655
                tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR);  // roll angle in deg
1664
                tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR);  // roll angle in deg
1656
                CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg
1665
                CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg
1657
                LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle
1666
                LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle
1658
                CosAttitude = c_cos_8192(CosAttitude);  // cos of actual attitude
1667
                CosAttitude = c_cos_8192(CosAttitude);  // cos of actual attitude
1659
                VarioCharacter = ' ';
1668
                VarioCharacter = ' ';
1660
                AltitudeSetpointTrimming = 0;
1669
                AltitudeSetpointTrimming = 0;
1661
                if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING))
1670
                if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING))
1662
                {
1671
                {
1663
                        #define HEIGHT_CONTROL_STICKTHRESHOLD 15
1672
                        #define HEIGHT_CONTROL_STICKTHRESHOLD 15
1664
                // Holger original version
1673
                // Holger original version
1665
                // start of height control algorithm
1674
                // start of height control algorithm
1666
                // the height control is only an attenuation of the actual gas stick.
1675
                // the height control is only an attenuation of the actual gas stick.
1667
                // I.e. it will work only if the gas stick is higher than the hover gas
1676
                // I.e. it will work only if the gas stick is higher than the hover gas
1668
                // and the hover height will be allways larger than height setpoint.
1677
                // and the hover height will be allways larger than height setpoint.
1669
                FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL;
1678
                FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL;
1670
        if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER))  // Regler wird über Schalter gesteuert)
1679
        if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER))  // Regler wird über Schalter gesteuert)
1671
              {  // old version
1680
              {  // old version
1672
                        HCGas = GasMischanteil; // take current stick gas as neutral point for the height control
1681
                        HCGas = GasMischanteil; // take current stick gas as neutral point for the height control
1673
                        HeightTrimming = 0;
1682
                        HeightTrimming = 0;
1674
                        AltitudeSetpointTrimming = 0;
1683
                        AltitudeSetpointTrimming = 0;
1675
                        // set both flags to indicate no vario mode
1684
                        // set both flags to indicate no vario mode
1676
                        FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1685
                        FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1677
          }
1686
          }
1678
                  else
1687
                  else
1679
                  {
1688
                  {
1680
                // alternative height control
1689
                // alternative height control
1681
                // PD-Control with respect to hoover point
1690
                // PD-Control with respect to hoover point
1682
                // the thrust loss out of horizontal attitude is compensated
1691
                // the thrust loss out of horizontal attitude is compensated
1683
                // the setpoint will be fine adjusted with the gas stick position
1692
                // the setpoint will be fine adjusted with the gas stick position
1684
                        if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying
1693
                        if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying
1685
                        {   // gas stick is above hoover point
1694
                        {   // gas stick is above hoover point
1686
                                if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit)
1695
                                if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit)
1687
                                {
1696
                                {
1688
if(HeightDeviation > 20) SollHoehe = HoehenWertF; // update setpoint to current heigth 
1697
if(HeightDeviation > 20) SollHoehe = HoehenWertF; // update setpoint to current heigth 
1689
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)
1698
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)
1690
                                        {
1699
                                        {
1691
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1700
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1692
                                                SollHoehe = HoehenWertF; // update setpoint to current heigth
1701
                                                SollHoehe = HoehenWertF; // update setpoint to current heigth
1693
                                        }
1702
                                        }
1694
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP;
1703
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP;
1695
                                        // Limit the maximum Altitude
1704
                                        // Limit the maximum Altitude
1696
                                        if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0;
1705
                                        if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0;
1697
                                        else
1706
                                        else
1698
                                        {
1707
                                        {
1699
//                                      SollHoehe = (long) Parameter_MaximumAltitude * 100L;
1708
//                                      SollHoehe = (long) Parameter_MaximumAltitude * 100L;
1700
//                                      HeightTrimming += abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1709
//                                      HeightTrimming += abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1701
                                        AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD));
1710
                                        AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD));
1702
                                        VarioCharacter = '+';
1711
                                        VarioCharacter = '+';
1703
                                        }
1712
                                        }
1704
                                        WaypointTrimming = 0;
1713
                                        WaypointTrimming = 0;
1705
                                } // gas stick is below hoover point
1714
                                } // gas stick is below hoover point
1706
                                else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit )
1715
                                else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit )
1707
                                {
1716
                                {
1708
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP)
1717
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP)
1709
                                        {
1718
                                        {
1710
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1719
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1711
                                                SollHoehe = HoehenWertF; // update setpoint to current heigth
1720
                                                SollHoehe = HoehenWertF; // update setpoint to current heigth
1712
                                        }
1721
                                        }
1713
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN;
1722
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN;
1714
                                        AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1723
                                        AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1715
//                                      HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1724
//                                      HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1716
                                        VarioCharacter = '-';
1725
                                        VarioCharacter = '-';
1717
                                        WaypointTrimming = 0;
1726
                                        WaypointTrimming = 0;
1718
                                }
1727
                                }
1719
                                else // Gas Stick in Hover Range
1728
                                else // Gas Stick in Hover Range
1720
                                {
1729
                                {
1721
                                        VarioCharacter = '=';
1730
                                        VarioCharacter = '=';
1722
                    if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen
1731
                    if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen
1723
                                         {
1732
                                         {
1724
                                                FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP;
1733
                                                FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP;
1725
                                                AltitudeSetpointTrimming = FromNC_AltitudeSpeed;
1734
                                                AltitudeSetpointTrimming = FromNC_AltitudeSpeed;
1726
                                                //HeightTrimming += FromNC_AltitudeSpeed;
1735
                                                //HeightTrimming += FromNC_AltitudeSpeed;
1727
                                                WaypointTrimming = 10;
1736
                                                WaypointTrimming = 10;
1728
                                                VarioCharacter = '^';
1737
                                                VarioCharacter = '^';
1729
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)  // changed from sinking to rising
1738
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)  // changed from sinking to rising
1730
                                                {
1739
                                                {
1731
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1740
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1732
                                                        SollHoehe = HoehenWertF; // update setpoint to current heigth
1741
                                                        SollHoehe = HoehenWertF; // update setpoint to current heigth
1733
                                                }
1742
                                                }
1734
                                         }
1743
                                         }
1735
                                         else
1744
                                         else
1736
                    if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken
1745
                    if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken
1737
                                         {
1746
                                         {
1738
                                                FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN;
1747
                                                FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN;
1739
                                                AltitudeSetpointTrimming = -FromNC_AltitudeSpeed;
1748
                                                AltitudeSetpointTrimming = -FromNC_AltitudeSpeed;
1740
                                                //HeightTrimming -= FromNC_AltitudeSpeed;
1749
                                                //HeightTrimming -= FromNC_AltitudeSpeed;
1741
                                                WaypointTrimming = -10;
1750
                                                WaypointTrimming = -10;
1742
                                                VarioCharacter = 'v';
1751
                                                VarioCharacter = 'v';
1743
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking
1752
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking
1744
                                                {
1753
                                                {
1745
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1754
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1746
                                                        SollHoehe = HoehenWertF; // update setpoint to current heigth
1755
                                                        SollHoehe = HoehenWertF; // update setpoint to current heigth
1747
                                                }
1756
                                                }
1748
                                         }
1757
                                         }
1749
                                        else
1758
                                        else
1750
                                        if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN))
1759
                                        if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN))
1751
                                        {
1760
                                        {
1752
                                                if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWertF-200), (HoehenWertF+200)) // max. 2m Unterschied
1761
                                                if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWertF-200), (HoehenWertF+200)) // max. 2m Unterschied
1753
                                                else                                    WaypointTrimming = 0;
1762
                                                else                                    WaypointTrimming = 0;
1754
                                                FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1763
                                                FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1755
                                                HeightTrimming = 0;
1764
                                                HeightTrimming = 0;
1756
                                                if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500;
1765
                                                if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500;
1757
                                                if(!StartTrigger && HoehenWert > 50)
1766
                                                if(!StartTrigger && HoehenWert > 50)
1758
                                                {
1767
                                                {
1759
                                                 StartTrigger = 1;
1768
                                                 StartTrigger = 1;
1760
                                                }
1769
                                                }
1761
                                        }
1770
                                        }
1762
                                }
1771
                                }
1763
                                // Trim height set point
1772
                                // Trim height set point
1764
                                HeightTrimming += AltitudeSetpointTrimming;
1773
                                HeightTrimming += AltitudeSetpointTrimming;
1765
                                if(abs(HeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz
1774
                                if(abs(HeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz
1766
                                {
1775
                                {
1767
                                        if(WaypointTrimming)
1776
                                        if(WaypointTrimming)
1768
                                         {
1777
                                         {
1769
                                          if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) SollHoehe = FromNC_AltitudeSetpoint;
1778
                                          if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) SollHoehe = FromNC_AltitudeSetpoint;
1770
                                          else SollHoehe += WaypointTrimming;
1779
                                          else SollHoehe += WaypointTrimming;
1771
                                          }
1780
                                          }
1772
                                        else
1781
                                        else
1773
                                          {
1782
                                          {
1774
                                          if(HeightTrimming > 0)        SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3;
1783
                                          if(HeightTrimming > 0)        SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3;
1775
                                          else                    SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3;
1784
                                          else                    SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3;
1776
                                          }
1785
                                          }
1777
                                        HeightTrimming = 0;
1786
                                        HeightTrimming = 0;
1778
                                        LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied
1787
                                        LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied
1779
                                        if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100;
1788
                                        if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100;
1780
                                        //update hoover gas stick value when setpoint is shifted
1789
                                        //update hoover gas stick value when setpoint is shifted
1781
                       if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0)
1790
                       if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0)
1782
                       {
1791
                       {
1783
                           StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value
1792
                           StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value
1784
                           StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1793
                           StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1785
                           if(StickGasHover < 70) StickGasHover = 70;
1794
                           if(StickGasHover < 70) StickGasHover = 70;
1786
                           else if(StickGasHover > 150) StickGasHover = 150;
1795
                           else if(StickGasHover > 150) StickGasHover = 150;
1787
                       }
1796
                       }
1788
                                }
1797
                                }
1789
              if(BaroExpandActive) SollHoehe = HoehenWertF; // update setpoint to current altitude if Expanding is active
1798
              if(BaroExpandActive) SollHoehe = HoehenWertF; // update setpoint to current altitude if Expanding is active
1790
                        } //if FCFlags & MKFCFLAG_FLY
1799
                        } //if FCFlags & MKFCFLAG_FLY
1791
                        else
1800
                        else
1792
                        {
1801
                        {
1793
                         SollHoehe = HoehenWert - 400;
1802
                         SollHoehe = HoehenWert - 400;
1794
                         if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1803
                         if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1795
                         else StickGasHover = 120;
1804
                         else StickGasHover = 120;
1796
                         HoverGas = GasMischanteil;
1805
                         HoverGas = GasMischanteil;
1797
                         VarioCharacter = '.';
1806
                         VarioCharacter = '.';
1798
                         }
1807
                         }
1799
                        HCGas = HoverGas;      // take hover gas (neutral point)
1808
                        HCGas = HoverGas;      // take hover gas (neutral point)
1800
                   }
1809
                   }
1801
         if(HoehenWertF > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT))
1810
         if(HoehenWertF > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT))
1802
                 {
1811
                 {
1803
                  if(!ACC_AltitudeControl)
1812
                  if(!ACC_AltitudeControl)
1804
                  {
1813
                  {
1805
                        // from this point the Heigth Control Algorithm is identical for both versions
1814
                        // from this point the Heigth Control Algorithm is identical for both versions
1806
                        if(BaroExpandActive) // baro range expanding active
1815
                        if(BaroExpandActive) // baro range expanding active
1807
                        {
1816
                        {
1808
                                HCGas = HoverGas; // hover while expanding baro adc range
1817
                                HCGas = HoverGas; // hover while expanding baro adc range
1809
                                HeightDeviation = 0;
1818
                                HeightDeviation = 0;
1810
                        } // EOF // baro range expanding active
1819
                        } // EOF // baro range expanding active
1811
                        else // valid data from air pressure sensor
1820
                        else // valid data from air pressure sensor
1812
                        {
1821
                        {
1813
                                // ------------------------- P-Part ----------------------------
1822
                                // ------------------------- P-Part ----------------------------
1814
                                tmp_long = (HoehenWertF - SollHoehe); // positive when too high
1823
                                tmp_long = (HoehenWertF - SollHoehe); // positive when too high
1815
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1824
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1816
                                HeightDeviation = (int)(tmp_long); // positive when too high
1825
                                HeightDeviation = (int)(tmp_long); // positive when too high
1817
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1826
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1818
                                LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense
1827
                                LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense
1819
                                GasReduction = tmp_long;
1828
                                GasReduction = tmp_long;
1820
                                // ------------------------- D-Part 1: Vario Meter ----------------------------
1829
                                // ------------------------- D-Part 1: Vario Meter ----------------------------
1821
                                tmp_int = VarioMeter / 8;
1830
                                tmp_int = VarioMeter / 8;
1822
                                LIMIT_MIN_MAX(tmp_int, -127, 128);
1831
                                LIMIT_MIN_MAX(tmp_int, -127, 128);
1823
                                tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter
1832
                                tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter
1824
                                LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN);
1833
                                LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN);
1825
                                if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) tmp_int /= 4; // reduce d-part while trimming setpoint
1834
                                if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) tmp_int /= 4; // reduce d-part while trimming setpoint
1826
                                else
1835
                                else
1827
                                if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode
1836
                                if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode
1828
                                GasReduction += tmp_int;
1837
                                GasReduction += tmp_int;
1829
                        } // EOF no baro range expanding
1838
                        } // EOF no baro range expanding
1830
                        // ------------------------ D-Part 2: ACC-Z Integral  ------------------------
1839
                        // ------------------------ D-Part 2: ACC-Z Integral  ------------------------
1831
            if(Parameter_Hoehe_ACC_Wirkung)
1840
            if(Parameter_Hoehe_ACC_Wirkung)
1832
                         {
1841
                         {
1833
                          tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN);
1842
                          tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN);
1834
                          LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN);
1843
                          LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN);
1835
                          GasReduction += tmp_long;
1844
                          GasReduction += tmp_long;
1836
                         }
1845
                         }
1837
                        // ------------------------ D-Part 3: GpsZ  ----------------------------------
1846
                        // ------------------------ D-Part 3: GpsZ  ----------------------------------
1838
                        tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L;
1847
                        tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L;
1839
            LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN);
1848
            LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN);
1840
                        GasReduction += tmp_int;
1849
                        GasReduction += tmp_int;
1841
            GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value
1850
            GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value
1842
 
1851
 
1843
                        // ------------------------                  ----------------------------------
1852
                        // ------------------------                  ----------------------------------
1844
                        HCGas -= GasReduction;
1853
                        HCGas -= GasReduction;
1845
                        // limit deviation from hoover point within the target region
1854
                        // limit deviation from hoover point within the target region
1846
                        if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero
1855
                        if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero
1847
                        {
1856
                        {
1848
                         unsigned int tmp;
1857
                         unsigned int tmp;
1849
                         tmp = abs(HeightDeviation);
1858
                         tmp = abs(HeightDeviation);
1850
                         if(tmp <= 60)
1859
                         if(tmp <= 60)
1851
                         {
1860
                         {
1852
                          LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point
1861
                          LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point
1853
                         }
1862
                         }
1854
                         else
1863
                         else
1855
                         {
1864
                         {
1856
                                tmp = (tmp - 60) / 32;
1865
                                tmp = (tmp - 60) / 32;
1857
                                if(tmp > 15) tmp = 15;
1866
                                if(tmp > 15) tmp = 15;
1858
                           if(HeightDeviation > 0)
1867
                           if(HeightDeviation > 0)
1859
                                {
1868
                                {
1860
                                tmp = (HoverGasMin * (16 - tmp)) / 16;
1869
                                tmp = (HoverGasMin * (16 - tmp)) / 16;
1861
                                LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point
1870
                                LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point
1862
                                }
1871
                                }
1863
                                else
1872
                                else
1864
                                {
1873
                                {
1865
                                tmp = (HoverGasMax * (tmp + 16)) / 16;
1874
                                tmp = (HoverGasMax * (tmp + 16)) / 16;
1866
                                LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point
1875
                                LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point
1867
                                }
1876
                                }
1868
                          }
1877
                          }
1869
                        }
1878
                        }
1870
                        // strech control output by inverse attitude projection 1/cos
1879
                        // strech control output by inverse attitude projection 1/cos
1871
            // + 1/cos(angle)  ++++++++++++++++++++++++++
1880
            // + 1/cos(angle)  ++++++++++++++++++++++++++
1872
                        tmp_long2 = (int32_t)HCGas;
1881
                        tmp_long2 = (int32_t)HCGas;
1873
                        tmp_long2 *= 8192L;
1882
                        tmp_long2 *= 8192L;
1874
                        tmp_long2 /= CosAttitude;
1883
                        tmp_long2 /= CosAttitude;
1875
                        HCGas = (int16_t)tmp_long2;
1884
                        HCGas = (int16_t)tmp_long2;
1876
                        // update height control gas averaging
1885
                        // update height control gas averaging
1877
                        FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE;
1886
                        FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE;
1878
                        // limit height control gas pd-control output
1887
                        // limit height control gas pd-control output
1879
                        LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN);
1888
                        LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN);
1880
                        // set GasMischanteil to HeightControlGasFilter
1889
                        // set GasMischanteil to HeightControlGasFilter
1881
            if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)
1890
            if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)
1882
                        {  // old version
1891
                        {  // old version
1883
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1892
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1884
                                GasMischanteil = FilterHCGas;
1893
                                GasMischanteil = FilterHCGas;
1885
                        }
1894
                        }
1886
                        else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode
1895
                        else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode
1887
                   }
1896
                   }
1888
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1897
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1889
          else // ACC-Altitude control
1898
          else // ACC-Altitude control
1890
                   {
1899
                   {
1891
                        // from this point the Heigth Control Algorithm is identical for both versions
1900
                        // from this point the Heigth Control Algorithm is identical for both versions
1892
                        if(BaroExpandActive) // baro range expanding active
1901
                        if(BaroExpandActive) // baro range expanding active
1893
                        {
1902
                        {
1894
                                HCGas = HoverGas; // hover while expanding baro adc range
1903
                                HCGas = HoverGas; // hover while expanding baro adc range
1895
                                HeightDeviation = 0;
1904
                                HeightDeviation = 0;
1896
                        } // EOF // baro range expanding active
1905
                        } // EOF // baro range expanding active
1897
                        else // valid data from air pressure sensor
1906
                        else // valid data from air pressure sensor
1898
                        {
1907
                        {
1899
                                // ------------------------- P-Part ----------------------------
1908
                                // ------------------------- P-Part ----------------------------
1900
                                tmp_long = (HoehenWertF - SollHoehe); // positive when too high
1909
                                tmp_long = (HoehenWertF - SollHoehe); // positive when too high
1901
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1910
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1902
                                HeightDeviation = (int)(tmp_long); // positive when too high
1911
                                HeightDeviation = (int)(tmp_long); // positive when too high
1903
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1912
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1904
                                LIMIT_MIN_MAX(tmp_long, -511 * STICK_GAIN, 512 * STICK_GAIN); // more than full range makes sense
1913
                                LIMIT_MIN_MAX(tmp_long, -511 * STICK_GAIN, 512 * STICK_GAIN); // more than full range makes sense
1905
                                GasReduction = tmp_long;
1914
                                GasReduction = tmp_long;
1906
                                // ------------------------ D-Part: ACC-Z Integral  ------------------------
1915
                                // ------------------------ D-Part: ACC-Z Integral  ------------------------
1907
                                tmp_long = VarioMeter + (AdWertAccHoch * Parameter_Hoehe_ACC_Wirkung)/256;
1916
                                tmp_long = VarioMeter + (AdWertAccHoch * Parameter_Hoehe_ACC_Wirkung)/256;
1908
                                // ------------------------- D-Part: Vario Meter ----------------------------
1917
                                // ------------------------- D-Part: Vario Meter ----------------------------
1909
                                if(WaypointTrimming) {
1918
                                if(WaypointTrimming) {
1910
                                        Variance = AltitudeSetpointTrimming * 8;       
1919
                                        Variance = AltitudeSetpointTrimming * 8;       
1911
                                } else {
1920
                                } else {
1912
                                        Variance = AltitudeSetpointTrimming * EE_Parameter.Hoehe_Verstaerkung*9/32;
1921
                                        Variance = AltitudeSetpointTrimming * EE_Parameter.Hoehe_Verstaerkung*9/32;
1913
                                }
1922
                                }
1914
                                tmp_long -= (long)Variance;
1923
                                tmp_long -= (long)Variance;
1915
                                tmp_long = (tmp_long * (long)Parameter_Luftdruck_D) / 32; // scale to d-gain parameter
1924
                                tmp_long = (tmp_long * (long)Parameter_Luftdruck_D) / 32; // scale to d-gain parameter
1916
                                LIMIT_MIN_MAX(tmp_long,-511 * STICK_GAIN, 512 * STICK_GAIN);
1925
                                LIMIT_MIN_MAX(tmp_long,-511 * STICK_GAIN, 512 * STICK_GAIN);
1917
                                GasReduction += tmp_long;
1926
                                GasReduction += tmp_long;
1918
                        } // EOF no baro range expanding
1927
                        } // EOF no baro range expanding
1919
                        HCGas -= GasReduction;
1928
                        HCGas -= GasReduction;
1920
                        LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limits gas around hover point
1929
                        LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limits gas around hover point
1921
                        // strech control output by inverse attitude projection 1/cos
1930
                        // strech control output by inverse attitude projection 1/cos
1922
            // + 1/cos(angle)  ++++++++++++++++++++++++++
1931
            // + 1/cos(angle)  ++++++++++++++++++++++++++
1923
                        tmp_long2 = (int32_t)HCGas;
1932
                        tmp_long2 = (int32_t)HCGas;
1924
                        tmp_long2 *= 8192L;
1933
                        tmp_long2 *= 8192L;
1925
                        tmp_long2 /= CosAttitude;
1934
                        tmp_long2 /= CosAttitude;
1926
                        HCGas = (int16_t)tmp_long2;
1935
                        HCGas = (int16_t)tmp_long2;
1927
                        // update height control gas averaging
1936
                        // update height control gas averaging
1928
                        FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE;
1937
                        FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE;
1929
                        // limit height control gas pd-control output
1938
                        // limit height control gas pd-control output
1930
                        LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN);
1939
                        LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN);
1931
                        // set GasMischanteil to HeightControlGasFilter
1940
                        // set GasMischanteil to HeightControlGasFilter
1932
            if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)
1941
            if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)
1933
                        {  // old version
1942
                        {  // old version
1934
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1943
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1935
                                GasMischanteil = FilterHCGas;
1944
                                GasMischanteil = FilterHCGas;
1936
                        }
1945
                        }
1937
                        else GasMischanteil = FilterHCGas;
1946
                        else GasMischanteil = FilterHCGas;
1938
           } // end of ACC-Altitude control
1947
           } // end of ACC-Altitude control
1939
#endif
1948
#endif
1940
                  }
1949
                  }
1941
                }// EOF height control active
1950
                }// EOF height control active
1942
                else // HC not active
1951
                else // HC not active
1943
                {
1952
                {
1944
                        //update hoover gas stick value when HC is not active
1953
                        //update hoover gas stick value when HC is not active
1945
                        if(!EE_Parameter.Hoehe_StickNeutralPoint)
1954
                        if(!EE_Parameter.Hoehe_StickNeutralPoint)
1946
                        {
1955
                        {
1947
                                StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value
1956
                                StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value
1948
                                StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1957
                                StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1949
                        }
1958
                        }
1950
                        else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1959
                        else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1951
            LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down
1960
            LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down
1952
                        FilterHCGas = GasMischanteil;
1961
                        FilterHCGas = GasMischanteil;
1953
                        // set both flags to indicate no vario mode
1962
                        // set both flags to indicate no vario mode
1954
                        FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1963
                        FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1955
                        FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL;
1964
                        FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL;
1956
                }
1965
                }
1957
                // Hover gas estimation by averaging gas control output on small z-velocities
1966
                // Hover gas estimation by averaging gas control output on small z-velocities
1958
                // this is done only if height contol option is selected in global config and aircraft is flying
1967
                // this is done only if height contol option is selected in global config and aircraft is flying
1959
                if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING))
1968
                if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING))
1960
                {
1969
                {
1961
                        //if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation
1970
                        //if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation
1962
                        if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(HoverGas); // 0.90f: geändert
1971
                        if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(HoverGas); // 0.90f: geändert
1963
                        if(StartTrigger == 1) StartTrigger = 2;
1972
                        if(StartTrigger == 1) StartTrigger = 2;
1964
                                tmp_long2 = (int32_t)GasMischanteil; // take current thrust
1973
                                tmp_long2 = (int32_t)GasMischanteil; // take current thrust
1965
                                tmp_long2 *= CosAttitude;            // apply attitude projection
1974
                                tmp_long2 *= CosAttitude;            // apply attitude projection
1966
                                tmp_long2 /= 8192;
1975
                                tmp_long2 /= 8192;
1967
                                // average vertical projected thrust
1976
                                // average vertical projected thrust
1968
                            if(modell_fliegt < 4000) // the first 8 seconds
1977
                            if(modell_fliegt < 4000) // the first 8 seconds
1969
                                {   // reduce the time constant of averaging by factor of 4 to get much faster a stable value
1978
                                {   // reduce the time constant of averaging by factor of 4 to get much faster a stable value
1970
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L);
1979
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L);
1971
                                        HoverGasFilter += 16L * tmp_long2;
1980
                                        HoverGasFilter += 16L * tmp_long2;
1972
                                }
1981
                                }
1973
                if(modell_fliegt < 8000) // the first 16 seconds
1982
                if(modell_fliegt < 8000) // the first 16 seconds
1974
                                {   // reduce the time constant of averaging by factor of 2 to get much faster a stable value
1983
                                {   // reduce the time constant of averaging by factor of 2 to get much faster a stable value
1975
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L);
1984
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L);
1976
                                        HoverGasFilter += 4L * tmp_long2;
1985
                                        HoverGasFilter += 4L * tmp_long2;
1977
                                }
1986
                                }
1978
                          else //later
1987
                          else //later
1979
                          if(abs(VarioMeter) < 100 && abs(HoehenWertF - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending)
1988
                          if(abs(VarioMeter) < 100 && abs(HoehenWertF - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending)
1980
                                {
1989
                                {
1981
                                        HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE;
1990
                                        HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE;
1982
                                        HoverGasFilter += tmp_long2;
1991
                                        HoverGasFilter += tmp_long2;
1983
                                }
1992
                                }
1984
                                HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE);
1993
                                HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE);
1985
                                if(EE_Parameter.Hoehe_HoverBand)
1994
                                if(EE_Parameter.Hoehe_HoverBand)
1986
                                {
1995
                                {
1987
                                        int16_t band;
1996
                                        int16_t band;
1988
                                        band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range
1997
                                        band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range
1989
                                        HoverGasMin = HoverGas - band;
1998
                                        HoverGasMin = HoverGas - band;
1990
                                        HoverGasMax = HoverGas + band;
1999
                                        HoverGasMax = HoverGas + band;
1991
                                }
2000
                                }
1992
                                else
2001
                                else
1993
                                {       // no limit
2002
                                {       // no limit
1994
                                        HoverGasMin = 0;
2003
                                        HoverGasMin = 0;
1995
                                        HoverGasMax = 1023;
2004
                                        HoverGasMax = 1023;
1996
                                }
2005
                                }
1997
                }
2006
                }
1998
                 else
2007
                 else
1999
                  {
2008
                  {
2000
                   StartTrigger = 0;
2009
                   StartTrigger = 0;
2001
                   HoverGasFilter = 0;
2010
                   HoverGasFilter = 0;
2002
                   HoverGas = 0;
2011
                   HoverGas = 0;
2003
                  }
2012
                  }
2004
        }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL
2013
        }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL
2005
        else
2014
        else
2006
        {
2015
        {
2007
                // set undefined state to indicate vario off
2016
                // set undefined state to indicate vario off
2008
                FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
2017
                FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
2009
        } // EOF no height control
2018
        } // EOF no height control
2010
 
2019
 
2011
   // Limits the maximum gas in case of "Out of Range emergency landing"
2020
   // Limits the maximum gas in case of "Out of Range emergency landing"
2012
   if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING)
2021
   if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING)
2013
        {
2022
        {
2014
         if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN;
2023
         if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN;
2015
         SollHoehe = HoehenWertF; // update setpoint to current heigth
2024
         SollHoehe = HoehenWertF; // update setpoint to current heigth
2016
          beeptime = 15000;
2025
          beeptime = 15000;
2017
          BeepMuster = 0x0E00;
2026
          BeepMuster = 0x0E00;
2018
        }
2027
        }
2019
    // limit gas to parameter setting
2028
    // limit gas to parameter setting
2020
  LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN);
2029
  LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN);
2021
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
2030
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
2022
 
2031
 
2023
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2032
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2024
// all BL-Ctrl connected?
2033
// all BL-Ctrl connected?
2025
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2034
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2026
  if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode)      // wait until all BL-Ctrls started and no Errors
2035
  if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode)      // wait until all BL-Ctrls started and no Errors
2027
  if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)    // only during start-phase
2036
  if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)    // only during start-phase
2028
   {
2037
   {
2029
    modell_fliegt = 1;
2038
    modell_fliegt = 1;
2030
        GasMischanteil = (MIN_GAS + 10) * STICK_GAIN;
2039
        GasMischanteil = (MIN_GAS + 10) * STICK_GAIN;
2031
   }
2040
   }
2032
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2041
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2033
// + Mischer und PI-Regler
2042
// + Mischer und PI-Regler
2034
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2043
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2035
  DebugOut.Analog[7] = GasMischanteil;
2044
  DebugOut.Analog[7] = GasMischanteil;
2036
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2045
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2037
// Gier-Anteil
2046
// Gier-Anteil
2038
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2047
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2039
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
2048
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
2040
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
2049
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
2041
   if(GasMischanteil > MIN_GIERGAS)
2050
   if(GasMischanteil > MIN_GIERGAS)
2042
    {
2051
    {
2043
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
2052
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
2044
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
2053
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
2045
    }
2054
    }
2046
    else
2055
    else
2047
    {
2056
    {
2048
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
2057
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
2049
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
2058
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
2050
    }
2059
    }
2051
    tmp_int = MAX_GAS*STICK_GAIN;
2060
    tmp_int = MAX_GAS*STICK_GAIN;
2052
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
2061
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
2053
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
2062
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
2054
 
2063
 
2055
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2064
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2056
// Nick-Achse
2065
// Nick-Achse
2057
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2066
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2058
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
2067
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
2059
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
2068
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
2060
    else  SummeNick += DiffNick; // I-Anteil bei HH
2069
    else  SummeNick += DiffNick; // I-Anteil bei HH
2061
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
2070
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
2062
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
2071
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
2063
 
2072
 
2064
    if(EE_Parameter.Gyro_Stability <= 8)        pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick
2073
    if(EE_Parameter.Gyro_Stability <= 8)        pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick
2065
    else                                                                        pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern
2074
    else                                                                        pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern
2066
    pd_ergebnis_nick +=  SummeNick / Ki;
2075
    pd_ergebnis_nick +=  SummeNick / Ki;
2067
 
2076
 
2068
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
2077
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
2069
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
2078
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
2070
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
2079
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
2071
 
2080
 
2072
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2081
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2073
// Roll-Achse
2082
// Roll-Achse
2074
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2083
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2075
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
2084
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
2076
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
2085
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
2077
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
2086
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
2078
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
2087
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
2079
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
2088
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
2080
 
2089
 
2081
    if(EE_Parameter.Gyro_Stability <= 8)        pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8;        // PI-Regler für Roll
2090
    if(EE_Parameter.Gyro_Stability <= 8)        pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8;        // PI-Regler für Roll
2082
        else                                                                    pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4;  // Überlauf verhindern
2091
        else                                                                    pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4;  // Überlauf verhindern
2083
    pd_ergebnis_roll += SummeRoll / Ki;
2092
    pd_ergebnis_roll += SummeRoll / Ki;
2084
       
2093
       
2085
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
2094
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
2086
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
2095
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
2087
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
2096
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
2088
 
2097
 
2089
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2098
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2090
// Universal Mixer
2099
// Universal Mixer
2091
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2100
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2092
        for(i=0; i<MAX_MOTORS; i++)
2101
        for(i=0; i<MAX_MOTORS; i++)
2093
        {
2102
        {
2094
                signed int tmp_int;
2103
                signed int tmp_int;
2095
                if(Mixer.Motor[i][0] > 0)
2104
                if(Mixer.Motor[i][0] > 0)
2096
                {
2105
                {
2097
                        // Gas
2106
                        // Gas
2098
                        if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
2107
                        if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
2099
                        // Nick
2108
                        // Nick
2100
                        if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick;
2109
                        if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick;
2101
                        else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick;
2110
                        else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick;
2102
                        else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
2111
                        else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
2103
            // Roll
2112
            // Roll
2104
                        if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll;
2113
                        if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll;
2105
                        else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll;
2114
                        else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll;
2106
                        else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
2115
                        else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
2107
            // Gier
2116
            // Gier
2108
                        if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil;
2117
                        if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil;
2109
                        else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil;
2118
                        else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil;
2110
                        else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
2119
                        else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
2111
 
2120
 
2112
                        if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2;      // MotorSmoothing
2121
                        if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2;      // MotorSmoothing
2113
//                      else tmp_int = 2 * tmp_int - tmp_motorwert[i];                       // original MotorSmoothing
2122
//                      else tmp_int = 2 * tmp_int - tmp_motorwert[i];                       // original MotorSmoothing
2114
            else
2123
            else
2115
                        {
2124
                        {
2116
                            if(EE_Parameter.MotorSmooth == 0)
2125
                            if(EE_Parameter.MotorSmooth == 0)
2117
                                {
2126
                                {
2118
                                  tmp_int = 2 * tmp_int - tmp_motorwert[i];  // original MotorSmoothing
2127
                                  tmp_int = 2 * tmp_int - tmp_motorwert[i];  // original MotorSmoothing
2119
                                }
2128
                                }
2120
                                                        else  // 1 means tmp_int = tmp_int;
2129
                                                        else  // 1 means tmp_int = tmp_int;
2121
                            if(EE_Parameter.MotorSmooth > 1)
2130
                            if(EE_Parameter.MotorSmooth > 1)
2122
                                {
2131
                                {
2123
                                        // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value.
2132
                                        // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value.
2124
                                  tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/EE_Parameter.MotorSmooth);
2133
                                  tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/EE_Parameter.MotorSmooth);
2125
                                }
2134
                                }
2126
                        }
2135
                        }
2127
 
2136
 
2128
                        LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4);
2137
                        LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4);
2129
                        Motor[i].SetPoint = tmp_int / 4;
2138
                        Motor[i].SetPoint = tmp_int / 4;
2130
                        Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total)
2139
                        Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total)
2131
            tmp_motorwert[i] = tmp_int;
2140
            tmp_motorwert[i] = tmp_int;
2132
                }
2141
                }
2133
                else
2142
                else
2134
                {
2143
                {
2135
                        Motor[i].SetPoint = 0;
2144
                        Motor[i].SetPoint = 0;
2136
                        Motor[i].SetPointLowerBits = 0;
2145
                        Motor[i].SetPointLowerBits = 0;
2137
                }
2146
                }
2138
        }
2147
        }
2139
}
2148
}
2140
//DebugOut.Analog[16]
2149
//DebugOut.Analog[16]
2141
 
2150