Subversion Repositories FlightCtrl

Rev

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

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