Subversion Repositories FlightCtrl

Rev

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

Rev 1244 Rev 1265
1
/*#######################################################################################
1
/*#######################################################################################
2
Flight Control
2
Flight Control
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
12
// + bzgl. der Nutzungsbedingungen aufzunehmen.
12
// + bzgl. der Nutzungsbedingungen aufzunehmen.
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + mit unserer Zustimmung zulässig
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
33
// + this list of conditions and the following disclaimer.
33
// + this list of conditions and the following disclaimer.
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +     from this software without specific prior written permission.
35
// +     from this software without specific prior written permission.
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
37
// +     for non-commercial use (directly or indirectly)
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
39
// +     with our written permission
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// +     clearly linked as origin
41
// +     clearly linked as origin
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  POSSIBILITY OF SUCH DAMAGE.
52
// +  POSSIBILITY OF SUCH DAMAGE.
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
 
54
 
55
#include "main.h"
55
#include "main.h"
56
#include "eeprom.c"
56
#include "eeprom.c"
57
 
57
 
58
unsigned char h,m,s;
58
unsigned char h,m,s;
59
volatile unsigned int I2CTimeout = 100;
59
volatile unsigned int I2CTimeout = 100;
60
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
60
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
61
int TrimNick, TrimRoll;
61
int TrimNick, TrimRoll;
62
int AdNeutralGierBias;
62
int AdNeutralGierBias;
63
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
63
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
64
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
64
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
65
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
65
int NaviAccNick, NaviAccRoll,NaviCntAcc = 0;
66
volatile float NeutralAccZ = 0;
66
volatile float NeutralAccZ = 0;
67
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
67
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
68
long IntegralNick = 0,IntegralNick2 = 0;
68
long IntegralNick = 0,IntegralNick2 = 0;
69
long IntegralRoll = 0,IntegralRoll2 = 0;
69
long IntegralRoll = 0,IntegralRoll2 = 0;
70
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
70
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
71
long Integral_Gier = 0;
71
long Integral_Gier = 0;
72
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
72
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
73
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
73
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
74
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
74
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
75
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
75
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
76
volatile long Mess_Integral_Hoch = 0;
76
volatile long Mess_Integral_Hoch = 0;
77
int  KompassValue = 0;
77
int  KompassValue = 0;
78
int  KompassStartwert = 0;
78
int  KompassStartwert = 0;
79
int  KompassRichtung = 0;
79
int  KompassRichtung = 0;
80
unsigned int  KompassSignalSchlecht = 500;
80
unsigned int  KompassSignalSchlecht = 500;
81
unsigned char  MAX_GAS,MIN_GAS;
81
unsigned char  MAX_GAS,MIN_GAS;
82
unsigned char Notlandung = 0;
82
unsigned char Notlandung = 0;
83
unsigned char HoehenReglerAktiv = 0;
83
unsigned char HoehenReglerAktiv = 0;
84
unsigned char TrichterFlug = 0;
84
unsigned char TrichterFlug = 0;
85
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
85
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
86
long  ErsatzKompass;
86
long  ErsatzKompass;
87
int   ErsatzKompassInGrad; // Kompasswert in Grad
87
int   ErsatzKompassInGrad; // Kompasswert in Grad
88
int   GierGyroFehler = 0;
88
int   GierGyroFehler = 0;
89
char GyroFaktor,GyroFaktorGier;
89
char GyroFaktor,GyroFaktorGier;
90
char IntegralFaktor,IntegralFaktorGier;
90
char IntegralFaktor,IntegralFaktorGier;
91
int  DiffNick,DiffRoll;
91
int  DiffNick,DiffRoll;
92
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
92
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
93
volatile unsigned char SenderOkay = 0;
93
volatile unsigned char SenderOkay = 0;
94
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
94
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
95
char MotorenEin = 0;
95
char MotorenEin = 0;
96
int HoehenWert = 0;
96
int HoehenWert = 0;
97
int SollHoehe = 0;
97
int SollHoehe = 0;
98
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
98
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
99
//float Ki =  FAKTOR_I;
99
//float Ki =  FAKTOR_I;
100
int Ki = 10300 / 33;
100
int Ki = 10300 / 33;
101
unsigned char Looping_Nick = 0,Looping_Roll = 0;
101
unsigned char Looping_Nick = 0,Looping_Roll = 0;
102
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
102
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
103
 
103
 
104
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
104
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
105
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
105
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
106
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
106
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
107
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
107
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
108
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
108
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
109
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
109
unsigned char Parameter_Gyro_D = 8;             // Wert : 0-250
110
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
110
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
111
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
111
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
112
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
112
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
113
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
113
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
114
unsigned char Parameter_UserParam1 = 0;
114
unsigned char Parameter_UserParam1 = 0;
115
unsigned char Parameter_UserParam2 = 0;
115
unsigned char Parameter_UserParam2 = 0;
116
unsigned char Parameter_UserParam3 = 0;
116
unsigned char Parameter_UserParam3 = 0;
117
unsigned char Parameter_UserParam4 = 0;
117
unsigned char Parameter_UserParam4 = 0;
118
unsigned char Parameter_UserParam5 = 0;
118
unsigned char Parameter_UserParam5 = 0;
119
unsigned char Parameter_UserParam6 = 0;
119
unsigned char Parameter_UserParam6 = 0;
120
unsigned char Parameter_UserParam7 = 0;
120
unsigned char Parameter_UserParam7 = 0;
121
unsigned char Parameter_UserParam8 = 0;
121
unsigned char Parameter_UserParam8 = 0;
122
unsigned char Parameter_ServoNickControl = 100;
122
unsigned char Parameter_ServoNickControl = 100;
123
unsigned char Parameter_LoopGasLimit = 70;
123
unsigned char Parameter_LoopGasLimit = 70;
124
unsigned char Parameter_AchsKopplung1 = 90;
124
unsigned char Parameter_AchsKopplung1 = 90;
125
unsigned char Parameter_AchsKopplung2 = 65;
125
unsigned char Parameter_AchsKopplung2 = 65;
126
unsigned char Parameter_CouplingYawCorrection = 64;
126
unsigned char Parameter_CouplingYawCorrection = 64;
127
//unsigned char Parameter_AchsGegenKopplung1 = 0;
127
//unsigned char Parameter_AchsGegenKopplung1 = 0;
128
unsigned char Parameter_DynamicStability = 100;
128
unsigned char Parameter_DynamicStability = 100;
129
unsigned char Parameter_J16Bitmask;             // for the J16 Output
129
unsigned char Parameter_J16Bitmask;             // for the J16 Output
130
unsigned char Parameter_J16Timing;              // for the J16 Output
130
unsigned char Parameter_J16Timing;              // for the J16 Output
131
unsigned char Parameter_J17Bitmask;             // for the J17 Output
131
unsigned char Parameter_J17Bitmask;             // for the J17 Output
132
unsigned char Parameter_J17Timing;              // for the J17 Output
132
unsigned char Parameter_J17Timing;              // for the J17 Output
133
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
133
unsigned char Parameter_NaviGpsModeControl;     // Parameters for the Naviboard
134
unsigned char Parameter_NaviGpsGain;
134
unsigned char Parameter_NaviGpsGain;
135
unsigned char Parameter_NaviGpsP;
135
unsigned char Parameter_NaviGpsP;
136
unsigned char Parameter_NaviGpsI;
136
unsigned char Parameter_NaviGpsI;
137
unsigned char Parameter_NaviGpsD;
137
unsigned char Parameter_NaviGpsD;
138
unsigned char Parameter_NaviGpsACC;
138
unsigned char Parameter_NaviGpsACC;
139
unsigned char Parameter_NaviOperatingRadius;
139
unsigned char Parameter_NaviOperatingRadius;
140
unsigned char Parameter_NaviWindCorrection;
140
unsigned char Parameter_NaviWindCorrection;
141
unsigned char Parameter_NaviSpeedCompensation;
141
unsigned char Parameter_NaviSpeedCompensation;
142
unsigned char Parameter_ExternalControl;
142
unsigned char Parameter_ExternalControl;
143
struct mk_param_struct EE_Parameter;
143
struct mk_param_struct EE_Parameter;
144
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
144
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
145
int MaxStickNick = 0,MaxStickRoll = 0;
145
int MaxStickNick = 0,MaxStickRoll = 0;
146
unsigned int  modell_fliegt = 0;
146
unsigned int  modell_fliegt = 0;
147
volatile unsigned char MikroKopterFlags = 0;
147
volatile unsigned char MikroKopterFlags = 0;
148
long GIER_GRAD_FAKTOR = 1291;
148
long GIER_GRAD_FAKTOR = 1291;
149
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
149
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
150
unsigned char RequiredMotors = 4;
150
unsigned char RequiredMotors = 4;
151
unsigned char Motor[MAX_MOTORS];
151
unsigned char Motor[MAX_MOTORS];
152
signed int tmp_motorwert[MAX_MOTORS];
152
signed int tmp_motorwert[MAX_MOTORS];
153
 
153
 
154
int MotorSmoothing(int neu, int alt)
154
int MotorSmoothing(int neu, int alt)
155
{
155
{
156
 int motor;
156
 int motor;
157
 
157
 
158
 if(neu > alt)
158
 if(neu > alt)
159
 {
159
 {
160
        motor = (1*(int)alt + neu) / 2;
160
        motor = (1*(int)alt + neu) / 2;
161
 }
161
 }
162
 else
162
 else
163
 
163
 
164
// Arthur P: the original code allowed the motor value to drop to 0 or negative values
164
// Arthur P: the original code allowed the motor value to drop to 0 or negative values
165
// straight off, i.e. could amplify an intended decrease excessively while upregulation
165
// straight off, i.e. could amplify an intended decrease excessively while upregulation
166
// is dampened. The modification would still allow immediate drop below intended value 
166
// is dampened. The modification would still allow immediate drop below intended value 
167
// but would dampen this. This would still allow for airbraking of the prop to have effect
167
// but would dampen this. This would still allow for airbraking of the prop to have effect
168
// but it might lead to less sudden excessive drops in rpm with only gradual recovery.
168
// but it might lead to less sudden excessive drops in rpm with only gradual recovery.
-
 
169
// 090807 Arthur P: Due to problems with uart.c which still refers to user parameter 1 and 2 and 
-
 
170
// possible timing issues with the shutter interval load, removed the shutter interval functions
-
 
171
// and switched to use of userparam6 for the motor smoothing.
169
 
172
 
170
 {
173
 {
171
        if(Parameter_UserParam1 < 1)
174
        if(Parameter_UserParam6 < 1)
172
        { // Original function
175
        { // Original function
173
                motor = neu - (alt - neu)*1;
176
                motor = neu - (alt - neu)*1;
174
        }
177
        }
175
        else
178
        else
176
        {
179
        {
177
                if(Parameter_UserParam1 == 1)  // If userpara1 = 1 then 150% down on the first step followed by upsmoothing.
180
                if(Parameter_UserParam6 == 1)  // If userpara1 = 1 then 150% down on the first step followed by upsmoothing.
178
                {
181
                {
179
                        motor = neu - (1*(alt - neu)/2);
182
                        motor = neu - (1*(alt - neu)/2);
180
                }
183
                }
181
                else // If userpara1 > 1 then allow >= 50% of the intended step down to rapidly reach the intended value.
184
                else // If userpara5 > 1 then allow >= 50% of the intended step down to rapidly reach the intended value.
182
                {
185
                {
183
                        motor = neu + ((alt - neu)/Parameter_UserParam1);
186
                        motor = neu + ((alt - neu)/Parameter_UserParam6);
184
                }
187
                }
185
        }
188
        }
186
 }
189
 }
187
//if(Poti2 < 20)  return(neu);
190
//if(Poti2 < 20)  return(neu);
188
 return(motor);
191
 return(motor);
189
}
192
}
190
 
193
 
191
 
194
 
192
void Piep(unsigned char Anzahl)
195
void Piep(unsigned char Anzahl)
193
{
196
{
194
 while(Anzahl--)
197
 while(Anzahl--)
195
 {
198
 {
196
  if(MotorenEin) return; //auf keinen Fall im Flug!
199
  if(MotorenEin) return; //auf keinen Fall im Flug!
197
  beeptime = 100;
200
  beeptime = 100;
198
  Delay_ms(250);
201
  Delay_ms(250);
199
 }
202
 }
200
}
203
}
201
 
204
 
202
//############################################################################
205
//############################################################################
203
//  Nullwerte ermitteln
206
//  Nullwerte ermitteln
204
void SetNeutral(void)
207
void SetNeutral(void)
205
//############################################################################
208
//############################################################################
206
{
209
{
207
 unsigned char i;
210
 unsigned char i;
208
 unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
211
 unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0;
209
    ServoActive = 0; HEF4017R_ON;
212
    ServoActive = 0; HEF4017R_ON;
210
        NeutralAccX = 0;
213
        NeutralAccX = 0;
211
        NeutralAccY = 0;
214
        NeutralAccY = 0;
212
        NeutralAccZ = 0;
215
        NeutralAccZ = 0;
213
    AdNeutralNick = 0;
216
    AdNeutralNick = 0;
214
        AdNeutralRoll = 0;
217
        AdNeutralRoll = 0;
215
        AdNeutralGier = 0;
218
        AdNeutralGier = 0;
216
    AdNeutralGierBias = 0;
219
    AdNeutralGierBias = 0;
217
    Parameter_AchsKopplung1 = 0;
220
    Parameter_AchsKopplung1 = 0;
218
    Parameter_AchsKopplung2 = 0;
221
    Parameter_AchsKopplung2 = 0;
219
    ExpandBaro = 0;
222
    ExpandBaro = 0;
220
    CalibrierMittelwert();
223
    CalibrierMittelwert();
221
    Delay_ms_Mess(100);
224
    Delay_ms_Mess(100);
222
        CalibrierMittelwert();
225
        CalibrierMittelwert();
223
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
226
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
224
     {
227
     {
225
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
228
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
226
     }
229
     }
227
#define NEUTRAL_FILTER 32
230
#define NEUTRAL_FILTER 32
228
    for(i=0; i<NEUTRAL_FILTER; i++)
231
    for(i=0; i<NEUTRAL_FILTER; i++)
229
         {
232
         {
230
          Delay_ms_Mess(10);
233
          Delay_ms_Mess(10);
231
          gier_neutral += AdWertGier;
234
          gier_neutral += AdWertGier;
232
          nick_neutral += AdWertNick;
235
          nick_neutral += AdWertNick;
233
          roll_neutral += AdWertRoll;
236
          roll_neutral += AdWertRoll;
234
         }
237
         }
235
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
238
     AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
236
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
239
         AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
237
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
240
         AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER);
238
     AdNeutralGierBias = AdNeutralGier;
241
     AdNeutralGierBias = AdNeutralGier;
239
     StartNeutralRoll = AdNeutralRoll;
242
     StartNeutralRoll = AdNeutralRoll;
240
     StartNeutralNick = AdNeutralNick;
243
     StartNeutralNick = AdNeutralNick;
241
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
244
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
242
    {
245
    {
243
      NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
246
      NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY);
244
          NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
247
          NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY);
245
          NeutralAccZ = Aktuell_az;
248
          NeutralAccZ = Aktuell_az;
246
    }
249
    }
247
    else
250
    else
248
    {
251
    {
249
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
252
      NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]);
250
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
253
          NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]);
251
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
254
          NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]);
252
    }
255
    }
253
 
256
 
254
    MesswertNick = 0;
257
    MesswertNick = 0;
255
    MesswertRoll = 0;
258
    MesswertRoll = 0;
256
    MesswertGier = 0;
259
    MesswertGier = 0;
257
    Delay_ms_Mess(100);
260
    Delay_ms_Mess(100);
258
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
261
    Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
259
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
262
    Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
260
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
263
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
261
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
264
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
262
    Mess_IntegralNick2 = IntegralNick;
265
    Mess_IntegralNick2 = IntegralNick;
263
    Mess_IntegralRoll2 = IntegralRoll;
266
    Mess_IntegralRoll2 = IntegralRoll;
264
    Mess_Integral_Gier = 0;
267
    Mess_Integral_Gier = 0;
265
    StartLuftdruck = Luftdruck;
268
    StartLuftdruck = Luftdruck;
266
    HoeheD = 0;
269
    HoeheD = 0;
267
    Mess_Integral_Hoch = 0;
270
    Mess_Integral_Hoch = 0;
268
    KompassStartwert = KompassValue;
271
    KompassStartwert = KompassValue;
269
    GPS_Neutral();
272
    GPS_Neutral();
270
    beeptime = 50;
273
    beeptime = 50;
271
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
274
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
272
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
275
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
273
    ExternHoehenValue = 0;
276
    ExternHoehenValue = 0;
274
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
277
    ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
275
    GierGyroFehler = 0;
278
    GierGyroFehler = 0;
276
    SendVersionToNavi = 1;
279
    SendVersionToNavi = 1;
277
    LED_Init();
280
    LED_Init();
278
    MikroKopterFlags |= FLAG_CALIBRATE;
281
    MikroKopterFlags |= FLAG_CALIBRATE;
279
    FromNaviCtrl_Value.Kalman_K = -1;
282
    FromNaviCtrl_Value.Kalman_K = -1;
280
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
283
    FromNaviCtrl_Value.Kalman_MaxDrift = 0;
281
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
284
    FromNaviCtrl_Value.Kalman_MaxFusion = 32;
282
    Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110;
285
    Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110;
283
    Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110;
286
    Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110;
284
    Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110;
287
    Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110;
285
    Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110;
288
    Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110;
286
    ServoActive = 1;
289
    ServoActive = 1;
287
    SenderOkay = 100;
290
    SenderOkay = 100;
288
}
291
}
289
 
292
 
290
//############################################################################
293
//############################################################################
291
// Bearbeitet die Messwerte
294
// Bearbeitet die Messwerte
292
void Mittelwert(void)
295
void Mittelwert(void)
293
//############################################################################
296
//############################################################################
294
{
297
{
295
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
298
    static signed long tmpl,tmpl2,tmpl3,tmpl4;
296
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
299
        static signed int oldNick, oldRoll, d2Roll, d2Nick;
297
        signed long winkel_nick, winkel_roll;
300
        signed long winkel_nick, winkel_roll;
298
 
301
 
299
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
302
        MesswertGier = (signed int) AdNeutralGier - AdWertGier;
300
//    MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier;
303
//    MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier;
301
    MesswertNick = (signed int) AdWertNickFilter / 8;
304
    MesswertNick = (signed int) AdWertNickFilter / 8;
302
    MesswertRoll = (signed int) AdWertRollFilter / 8;
305
    MesswertRoll = (signed int) AdWertRollFilter / 8;
303
    RohMesswertNick = MesswertNick;
306
    RohMesswertNick = MesswertNick;
304
    RohMesswertRoll = MesswertRoll;
307
    RohMesswertRoll = MesswertRoll;
305
//DebugOut.Analog[21] = MesswertNick;
308
//DebugOut.Analog[21] = MesswertNick;
306
//DebugOut.Analog[22] = MesswertRoll;
309
//DebugOut.Analog[22] = MesswertRoll;
307
//DebugOut.Analog[22] = Mess_Integral_Gier;
310
//DebugOut.Analog[22] = Mess_Integral_Gier;
308
//DebugOut.Analog[21] = MesswertNick;
311
//DebugOut.Analog[21] = MesswertNick;
309
//DebugOut.Analog[22] = MesswertRoll;
312
//DebugOut.Analog[22] = MesswertRoll;
310
 
313
 
311
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
314
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
312
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
315
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L;
313
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
316
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L;
314
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
317
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L;
315
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
318
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
316
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
319
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
317
    NaviAccNick    += AdWertAccNick;
320
    NaviAccNick    += AdWertAccNick;
318
    NaviAccRoll    += AdWertAccRoll;
321
    NaviAccRoll    += AdWertAccRoll;
319
    NaviCntAcc++;
322
    NaviCntAcc++;
320
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
323
    IntegralAccZ  += Aktuell_az - NeutralAccZ;
321
 
324
 
322
//++++++++++++++++++++++++++++++++++++++++++++++++
325
//++++++++++++++++++++++++++++++++++++++++++++++++
323
// ADC einschalten
326
// ADC einschalten
324
    ANALOG_ON;
327
    ANALOG_ON;
325
        AdReady = 0;
328
        AdReady = 0;
326
//++++++++++++++++++++++++++++++++++++++++++++++++
329
//++++++++++++++++++++++++++++++++++++++++++++++++
327
 
330
 
328
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
331
    if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L;
329
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
332
        else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L;
330
        else winkel_roll = Mess_IntegralRoll;
333
        else winkel_roll = Mess_IntegralRoll;
331
 
334
 
332
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
335
    if(Mess_IntegralNick > 93000L) winkel_nick = 93000L;
333
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
336
        else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L;
334
        else winkel_nick = Mess_IntegralNick;
337
        else winkel_nick = Mess_IntegralNick;
335
 
338
 
336
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
339
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
337
   Mess_Integral_Gier += MesswertGier;
340
   Mess_Integral_Gier += MesswertGier;
338
   ErsatzKompass += MesswertGier;
341
   ErsatzKompass += MesswertGier;
339
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
342
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
340
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
343
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
341
         {
344
         {
342
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
345
            tmpl3 = (MesswertRoll * winkel_nick) / 2048L;
343
            tmpl3 *= Parameter_AchsKopplung2; //65
346
            tmpl3 *= Parameter_AchsKopplung2; //65
344
            tmpl3 /= 4096L;
347
            tmpl3 /= 4096L;
345
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
348
            tmpl4 = (MesswertNick * winkel_roll) / 2048L;
346
            tmpl4 *= Parameter_AchsKopplung2; //65
349
            tmpl4 *= Parameter_AchsKopplung2; //65
347
            tmpl4 /= 4096L;
350
            tmpl4 /= 4096L;
348
            KopplungsteilNickRoll = tmpl3;
351
            KopplungsteilNickRoll = tmpl3;
349
            KopplungsteilRollNick = tmpl4;
352
            KopplungsteilRollNick = tmpl4;
350
            tmpl4 -= tmpl3;
353
            tmpl4 -= tmpl3;
351
            ErsatzKompass += tmpl4;
354
            ErsatzKompass += tmpl4;
352
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
355
            if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen
353
 
356
 
354
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
357
            tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L;
355
            tmpl *= Parameter_AchsKopplung1;  // 90
358
            tmpl *= Parameter_AchsKopplung1;  // 90
356
            tmpl /= 4096L;
359
            tmpl /= 4096L;
357
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
360
            tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L;
358
            tmpl2 *= Parameter_AchsKopplung1;
361
            tmpl2 *= Parameter_AchsKopplung1;
359
            tmpl2 /= 4096L;
362
            tmpl2 /= 4096L;
360
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
363
            if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1;
361
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
364
            //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256;
362
         }
365
         }
363
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
366
      else  tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0;
364
 
367
 
365
TrimRoll = tmpl - tmpl2 / 100L;
368
TrimRoll = tmpl - tmpl2 / 100L;
366
TrimNick = -tmpl2 + tmpl / 100L;
369
TrimNick = -tmpl2 + tmpl / 100L;
367
 
370
 
368
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
371
// Kompasswert begrenzen  ++++++++++++++++++++++++++++++++++++++++++++++++
369
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
372
                    if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR;  // 360° Umschlag
370
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
373
                    if(ErsatzKompass < 0)                          ErsatzKompass += 360L * GIER_GRAD_FAKTOR;
371
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
374
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
372
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
375
            Mess_IntegralRoll2 += MesswertRoll + TrimRoll;
373
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
376
            Mess_IntegralRoll +=  MesswertRoll + TrimRoll - LageKorrekturRoll;
374
            if(Mess_IntegralRoll > Umschlag180Roll)
377
            if(Mess_IntegralRoll > Umschlag180Roll)
375
            {
378
            {
376
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
379
             Mess_IntegralRoll  = -(Umschlag180Roll - 25000L);
377
             Mess_IntegralRoll2 = Mess_IntegralRoll;
380
             Mess_IntegralRoll2 = Mess_IntegralRoll;
378
            }
381
            }
379
            if(Mess_IntegralRoll <-Umschlag180Roll)
382
            if(Mess_IntegralRoll <-Umschlag180Roll)
380
            {
383
            {
381
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
384
             Mess_IntegralRoll =  (Umschlag180Roll - 25000L);
382
             Mess_IntegralRoll2 = Mess_IntegralRoll;
385
             Mess_IntegralRoll2 = Mess_IntegralRoll;
383
            }
386
            }
384
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
387
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
385
            Mess_IntegralNick2 += MesswertNick + TrimNick;
388
            Mess_IntegralNick2 += MesswertNick + TrimNick;
386
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
389
            Mess_IntegralNick  += MesswertNick + TrimNick - LageKorrekturNick;
387
            if(Mess_IntegralNick > Umschlag180Nick)
390
            if(Mess_IntegralNick > Umschlag180Nick)
388
             {
391
             {
389
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
392
              Mess_IntegralNick = -(Umschlag180Nick - 25000L);
390
              Mess_IntegralNick2 = Mess_IntegralNick;
393
              Mess_IntegralNick2 = Mess_IntegralNick;
391
             }
394
             }
392
            if(Mess_IntegralNick <-Umschlag180Nick)
395
            if(Mess_IntegralNick <-Umschlag180Nick)
393
            {
396
            {
394
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
397
             Mess_IntegralNick =  (Umschlag180Nick - 25000L);
395
             Mess_IntegralNick2 = Mess_IntegralNick;
398
             Mess_IntegralNick2 = Mess_IntegralNick;
396
            }
399
            }
397
 
400
 
398
    Integral_Gier  = Mess_Integral_Gier;
401
    Integral_Gier  = Mess_Integral_Gier;
399
    IntegralNick = Mess_IntegralNick;
402
    IntegralNick = Mess_IntegralNick;
400
    IntegralRoll = Mess_IntegralRoll;
403
    IntegralRoll = Mess_IntegralRoll;
401
    IntegralNick2 = Mess_IntegralNick2;
404
    IntegralNick2 = Mess_IntegralNick2;
402
    IntegralRoll2 = Mess_IntegralRoll2;
405
    IntegralRoll2 = Mess_IntegralRoll2;
403
 
406
 
404
#define D_LIMIT 128
407
#define D_LIMIT 128
405
 
408
 
406
   MesswertNick = HiResNick / 8;
409
   MesswertNick = HiResNick / 8;
407
   MesswertRoll = HiResRoll / 8;
410
   MesswertRoll = HiResRoll / 8;
408
 
411
 
409
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
412
   if(AdWertNick < 15)   MesswertNick = -1000;  if(AdWertNick <  7)   MesswertNick = -2000;
410
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
413
   if(PlatinenVersion == 10)  { if(AdWertNick > 1010) MesswertNick = +1000;  if(AdWertNick > 1017) MesswertNick = +2000; }
411
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
414
   else  {  if(AdWertNick > 2000) MesswertNick = +1000;  if(AdWertNick > 2015) MesswertNick = +2000; }
412
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
415
   if(AdWertRoll < 15)   MesswertRoll = -1000;  if(AdWertRoll <  7)   MesswertRoll = -2000;
413
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
416
   if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000;  if(AdWertRoll > 1017) MesswertRoll = +2000; }
414
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
417
   else { if(AdWertRoll > 2000) MesswertRoll = +1000;  if(AdWertRoll > 2015) MesswertRoll = +2000;  }
415
 
418
 
416
  if(Parameter_Gyro_D)
419
  if(Parameter_Gyro_D)
417
  {
420
  {
418
   d2Nick = HiResNick - oldNick;
421
   d2Nick = HiResNick - oldNick;
419
   oldNick = (oldNick + HiResNick)/2;
422
   oldNick = (oldNick + HiResNick)/2;
420
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
423
   if(d2Nick > D_LIMIT) d2Nick = D_LIMIT;
421
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
424
   else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT;
422
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
425
   MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16;
423
   d2Roll = HiResRoll - oldRoll;
426
   d2Roll = HiResRoll - oldRoll;
424
   oldRoll = (oldRoll + HiResRoll)/2;
427
   oldRoll = (oldRoll + HiResRoll)/2;
425
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
428
   if(d2Roll > D_LIMIT) d2Roll = D_LIMIT;
426
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
429
   else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT;
427
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
430
   MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16;
428
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
431
   HiResNick += (d2Nick * (signed int) Parameter_Gyro_D);
429
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
432
   HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D);
430
  }
433
  }
431
 
434
 
432
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
435
 if(RohMesswertRoll > 0) TrimRoll  += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
433
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
436
 else                    TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L;
434
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
437
 if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
435
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
438
 else                    TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L;
436
 
439
 
437
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
440
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
438
  {
441
  {
439
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
442
    if(RohMesswertNick > 256)       MesswertNick += 1 * (RohMesswertNick - 256);
440
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
443
    else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256);
441
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
444
    if(RohMesswertRoll > 256)       MesswertRoll += 1 * (RohMesswertRoll - 256);
442
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
445
    else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256);
443
  }
446
  }
444
 
447
 
445
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
448
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
446
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
449
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
447
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
450
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
448
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
451
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
449
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
452
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
450
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
453
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
451
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
454
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
452
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
455
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
453
}
456
}
454
 
457
 
455
//############################################################################
458
//############################################################################
456
// Messwerte beim Ermitteln der Nullage
459
// Messwerte beim Ermitteln der Nullage
457
void CalibrierMittelwert(void)
460
void CalibrierMittelwert(void)
458
//############################################################################
461
//############################################################################
459
{
462
{
460
    if(PlatinenVersion == 13) SucheGyroOffset();
463
    if(PlatinenVersion == 13) SucheGyroOffset();
461
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
464
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
462
        ANALOG_OFF;
465
        ANALOG_OFF;
463
        MesswertNick = AdWertNick;
466
        MesswertNick = AdWertNick;
464
        MesswertRoll = AdWertRoll;
467
        MesswertRoll = AdWertRoll;
465
        MesswertGier = AdWertGier;
468
        MesswertGier = AdWertGier;
466
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
469
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
467
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
470
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
468
        Mittelwert_AccHoch = (long)AdWertAccHoch;
471
        Mittelwert_AccHoch = (long)AdWertAccHoch;
469
   // ADC einschalten
472
   // ADC einschalten
470
    ANALOG_ON;
473
    ANALOG_ON;
471
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
474
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
472
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
475
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
473
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
476
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
474
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
477
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
475
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
478
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
476
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
479
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
477
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
480
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
478
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
481
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
479
 
482
 
480
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
483
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
481
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
484
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
482
}
485
}
483
 
486
 
484
//############################################################################
487
//############################################################################
485
// Senden der Motorwerte per I2C-Bus
488
// Senden der Motorwerte per I2C-Bus
486
void SendMotorData(void)
489
void SendMotorData(void)
487
//############################################################################
490
//############################################################################
488
{
491
{
489
 unsigned char i;
492
 unsigned char i;
490
    if(!MotorenEin)
493
    if(!MotorenEin)
491
        {
494
        {
492
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
495
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
493
                 for(i=0;i<MAX_MOTORS;i++)
496
                 for(i=0;i<MAX_MOTORS;i++)
494
                  {
497
                  {
495
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
498
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
496
                   Motor[i] = MotorTest[i];
499
                   Motor[i] = MotorTest[i];
497
                  }
500
                  }
498
          if(PC_MotortestActive) PC_MotortestActive--;
501
          if(PC_MotortestActive) PC_MotortestActive--;
499
        }
502
        }
500
        else MikroKopterFlags |= FLAG_MOTOR_RUN;
503
        else MikroKopterFlags |= FLAG_MOTOR_RUN;
501
 
504
 
502
    DebugOut.Analog[12] = Motor[0];
505
    DebugOut.Analog[12] = Motor[0];
503
    DebugOut.Analog[13] = Motor[1];
506
    DebugOut.Analog[13] = Motor[1];
504
    DebugOut.Analog[14] = Motor[3];
507
    DebugOut.Analog[14] = Motor[3];
505
    DebugOut.Analog[15] = Motor[2];
508
    DebugOut.Analog[15] = Motor[2];
506
 
509
 
507
    //Start I2C Interrupt Mode
510
    //Start I2C Interrupt Mode
508
    twi_state = 0;
511
    twi_state = 0;
509
    motor = 0;
512
    motor = 0;
510
    i2c_start();
513
    i2c_start();
511
}
514
}
512
 
515
 
513
 
516
 
514
 
517
 
515
//############################################################################
518
//############################################################################
516
// Trägt ggf. das Poti als Parameter ein
519
// Trägt ggf. das Poti als Parameter ein
517
void ParameterZuordnung(void)
520
void ParameterZuordnung(void)
518
//############################################################################
521
//############################################################################
519
{
522
{
520
 #define CHK_POTI_MM(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;}
523
 #define CHK_POTI_MM(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;}
521
 #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; }
524
 #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; }
522
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
525
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
523
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
526
 CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
524
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
527
 CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
525
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
528
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
526
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
529
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
527
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
530
 CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
528
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
531
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
529
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255);
532
 CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255);
530
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
533
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
531
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
534
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
532
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
535
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
533
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
536
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
534
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
537
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
535
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
538
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
536
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
539
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
537
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
540
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
538
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
541
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
539
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
542
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
540
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
543
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
541
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
544
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
542
 CHK_POTI(Parameter_AchsKopplung2,    EE_Parameter.AchsKopplung2,0,255);
545
 CHK_POTI(Parameter_AchsKopplung2,    EE_Parameter.AchsKopplung2,0,255);
543
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255);
546
 CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255);
544
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
547
// CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
545
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
548
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
546
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
549
 CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255);
547
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
550
 CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255);
548
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
551
 CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255);
549
 Ki = 10300 / (Parameter_I_Faktor + 1);
552
 Ki = 10300 / (Parameter_I_Faktor + 1);
550
 MAX_GAS = EE_Parameter.Gas_Max;
553
 MAX_GAS = EE_Parameter.Gas_Max;
551
 MIN_GAS = EE_Parameter.Gas_Min;
554
 MIN_GAS = EE_Parameter.Gas_Min;
552
}
555
}
553
 
556
 
554
 
557
 
555
 
558
 
556
//############################################################################
559
//############################################################################
557
//
560
//
558
void MotorRegler(void)
561
void MotorRegler(void)
559
//############################################################################
562
//############################################################################
560
{
563
{
561
         int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int;
564
         int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int;
562
         int GierMischanteil,GasMischanteil;
565
         int GierMischanteil,GasMischanteil;
563
     static long SummeNick=0,SummeRoll=0;
566
     static long SummeNick=0,SummeRoll=0;
564
     static long sollGier = 0,tmp_long,tmp_long2;
567
     static long sollGier = 0,tmp_long,tmp_long2;
565
     static long IntegralFehlerNick = 0;
568
     static long IntegralFehlerNick = 0;
566
     static long IntegralFehlerRoll = 0;
569
     static long IntegralFehlerRoll = 0;
567
         static unsigned int RcLostTimer;
570
         static unsigned int RcLostTimer;
568
         static unsigned char delay_neutral = 0;
571
         static unsigned char delay_neutral = 0;
569
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
572
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
570
     static int hoehenregler = 0;
573
     static int hoehenregler = 0;
571
     static char TimerWerteausgabe = 0;
574
     static char TimerWerteausgabe = 0;
572
     static char NeueKompassRichtungMerken = 0;
575
     static char NeueKompassRichtungMerken = 0;
573
     static long ausgleichNick, ausgleichRoll;
576
     static long ausgleichNick, ausgleichRoll;
574
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
577
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
575
         unsigned char i;
578
         unsigned char i;
576
        Mittelwert();
579
        Mittelwert();
577
 
580
 
578
    GRN_ON;
581
    GRN_ON;
579
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
582
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
580
// Gaswert ermitteln
583
// Gaswert ermitteln
581
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
584
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
582
        GasMischanteil = StickGas;
585
        GasMischanteil = StickGas;
583
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
586
    if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10;
584
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
587
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
585
// Empfang schlecht
588
// Empfang schlecht
586
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
589
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
587
   if(SenderOkay < 100)
590
   if(SenderOkay < 100)
588
        {
591
        {
589
        if(!PcZugriff)
592
        if(!PcZugriff)
590
         {
593
         {
591
           if(BeepMuster == 0xffff)
594
           if(BeepMuster == 0xffff)
592
            {
595
            {
593
             beeptime = 15000;
596
             beeptime = 15000;
594
             BeepMuster = 0x0c00;
597
             BeepMuster = 0x0c00;
595
            }
598
            }
596
         }
599
         }
597
        if(RcLostTimer) RcLostTimer--;
600
        if(RcLostTimer) RcLostTimer--;
598
        else
601
        else
599
         {
602
         {
600
          MotorenEin = 0;
603
          MotorenEin = 0;
601
          Notlandung = 0;
604
          Notlandung = 0;
602
         }
605
         }
603
        ROT_ON;
606
        ROT_ON;
604
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
607
        if(modell_fliegt > 1000)  // wahrscheinlich in der Luft --> langsam absenken
605
            {
608
            {
606
            GasMischanteil = EE_Parameter.NotGas;
609
            GasMischanteil = EE_Parameter.NotGas;
607
            Notlandung = 1;
610
            Notlandung = 1;
608
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
611
            PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
609
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
612
            PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
610
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
613
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
611
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
614
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
612
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
615
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
613
            }
616
            }
614
         else MotorenEin = 0;
617
         else MotorenEin = 0;
615
        }
618
        }
616
        else
619
        else
617
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
620
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
618
// Emfang gut
621
// Emfang gut
619
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
622
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
620
        if(SenderOkay > 140)
623
        if(SenderOkay > 140)
621
            {
624
            {
622
            Notlandung = 0;
625
            Notlandung = 0;
623
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
626
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
624
            if(GasMischanteil > 40 && MotorenEin)
627
            if(GasMischanteil > 40 && MotorenEin)
625
                {
628
                {
626
                if(modell_fliegt < 0xffff) modell_fliegt++;
629
                if(modell_fliegt < 0xffff) modell_fliegt++;
627
                }
630
                }
628
            if((modell_fliegt < 256))
631
            if((modell_fliegt < 256))
629
                {
632
                {
630
                SummeNick = 0;
633
                SummeNick = 0;
631
                SummeRoll = 0;
634
                SummeRoll = 0;
632
                if(modell_fliegt == 250)
635
                if(modell_fliegt == 250)
633
                 {
636
                 {
634
                  NeueKompassRichtungMerken = 1;
637
                  NeueKompassRichtungMerken = 1;
635
                  sollGier = 0;
638
                  sollGier = 0;
636
                  Mess_Integral_Gier = 0;
639
                  Mess_Integral_Gier = 0;
637
//                  Mess_Integral_Gier2 = 0;
640
//                  Mess_Integral_Gier2 = 0;
638
                 }
641
                 }
639
                } else MikroKopterFlags |= FLAG_FLY;
642
                } else MikroKopterFlags |= FLAG_FLY;
640
 
643
 
641
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
644
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
642
                {
645
                {
643
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
646
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
644
// auf Nullwerte kalibrieren
647
// auf Nullwerte kalibrieren
645
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
648
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
646
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
649
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
647
                    {
650
                    {
648
                    if(++delay_neutral > 200)  // nicht sofort
651
                    if(++delay_neutral > 200)  // nicht sofort
649
                        {
652
                        {
650
                        GRN_OFF;
653
                        GRN_OFF;
651
                        MotorenEin = 0;
654
                        MotorenEin = 0;
652
                        delay_neutral = 0;
655
                        delay_neutral = 0;
653
                        modell_fliegt = 0;
656
                        modell_fliegt = 0;
654
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
657
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
655
                        {
658
                        {
656
                         unsigned char setting=1;
659
                         unsigned char setting=1;
657
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
660
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
658
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
661
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
659
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
662
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
660
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
663
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
661
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
664
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
662
                         SetActiveParamSetNumber(setting);  // aktiven Datensatz merken
665
                         SetActiveParamSetNumber(setting);  // aktiven Datensatz merken
663
                        }
666
                        }
664
//                        else
667
//                        else
665
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
668
                         if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70)
666
                          {
669
                          {
667
                           WinkelOut.CalcState = 1;
670
                           WinkelOut.CalcState = 1;
668
                           beeptime = 1000;
671
                           beeptime = 1000;
669
                          }
672
                          }
670
                          else
673
                          else
671
                          {
674
                          {
672
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
675
                               ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
673
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
676
                           if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
674
                            {
677
                            {
675
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
678
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
676
                            }
679
                            }
677
                           SetNeutral();
680
                           SetNeutral();
678
                           Piep(GetActiveParamSetNumber());
681
                           Piep(GetActiveParamSetNumber());
679
                         }
682
                         }
680
                        }
683
                        }
681
                    }
684
                    }
682
                 else
685
                 else
683
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
686
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
684
                    {
687
                    {
685
                    if(++delay_neutral > 200)  // nicht sofort
688
                    if(++delay_neutral > 200)  // nicht sofort
686
                        {
689
                        {
687
                        GRN_OFF;
690
                        GRN_OFF;
688
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
691
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen
689
                        MotorenEin = 0;
692
                        MotorenEin = 0;
690
                        delay_neutral = 0;
693
                        delay_neutral = 0;
691
                        modell_fliegt = 0;
694
                        modell_fliegt = 0;
692
                        SetNeutral();
695
                        SetNeutral();
693
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
696
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern
694
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
697
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern
695
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
698
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256);
696
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
699
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256);
697
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
700
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256);
698
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
701
                        eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256);
699
                        Piep(GetActiveParamSetNumber());
702
                        Piep(GetActiveParamSetNumber());
700
                        }
703
                        }
701
                    }
704
                    }
702
                 else delay_neutral = 0;
705
                 else delay_neutral = 0;
703
                }
706
                }
704
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
707
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
705
// Gas ist unten
708
// Gas ist unten
706
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
709
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
707
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
710
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
708
                {
711
                {
709
                // Starten
712
                // Starten
710
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
713
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
711
                    {
714
                    {
712
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
715
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
713
// Einschalten
716
// Einschalten
714
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
717
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
715
                    if(++delay_einschalten > 200)
718
                    if(++delay_einschalten > 200)
716
                        {
719
                        {
717
                        delay_einschalten = 200;
720
                        delay_einschalten = 200;
718
                        modell_fliegt = 1;
721
                        modell_fliegt = 1;
719
                        MotorenEin = 1;
722
                        MotorenEin = 1;
720
                        sollGier = 0;
723
                        sollGier = 0;
721
                        Mess_Integral_Gier = 0;
724
                        Mess_Integral_Gier = 0;
722
                        Mess_Integral_Gier2 = 0;
725
                        Mess_Integral_Gier2 = 0;
723
                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
726
                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
724
                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
727
                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
725
                        Mess_IntegralNick2 = IntegralNick;
728
                        Mess_IntegralNick2 = IntegralNick;
726
                        Mess_IntegralRoll2 = IntegralRoll;
729
                        Mess_IntegralRoll2 = IntegralRoll;
727
                        SummeNick = 0;
730
                        SummeNick = 0;
728
                        SummeRoll = 0;
731
                        SummeRoll = 0;
729
                        MikroKopterFlags |= FLAG_START;
732
                        MikroKopterFlags |= FLAG_START;
730
                        }
733
                        }
731
                    }
734
                    }
732
                    else delay_einschalten = 0;
735
                    else delay_einschalten = 0;
733
                //Auf Neutralwerte setzen
736
                //Auf Neutralwerte setzen
734
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
737
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
735
// Auschalten
738
// Auschalten
736
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
739
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
737
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
740
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
738
                    {
741
                    {
739
                    if(++delay_ausschalten > 200)  // nicht sofort
742
                    if(++delay_ausschalten > 200)  // nicht sofort
740
                        {
743
                        {
741
                        MotorenEin = 0;
744
                        MotorenEin = 0;
742
                        delay_ausschalten = 200;
745
                        delay_ausschalten = 200;
743
                        modell_fliegt = 0;
746
                        modell_fliegt = 0;
744
                        }
747
                        }
745
                    }
748
                    }
746
                else delay_ausschalten = 0;
749
                else delay_ausschalten = 0;
747
                }
750
                }
748
            }
751
            }
749
 
752
 
750
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
753
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
751
// neue Werte von der Funke
754
// neue Werte von der Funke
752
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
755
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
753
 
756
 
754
 if(!NewPpmData-- || Notlandung)
757
 if(!NewPpmData-- || Notlandung)
755
  {
758
  {
756
        static int stick_nick,stick_roll;
759
        static int stick_nick,stick_roll;
757
    ParameterZuordnung();
760
    ParameterZuordnung();
758
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
761
    stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
759
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
762
    stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
760
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
763
    StickNick = stick_nick - (GPS_Nick + GPS_Nick2);
761
 
764
 
762
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
765
    stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
763
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
766
    stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
764
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
767
    StickRoll = stick_roll - (GPS_Roll + GPS_Roll2);
765
 
768
 
766
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
769
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
767
        if(StickGier > 2) StickGier -= 2;       else
770
        if(StickGier > 2) StickGier -= 2;       else
768
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
771
        if(StickGier < -2) StickGier += 2; else StickGier = 0;
769
 
772
 
770
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
773
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
771
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
774
    GyroFaktor     = (Parameter_Gyro_P + 10.0);
772
    IntegralFaktor = Parameter_Gyro_I;
775
    IntegralFaktor = Parameter_Gyro_I;
773
    GyroFaktorGier     = (Parameter_Gyro_P + 10.0);
776
    GyroFaktorGier     = (Parameter_Gyro_P + 10.0);
774
    IntegralFaktorGier = Parameter_Gyro_I;
777
    IntegralFaktorGier = Parameter_Gyro_I;
775
 
778
 
776
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
779
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
777
//+ Analoge Steuerung per Seriell
780
//+ Analoge Steuerung per Seriell
778
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
781
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
779
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
782
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
780
    {
783
    {
781
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
784
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
782
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
785
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
783
         StickGier += ExternControl.Gier;
786
         StickGier += ExternControl.Gier;
784
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
787
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
785
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
788
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
786
    }
789
    }
787
    if(StickGas < 0) StickGas = 0;
790
    if(StickGas < 0) StickGas = 0;
788
 
791
 
789
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
792
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
790
    if(GyroFaktor < 0) GyroFaktor = 0;
793
    if(GyroFaktor < 0) GyroFaktor = 0;
791
    if(IntegralFaktor < 0) IntegralFaktor = 0;
794
    if(IntegralFaktor < 0) IntegralFaktor = 0;
792
 
795
 
793
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
796
    if(abs(StickNick/STICK_GAIN) > MaxStickNick)
794
     {
797
     {
795
      MaxStickNick = abs(StickNick)/STICK_GAIN;
798
      MaxStickNick = abs(StickNick)/STICK_GAIN;
796
      if(MaxStickNick > 100) MaxStickNick = 100;
799
      if(MaxStickNick > 100) MaxStickNick = 100;
797
     }
800
     }
798
     else MaxStickNick--;
801
     else MaxStickNick--;
799
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
802
    if(abs(StickRoll/STICK_GAIN) > MaxStickRoll)
800
     {
803
     {
801
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
804
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
802
      if(MaxStickRoll > 100) MaxStickRoll = 100;
805
      if(MaxStickRoll > 100) MaxStickRoll = 100;
803
     }
806
     }
804
     else MaxStickRoll--;
807
     else MaxStickRoll--;
805
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
808
    if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
806
 
809
 
807
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
810
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
808
// Looping?
811
// Looping?
809
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
812
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
810
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
813
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
811
  else
814
  else
812
   {
815
   {
813
     {
816
     {
814
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
817
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;
815
     }
818
     }
816
   }
819
   }
817
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
820
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
818
   else
821
   else
819
   {
822
   {
820
   if(Looping_Rechts) // Hysterese
823
   if(Looping_Rechts) // Hysterese
821
     {
824
     {
822
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
825
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
823
     }
826
     }
824
   }
827
   }
825
 
828
 
826
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
829
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
827
  else
830
  else
828
   {
831
   {
829
    if(Looping_Oben)  // Hysterese
832
    if(Looping_Oben)  // Hysterese
830
     {
833
     {
831
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
834
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;
832
     }
835
     }
833
   }
836
   }
834
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
837
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
835
   else
838
   else
836
   {
839
   {
837
    if(Looping_Unten) // Hysterese
840
    if(Looping_Unten) // Hysterese
838
     {
841
     {
839
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
842
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
840
     }
843
     }
841
   }
844
   }
842
 
845
 
843
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
846
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
844
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
847
   if(Looping_Oben  || Looping_Unten) {  Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
845
  } // Ende neue Funken-Werte
848
  } // Ende neue Funken-Werte
846
 
849
 
847
  if(Looping_Roll || Looping_Nick)
850
  if(Looping_Roll || Looping_Nick)
848
   {
851
   {
849
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
852
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
850
        TrichterFlug = 1;
853
        TrichterFlug = 1;
851
   }
854
   }
852
 
855
 
853
 
856
 
854
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
857
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
855
// Bei Empfangsausfall im Flug
858
// Bei Empfangsausfall im Flug
856
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
859
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
857
   if(Notlandung)
860
   if(Notlandung)
858
    {
861
    {
859
     StickGier = 0;
862
     StickGier = 0;
860
     StickNick = 0;
863
     StickNick = 0;
861
     StickRoll = 0;
864
     StickRoll = 0;
862
     GyroFaktor     = 90;
865
     GyroFaktor     = 90;
863
     IntegralFaktor = 120;
866
     IntegralFaktor = 120;
864
     GyroFaktorGier     = 90;
867
     GyroFaktorGier     = 90;
865
     IntegralFaktorGier = 120;
868
     IntegralFaktorGier = 120;
866
     Looping_Roll = 0;
869
     Looping_Roll = 0;
867
     Looping_Nick = 0;
870
     Looping_Nick = 0;
868
    }
871
    }
869
 
872
 
870
 
873
 
871
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
874
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
872
// Integrale auf ACC-Signal abgleichen
875
// Integrale auf ACC-Signal abgleichen
873
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
876
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
874
#define ABGLEICH_ANZAHL 256L
877
#define ABGLEICH_ANZAHL 256L
875
 
878
 
876
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
879
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
877
 MittelIntegralRoll  += IntegralRoll;
880
 MittelIntegralRoll  += IntegralRoll;
878
 MittelIntegralNick2 += IntegralNick2;
881
 MittelIntegralNick2 += IntegralNick2;
879
 MittelIntegralRoll2 += IntegralRoll2;
882
 MittelIntegralRoll2 += IntegralRoll2;
880
 
883
 
881
 if(Looping_Nick || Looping_Roll)
884
 if(Looping_Nick || Looping_Roll)
882
  {
885
  {
883
    IntegralAccNick = 0;
886
    IntegralAccNick = 0;
884
    IntegralAccRoll = 0;
887
    IntegralAccRoll = 0;
885
    MittelIntegralNick = 0;
888
    MittelIntegralNick = 0;
886
    MittelIntegralRoll = 0;
889
    MittelIntegralRoll = 0;
887
    MittelIntegralNick2 = 0;
890
    MittelIntegralNick2 = 0;
888
    MittelIntegralRoll2 = 0;
891
    MittelIntegralRoll2 = 0;
889
    Mess_IntegralNick2 = Mess_IntegralNick;
892
    Mess_IntegralNick2 = Mess_IntegralNick;
890
    Mess_IntegralRoll2 = Mess_IntegralRoll;
893
    Mess_IntegralRoll2 = Mess_IntegralRoll;
891
    ZaehlMessungen = 0;
894
    ZaehlMessungen = 0;
892
    LageKorrekturNick = 0;
895
    LageKorrekturNick = 0;
893
    LageKorrekturRoll = 0;
896
    LageKorrekturRoll = 0;
894
  }
897
  }
895
 
898
 
896
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
899
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
897
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
900
  if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin))
898
  {
901
  {
899
   long tmp_long, tmp_long2;
902
   long tmp_long, tmp_long2;
900
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
903
   if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/)
901
     {
904
     {
902
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
905
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
903
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
906
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
904
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
907
      tmp_long  = (tmp_long  * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
905
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
908
      tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16);
906
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
909
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
907
      {
910
      {
908
      tmp_long  /= 2;
911
      tmp_long  /= 2;
909
      tmp_long2 /= 2;
912
      tmp_long2 /= 2;
910
      }
913
      }
911
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
914
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
912
      {
915
      {
913
      tmp_long  /= 3;
916
      tmp_long  /= 3;
914
      tmp_long2 /= 3;
917
      tmp_long2 /= 3;
915
      }
918
      }
916
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
919
      if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
917
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
920
      if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
918
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
921
      if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
919
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
922
      if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
920
     }
923
     }
921
     else
924
     else
922
     {
925
     {
923
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
926
      tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
924
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
927
      tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
925
      tmp_long /= 16;
928
      tmp_long /= 16;
926
      tmp_long2 /= 16;
929
      tmp_long2 /= 16;
927
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
930
     if((MaxStickNick > 64) || (MaxStickRoll > 64))
928
      {
931
      {
929
      tmp_long  /= 3;
932
      tmp_long  /= 3;
930
      tmp_long2 /= 3;
933
      tmp_long2 /= 3;
931
      }
934
      }
932
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
935
     if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
933
      {
936
      {
934
      tmp_long  /= 3;
937
      tmp_long  /= 3;
935
      tmp_long2 /= 3;
938
      tmp_long2 /= 3;
936
      }
939
      }
937
 
940
 
938
#define AUSGLEICH  32
941
#define AUSGLEICH  32
939
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
942
      if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
940
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
943
      if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
941
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
944
      if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
942
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
945
      if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
943
     }
946
     }
944
 
947
 
945
//if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;}
948
//if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;}
946
   Mess_IntegralNick -= tmp_long;
949
   Mess_IntegralNick -= tmp_long;
947
   Mess_IntegralRoll -= tmp_long2;
950
   Mess_IntegralRoll -= tmp_long2;
948
  }
951
  }
949
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
952
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
950
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
953
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
951
 {
954
 {
952
  static int cnt = 0;
955
  static int cnt = 0;
953
  static char last_n_p,last_n_n,last_r_p,last_r_n;
956
  static char last_n_p,last_n_n,last_r_p,last_r_n;
954
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
957
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
955
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
958
  if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp)
956
  {
959
  {
957
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
960
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
958
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
961
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
959
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
962
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
960
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
963
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
961
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
964
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
962
#define MAX_I 0//(Poti2/10)
965
#define MAX_I 0//(Poti2/10)
963
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
966
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
964
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
967
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
965
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
968
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
966
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
969
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++
967
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
970
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
968
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
971
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
969
 
972
 
970
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
973
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
971
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
974
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
972
 
975
 
973
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
976
   if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1))
974
    {
977
    {
975
     LageKorrekturNick /= 2;
978
     LageKorrekturNick /= 2;
976
     LageKorrekturRoll /= 2;
979
     LageKorrekturRoll /= 2;
977
    }
980
    }
978
 
981
 
979
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
982
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
980
// Gyro-Drift ermitteln
983
// Gyro-Drift ermitteln
981
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
984
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
982
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
985
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
983
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
986
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
984
    tmp_long  = IntegralNick2 - IntegralNick;
987
    tmp_long  = IntegralNick2 - IntegralNick;
985
    tmp_long2 = IntegralRoll2 - IntegralRoll;
988
    tmp_long2 = IntegralRoll2 - IntegralRoll;
986
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
989
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
987
 
990
 
988
    IntegralFehlerNick = tmp_long;
991
    IntegralFehlerNick = tmp_long;
989
    IntegralFehlerRoll = tmp_long2;
992
    IntegralFehlerRoll = tmp_long2;
990
    Mess_IntegralNick2 -= IntegralFehlerNick;
993
    Mess_IntegralNick2 -= IntegralFehlerNick;
991
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
994
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
992
 
995
 
993
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
996
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
994
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
997
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
995
  if(EE_Parameter.Driftkomp)
998
  if(EE_Parameter.Driftkomp)
996
   {
999
   {
997
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
1000
    if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; }
998
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
1001
    if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; }
999
   }
1002
   }
1000
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
1003
//DebugOut.Analog[22] = MittelIntegralRoll / 26;
1001
//DebugOut.Analog[24] = GierGyroFehler;
1004
//DebugOut.Analog[24] = GierGyroFehler;
1002
    GierGyroFehler = 0;
1005
    GierGyroFehler = 0;
1003
 
1006
 
1004
 
1007
 
1005
/*DebugOut.Analog[17] = IntegralAccNick / 26;
1008
/*DebugOut.Analog[17] = IntegralAccNick / 26;
1006
DebugOut.Analog[18] = IntegralAccRoll / 26;
1009
DebugOut.Analog[18] = IntegralAccRoll / 26;
1007
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
1010
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
1008
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
1011
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
1009
*/
1012
*/
1010
//DebugOut.Analog[21] = MittelIntegralNick / 26;
1013
//DebugOut.Analog[21] = MittelIntegralNick / 26;
1011
//MittelIntegralRoll = MittelIntegralRoll;
1014
//MittelIntegralRoll = MittelIntegralRoll;
1012
//DebugOut.Analog[28] = ausgleichNick;
1015
//DebugOut.Analog[28] = ausgleichNick;
1013
/*
1016
/*
1014
DebugOut.Analog[29] = ausgleichRoll;
1017
DebugOut.Analog[29] = ausgleichRoll;
1015
DebugOut.Analog[30] = LageKorrekturRoll * 10;
1018
DebugOut.Analog[30] = LageKorrekturRoll * 10;
1016
*/
1019
*/
1017
 
