Subversion Repositories FlightCtrl

Rev

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

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