Subversion Repositories FlightCtrl

Rev

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

Rev 492 Rev 498
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;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
63
volatile float NeutralAccZ = 0;
63
volatile float NeutralAccZ = 0;
64
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
64
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
65
volatile long IntegralNick = 0,IntegralNick2 = 0;
65
volatile long IntegralNick = 0,IntegralNick2 = 0;
66
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
66
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
67
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
67
volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
68
volatile long Integral_Gier = 0;
68
volatile long Integral_Gier = 0;
69
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
69
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
70
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
70
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
71
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
71
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
72
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
72
volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
73
volatile long Mess_Integral_Hoch = 0;
73
volatile long Mess_Integral_Hoch = 0;
74
volatile int  KompassValue = 0;
74
volatile int  KompassValue = 0;
75
volatile int  KompassStartwert = 0;
75
volatile int  KompassStartwert = 0;
76
volatile int  KompassRichtung = 0;
76
volatile int  KompassRichtung = 0;
77
unsigned char MAX_GAS,MIN_GAS;
77
unsigned char MAX_GAS,MIN_GAS;
78
unsigned char Notlandung = 0;
78
unsigned char Notlandung = 0;
79
unsigned char HoehenReglerAktiv = 0;
79
unsigned char HoehenReglerAktiv = 0;
80
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
80
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
81
 
81
 
82
float GyroFaktor;
82
float GyroFaktor;
83
float IntegralFaktor;
83
float IntegralFaktor;
84
volatile int  DiffNick,DiffRoll;
84
volatile int  DiffNick,DiffRoll;
85
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
85
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
86
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
86
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
87
unsigned char MotorWert[5];
87
unsigned char MotorWert[5];
88
volatile unsigned char SenderOkay = 0;
88
volatile unsigned char SenderOkay = 0;
89
int StickNick = 0,StickRoll = 0,StickGier = 0;
89
int StickNick = 0,StickRoll = 0,StickGier = 0;
90
char MotorenEin = 0;
90
char MotorenEin = 0;
91
int HoehenWert = 0;
91
int HoehenWert = 0;
92
int SollHoehe = 0;
92
int SollHoehe = 0;
93
int I_LageRoll = 0,I_LageNick = 0;
93
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
94
float Kp =  FAKTOR_P;
94
float Kp =  FAKTOR_P;
95
float Ki =  FAKTOR_I;
95
float Ki =  FAKTOR_I;
96
unsigned char Looping_Nick = 0,Looping_Roll = 0;
96
unsigned char Looping_Nick = 0,Looping_Roll = 0;
97
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
97
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
98
 
98
 
99
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
99
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
100
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
100
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
101
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
101
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
102
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
102
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
103
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
103
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
104
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
104
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
105
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
105
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
106
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
106
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
107
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
107
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
108
unsigned char Parameter_UserParam1 = 0;
108
unsigned char Parameter_UserParam1 = 0;
109
unsigned char Parameter_UserParam2 = 0;
109
unsigned char Parameter_UserParam2 = 0;
110
unsigned char Parameter_UserParam3 = 0;
110
unsigned char Parameter_UserParam3 = 0;
111
unsigned char Parameter_UserParam4 = 0;
111
unsigned char Parameter_UserParam4 = 0;
112
unsigned char Parameter_ServoNickControl = 100;
112
unsigned char Parameter_ServoNickControl = 100;
113
unsigned char Parameter_LoopGasLimit = 70;
113
unsigned char Parameter_LoopGasLimit = 70;
114
unsigned char Parameter_AchsKopplung1 = 0;
114
unsigned char Parameter_AchsKopplung1 = 0;
115
unsigned char Parameter_AchsGegenKopplung1 = 0;
115
unsigned char Parameter_AchsGegenKopplung1 = 0;
116
struct mk_param_struct EE_Parameter;
116
struct mk_param_struct EE_Parameter;
117
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
117
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
118
 
118
 
119
void Piep(unsigned char Anzahl)
119
void Piep(unsigned char Anzahl)
120
{
120
{
121
 while(Anzahl--)
121
 while(Anzahl--)
122
 {
122
 {
123
  if(MotorenEin) return; //auf keinen Fall im Flug!
123
  if(MotorenEin) return; //auf keinen Fall im Flug!
124
  beeptime = 100;
124
  beeptime = 100;
125
  Delay_ms(250);
125
  Delay_ms(250);
126
 }
126
 }
127
}
127
}
128
 
128
 
129
//############################################################################
129
//############################################################################
130
//  Nullwerte ermitteln
130
//  Nullwerte ermitteln
131
void SetNeutral(void)
131
void SetNeutral(void)
132
//############################################################################
132
//############################################################################
133
{
133
{
134
        NeutralAccX = 0;
134
        NeutralAccX = 0;
135
        NeutralAccY = 0;
135
        NeutralAccY = 0;
136
        NeutralAccZ = 0;
136
        NeutralAccZ = 0;
137
    AdNeutralNick = 0; 
137
    AdNeutralNick = 0; 
138
        AdNeutralRoll = 0;     
138
        AdNeutralRoll = 0;     
139
        AdNeutralGier = 0;
139
        AdNeutralGier = 0;
140
    Parameter_AchsKopplung1 = 0;
140
    Parameter_AchsKopplung1 = 0;
141
    Parameter_AchsGegenKopplung1 = 0;
141
    Parameter_AchsGegenKopplung1 = 0;
142
    CalibrierMittelwert();     
142
    CalibrierMittelwert();     
143
    Delay_ms_Mess(100);
143
    Delay_ms_Mess(100);
144
        CalibrierMittelwert();
144
        CalibrierMittelwert();
145
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
145
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
146
     {    
146
     {    
147
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
147
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
148
     }
148
     }
149
 
149
 
150
     AdNeutralNick= AdWertNick;
150
     AdNeutralNick= AdWertNick;
151
         AdNeutralRoll= AdWertRoll;    
151
         AdNeutralRoll= AdWertRoll;    
152
         AdNeutralGier= AdWertGier;
152
         AdNeutralGier= AdWertGier;
153
     StartNeutralRoll = AdNeutralRoll;
153
     StartNeutralRoll = AdNeutralRoll;
154
     StartNeutralNick = AdNeutralNick;
154
     StartNeutralNick = AdNeutralNick;
155
    NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
155
    NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
156
        NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
156
        NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
157
        NeutralAccZ = Aktuell_az;
157
        NeutralAccZ = Aktuell_az;
158
   
158
   
159
        Mess_IntegralNick = 0; 
159
        Mess_IntegralNick = 0; 
160
    Mess_IntegralNick2 = 0;
160
    Mess_IntegralNick2 = 0;
161
    Mess_IntegralRoll = 0;     
161
    Mess_IntegralRoll = 0;     
162
    Mess_IntegralRoll2 = 0;
162
    Mess_IntegralRoll2 = 0;
163
    Mess_Integral_Gier = 0;    
163
    Mess_Integral_Gier = 0;    
164
    MesswertNick = 0;
164
    MesswertNick = 0;
165
    MesswertRoll = 0;
165
    MesswertRoll = 0;
166
    MesswertGier = 0;
166
    MesswertGier = 0;
167
    StartLuftdruck = Luftdruck;
167
    StartLuftdruck = Luftdruck;
168
    HoeheD = 0;
168
    HoeheD = 0;
169
    Mess_Integral_Hoch = 0;
169
    Mess_Integral_Hoch = 0;
170
    KompassStartwert = KompassValue;
170
    KompassStartwert = KompassValue;
171
    GPS_Neutral();
171
    GPS_Neutral();
172
    beeptime = 50;  
172
    beeptime = 50;  
173
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
173
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
174
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
174
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
175
    ExternHoehenValue = 0;
175
    ExternHoehenValue = 0;
176
}
176
}
177
 