1020
 
1018
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2) 
1021
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL / 2) 
1019
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 
1022
#define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 
1020
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1023
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16
1021
#define BEWEGUNGS_LIMIT 20000
1024
#define BEWEGUNGS_LIMIT 20000
1022
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1025
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
1023
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1026
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1024
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1027
        if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4;
1025
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1028
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1026
        {
1029
        {
1027
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1030
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
1028
         {
1031
         {
1029
           if(last_n_p)
1032
           if(last_n_p)
1030
           {
1033
           {
1031
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1034
            cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1032
            ausgleichNick = IntegralFehlerNick / 8;
1035
            ausgleichNick = IntegralFehlerNick / 8;
1033
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1036
            if(ausgleichNick > 5000) ausgleichNick = 5000;
1034
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1037
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1035
           }
1038
           }
1036
           else last_n_p = 1;
1039
           else last_n_p = 1;
1037
         } else  last_n_p = 0;
1040
         } else  last_n_p = 0;
1038
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1041
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
1039
         {
1042
         {
1040
           if(last_n_n)
1043
           if(last_n_n)
1041
            {
1044
            {
1042
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1045
             cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8);
1043
             ausgleichNick = IntegralFehlerNick / 8;
1046
             ausgleichNick = IntegralFehlerNick / 8;
1044
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1047
             if(ausgleichNick < -5000) ausgleichNick = -5000;
1045
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1048
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
1046
            }
1049
            }
1047
           else last_n_n = 1;
1050
           else last_n_n = 1;
1048
         } else  last_n_n = 0;
1051
         } else  last_n_n = 0;
1049
        }
