Subversion Repositories FlightCtrl

Rev

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

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