177
 
178
//############################################################################
178
//############################################################################
179
// Bearbeitet die Messwerte
179
// Bearbeitet die Messwerte
180
void Mittelwert(void)
180
void Mittelwert(void)
181
//############################################################################
181
//############################################################################
182
{      
182
{      
183
    static signed long tmpl,tmpl2;     
183
    static signed long tmpl,tmpl2;     
184
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
184
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
185
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
185
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
186
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
186
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
187
 
187
 
188
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
188
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
189
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
189
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
190
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
190
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
191
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
191
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
192
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
192
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
193
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
193
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
194
    IntegralAccZ    += Aktuell_az - 704;//NeutralAccZ;
194
    IntegralAccZ    += Aktuell_az - 704;//NeutralAccZ;
195
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
195
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
196
            Mess_Integral_Gier +=  MesswertGier;
196
            Mess_Integral_Gier +=  MesswertGier;
197
            Mess_Integral_Gier2 += MesswertGier;
197
            Mess_Integral_Gier2 += MesswertGier;
198
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
198
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
199
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
199
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
200
         {
200
         {
201
            tmpl = Mess_IntegralNick / 4096L;
201
            tmpl = Mess_IntegralNick / 4096L;
202
            tmpl *= MesswertGier;
202
            tmpl *= MesswertGier;
203
            tmpl *= Parameter_AchsKopplung1;  //125
203
            tmpl *= Parameter_AchsKopplung1;  //125
204
            tmpl /= 2048L;
204
            tmpl /= 2048L;
205
            tmpl2 = Mess_IntegralRoll / 4096L;
205
            tmpl2 = Mess_IntegralRoll / 4096L;
206
            tmpl2 *= MesswertGier;
206
            tmpl2 *= MesswertGier;
207
            tmpl2 *= Parameter_AchsKopplung1;
207
            tmpl2 *= Parameter_AchsKopplung1;
208
            tmpl2 /= 2048L;
208
            tmpl2 /= 2048L;
209
         }
209
         }
210
      else  tmpl = tmpl2 = 0;
210
      else  tmpl = tmpl2 = 0;
211
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
211
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
212
            MesswertRoll += tmpl;
212
            MesswertRoll += tmpl;
213
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
213
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
214
            Mess_IntegralRoll2 += MesswertRoll;
214
            Mess_IntegralRoll2 += MesswertRoll;
215
            Mess_IntegralRoll +=  MesswertRoll - I_LageRoll;
215
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
216
            if(Mess_IntegralRoll > Umschlag180Roll)
216
            if(Mess_IntegralRoll > Umschlag180Roll)
217
            {
217
            {
218
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
218
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
219
             Mess_IntegralRoll2 = Mess_IntegralRoll;
219
             Mess_IntegralRoll2 = Mess_IntegralRoll;
220
            }
220
            }
221
            if(Mess_IntegralRoll <-Umschlag180Roll)
221
            if(Mess_IntegralRoll <-Umschlag180Roll)
222
            {
222
            {
223
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
223
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
224
             Mess_IntegralRoll2 = Mess_IntegralRoll;
224
             Mess_IntegralRoll2 = Mess_IntegralRoll;
225
            }  
225
            }  
226
            if(AdWertRoll < 15)   MesswertRoll = -1000;
226
            if(AdWertRoll < 15)   MesswertRoll = -1000;
227
            if(AdWertRoll <  7)   MesswertRoll = -2000;
227
            if(AdWertRoll <  7)   MesswertRoll = -2000;
228
            if(PlatinenVersion == 10)
228
            if(PlatinenVersion == 10)
229
                         {
229
                         {
230
              if(AdWertRoll > 1010) MesswertRoll = +1000;
230
              if(AdWertRoll > 1010) MesswertRoll = +1000;
231
              if(AdWertRoll > 1017) MesswertRoll = +2000;
231
              if(AdWertRoll > 1017) MesswertRoll = +2000;
232
                         }
232
                         }
233
                         else
233
                         else
234
                         {
234
                         {
235
              if(AdWertRoll > 2020) MesswertRoll = +1000;
235
              if(AdWertRoll > 2020) MesswertRoll = +1000;
236
              if(AdWertRoll > 2034) MesswertRoll = +2000;
236
              if(AdWertRoll > 2034) MesswertRoll = +2000;
237
                         }
237
                         }
238
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
238
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
239
            MesswertNick -= tmpl2;
239
            MesswertNick -= tmpl2;
240
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
240
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
241
            Mess_IntegralNick2 += MesswertNick;
241
            Mess_IntegralNick2 += MesswertNick;
242
            Mess_IntegralNick  += MesswertNick - I_LageNick;
242
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
243
            if(Mess_IntegralNick > Umschlag180Nick)
243
            if(Mess_IntegralNick > Umschlag180Nick)
244
            {
244
            {
245
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
245
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
246
             Mess_IntegralNick2 = Mess_IntegralNick;
246
             Mess_IntegralNick2 = Mess_IntegralNick;
247
            }
247
            }
248
            if(Mess_IntegralNick <-Umschlag180Nick)
248
            if(Mess_IntegralNick <-Umschlag180Nick)
249
            {
249
            {
250
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
250
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
251
             Mess_IntegralNick2 = Mess_IntegralNick;
251
             Mess_IntegralNick2 = Mess_IntegralNick;
252
            }
252
            }
253
            if(AdWertNick < 15)   MesswertNick = -1000;
253
            if(AdWertNick < 15)   MesswertNick = -1000;
254
            if(AdWertNick <  7)   MesswertNick = -2000;
254
            if(AdWertNick <  7)   MesswertNick = -2000;
255
            if(PlatinenVersion == 10)
255
            if(PlatinenVersion == 10)
256
                         {
256
                         {
257
              if(AdWertNick > 1010) MesswertNick = +1000;
257
              if(AdWertNick > 1010) MesswertNick = +1000;
258
              if(AdWertNick > 1017) MesswertNick = +2000;
258
              if(AdWertNick > 1017) MesswertNick = +2000;
259
                         }
259
                         }
260
                         else
260
                         else
261
                         {
261
                         {
262
              if(AdWertNick > 2020) MesswertNick = +1000;
262
              if(AdWertNick > 2020) MesswertNick = +1000;
263
              if(AdWertNick > 2034) MesswertNick = +2000;
263
              if(AdWertNick > 2034) MesswertNick = +2000;
264
                         }
264
                         }
265
//++++++++++++++++++++++++++++++++++++++++++++++++
265
//++++++++++++++++++++++++++++++++++++++++++++++++
266
// ADC einschalten
266
// ADC einschalten
267
    ANALOG_ON; 
267
    ANALOG_ON; 
268
//++++++++++++++++++++++++++++++++++++++++++++++++
268
//++++++++++++++++++++++++++++++++++++++++++++++++
269
DebugOut.Analog[11] = MesswertRoll;
269
DebugOut.Analog[11] = MesswertRoll;
270
//DebugOut.Analog[11] = AdWertNick;
270
//DebugOut.Analog[11] = AdWertNick;
271
 
271
 
272
    Integral_Gier  = Mess_Integral_Gier;
272
    Integral_Gier  = Mess_Integral_Gier;
273
    IntegralNick = Mess_IntegralNick;
273
    IntegralNick = Mess_IntegralNick;
274
    IntegralRoll = Mess_IntegralRoll;
274
    IntegralRoll = Mess_IntegralRoll;
275
    IntegralNick2 = Mess_IntegralNick2;
275
    IntegralNick2 = Mess_IntegralNick2;
276
    IntegralRoll2 = Mess_IntegralRoll2;
276
    IntegralRoll2 = Mess_IntegralRoll2;
277
 
277
 
278
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
278
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
279
  {
279
  {
280
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
280
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
281
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
281
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
282
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
282
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
283
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
283
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
284
  }
284
  }
285
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
285
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
286
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
286
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
287
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
287
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
288
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
288
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
289
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
289
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
290
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
290
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
291
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
291
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
292
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
292
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
293
}
293
}
294
 