1052
        }
1050
        else
1053
        else
1051
        {
1054
        {
1052
         cnt = 0;
1055
         cnt = 0;
1053
         KompassSignalSchlecht = 1000;
1056
         KompassSignalSchlecht = 1000;
1054
        }
1057
        }
1055
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1058
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1056
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1059
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1057
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1060
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
1058
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1061
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
1059
 
1062
 
1060
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1063
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
1061
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1064
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
1062
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1065
        if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4;
1063
        ausgleichRoll = 0;
1066
        ausgleichRoll = 0;
1064
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1067
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8))
1065
        {
1068
        {
1066
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1069
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
1067
         {
1070
         {
1068
           if(last_r_p)
1071
           if(last_r_p)
1069
           {
1072
           {
1070
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1073
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1071
            ausgleichRoll = IntegralFehlerRoll / 8;
1074
            ausgleichRoll = IntegralFehlerRoll / 8;
1072
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1075
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
1073
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1076
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1074
           }
1077
           }
1075
           else last_r_p = 1;
1078
           else last_r_p = 1;
1076
         } else  last_r_p = 0;
1079
         } else  last_r_p = 0;
1077
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1080
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
1078
         {
1081
         {
1079
           if(last_r_n)
1082
           if(last_r_n)
1080
           {
1083
           {
1081
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1084
            cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8);
1082
            ausgleichRoll = IntegralFehlerRoll / 8;
1085
            ausgleichRoll = IntegralFehlerRoll / 8;
1083
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1086
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
1084
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1087
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
1085
           }
1088
           }
1086
           else last_r_n = 1;
1089
           else last_r_n = 1;
1087
         } else  last_r_n = 0;
1090
         } else  last_r_n = 0;
1088
        } else
