Subversion Repositories FlightCtrl

Rev

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

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