294
 
295
//############################################################################
295
//############################################################################
296
// Messwerte beim Ermitteln der Nullage
296
// Messwerte beim Ermitteln der Nullage
297
void CalibrierMittelwert(void)
297
void CalibrierMittelwert(void)
298
//############################################################################
298
//############################################################################
299
{                
299
{                
300
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
300
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
301
        ANALOG_OFF;
301
        ANALOG_OFF;
302
        MesswertNick = AdWertNick;
302
        MesswertNick = AdWertNick;
303
        MesswertRoll = AdWertRoll;
303
        MesswertRoll = AdWertRoll;
304
        MesswertGier = AdWertGier;
304
        MesswertGier = AdWertGier;
305
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
305
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
306
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
306
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
307
        Mittelwert_AccHoch = (long)AdWertAccHoch;
307
        Mittelwert_AccHoch = (long)AdWertAccHoch;
308
   // ADC einschalten
308
   // ADC einschalten
309
    ANALOG_ON; 
309
    ANALOG_ON; 
310
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
310
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
311
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
311
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
312
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
312
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
313
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
313
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
314
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
314
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
315
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
315
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
316
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
316
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
317
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
317
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
318
 
318
 
319
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
319
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
320
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
320
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
321
}
321
}
322
 
322
 
323
//############################################################################
323
//############################################################################
324
// Senden der Motorwerte per I2C-Bus
324
// Senden der Motorwerte per I2C-Bus
325
void SendMotorData(void)
325
void SendMotorData(void)
326
//############################################################################
326
//############################################################################
327
{
327
{
328
    if(MOTOR_OFF || !MotorenEin)
328
    if(MOTOR_OFF || !MotorenEin)
329
        {
329
        {
330
        Motor_Hinten = 0;
330
        Motor_Hinten = 0;
331
        Motor_Vorne = 0;
331
        Motor_Vorne = 0;
332
        Motor_Rechts = 0;
332
        Motor_Rechts = 0;
333
        Motor_Links = 0;
333
        Motor_Links = 0;
334
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
334
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
335
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
335
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
336
        if(MotorTest[2]) Motor_Links = MotorTest[2];
336
        if(MotorTest[2]) Motor_Links = MotorTest[2];
337
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
337
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
338
        }
338
        }
339
 
339
 
340
    DebugOut.Analog[12] = Motor_Vorne;
340
    DebugOut.Analog[12] = Motor_Vorne;
341
    DebugOut.Analog[13] = Motor_Hinten;
341
    DebugOut.Analog[13] = Motor_Hinten;
342
    DebugOut.Analog[14] = Motor_Links;
342
    DebugOut.Analog[14] = Motor_Links;
343
    DebugOut.Analog[15] = Motor_Rechts;  
343
    DebugOut.Analog[15] = Motor_Rechts;  
344
 
344
 
345
    //Start I2C Interrupt Mode
345
    //Start I2C Interrupt Mode
346
    twi_state = 0;
346
    twi_state = 0;
347
    motor = 0;
347
    motor = 0;
348
    i2c_start();
348
    i2c_start();
349
}
349
}
350
 
350
 
351
 
351
 
352
 
352
 
353
//############################################################################
353
//############################################################################
354
// Trägt ggf. das Poti als Parameter ein
354
// Trägt ggf. das Poti als Parameter ein
355
void ParameterZuordnung(void)
355
void ParameterZuordnung(void)
356
//############################################################################
356
//############################################################################
357
{
357
{
358
 
358
 
359
 #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; if(b <= min) b = min; else if(b >= max) b = max;}
359
 #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; if(b <= min) b = min; else if(b >= max) b = max;}
360
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
360
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
361
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
361
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
362
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
362
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
363
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
363
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
364
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
364
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
365
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
365
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
366
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
366
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
367
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
367
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
368
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
368
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
369
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
369
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
370
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
370
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
371
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
371
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
372
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
372
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
373
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
373
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
374
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
374
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
375
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
375
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
376
 
376
 
377
 Ki = (float) Parameter_I_Faktor * 0.0001;
377
 Ki = (float) Parameter_I_Faktor * 0.0001;
378
 MAX_GAS = EE_Parameter.Gas_Max;
378
 MAX_GAS = EE_Parameter.Gas_Max;
379
 MIN_GAS = EE_Parameter.Gas_Min;
379
 MIN_GAS = EE_Parameter.Gas_Min;
380
}
380
}
381
 
381
 
382
 
382
 
