Subversion Repositories FlightCtrl

Rev

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

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