Subversion Repositories FlightCtrl

Rev

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

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