383
//############################################################################
383
//############################################################################
384
//
384
//
385
void MotorRegler(void)
385
void MotorRegler(void)
386
//############################################################################
386
//############################################################################
387
{
387
{
388
         int motorwert,pd_ergebnis,h,tmp_int;
388
         int motorwert,pd_ergebnis,h,tmp_int;
389
         int GierMischanteil,GasMischanteil;
389
         int GierMischanteil,GasMischanteil;
390
     static long SummeNick=0,SummeRoll=0;
390
     static long SummeNick=0,SummeRoll=0;
391
     static long sollGier = 0,tmp_long,tmp_long2;
391
     static long sollGier = 0,tmp_long,tmp_long2;
392
     static long IntegralFehlerNick = 0;
392
     static long IntegralFehlerNick = 0;
393
     static long IntegralFehlerRoll = 0;
393
     static long IntegralFehlerRoll = 0;
394
         static unsigned int RcLostTimer;
394
         static unsigned int RcLostTimer;
395
         static unsigned char delay_neutral = 0;
395
         static unsigned char delay_neutral = 0;
396
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
396
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
397
         static unsigned int  modell_fliegt = 0;
397
         static unsigned int  modell_fliegt = 0;
398
     static int hoehenregler = 0;
398
     static int hoehenregler = 0;
399
     static char TimerWerteausgabe = 0;
399
     static char TimerWerteausgabe = 0;
400
     static char NeueKompassRichtungMerken = 0;
400
     static char NeueKompassRichtungMerken = 0;
401
     static long ausgleichNick, ausgleichRoll;
401
     static long ausgleichNick, ausgleichRoll;
402
     
402
     
403
        Mittelwert();
403
        Mittelwert();
404
 
404
 
405
    GRN_ON;
405
    GRN_ON;
406
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
406
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
407
// Gaswert ermitteln
407
// Gaswert ermitteln
408
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
408
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
409
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
409
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
410
    if(GasMischanteil < 0) GasMischanteil = 0;
410
    if(GasMischanteil < 0) GasMischanteil = 0;
411
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
411
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
412
// Emfang schlecht
412
// Emfang schlecht
413
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
413
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
414
   if(SenderOkay < 100)
414
   if(SenderOkay < 100)
415
        {
415
        {
416
        if(!PcZugriff)
416
        if(!PcZugriff)
417
         {
417
         {
418
           if(BeepMuster == 0xffff)
418
           if(BeepMuster == 0xffff)
419
            {
419
            {
420
             beeptime = 15000;
420
             beeptime = 15000;
421
             BeepMuster = 0x0c00;
421
             BeepMuster = 0x0c00;
422
            }
422
            }
423
         }
423
         }
424
        if(RcLostTimer) RcLostTimer--;
424
        if(RcLostTimer) RcLostTimer--;
425
        else
425
        else
426
         {
426
         {
427
          MotorenEin = 0;
427
          MotorenEin = 0;
428
          Notlandung = 0;
428
          Notlandung = 0;
429
         }
429
         }
430
        ROT_ON;
430
        ROT_ON;
431
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
431
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
432
            {
432
            {
433
            GasMischanteil = EE_Parameter.NotGas;
433
            GasMischanteil = EE_Parameter.NotGas;
434
            Notlandung = 1;
434
            Notlandung = 1;
435
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
435
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
436
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
436
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
437
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
437
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
438
            }
438
            }
439
         else MotorenEin = 0;
439
         else MotorenEin = 0;
440
        }
440
        }
441
        else
441
        else
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
443
// Emfang gut
443
// Emfang gut
444
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
444
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
445
        if(SenderOkay > 140)
445
        if(SenderOkay > 140)
446
            {
446
            {
447
            Notlandung = 0;
447
            Notlandung = 0;
448
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
448
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
449
            if(GasMischanteil > 40)
449
            if(GasMischanteil > 40)
450
                {
450
                {
451
                if(modell_fliegt < 0xffff) modell_fliegt++;
451
                if(modell_fliegt < 0xffff) modell_fliegt++;
452
                }
452
                }
453
            if((modell_fliegt < 200) || (GasMischanteil < 40))
453
            if((modell_fliegt < 200) || (GasMischanteil < 40))
454
                {
454
                {
455
                SummeNick = 0;
455
                SummeNick = 0;
456
                SummeRoll = 0;
456
                SummeRoll = 0;
457
                Mess_Integral_Gier = 0;
457
                Mess_Integral_Gier = 0;
458
                Mess_Integral_Gier2 = 0;
458
                Mess_Integral_Gier2 = 0;
459
                }
459
                }
460
            if((GasMischanteil > 200) && MotorenEin == 0)
460
            if((GasMischanteil > 200) && MotorenEin == 0)
461
                {
461
                {
462
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
462
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
463
// auf Nullwerte kalibrieren
463
// auf Nullwerte kalibrieren
464
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
464
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
465
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
465
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
466
                    {
466
                    {
467
                    unsigned char setting = 2;
467
                    unsigned char setting = 2;
468
                    if(++delay_neutral > 200)  // nicht sofort
468
                    if(++delay_neutral > 200)  // nicht sofort
469
                        {
469
                        {
470
                        GRN_OFF;
470
                        GRN_OFF;
471
                        MotorenEin = 0;
471
                        MotorenEin = 0;
472
                        delay_neutral = 0;
472
                        delay_neutral = 0;
473
                        modell_fliegt = 0;
473
                        modell_fliegt = 0;
474
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
474
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
475
                        {
475
                        {
476
                         unsigned char setting=1;
476
                         unsigned char setting=1;
477
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
477
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
478
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
478
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
479
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
479
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
480
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
480
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
481
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
481
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
482
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
482
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
483
                        }
483
                        }
484
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
484
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
485
                          {
485
                          {
486
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
486
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
487
                          }  
487
                          }  
488
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
488
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
489
                        SetNeutral();
489
                        SetNeutral();
490
                        Piep(GetActiveParamSetNumber());
490
                        Piep(GetActiveParamSetNumber());
491
                        }
491
                        }
492
                    }
492
                    }
493
                 else delay_neutral = 0;
493
                 else delay_neutral = 0;
494
                }
494
                }
495
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
495
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
496
// Gas ist unten
496
// Gas ist unten
497
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
497
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
498
            if(GasMischanteil < 35)
498
            if(GasMischanteil < 35)
499
                {
499
                {
500
                // Starten
500
                // Starten
501
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
501
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
502
                    {
502
                    {
503
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
503
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
504
// Einschalten
504
// Einschalten
505
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
505
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
506
                    if(++delay_einschalten > 200)
506
                    if(++delay_einschalten > 200)
507
                        {
507
                        {
508
                        delay_einschalten = 200;
508
                        delay_einschalten = 200;
509
                        modell_fliegt = 1;
509
                        modell_fliegt = 1;
510
                        MotorenEin = 1;
510
                        MotorenEin = 1;
511
                        sollGier = 0;
511
                        sollGier = 0;
512
                        Mess_Integral_Gier = 0;
512
                        Mess_Integral_Gier = 0;
513
                        Mess_Integral_Gier2 = 0;
513
                        Mess_Integral_Gier2 = 0;
514
                        Mess_IntegralNick = 0;
514
                        Mess_IntegralNick = 0;
515
                        Mess_IntegralRoll = 0;
515
                        Mess_IntegralRoll = 0;
516
                        Mess_IntegralNick2 = IntegralNick;
516
                        Mess_IntegralNick2 = IntegralNick;
517
                        Mess_IntegralRoll2 = IntegralRoll;
517
                        Mess_IntegralRoll2 = IntegralRoll;
518
                        SummeNick = 0;
518
                        SummeNick = 0;
519
                        SummeRoll = 0;
519
                        SummeRoll = 0;
520
                        }          
520
                        }          
521
                    }  
521
                    }  
522
                    else delay_einschalten = 0;
522
                    else delay_einschalten = 0;
523
                //Auf Neutralwerte setzen
523
                //Auf Neutralwerte setzen
524
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
524
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
525
// Auschalten
525
// Auschalten
526
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
526
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
527
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
527
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
528
                    {
528
                    {
529
                    if(++delay_ausschalten > 200)  // nicht sofort
529
                    if(++delay_ausschalten > 200)  // nicht sofort
530
                        {
530
                        {
531
                        MotorenEin = 0;
531
                        MotorenEin = 0;
532
                        delay_ausschalten = 200;
532
                        delay_ausschalten = 200;
533
                        modell_fliegt = 0;
533
                        modell_fliegt = 0;
534
                        }
534
                        }
535
                    }
535
                    }
536
                else delay_ausschalten = 0;
536
                else delay_ausschalten = 0;
537
                }
537
                }
538
            }
538
            }
539
 
539
 
540
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
540
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
541
// neue Werte von der Funke
541
// neue Werte von der Funke
542
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
542
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
543
 if(!NewPpmData-- || Notlandung)  
543
 if(!NewPpmData-- || Notlandung)  
544
  {
544
  {
545
    int tmp_int;
545
    int tmp_int;
546
    ParameterZuordnung();
546
    ParameterZuordnung();
547
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
547
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
548
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
548
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
549
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
549
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
550
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
550
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
551
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
551
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
552
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
552
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
553
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
553
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
554
 
554
 
555
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
555
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
556
if(DubWiseKeys[1]) beeptime = 10;
556
if(DubWiseKeys[1]) beeptime = 10;
557
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
557
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
558
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
558
    if(DubWiseKeys[1] & DUB_KEY_DOWN)  tmp_int = -KEY_VALUE;  else   tmp_int = 0;
559
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
559
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
560
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
560
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
561
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
561
    if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0;
562
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
562
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
563
 
563
 
564
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
564
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
565
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
565
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
566
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
566
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
567
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
567
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
568
 
568
 
569
    StickNick += ExternStickNick / 8;
569
    StickNick += ExternStickNick / 8;
570
    StickRoll += ExternStickRoll / 8;
570
    StickRoll += ExternStickRoll / 8;
571
    StickGier += ExternStickGier;
571
    StickGier += ExternStickGier;
572
 
572
 
573
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
573
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
574
    if(GyroFaktor < 0) GyroFaktor = 0;
574
    if(GyroFaktor < 0) GyroFaktor = 0;
575
    if(IntegralFaktor < 0) IntegralFaktor = 0;
575
    if(IntegralFaktor < 0) IntegralFaktor = 0;
576
    // greift in den Stick ein, um ungewolltes überschlagen zu verhindern
576
    // greift in den Stick ein, um ungewolltes überschlagen zu verhindern
577
    if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
577
    if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS))
578
     {
578
     {
579
      if(IntegralNick >  60000)  
579
      if(IntegralNick >  60000)  
580
      {
580
      {
581
       StickNick -=  8 * EE_Parameter.Stick_P;      
581
       StickNick -=  8 * EE_Parameter.Stick_P;      
582
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
582
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
583
      }
583
      }
584
      else
584
      else
585
      if(IntegralNick < -60000)  
585
      if(IntegralNick < -60000)  
586
      {
586
      {
587
       StickNick += 8 * EE_Parameter.Stick_P;
587
       StickNick += 8 * EE_Parameter.Stick_P;
588
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
588
       if(IntegralNick >  80000) StickNick -= 16 * EE_Parameter.Stick_P;      
589
      }
589
      }
590
      if(IntegralRoll >  60000)  
590
      if(IntegralRoll >  60000)  
591
      {
591
      {
592
       StickRoll -=  8 * EE_Parameter.Stick_P;      
592
       StickRoll -=  8 * EE_Parameter.Stick_P;      
593
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
593
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
594
      }
594
      }
595
      else
595
      else
596
      if(IntegralRoll < -60000)  
596
      if(IntegralRoll < -60000)  
597
      {
597
      {
598
       StickRoll += 8 * EE_Parameter.Stick_P;
598
       StickRoll += 8 * EE_Parameter.Stick_P;
599
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
599
       if(IntegralRoll >  80000) StickRoll -= 16 * EE_Parameter.Stick_P;      
600
      }
600
      }
601
     }
601
     }
602
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
602
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
603
// Looping?
603
// Looping?
604
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
604
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
605
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
605
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
606
  else
606
  else
607
   {
607
   {
608
     {
608
     {
609
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
609
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
610
     }  
610
     }  
611
   }
611
   }
612
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
612
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
613
   else
613
   else
614
   {
614
   {
615
   if(Looping_Rechts) // Hysterese
615
   if(Looping_Rechts) // Hysterese
616
     {
616
     {
617
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
617
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
618
     }
618
     }
619
   }
619
   }
620
 
620
 
621
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
621
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
622
  else
622
  else
623
   {
623
   {
624
    if(Looping_Oben)  // Hysterese
624
    if(Looping_Oben)  // Hysterese
625
     {
625
     {
626
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
626
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
627
     }  
627
     }  
628
   }
628
   }
629
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
629
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
630
   else
630
   else
631
   {
631
   {
632
    if(Looping_Unten) // Hysterese
632
    if(Looping_Unten) // Hysterese
633
     {
633
     {
634
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
634
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
635
     }
635
     }
636
   }
636
   }
637
 
637
 
638
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
638
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
639
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
639
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
640
  } // Ende neue Funken-Werte
640
  } // Ende neue Funken-Werte
