Subversion Repositories FlightCtrl

Rev

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

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