1091
        } else
1089
        {
1092
        {
1090
         cnt = 0;
1093
         cnt = 0;
1091
         KompassSignalSchlecht = 1000;
1094
         KompassSignalSchlecht = 1000;
1092
        }
1095
        }
1093
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1096
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
1094
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1097
                if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift;
1095
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1098
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
1096
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1099
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
1097
  }
1100
  }
1098
  else
1101
  else
1099
  {
1102
  {
1100
   LageKorrekturRoll = 0;
1103
   LageKorrekturRoll = 0;
1101
   LageKorrekturNick = 0;
1104
   LageKorrekturNick = 0;
1102
   TrichterFlug = 0;
1105
   TrichterFlug = 0;
1103
  }
1106
  }
1104
 
1107
 
1105
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1108
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
1106
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1109
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1107
   MittelIntegralNick_Alt = MittelIntegralNick;
1110
   MittelIntegralNick_Alt = MittelIntegralNick;
1108
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1111
   MittelIntegralRoll_Alt = MittelIntegralRoll;
1109
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1112
// +++++++++++++++++++++++++++++++++++++++++++++++++++++
1110
    IntegralAccNick = 0;
1113
    IntegralAccNick = 0;
1111
    IntegralAccRoll = 0;
1114
    IntegralAccRoll = 0;