641
 
641
 
642
  if(Looping_Roll) beeptime = 100;
642
  if(Looping_Roll) beeptime = 100;
643
  if(Looping_Roll || Looping_Nick)
643
  if(Looping_Roll || Looping_Nick)
644
   {
644
   {
645
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
645
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
646
   }
646
   }
647
   
647
   
648
 
648
 
649
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
649
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
650
// Bei Empfangsausfall im Flug 
650
// Bei Empfangsausfall im Flug 
651
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
651
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
652
   if(Notlandung)
652
   if(Notlandung)
653
    {
653
    {
654
     StickGier = 0;
654
     StickGier = 0;
655
     StickNick = 0;
655
     StickNick = 0;
656
     StickRoll = 0;
656
     StickRoll = 0;
657
     GyroFaktor  = 0.1;
657
     GyroFaktor  = 0.1;
658
     IntegralFaktor = 0.005;
658
     IntegralFaktor = 0.005;
659
     Looping_Roll = 0;
659
     Looping_Roll = 0;
660
     Looping_Nick = 0;
660
     Looping_Nick = 0;
661
    }  
661
    }  
662
 
662
 
663
 
663
 
664
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
664
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
665
// Integrale auf ACC-Signal abgleichen
665
// Integrale auf ACC-Signal abgleichen
666
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
666
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
667
#define ABGLEICH_ANZAHL 256L
667
#define ABGLEICH_ANZAHL 256L
668
 
668
 
669
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
669
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
670
 MittelIntegralRoll  += IntegralRoll;
670
 MittelIntegralRoll  += IntegralRoll;
671
 MittelIntegralNick2 += IntegralNick2;
671
 MittelIntegralNick2 += IntegralNick2;
672
 MittelIntegralRoll2 += IntegralRoll2;
672
 MittelIntegralRoll2 += IntegralRoll2;
673
 
673
 
674
 if(Looping_Nick || Looping_Roll)
674
 if(Looping_Nick || Looping_Roll)
675
  {
675
  {
676
    IntegralAccNick = 0;
676
    IntegralAccNick = 0;
677
    IntegralAccRoll = 0;
677
    IntegralAccRoll = 0;
678
    MittelIntegralNick = 0;
678
    MittelIntegralNick = 0;
679
    MittelIntegralRoll = 0;
679
    MittelIntegralRoll = 0;
680
    MittelIntegralNick2 = 0;
680
    MittelIntegralNick2 = 0;
681
    MittelIntegralRoll2 = 0;
681
    MittelIntegralRoll2 = 0;
682
    Mess_IntegralNick2 = Mess_IntegralNick;
682
    Mess_IntegralNick2 = Mess_IntegralNick;
683
    Mess_IntegralRoll2 = Mess_IntegralRoll;
683
    Mess_IntegralRoll2 = Mess_IntegralRoll;
684
    ZaehlMessungen = 0;
684
    ZaehlMessungen = 0;
685
    I_LageNick = 0;
685
    LageKorrekturNick = 0;
686
    I_LageRoll = 0;
686
    LageKorrekturRoll = 0;
687
  }
687
  }
688
 
688
 
689
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
689
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
690
  if(IntegralFaktor && !Looping_Nick && !Looping_Roll)
690
  if(!Looping_Nick && !Looping_Roll)
691
  {
691
  {
692
   long tmp_long, tmp_long2;
692
   long tmp_long, tmp_long2;
693
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
693
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
694
    tmp_long /= 16;
694
    tmp_long /= 16;
695
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
695
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
696
    tmp_long2 /= 16;
696
    tmp_long2 /= 16;
697
 #define AUSGLEICH 32 //(Parameter_UserParam1 / 2)
697
 #define AUSGLEICH 32 //(Parameter_UserParam1 / 2)
698
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
698
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
699
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
699
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
700
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
700
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
701
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
701
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
702
    Mess_IntegralNick -= tmp_long;
702
    Mess_IntegralNick -= tmp_long;
703
    Mess_IntegralRoll -= tmp_long2;
703
    Mess_IntegralRoll -= tmp_long2;
704
  }
704
  }
705
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
705
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
706
 
706
 
707
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
707
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
708
 {
708
 {
709
  static int cnt = 0;
709
  static int cnt = 0;
710
  static char last_n_p,last_n_n,last_r_p,last_r_n;
710
  static char last_n_p,last_n_n,last_r_p,last_r_n;
711
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
711
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
712
  if(!Looping_Nick && !Looping_Roll)
712
  if(!Looping_Nick && !Looping_Roll)
713
  {
713
  {
714
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
714
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
715
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
715
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
716
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
716
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
717
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
717
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
718
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
718
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
719
#define MAX_I 0//(Poti2/10)
719
#define MAX_I 0//(Poti2/10)
720
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
720
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
721
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
721
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
722
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
722
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
723
/*    if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < 5000)
-
 
724
     {
-
 
725
       tmp_long = IntegralFehlerNick / 256L;
723
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
726
       if(tmp_long > MAX_I) tmp_long = MAX_I;
-
 
727
       if(tmp_long <-MAX_I) tmp_long =-MAX_I;
-
 
728
       I_LageNick = tmp_long;    
-
 
729
     }
-
 
730
     else
-
 
731
     {
-
 
732
      I_LageNick /= 2;
-
 
733
     }
-
 
734
*/
-
 
735
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
724
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
736
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
725
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
737
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
726
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
738
/*    if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < 5000)
-
 
739
     {
-
 
740
      tmp_long2 = IntegralFehlerRoll / 256L;
727
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
741
      if(tmp_long2 > MAX_I) tmp_long2 = MAX_I;
-
 
742
      if(tmp_long2 <-MAX_I) tmp_long2 =-MAX_I;
-
 
743
      I_LageRoll = tmp_long2;    
-
 
744
     }
-
 
745
     else
-
 
746
     {
-
 
747
      I_LageRoll /=2;
-
 
748
     }
-
 
749
*/
728
 
750
    Mess_IntegralNick -= ausgleichNick;
729
//    Mess_IntegralNick -= ausgleichNick;
751
    Mess_IntegralRoll -= ausgleichRoll;
730
//    Mess_IntegralRoll -= ausgleichRoll;
752
 
731
 
753
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
732
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
754
// Gyro-Drift ermitteln
733
// Gyro-Drift ermitteln
755
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
734
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
756
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
735
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
757
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
736
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
758
//    tmp_long  = (long)(MittelIntegralNick2 - (long)IntegralAccNick); 
737
//    tmp_long  = (long)(MittelIntegralNick2 - (long)IntegralAccNick); 
759
//    tmp_long2 = (long)(MittelIntegralRoll2 - (long)IntegralAccRoll); 
738
//    tmp_long2 = (long)(MittelIntegralRoll2 - (long)IntegralAccRoll); 
760
    tmp_long  = IntegralNick2 - IntegralNick;
739
    tmp_long  = IntegralNick2 - IntegralNick;
761
    tmp_long2 = IntegralRoll2 - IntegralRoll;
740
    tmp_long2 = IntegralRoll2 - IntegralRoll;
762
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
741
    //DebugOut.Analog[25] = MittelIntegralRoll2 / 26;
763
 
742
 
764
    IntegralFehlerNick = tmp_long;
743
    IntegralFehlerNick = tmp_long;
765
    IntegralFehlerRoll = tmp_long2;
744
    IntegralFehlerRoll = tmp_long2;
766
    Mess_IntegralNick2 -= IntegralFehlerNick;
745
    Mess_IntegralNick2 -= IntegralFehlerNick;
767
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
746
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
768
 
747
 
769
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
748
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
770
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
749
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
771
 
750
 
772
 
751
 
773
DebugOut.Analog[17] = IntegralAccNick / 26;
752
DebugOut.Analog[17] = IntegralAccNick / 26;
774
DebugOut.Analog[18] = IntegralAccRoll / 26;
753
DebugOut.Analog[18] = IntegralAccRoll / 26;
775
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
754
DebugOut.Analog[19] = IntegralFehlerNick;// / 26;
776
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
755
DebugOut.Analog[20] = IntegralFehlerRoll;// / 26;
777
DebugOut.Analog[21] = MittelIntegralNick / 26;
756
DebugOut.Analog[21] = MittelIntegralNick / 26;
778
DebugOut.Analog[22] = MittelIntegralRoll / 26;
757
DebugOut.Analog[22] = MittelIntegralRoll / 26;
779
//DebugOut.Analog[28] = ausgleichNick;
758
//DebugOut.Analog[28] = ausgleichNick;
780
DebugOut.Analog[29] = ausgleichRoll;
759
DebugOut.Analog[29] = ausgleichRoll;
781
DebugOut.Analog[30] = I_LageRoll * 10;
760
DebugOut.Analog[30] = LageKorrekturRoll * 10;
782
 
761
 
783
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
762
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
784
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
763
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
785
#define BEWEGUNGS_LIMIT 20000
764
#define BEWEGUNGS_LIMIT 20000
786
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
765
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
787
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
766
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
788
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
767
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
789
        {
768
        {
790
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
769
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
791
         {
770
         {
792
           if(last_n_p)
771
           if(last_n_p)
793
           {
772
           {
794
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
773
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
795
            ausgleichNick = IntegralFehlerNick / 8;
774
            ausgleichNick = IntegralFehlerNick / 8;
796
            if(ausgleichNick > 5000) ausgleichNick = 5000;
775
            if(ausgleichNick > 5000) ausgleichNick = 5000;
-
 
776
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
797
            Mess_IntegralNick -= ausgleichNick;
777
//            Mess_IntegralNick -= ausgleichNick;
798
           }
778
           }
799
           else last_n_p = 1;
779
           else last_n_p = 1;
800
         } else  last_n_p = 0;
780
         } else  last_n_p = 0;
801
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
781
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
802
         {
782
         {
803
           if(last_n_n)
783
           if(last_n_n)
804
            {
784
            {
805
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
785
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
806
             ausgleichNick = IntegralFehlerNick / 8;
786
             ausgleichNick = IntegralFehlerNick / 8;
807
             if(ausgleichNick < -5000) ausgleichNick = -5000;
787
             if(ausgleichNick < -5000) ausgleichNick = -5000;
-
 
788
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
808
             Mess_IntegralNick -= ausgleichNick;
789
//             Mess_IntegralNick -= ausgleichNick;
809
            }
790
            }
810
           else last_n_n = 1;
791
           else last_n_n = 1;
811
         } else  last_n_n = 0;
792
         } else  last_n_n = 0;
812
        } else cnt = 0;
793
        } else cnt = 0;
813
        if(cnt > 4) cnt = 4;
794
        if(cnt > 4) cnt = 4;
814
//        if(cnt > Poti2 / 40) cnt =  Poti2 / 40;
795
//        if(cnt > Poti2 / 40) cnt =  Poti2 / 40;
815
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
796
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
816
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
797
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
817
 
798
 
818
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
799
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
819
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
800
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
820
 
801
 
821
ausgleichRoll = 0;
802
        ausgleichRoll = 0;
822
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
803
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
823
        {
804
        {
824
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
805
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
825
         {
806
         {
826
           if(last_r_p)
807
           if(last_r_p)
827
           {
808
           {
828
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
809
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
829
            ausgleichRoll = IntegralFehlerRoll / 8;
810
            ausgleichRoll = IntegralFehlerRoll / 8;
830
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
811
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
831
            Mess_IntegralRoll -= ausgleichRoll;
812
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
832
//            beeptime = 50;
813
//            Mess_IntegralRoll -= ausgleichRoll;
833
           }
814
           }
834
           else last_r_p = 1;
815
           else last_r_p = 1;
835
         } else  last_r_p = 0;
816
         } else  last_r_p = 0;
836
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
817
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
837
         {
818
         {
838
           if(last_r_n)
819
           if(last_r_n)
839
           {
820
           {
840
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
821
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
841
            ausgleichRoll = IntegralFehlerRoll / 8;
822
            ausgleichRoll = IntegralFehlerRoll / 8;
842
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
823
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
843
            Mess_IntegralRoll -= ausgleichRoll;
824
//            Mess_IntegralRoll -= ausgleichRoll;
844
//            beeptime = 50;
825
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
845
           }
826
           }
846
           else last_r_n = 1;
827
           else last_r_n = 1;
847
         } else  last_r_n = 0;
828
         } else  last_r_n = 0;
848
        } else
829
        } else
849
        {
830
        {
850
         beeptime = 50;
-
 
851
         cnt = 0;
831
         cnt = 0;
852
        }
832
        }
853
DebugOut.Analog[27] = ausgleichRoll;
833
DebugOut.Analog[27] = ausgleichRoll;
854
        if(cnt > 4) cnt = 4;
834
        if(cnt > 4) cnt = 4;
855
//        if(cnt > Poti2 / 40) cnt =  Poti2 / 40;
835
//        if(cnt > Poti2 / 40) cnt =  Poti2 / 40;
856
 
-
 
-
 
836
//if(cnt > 1) beeptime = 50;
857
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
837
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
858
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
838
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
859
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
839
DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
860
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
840
DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
861
 
-
 
862
  }
841
  }
-
 
842
  else
-
 
843
  {
-
 
844
   LageKorrekturRoll = 0;
-
 
845
   LageKorrekturNick = 0;
-
 
846
  }
-
 
847
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
863
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
848
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
864
   MittelIntegralNick_Alt = MittelIntegralNick;      
849
   MittelIntegralNick_Alt = MittelIntegralNick;      
865
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
850
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
866
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
851
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
867
    IntegralAccNick = 0;
852
    IntegralAccNick = 0;
868
    IntegralAccRoll = 0;
853
    IntegralAccRoll = 0;
869
    IntegralAccZ = 0;
854
    IntegralAccZ = 0;
870
    MittelIntegralNick = 0;
855
    MittelIntegralNick = 0;
871
    MittelIntegralRoll = 0;
856
    MittelIntegralRoll = 0;
872
    MittelIntegralNick2 = 0;
857
    MittelIntegralNick2 = 0;
873
    MittelIntegralRoll2 = 0;
858
    MittelIntegralRoll2 = 0;
874
    ZaehlMessungen = 0;
859
    ZaehlMessungen = 0;
875
 }
860
 }