1112
    IntegralAccZ = 0;
1115
    IntegralAccZ = 0;
1113
    MittelIntegralNick = 0;
1116
    MittelIntegralNick = 0;
1114
    MittelIntegralRoll = 0;
1117
    MittelIntegralRoll = 0;
1115
    MittelIntegralNick2 = 0;
1118
    MittelIntegralNick2 = 0;
1116
    MittelIntegralRoll2 = 0;
1119
    MittelIntegralRoll2 = 0;
1117
    ZaehlMessungen = 0;
1120
    ZaehlMessungen = 0;
1118
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1121
 } //  ZaehlMessungen >= ABGLEICH_ANZAHL
1119
 
1122
 
1120
 
1123
 
1121
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1124
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1122
//  Gieren
1125
//  Gieren
1123
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1126
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1124
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
1127
//    if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;};
1125
    if(abs(StickGier) > 15) // war 35
1128
    if(abs(StickGier) > 15) // war 35
1126
     {
1129
     {
1127
      KompassSignalSchlecht = 1000;
1130
      KompassSignalSchlecht = 1000;
1128
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1131
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX))
1129
       {
1132
       {
1130
         NeueKompassRichtungMerken = 1;
1133
         NeueKompassRichtungMerken = 1;
1131
        };
1134
        };