876
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
861
//DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor);
877
 
862
 
878
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
863
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
879
//  Gieren
864
//  Gieren
880
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
865
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
881
    if(abs(StickGier) > 20) // war 35 
866
    if(abs(StickGier) > 20) // war 35 
882
     {
867
     {
883
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
868
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
884
     }
869
     }
885
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
870
    tmp_int  = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
886
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
871
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
887
    sollGier = tmp_int;
872
    sollGier = tmp_int;
888
    Mess_Integral_Gier -= tmp_int;  
873
    Mess_Integral_Gier -= tmp_int;  
889
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
874
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
890
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
875
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
891
 
876
 
892
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
877
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
893
//  Kompass
878
//  Kompass
894
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
879
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
895
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
880
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
896
     {
881
     {
897
       int w,v;
882
       int w,v;
898
       static int SignalSchlecht = 0;
883
       static int SignalSchlecht = 0;
899
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
884
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
900
       v = abs(IntegralRoll /512);
885
       v = abs(IntegralRoll /512);
901
       if(v > w) w = v; // grösste Neigung ermitteln
886
       if(v > w) w = v; // grösste Neigung ermitteln
902
       if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht)    
887
       if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht)    
903
        {
888
        {
904
         KompassStartwert = KompassValue;
889
         KompassStartwert = KompassValue;
905
         NeueKompassRichtungMerken = 0;
890
         NeueKompassRichtungMerken = 0;
906
        }
891
        }
907
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
892
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
908
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
893
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
909
       if(w > 0)
894
       if(w > 0)
910
        {
895
        {
911
          if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
896
          if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
912
          if(SignalSchlecht) SignalSchlecht--;
897
          if(SignalSchlecht) SignalSchlecht--;
913
        }  
898
        }  
914
        else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
899
        else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
915
     }
900
     }
916
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
901
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
917
 
902
 
918
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
903
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
919
//  Debugwerte zuordnen
904
//  Debugwerte zuordnen
920
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
905
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
921
  if(!TimerWerteausgabe--)
906
  if(!TimerWerteausgabe--)
922
   {
907
   {
923
    TimerWerteausgabe = 24;
908
    TimerWerteausgabe = 24;
924
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
909
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
925
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
910
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
926
    DebugOut.Analog[2] = Mittelwert_AccNick;
911
    DebugOut.Analog[2] = Mittelwert_AccNick;
927
    DebugOut.Analog[3] = Mittelwert_AccRoll;
912
    DebugOut.Analog[3] = Mittelwert_AccRoll;
928
    DebugOut.Analog[4] = MesswertGier;
913
    DebugOut.Analog[4] = MesswertGier;
929
    DebugOut.Analog[5] = HoehenWert;
914
    DebugOut.Analog[5] = HoehenWert;
930
    DebugOut.Analog[6] =(Mess_Integral_Hoch / 512);
915
    DebugOut.Analog[6] =(Mess_Integral_Hoch / 512);
931
    DebugOut.Analog[8] = KompassValue;
916
    DebugOut.Analog[8] = KompassValue;
932
    DebugOut.Analog[9] = UBat;
917
    DebugOut.Analog[9] = UBat;
933
    DebugOut.Analog[10] = SenderOkay;
918
    DebugOut.Analog[10] = SenderOkay;
934
    DebugOut.Analog[16] = Mittelwert_AccHoch;
919
    DebugOut.Analog[16] = Mittelwert_AccHoch;
935
 
920
 
936
/*    DebugOut.Analog[16] = motor_rx[0];
921
/*    DebugOut.Analog[16] = motor_rx[0];
937
    DebugOut.Analog[17] = motor_rx[1];
922
    DebugOut.Analog[17] = motor_rx[1];
938
    DebugOut.Analog[18] = motor_rx[2];
923
    DebugOut.Analog[18] = motor_rx[2];
939
    DebugOut.Analog[19] = motor_rx[3];
924
    DebugOut.Analog[19] = motor_rx[3];
940
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
925
    DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3];
941
    DebugOut.Analog[20] /= 14;
926
    DebugOut.Analog[20] /= 14;
942
    DebugOut.Analog[21] = motor_rx[4];
927
    DebugOut.Analog[21] = motor_rx[4];
943
    DebugOut.Analog[22] = motor_rx[5];
928
    DebugOut.Analog[22] = motor_rx[5];
944
    DebugOut.Analog[23] = motor_rx[6];
929
    DebugOut.Analog[23] = motor_rx[6];
945
    DebugOut.Analog[24] = motor_rx[7];
930
    DebugOut.Analog[24] = motor_rx[7];
946
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
931
    DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7];
947
*/
932
*/
948
//    DebugOut.Analog[9] = MesswertNick;
933
//    DebugOut.Analog[9] = MesswertNick;
949
//    DebugOut.Analog[9] = SollHoehe;
934
//    DebugOut.Analog[9] = SollHoehe;
950
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
935
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
951
//    DebugOut.Analog[11] = KompassStartwert;
936
//    DebugOut.Analog[11] = KompassStartwert;
952
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
937
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
953
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
938
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
954
//    DebugOut.Analog[9] = KompassRichtung;    
939
//    DebugOut.Analog[9] = KompassRichtung;    
955
//    DebugOut.Analog[10] = GasMischanteil;
940
//    DebugOut.Analog[10] = GasMischanteil;
956
//    DebugOut.Analog[3] = HoeheD * 32;
941
//    DebugOut.Analog[3] = HoeheD * 32;
957
//    DebugOut.Analog[4] = hoehenregler;
942
//    DebugOut.Analog[4] = hoehenregler;
958
  }
943
  }