1132
     }
1135
     }
1133
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1136
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1134
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1137
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
1135
    sollGier = tmp_int;
1138
    sollGier = tmp_int;
1136
    Mess_Integral_Gier -= tmp_int;
1139
    Mess_Integral_Gier -= tmp_int;
1137
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1140
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1138
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1141
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1139
 
1142
 
1140
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1143
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1141
//  Kompass
1144
//  Kompass
1142
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1145
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1143
//DebugOut.Analog[16] = KompassSignalSchlecht;
1146
//DebugOut.Analog[16] = KompassSignalSchlecht;
1144
 
1147
 
1145
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1148
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
1146
     {
1149
     {
1147
       int w,v,r,fehler,korrektur;
1150
       int w,v,r,fehler,korrektur;
1148
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1151
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
1149
       v = abs(IntegralRoll /512);
1152
       v = abs(IntegralRoll /512);
1150
       if(v > w) w = v; // grösste Neigung ermitteln
1153
       if(v > w) w = v; // grösste Neigung ermitteln
1151
       korrektur = w / 8 + 1;
1154
       korrektur = w / 8 + 1;
1152
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1155
       fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180;
1153
       if(abs(MesswertGier) > 128)
1156
       if(abs(MesswertGier) > 128)
1154
            {
1157
            {
1155
                 fehler = 0;
1158
                 fehler = 0;
1156
                }
1159
                }
1157
       if(!KompassSignalSchlecht && w < 25)
1160
       if(!KompassSignalSchlecht && w < 25)
1158
        {
1161
        {
1159
        GierGyroFehler += fehler;
1162
        GierGyroFehler += fehler;
1160
        if(NeueKompassRichtungMerken)
1163
        if(NeueKompassRichtungMerken)
1161
         {
1164
         {
1162
          beeptime = 200;
1165
          beeptime = 200;
1163
//         KompassStartwert = KompassValue;
1166
//         KompassStartwert = KompassValue;
1164
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1167
                  ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR;
1165
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1168
          KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR);
1166
          NeueKompassRichtungMerken = 0;
1169
          NeueKompassRichtungMerken = 0;
1167
         }
1170
         }
1168
        }
1171
        }
1169
       ErsatzKompass += (fehler * 8) / korrektur;
1172
       ErsatzKompass += (fehler * 8) / korrektur;
1170
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1173
       w = (w * Parameter_KompassWirkung) / 32;           // auf die Wirkung normieren
1171
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1174
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
1172
       if(w >= 0)
1175
       if(w >= 0)
1173
        {
1176
        {
1174
          if(!KompassSignalSchlecht)
1177
          if(!KompassSignalSchlecht)
1175
          {
1178
          {
1176
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1179
           v = 64 + ((MaxStickNick + MaxStickRoll)) / 8;
1177
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1180
           r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180;
1178
//           r = KompassRichtung;
1181
//           r = KompassRichtung;
1179
           v = (r * w) / v;  // nach Kompass ausrichten
1182
           v = (r * w) / v;  // nach Kompass ausrichten
1180
           w = 3 * Parameter_KompassWirkung;
1183
           w = 3 * Parameter_KompassWirkung;
1181
           if(v > w) v = w; // Begrenzen
1184
           if(v > w) v = w; // Begrenzen
1182
           else
1185
           else
1183
           if(v < -w) v = -w;
1186
           if(v < -w) v = -w;
1184
           Mess_Integral_Gier += v;
1187
           Mess_Integral_Gier += v;
1185
          }
1188
          }
1186
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1189
          if(KompassSignalSchlecht) KompassSignalSchlecht--;
1187
        }
1190
        }
1188
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1191
        else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
1189
     }