959
 
944
 
960
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
945
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
961
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
946
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
962
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
947
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
963
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
948
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
964
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
949
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
965
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
950
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
966
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
951
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
967
//    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
952
//    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
968
    MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2;
953
    MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2;
969
 
954
 
970
DebugOut.Analog[28] = MesswertRoll;
955
DebugOut.Analog[28] = MesswertRoll;
971
DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
956
DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
972
DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
957
DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
973
 
958
 
974
    // Maximalwerte abfangen
959
    // Maximalwerte abfangen
975
    #define MAX_SENSOR  2048
960
    #define MAX_SENSOR  2048
976
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
961
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
977
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
962
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
978
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
963
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
979
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
964
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
980
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
965
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
981
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
966
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
982
 
967
 
983
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
968
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
984
// Höhenregelung
969
// Höhenregelung
985
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
970
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
986
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
971
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
987
//OCR0B = 180 - (Poti1 + 120) / 4;
972
//OCR0B = 180 - (Poti1 + 120) / 4;
988
//DruckOffsetSetting = OCR0B;
973
//DruckOffsetSetting = OCR0B;
989
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
974
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
990
  {
975
  {
991
    int tmp_int;
976
    int tmp_int;
992
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
977
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
993
    {
978
    {
994
     if(Parameter_MaxHoehe < 50)
979
     if(Parameter_MaxHoehe < 50)
995
      {
980
      {
996
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
981
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
997
       HoehenReglerAktiv = 0;
982
       HoehenReglerAktiv = 0;
998
      }
983
      }
999
      else  
984
      else  
1000
        HoehenReglerAktiv = 1;
985
        HoehenReglerAktiv = 1;
1001
    }
986
    }
1002
    else
987
    else
1003
    {
988
    {
1004
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
989
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1005
     HoehenReglerAktiv = 1;
990
     HoehenReglerAktiv = 1;
1006
    }
991
    }
1007
 
992
 
1008
    if(Notlandung) SollHoehe = 0;
993
    if(Notlandung) SollHoehe = 0;
1009
    h = HoehenWert;
994
    h = HoehenWert;
1010
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
995
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1011
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
996
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1012
      h = GasMischanteil - h;         // vom Gas abziehen
997
      h = GasMischanteil - h;         // vom Gas abziehen
1013
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
998
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1014
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
999
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1015
      if(tmp_int > 50) tmp_int = 50;
1000
      if(tmp_int > 50) tmp_int = 50;
1016
      else if(tmp_int < -50) tmp_int = -50;
1001
      else if(tmp_int < -50) tmp_int = -50;
1017
      h -= tmp_int;
1002
      h -= tmp_int;
1018
      hoehenregler = (hoehenregler*15 + h) / 16;      
1003
      hoehenregler = (hoehenregler*15 + h) / 16;      
1019
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1004
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1020
       {
1005
       {
1021
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1006
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1022
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1007
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1023
       }  
1008
       }  
1024
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1009
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1025
      GasMischanteil = hoehenregler;
1010
      GasMischanteil = hoehenregler;
1026
     }
1011
     }
1027
  }
1012
  }
1028
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1013
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1029
// + Mischer und PI-Regler
1014
// + Mischer und PI-Regler
1030
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1015
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1031
  DebugOut.Analog[7] = GasMischanteil;
1016
  DebugOut.Analog[7] = GasMischanteil;
1032
 
1017
 
1033
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1018
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1034
// Gier-Anteil
1019
// Gier-Anteil
1035
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1020
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1036
#define MUL_G  1.0
1021
#define MUL_G  1.0
1037
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1022
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1038
//GierMischanteil = 0;
1023
//GierMischanteil = 0;
1039
    if(GierMischanteil > (MUL_G * GasMischanteil))  GierMischanteil = MUL_G * GasMischanteil;
1024
    if(GierMischanteil > (MUL_G * GasMischanteil))  GierMischanteil = MUL_G * GasMischanteil;
1040
    if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil);
1025
    if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil);
1041
    if(GierMischanteil > 100)  GierMischanteil = 100;
1026
    if(GierMischanteil > 100)  GierMischanteil = 100;
1042
    if(GierMischanteil < -100) GierMischanteil = -100;
1027
    if(GierMischanteil < -100) GierMischanteil = -100;
1043
 
1028
 
1044
    if(GasMischanteil < 20) GierMischanteil = 0;
1029
    if(GasMischanteil < 20) GierMischanteil = 0;
1045
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1030
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1046
// Nick-Achse
1031
// Nick-Achse
1047
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1032
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1048
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
1033
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
1049
    if(IntegralRoll) SummeNick += IntegralNick * IntegralFaktor - StickNick;
1034
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
1050
    else  SummeNick += DiffNick;                                   // I-Anteil
1035
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1051
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
1036
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
1052
    if(SummeNick >  16000) SummeNick =  16000;
1037
    if(SummeNick >  16000) SummeNick =  16000;
1053
    if(SummeNick < -16000) SummeNick = -16000;
1038
    if(SummeNick < -16000) SummeNick = -16000;
1054
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1039
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1055
    // Motor Vorn
1040
    // Motor Vorn
1056
#define MUL  2
1041
#define MUL  2
1057
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1042
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1058
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1043
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1059
 
1044
 
1060
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1045
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1061
        if ((motorwert < 0)) motorwert = 0;
1046
        if ((motorwert < 0)) motorwert = 0;
1062
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1047
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1063
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1048
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1064
        Motor_Vorne = motorwert;           
1049
        Motor_Vorne = motorwert;           
1065
    // Motor Heck
1050
    // Motor Heck
1066
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1051
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1067
        if ((motorwert < 0)) motorwert = 0;
1052
        if ((motorwert < 0)) motorwert = 0;
1068
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1053
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1069
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1054
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1070
        Motor_Hinten = motorwert;              
1055
        Motor_Hinten = motorwert;              
1071
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1056
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1072
// Roll-Achse
1057
// Roll-Achse
1073
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1058
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1074
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
1059
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
1075
    if(IntegralRoll) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll;
1060
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll  - GPS_Roll);// I-Anteil bei Winkelregelung
1076
    else                 SummeRoll += DiffRoll;                                                             // I-Anteil
1061
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1077
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
1062
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
1078
    if(SummeRoll >  16000) SummeRoll =  16000;
1063
    if(SummeRoll >  16000) SummeRoll =  16000;
1079
    if(SummeRoll < -16000) SummeRoll = -16000;
1064
    if(SummeRoll < -16000) SummeRoll = -16000;
1080
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1065
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1081
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1066
    if(pd_ergebnis >  MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis =  MUL * (GasMischanteil + abs(GierMischanteil));
1082
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1067
    if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil));
1083
    // Motor Links
1068
    // Motor Links
1084
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1069
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1085
        if ((motorwert < 0)) motorwert = 0;
1070
        if ((motorwert < 0)) motorwert = 0;
1086
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1071
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1087
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1072
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1088
        Motor_Links = motorwert;               
1073
        Motor_Links = motorwert;               
1089
    // Motor Rechts
1074
    // Motor Rechts
1090
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1075
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1091
        if ((motorwert < 0)) motorwert = 0;
1076
        if ((motorwert < 0)) motorwert = 0;
1092
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1077
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1093
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1078
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1094
        Motor_Rechts = motorwert;
1079
        Motor_Rechts = motorwert;
1095
   // +++++++++++++++++++++++++++++++++++++++++++++++
1080
   // +++++++++++++++++++++++++++++++++++++++++++++++
1096
}
1081
}
1097
 
1082
 
1098
 
1083