1192
     }
1190
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1193
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1191
 
1194
 
1192
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1195
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1193
//  Debugwerte zuordnen
1196
//  Debugwerte zuordnen
1194
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1197
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1195
  if(!TimerWerteausgabe--)
1198
  if(!TimerWerteausgabe--)
1196
   {
1199
   {
1197
    TimerWerteausgabe = 24;
1200
    TimerWerteausgabe = 24;
1198
 
1201
 
1199
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
1202
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
1200
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1203
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1201
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1204
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1202
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1205
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1203
    DebugOut.Analog[4] = MesswertGier;
1206
    DebugOut.Analog[4] = MesswertGier;
1204
    DebugOut.Analog[5] = HoehenWert;
1207
    DebugOut.Analog[5] = HoehenWert;
1205
    DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1208
    DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1206
    DebugOut.Analog[8] = KompassValue;
1209
    DebugOut.Analog[8] = KompassValue;
1207
    DebugOut.Analog[9] = UBat;
1210
    DebugOut.Analog[9] = UBat;
1208
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1211
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1209
    DebugOut.Analog[10] = SenderOkay;
1212
    DebugOut.Analog[10] = SenderOkay;
1210
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1213
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1211
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1214
    //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance;
1212
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1215
    //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar;
1213
    DebugOut.Analog[19] = WinkelOut.CalcState;
1216
    DebugOut.Analog[19] = WinkelOut.CalcState;
1214
    DebugOut.Analog[20] = ServoValue;
1217
    DebugOut.Analog[20] = ServoValue;
1215
//    DebugOut.Analog[24] = MesswertNick/2;
1218
//    DebugOut.Analog[24] = MesswertNick/2;
1216
//    DebugOut.Analog[25] = MesswertRoll/2;
1219
//    DebugOut.Analog[25] = MesswertRoll/2;
1217
    DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift;
1220
    DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift;
1218
//    DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion;
1221
//    DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion;
1219
//    DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K;
1222
//    DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K;
1220
    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
1223
    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
1221
    DebugOut.Analog[30] = GPS_Nick;
1224
    DebugOut.Analog[30] = GPS_Nick;
1222
    DebugOut.Analog[31] = GPS_Roll;
1225
    DebugOut.Analog[31] = GPS_Roll;
1223
 
1226
 
1224
 
1227
 
1225
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1228
//    DebugOut.Analog[19] -= DebugOut.Analog[19]/128;
1226
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1229
//    if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++;
1227
 
1230
 
1228
/*    DebugOut.Analog[16] = motor_rx[0];
1231
/*    DebugOut.Analog[16] = motor_rx[0];
1229
    DebugOut.Analog[17] = motor_rx[1];
1232
    DebugOut.Analog[17] = motor_rx[1];
1230
    DebugOut.Analog[18] = motor_rx[2];
1233
    DebugOut.Analog[18] = motor_rx[2];
1231
    DebugOut.Analog[19] = motor_rx[3];
1234
    DebugOut.Analog[19] = motor_rx[3];
1232
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1235
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
1233
    DebugOut.Analog[20] /= 14;
1236
    DebugOut.Analog[20] /= 14;
1234
    DebugOut.Analog[21] = motor_rx[4];
1237
    DebugOut.Analog[21] = motor_rx[4];
1235
    DebugOut.Analog[22] = motor_rx[5];
1238
    DebugOut.Analog[22] = motor_rx[5];
1236
    DebugOut.Analog[23] = motor_rx[6];
1239
    DebugOut.Analog[23] = motor_rx[6];
1237
    DebugOut.Analog[24] = motor_rx[7];
1240
    DebugOut.Analog[24] = motor_rx[7];
1238
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1241
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
1239
*/
1242
*/
1240
//    DebugOut.Analog[9] = MesswertNick;
1243
//    DebugOut.Analog[9] = MesswertNick;
1241
//    DebugOut.Analog[9] = SollHoehe;
1244
//    DebugOut.Analog[9] = SollHoehe;
1242
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1245
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
1243
//    DebugOut.Analog[11] = KompassStartwert;
1246
//    DebugOut.Analog[11] = KompassStartwert;
1244
//    DebugOut.Analog[10] = Parameter_Gyro_I;
1247
//    DebugOut.Analog[10] = Parameter_Gyro_I;
1245
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;
1248
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;
1246
//    DebugOut.Analog[9] = KompassRichtung;
1249
//    DebugOut.Analog[9] = KompassRichtung;
1247
//    DebugOut.Analog[10] = GasMischanteil;
1250
//    DebugOut.Analog[10] = GasMischanteil;
1248
//    DebugOut.Analog[3] = HoeheD * 32;
1251
//    DebugOut.Analog[3] = HoeheD * 32;
1249
//    DebugOut.Analog[4] = hoehenregler;
1252
//    DebugOut.Analog[4] = hoehenregler;
1250
  }
1253
  }
1251
 
1254
 
1252
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1255
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1253
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1256
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
1254
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1257
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1255
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1258
  if(TrichterFlug)  { SummeRoll = 0; SummeNick = 0;};
1256
 
1259
 
1257
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1260
  if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0;
1258
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1261
  if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) /  (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0;
1259
 
1262
 
1260
#define TRIM_MAX 200
1263
#define TRIM_MAX 200
1261
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1264
 if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else  if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX;
1262
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1265
 if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else  if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX;
1263
 
1266
 
1264
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1267
    MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN);
1265
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1268
    MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN);
1266
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1269
    MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN));
1267
 
1270
 
1268
    // Maximalwerte abfangen
1271
    // Maximalwerte abfangen
1269
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1272
//    #define MAX_SENSOR  (4096*STICK_GAIN)
1270
    #define MAX_SENSOR  (4096*4)
1273
    #define MAX_SENSOR  (4096*4)
1271
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1274
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
1272
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1275
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
1273
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1276
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
1274
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1277
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
1275
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1278
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
1276
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1279
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
1277
 
1280
 
1278
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1281
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1279
// all BL-Ctrl connected?
1282
// all BL-Ctrl connected?
1280
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1283
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1281
  if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1284
  if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1282
   {
1285
   {
1283
    modell_fliegt = 1;
1286
    modell_fliegt = 1;
1284
        GasMischanteil = MIN_GAS;
1287
        GasMischanteil = MIN_GAS;
1285
   }
1288
   }
1286
 
1289
 
1287
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1290
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1288
// Höhenregelung
1291
// Höhenregelung
1289
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1292
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1290
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1293
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1291
  GasMischanteil *= STICK_GAIN;
1294
  GasMischanteil *= STICK_GAIN;
1292
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1295
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1293
  {
1296
  {
1294
    int tmp_int;
1297
    int tmp_int;
1295
        static char delay = 100;
1298
        static char delay = 100;
1296
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1299
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1297
    {
1300
    {
1298
      if(Parameter_MaxHoehe < 50)
1301
      if(Parameter_MaxHoehe < 50)
1299
      {
1302
      {
1300
       if(!delay--)
1303
       if(!delay--)
1301
            {
1304
            {
1302
         if((MessLuftdruck > 1000) && OCR0A < 254)
1305
         if((MessLuftdruck > 1000) && OCR0A < 254)
1303
                  {
1306
                  {
1304
                    if(OCR0A < 244)
1307
                    if(OCR0A < 244)
1305
                     {
1308
                     {
1306
                      ExpandBaro -= 10;
1309
                      ExpandBaro -= 10;
1307
                      OCR0A = DruckOffsetSetting - ExpandBaro;
1310
                      OCR0A = DruckOffsetSetting - ExpandBaro;
1308
                         }
1311
                         }
1309
                         else OCR0A = 254;
1312
                         else OCR0A = 254;
1310
                beeptime = 300;
1313
                beeptime = 300;
1311
            delay = 250;
1314
            delay = 250;
1312
                  }
1315
                  }
1313
                  else      
1316
                  else      
1314
         if((MessLuftdruck < 100) && OCR0A > 1)
1317
         if((MessLuftdruck < 100) && OCR0A > 1)
1315
                  {
1318
                  {
1316
                   if(OCR0A > 10)
1319
                   if(OCR0A > 10)
1317
                    {
1320
                    {
1318
                     ExpandBaro += 10;
1321
                     ExpandBaro += 10;
1319
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1322
                     OCR0A = DruckOffsetSetting - ExpandBaro;
1320
                        }
1323
                        }
1321
                         else OCR0A = 1;
1324
                         else OCR0A = 1;
1322
                   beeptime = 300;
1325
                   beeptime = 300;
1323
           delay = 250;
1326
           delay = 250;
1324
                  }
1327
                  }
1325
          else
1328
          else
1326
          {
1329
          {
1327
               SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1330
               SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1328
           HoehenReglerAktiv = 0;
1331
           HoehenReglerAktiv = 0;
1329
                   delay = 1;
1332
                   delay = 1;
1330
                  }
1333
                  }
1331
                }
1334
                }
1332
      }
1335
      }
1333
      else
1336
      else
1334
        {
1337
        {
1335
         HoehenReglerAktiv = 1;
1338
         HoehenReglerAktiv = 1;
1336
                 delay = 200;
1339
                 delay = 200;
1337
                }
1340
                }
1338
    }
1341
    }
1339
    else
1342
    else
1340
    {
1343
    {
1341
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1344
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1342
     HoehenReglerAktiv = 1;
1345
     HoehenReglerAktiv = 1;
1343
    }
1346
    }
1344
 
1347
 
1345
    if(Notlandung) SollHoehe = 0;
1348
    if(Notlandung) SollHoehe = 0;
1346
    h = HoehenWert;
1349
    h = HoehenWert;
1347
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1350
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1348
     {
1351
     {
1349
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1352
      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil
1350
      h = GasMischanteil - h;         // vom Gas abziehen
1353
      h = GasMischanteil - h;         // vom Gas abziehen
1351
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1354
      h -= (HoeheD)/(8/STICK_GAIN);    // D-Anteil
1352
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1355
      tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN);
1353
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1356
      if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN;
1354
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1357
      else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN);
1355
      h -= tmp_int;
1358
      h -= tmp_int;
1356
      hoehenregler = (hoehenregler*15 + h) / 16;
1359
      hoehenregler = (hoehenregler*15 + h) / 16;
1357
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1360
      if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN
1358
       {
1361
       {
1359
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1362
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN;
1360
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1363
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil;
1361
       }
1364
       }
1362
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1365
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1363
      GasMischanteil = hoehenregler;
1366
      GasMischanteil = hoehenregler;
1364
     }
1367
     }
1365
  }
1368
  }
1366
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1369
  if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN;
1367
 
1370
 
1368
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1371
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1369
// + Mischer und PI-Regler
1372
// + Mischer und PI-Regler
1370
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1373
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1371
  DebugOut.Analog[7] = GasMischanteil;
1374
  DebugOut.Analog[7] = GasMischanteil;
1372
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1375
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1373
// Gier-Anteil
1376
// Gier-Anteil
1374
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1377
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1375
#define MUL_G  1.0
1378
#define MUL_G  1.0
1376
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1379
    GierMischanteil = MesswertGier - sollGier * STICK_GAIN;     // Regler für Gier
1377
// GierMischanteil = 0;
1380
// GierMischanteil = 0;
1378
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1381
#define MIN_GIERGAS  (40*STICK_GAIN)  // unter diesem Gaswert trotzdem Gieren
1379
   if(GasMischanteil > MIN_GIERGAS)
1382
   if(GasMischanteil > MIN_GIERGAS)
1380
    {
1383
    {
1381
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1384
     if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1382
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1385
     if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1383
    }
1386
    }
1384
    else
1387
    else
1385
    {
1388
    {
1386
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1389
     if(GierMischanteil > (MIN_GIERGAS / 2))  GierMischanteil = MIN_GIERGAS / 2;
1387
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1390
     if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2);
1388
    }
1391
    }
1389
    tmp_int = MAX_GAS*STICK_GAIN;
1392
    tmp_int = MAX_GAS*STICK_GAIN;
1390
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1393
    if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil));
1391
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1394
    if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil));
1392
 
1395
 
1393
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1396
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1394
// Nick-Achse
1397
// Nick-Achse
1395
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1398
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1396
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1399
    DiffNick = MesswertNick - StickNick;        // Differenz bestimmen
1397
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1400
    if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung
1398
    else  SummeNick += DiffNick; // I-Anteil bei HH
1401
    else  SummeNick += DiffNick; // I-Anteil bei HH
1399
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1402
    if(SummeNick >  (STICK_GAIN * 16000L)) SummeNick =  (STICK_GAIN * 16000L);
1400
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1403
    if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN);
1401
    pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick
1404
    pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick
1402
    // Motor Vorn
1405
    // Motor Vorn
1403
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1406
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1404
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1407
    if(pd_ergebnis_nick >  tmp_int) pd_ergebnis_nick =  tmp_int;
1405
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1408
    if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int;
1406
 
1409
 
1407
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1410
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1408
// Roll-Achse
1411
// Roll-Achse
1409
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1412
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1410
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1413
        DiffRoll = MesswertRoll - StickRoll;    // Differenz bestimmen
1411
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1414
    if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung
1412
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1415
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1413
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1416
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1414
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1417
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1415
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1418
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1416
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1419
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1417
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1420
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1418
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1421
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
1419
 
1422
 
1420
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1423
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1421
// Universal Mixer
1424
// Universal Mixer
1422
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1425
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1423
 for(i=0; i<MAX_MOTORS; i++)
1426
 for(i=0; i<MAX_MOTORS; i++)
1424
 {
1427
 {
1425
  signed int tmp_int;
1428
  signed int tmp_int;
1426
  if(Mixer.Motor[i][0] > 0)
1429
  if(Mixer.Motor[i][0] > 0)
1427
   {
1430
   {
1428
    tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1431
    tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
1429
    tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1432
    tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
1430
    tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1433
    tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1431
    tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1434
    tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1432
    tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]);  // Filter
1435
    tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]);  // Filter
1433
        tmp_int = tmp_motorwert[i] / STICK_GAIN;
1436
        tmp_int = tmp_motorwert[i] / STICK_GAIN;
1434
        CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS);
1437
        CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS);
1435
    Motor[i] = tmp_int;
1438
    Motor[i] = tmp_int;
1436
   }
1439
   }
1437
   else Motor[i] = 0;
1440
   else Motor[i] = 0;
1438
 }
1441
 }
1439
/*
1442
/*
1440
if(Poti1 > 20)  Motor1 = 0;
1443
if(Poti1 > 20)  Motor1 = 0;
1441
if(Poti1 > 90)  Motor6 = 0;
1444
if(Poti1 > 90)  Motor6 = 0;
1442
if(Poti1 > 140) Motor2 = 0;
1445
if(Poti1 > 140) Motor2 = 0;
1443
//if(Poti1 > 200) Motor7 = 0;
1446
//if(Poti1 > 200) Motor7 = 0;
1444
*/
1447
*/
1445
}
1448
}
1446
 
1449