Subversion Repositories FlightCtrl

Rev

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

Rev 742 Rev 743
1
/*#######################################################################################
1
/*#######################################################################################
2
Flight Control
2
Flight Control
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
5
// + Copyright (c) 04.2007 Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + www.MikroKopter.com
7
// + www.MikroKopter.com
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
9
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
10
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
11
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
12
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
13
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Verkauf von Luftbildaufnahmen, usw.
14
// + Verkauf von Luftbildaufnahmen, usw.
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
16
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
17
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
19
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
20
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + eindeutig als Ursprung verlinkt werden
21
// + eindeutig als Ursprung verlinkt werden
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
23
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Benutzung auf eigene Gefahr
24
// + Benutzung auf eigene Gefahr
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
25
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
27
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + mit unserer Zustimmung zulässig
28
// + mit unserer Zustimmung zulässig
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
30
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
32
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + this list of conditions and the following disclaimer.
33
// + this list of conditions and the following disclaimer.
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
34
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +     from this software without specific prior written permission.
35
// +     from this software without specific prior written permission.
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
36
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
37
// +     for non-commercial use (directly or indirectly)
37
// +     for non-commercial use (directly or indirectly)
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
38
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     with our written permission
39
// +     with our written permission
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
40
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +     clearly linked as origin 
41
// +     clearly linked as origin 
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
42
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  POSSIBILITY OF SUCH DAMAGE. 
52
// +  POSSIBILITY OF SUCH DAMAGE. 
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
 
54
 
55
#include "main.h"
55
#include "main.h"
56
#include "eeprom.c"
56
#include "eeprom.c"
57
 
57
 
58
unsigned char h,m,s;
58
unsigned char h,m,s;
59
volatile unsigned int I2CTimeout = 100;
59
volatile unsigned int I2CTimeout = 100;
60
int MesswertNick,MesswertRoll,MesswertGier;
60
int MesswertNick,MesswertRoll,MesswertGier;
61
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
61
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0;
62
int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch;
62
int Mittelwert_AccNick, Mittelwert_AccRoll;
63
 
63
 
64
long IntegralNick = 0,IntegralNick2 = 0;
64
long IntegralNick = 0,IntegralNick2 = 0;
65
long IntegralRoll = 0,IntegralRoll2 = 0;
65
long IntegralRoll = 0,IntegralRoll2 = 0;
66
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
66
long IntegralAccNick = 0,IntegralAccRoll = 0;
67
long Integral_Gier = 0;
67
long Integral_Gier = 0;
68
 
68
 
69
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
69
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
70
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
70
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
71
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
71
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
72
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
72
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
73
volatile long Mess_Integral_Hoch = 0;
73
volatile long Mess_Integral_Hoch = 0;
74
 
74
 
75
int KompassValue = 0;
75
int KompassValue = 0;
76
int KompassStartwert = 0;
76
int KompassStartwert = 0;
77
int KompassRichtung = 0;
77
int KompassRichtung = 0;
78
uint8_t updKompass = 0;
78
uint8_t updKompass = 0;
79
 
79
 
80
uint8_t DebugOutBlock = 0;
80
uint8_t DebugOutBlock = 0;
81
 
81
 
82
unsigned char MAX_GAS,MIN_GAS;
82
unsigned char MAX_GAS,MIN_GAS;
83
unsigned char Notlandung = 0;
83
unsigned char Notlandung = 0;
84
unsigned char HoehenReglerAktiv = 0;
84
unsigned char HoehenReglerAktiv = 0;
85
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
85
long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L;
86
 
86
 
87
float GyroFaktor;
87
float GyroFaktor;
88
float IntegralFaktor;
88
float IntegralFaktor;
89
volatile int DiffNick,DiffRoll;
89
int DiffNick,DiffRoll;
90
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
90
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
91
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
91
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
92
unsigned char MotorWert[5];
92
unsigned char MotorWert[5];
93
volatile unsigned char SenderOkay = 0;
93
volatile unsigned char SenderOkay = 0;
94
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
94
int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0;
95
char MotorenEin = 0;
95
char MotorenEin = 0;
96
int HoehenWert = 0;
96
int HoehenWert = 0;
97
int SollHoehe = 0;
97
int SollHoehe = 0;
98
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
98
int LageKorrekturRoll = 0,LageKorrekturNick = 0;
99
float Ki =  FAKTOR_I;
99
float Ki =  FAKTOR_I;
100
unsigned char Looping_Nick = 0,Looping_Roll = 0;
100
unsigned char Looping_Nick = 0,Looping_Roll = 0;
101
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
101
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0;
102
 
102
 
103
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
103
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
104
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
104
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
105
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
105
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
106
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
106
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
107
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
107
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
108
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
108
unsigned char Parameter_Gyro_P = 150;           // Wert : 10-250
109
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
109
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
110
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
110
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
111
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
111
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
112
unsigned char Parameter_UserParam1 = 0;
112
unsigned char Parameter_UserParam1 = 0;
113
unsigned char Parameter_UserParam2 = 0;
113
unsigned char Parameter_UserParam2 = 0;
114
unsigned char Parameter_UserParam3 = 0;
114
unsigned char Parameter_UserParam3 = 0;
115
unsigned char Parameter_UserParam4 = 0;
115
unsigned char Parameter_UserParam4 = 0;
116
unsigned char Parameter_UserParam5 = 0;
116
unsigned char Parameter_UserParam5 = 0;
117
unsigned char Parameter_UserParam6 = 0;
117
unsigned char Parameter_UserParam6 = 0;
118
unsigned char Parameter_UserParam7 = 0;
118
unsigned char Parameter_UserParam7 = 0;
119
unsigned char Parameter_UserParam8 = 0;
119
unsigned char Parameter_UserParam8 = 0;
120
unsigned char Parameter_ServoNickControl = 100;
120
unsigned char Parameter_ServoNickControl = 100;
121
unsigned char Parameter_LoopGasLimit = 70;
121
unsigned char Parameter_LoopGasLimit = 70;
122
unsigned char Parameter_AchsKopplung1 = 0;
122
unsigned char Parameter_AchsKopplung1 = 0;
123
unsigned char Parameter_AchsGegenKopplung1 = 0;
123
unsigned char Parameter_AchsGegenKopplung1 = 0;
124
unsigned char Parameter_DynamicStability = 100;
124
unsigned char Parameter_DynamicStability = 100;
125
 
125
 
126
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
126
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20;
127
int MaxStickNick = 0,MaxStickRoll = 0;
127
int MaxStickNick = 0,MaxStickRoll = 0;
128
 
128
 
129
struct mk_param_struct EE_Parameter;
129
struct mk_param_struct EE_Parameter;
130
struct acc_neutral_struct ee_acc_neutral EEMEM;         // Reservierung im EEPROM
130
struct acc_neutral_struct ee_acc_neutral EEMEM;         // Reservierung im EEPROM
131
struct acc_neutral_struct acc_neutral;
131
struct acc_neutral_struct acc_neutral;
132
 
132
 
133
void Piep(unsigned char Anzahl)
133
void Piep(unsigned char Anzahl)
134
{
134
{
135
 while(Anzahl--)
135
 while(Anzahl--)
136
 {
136
 {
137
  if(MotorenEin) return; //auf keinen Fall im Flug!
137
  if(MotorenEin) return; //auf keinen Fall im Flug!
138
  beeptime = 100;
138
  beeptime = 100;
139
  Delay_ms(250);
139
  Delay_ms(250);
140
 }
140
 }
141
}
141
}
142
 
142
 
143
//############################################################################
143
//############################################################################
144
//  Neutrallage kalibrieren und fest im EEPROM abspeichern
144
//  Neutrallage kalibrieren und fest im EEPROM abspeichern
145
void calib_acc(void)
145
void calib_acc(void)
146
//############################################################################
146
//############################################################################
147
{
147
{
148
        acc_neutral.X = 0;
148
        acc_neutral.X = 0;
149
        acc_neutral.Y = 0;
149
        acc_neutral.Y = 0;
150
        acc_neutral.Z = 0;
150
        acc_neutral.Z = 0;
151
    CalibrierMittelwert();     
151
    CalibrierMittelwert();     
152
    Delay_ms_Mess(100);
152
    Delay_ms_Mess(100);
153
        CalibrierMittelwert();
153
        CalibrierMittelwert();
154
               
154
               
155
        acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
155
        acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
156
        acc_neutral.Y = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
156
        acc_neutral.Y = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
157
        acc_neutral.Z = Aktuell_az;
157
        acc_neutral.Z = Aktuell_az;
158
       
158
       
159
        eeprom_write_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
159
        eeprom_write_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
160
}
160
}
161
 
161
 
162
//############################################################################
162
//############################################################################
163
//  Nullwerte ermitteln
163
//  Nullwerte ermitteln
164
void SetNeutral(void)
164
void SetNeutral(void)
165
//############################################################################
165
//############################################################################
166
{
166
{
167
        acc_neutral.X = 0;
167
        acc_neutral.X = 0;
168
        acc_neutral.Y = 0;
168
        acc_neutral.Y = 0;
169
        acc_neutral.Z = 0;
169
        acc_neutral.Z = 0;
170
    AdNeutralNick = 0; 
170
    AdNeutralNick = 0; 
171
        AdNeutralRoll = 0;     
171
        AdNeutralRoll = 0;     
172
        AdNeutralGier = 0;
172
        AdNeutralGier = 0;
173
    Parameter_AchsKopplung1 = 0;
173
    Parameter_AchsKopplung1 = 0;
174
    Parameter_AchsGegenKopplung1 = 0;
174
    Parameter_AchsGegenKopplung1 = 0;
175
    CalibrierMittelwert();     
175
    CalibrierMittelwert();     
176
    Delay_ms_Mess(100);
176
    Delay_ms_Mess(100);
177
        CalibrierMittelwert();
177
        CalibrierMittelwert();
178
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
178
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
179
     {    
179
     {    
180
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
180
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
181
     }
181
     }
182
 
182
 
183
     AdNeutralNick= AdWertNick;
183
     AdNeutralNick= AdWertNick;
184
         AdNeutralRoll= AdWertRoll;    
184
         AdNeutralRoll= AdWertRoll;    
185
         AdNeutralGier= AdWertGier;
185
         AdNeutralGier= AdWertGier;
186
     StartNeutralRoll = AdNeutralRoll;
186
     StartNeutralRoll = AdNeutralRoll;
187
     StartNeutralNick = AdNeutralNick;
187
     StartNeutralNick = AdNeutralNick;
188
 
188
 
189
        eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
189
        eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct));
190
   
190
   
191
        Mess_IntegralNick = 0; 
191
        Mess_IntegralNick = 0; 
192
    Mess_IntegralNick2 = 0;
192
    Mess_IntegralNick2 = 0;
193
    Mess_IntegralRoll = 0;     
193
    Mess_IntegralRoll = 0;     
194
    Mess_IntegralRoll2 = 0;
194
    Mess_IntegralRoll2 = 0;
195
    Mess_Integral_Gier = 0;    
195
    Mess_Integral_Gier = 0;    
196
    MesswertNick = 0;
196
    MesswertNick = 0;
197
    MesswertRoll = 0;
197
    MesswertRoll = 0;
198
    MesswertGier = 0;
198
    MesswertGier = 0;
199
    StartLuftdruck = Luftdruck;
199
    StartLuftdruck = Luftdruck;
200
    HoeheD = 0;
200
    HoeheD = 0;
201
    Mess_Integral_Hoch = 0;
201
    Mess_Integral_Hoch = 0;
202
    KompassStartwert = KompassValue;
202
    KompassStartwert = KompassValue;
203
    beeptime = 50;  
203
    beeptime = 50;  
204
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
204
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
205
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
205
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
206
    ExternHoehenValue = 0;
206
    ExternHoehenValue = 0;
207
}
207
}
208
 
208
 
209
//############################################################################
209
//############################################################################
210
// Bearbeitet die Messwerte
210
// Bearbeitet die Messwerte
211
void Mittelwert(void)
211
void Mittelwert(void)
212
//############################################################################
212
//############################################################################
213
{      
213
{      
214
    static signed long tmpl,tmpl2;     
214
    static signed long tmpl,tmpl2;     
215
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
215
    MesswertGier = (signed int) AdNeutralGier - AdWertGier;
216
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
216
    MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll;
217
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
217
    MesswertNick = (signed int) AdWertNick - AdNeutralNick;
218
 
218
 
219
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
219
// Beschleunigungssensor  ++++++++++++++++++++++++++++++++++++++++++++++++
220
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
220
        Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L;
221
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
221
        Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L;
222
        Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L;
-
 
223
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
222
    IntegralAccNick += ACC_AMPLIFY * AdWertAccNick;
224
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
223
    IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll;
225
    IntegralAccZ    += Aktuell_az - acc_neutral.Z;
-
 
226
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
224
// Gier  ++++++++++++++++++++++++++++++++++++++++++++++++
227
            Mess_Integral_Gier +=  MesswertGier;
225
            Mess_Integral_Gier +=  MesswertGier;
228
            Mess_Integral_Gier2 += MesswertGier;
226
            Mess_Integral_Gier2 += MesswertGier;
229
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
227
// Kopplungsanteil  +++++++++++++++++++++++++++++++++++++
230
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
228
      if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV))
231
         {
229
         {
232
            tmpl = Mess_IntegralNick / 4096L;
230
            tmpl = Mess_IntegralNick / 4096L;
233
            tmpl *= MesswertGier;
231
            tmpl *= MesswertGier;
234
            tmpl *= Parameter_AchsKopplung1;  //125
232
            tmpl *= Parameter_AchsKopplung1;  //125
235
            tmpl /= 2048L;
233
            tmpl /= 2048L;
236
            tmpl2 = Mess_IntegralRoll / 4096L;
234
            tmpl2 = Mess_IntegralRoll / 4096L;
237
            tmpl2 *= MesswertGier;
235
            tmpl2 *= MesswertGier;
238
            tmpl2 *= Parameter_AchsKopplung1;
236
            tmpl2 *= Parameter_AchsKopplung1;
239
            tmpl2 /= 2048L;
237
            tmpl2 /= 2048L;
240
         }
238
         }
241
      else  tmpl = tmpl2 = 0;
239
      else  tmpl = tmpl2 = 0;
242
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
240
// Roll  ++++++++++++++++++++++++++++++++++++++++++++++++
243
            MesswertRoll += tmpl;
241
            MesswertRoll += tmpl;
244
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
242
            MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109
245
            Mess_IntegralRoll2 += MesswertRoll;
243
            Mess_IntegralRoll2 += MesswertRoll;
246
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
244
            Mess_IntegralRoll +=  MesswertRoll - LageKorrekturRoll;
247
            if(Mess_IntegralRoll > Umschlag180Roll)
245
            if(Mess_IntegralRoll > Umschlag180Roll)
248
            {
246
            {
249
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
247
             Mess_IntegralRoll  = -(Umschlag180Roll - 10000L);
250
             Mess_IntegralRoll2 = Mess_IntegralRoll;
248
             Mess_IntegralRoll2 = Mess_IntegralRoll;
251
            }
249
            }
252
            if(Mess_IntegralRoll <-Umschlag180Roll)
250
            if(Mess_IntegralRoll <-Umschlag180Roll)
253
            {
251
            {
254
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
252
             Mess_IntegralRoll =  (Umschlag180Roll - 10000L);
255
             Mess_IntegralRoll2 = Mess_IntegralRoll;
253
             Mess_IntegralRoll2 = Mess_IntegralRoll;
256
            }  
254
            }  
257
            if(AdWertRoll < 15)   MesswertRoll = -1000;
255
            if(AdWertRoll < 15)   MesswertRoll = -1000;
258
            if(AdWertRoll <  7)   MesswertRoll = -2000;
256
            if(AdWertRoll <  7)   MesswertRoll = -2000;
259
            if(PlatinenVersion == 10)
257
            if(PlatinenVersion == 10)
260
                         {
258
                         {
261
              if(AdWertRoll > 1010) MesswertRoll = +1000;
259
              if(AdWertRoll > 1010) MesswertRoll = +1000;
262
              if(AdWertRoll > 1017) MesswertRoll = +2000;
260
              if(AdWertRoll > 1017) MesswertRoll = +2000;
263
                         }
261
                         }
264
                         else
262
                         else
265
                         {
263
                         {
266
              if(AdWertRoll > 2020) MesswertRoll = +1000;
264
              if(AdWertRoll > 2020) MesswertRoll = +1000;
267
              if(AdWertRoll > 2034) MesswertRoll = +2000;
265
              if(AdWertRoll > 2034) MesswertRoll = +2000;
268
                         }
266
                         }
269
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
267
// Nick  ++++++++++++++++++++++++++++++++++++++++++++++++
270
            MesswertNick -= tmpl2;
268
            MesswertNick -= tmpl2;
271
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
269
            MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L;
272
            Mess_IntegralNick2 += MesswertNick;
270
            Mess_IntegralNick2 += MesswertNick;
273
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
271
            Mess_IntegralNick  += MesswertNick - LageKorrekturNick;
274
            if(Mess_IntegralNick > Umschlag180Nick)
272
            if(Mess_IntegralNick > Umschlag180Nick)
275
            {
273
            {
276
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
274
             Mess_IntegralNick = -(Umschlag180Nick - 10000L);
277
             Mess_IntegralNick2 = Mess_IntegralNick;
275
             Mess_IntegralNick2 = Mess_IntegralNick;
278
            }
276
            }
279
            if(Mess_IntegralNick <-Umschlag180Nick)
277
            if(Mess_IntegralNick <-Umschlag180Nick)
280
            {
278
            {
281
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
279
             Mess_IntegralNick =  (Umschlag180Nick - 10000L);
282
             Mess_IntegralNick2 = Mess_IntegralNick;
280
             Mess_IntegralNick2 = Mess_IntegralNick;
283
            }
281
            }
284
            if(AdWertNick < 15)   MesswertNick = -1000;
282
            if(AdWertNick < 15)   MesswertNick = -1000;
285
            if(AdWertNick <  7)   MesswertNick = -2000;
283
            if(AdWertNick <  7)   MesswertNick = -2000;
286
            if(PlatinenVersion == 10)
284
            if(PlatinenVersion == 10)
287
                         {
285
                         {
288
              if(AdWertNick > 1010) MesswertNick = +1000;
286
              if(AdWertNick > 1010) MesswertNick = +1000;
289
              if(AdWertNick > 1017) MesswertNick = +2000;
287
              if(AdWertNick > 1017) MesswertNick = +2000;
290
                         }
288
                         }
291
                         else
289
                         else
292
                         {
290
                         {
293
              if(AdWertNick > 2020) MesswertNick = +1000;
291
              if(AdWertNick > 2020) MesswertNick = +1000;
294
              if(AdWertNick > 2034) MesswertNick = +2000;
292
              if(AdWertNick > 2034) MesswertNick = +2000;
295
                         }
293
                         }
296
//++++++++++++++++++++++++++++++++++++++++++++++++
294
//++++++++++++++++++++++++++++++++++++++++++++++++
297
// ADC einschalten
295
// ADC einschalten
298
    ANALOG_ON; 
296
    ANALOG_ON; 
299
//++++++++++++++++++++++++++++++++++++++++++++++++
297
//++++++++++++++++++++++++++++++++++++++++++++++++
300
 
298
 
301
    Integral_Gier  = Mess_Integral_Gier;
299
    Integral_Gier  = Mess_Integral_Gier;
302
    IntegralNick = Mess_IntegralNick;
300
    IntegralNick = Mess_IntegralNick;
303
    IntegralRoll = Mess_IntegralRoll;
301
    IntegralRoll = Mess_IntegralRoll;
304
    IntegralNick2 = Mess_IntegralNick2;
302
    IntegralNick2 = Mess_IntegralNick2;
305
    IntegralRoll2 = Mess_IntegralRoll2;
303
    IntegralRoll2 = Mess_IntegralRoll2;
306
 
304
 
307
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
305
  if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll)
308
  {
306
  {
309
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
307
    if(MesswertNick > 200)       MesswertNick += 4 * (MesswertNick - 200);
310
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
308
    else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
311
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
309
    if(MesswertRoll > 200)       MesswertRoll += 4 * (MesswertRoll - 200);
312
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
310
    else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
313
  }
311
  }
314
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
312
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
315
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
313
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
316
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
314
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
317
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
315
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
318
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
316
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
319
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
317
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
320
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
318
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
321
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
319
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
322
}
320
}
323
 
321
 
324
//############################################################################
322
//############################################################################
325
// Messwerte beim Ermitteln der Nullage
323
// Messwerte beim Ermitteln der Nullage
326
void CalibrierMittelwert(void)
324
void CalibrierMittelwert(void)
327
//############################################################################
325
//############################################################################
328
{                
326
{                
329
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
327
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
330
        ANALOG_OFF;
328
        ANALOG_OFF;
331
        MesswertNick = AdWertNick;
329
        MesswertNick = AdWertNick;
332
        MesswertRoll = AdWertRoll;
330
        MesswertRoll = AdWertRoll;
333
        MesswertGier = AdWertGier;
331
        MesswertGier = AdWertGier;
334
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
332
        Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick;
335
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
333
        Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll;
336
        Mittelwert_AccHoch = (long)AdWertAccHoch;
-
 
337
   // ADC einschalten
334
   // ADC einschalten
338
    ANALOG_ON; 
335
    ANALOG_ON; 
339
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
336
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
340
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
337
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
341
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
338
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
342
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
339
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
343
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
340
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
344
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
341
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
345
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
342
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
346
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
343
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
347
 
344
 
348
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
345
        Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
349
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
346
        Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
350
}
347
}
351
 
348
 
352
//############################################################################
349
//############################################################################
353
// Senden der Motorwerte per I2C-Bus
350
// Senden der Motorwerte per I2C-Bus
354
void SendMotorData(void)
351
void SendMotorData(void)
355
//############################################################################
352
//############################################################################
356
{
353
{
357
    if(MOTOR_OFF || !MotorenEin)
354
    if(MOTOR_OFF || !MotorenEin)
358
        {
355
        {
359
        Motor_Hinten = 0;
356
        Motor_Hinten = 0;
360
        Motor_Vorne = 0;
357
        Motor_Vorne = 0;
361
        Motor_Rechts = 0;
358
        Motor_Rechts = 0;
362
        Motor_Links = 0;
359
        Motor_Links = 0;
363
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
360
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
364
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
361
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
365
        if(MotorTest[2]) Motor_Links = MotorTest[2];
362
        if(MotorTest[2]) Motor_Links = MotorTest[2];
366
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
363
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
367
        }
364
        }
368
 
365
 
369
    //Start I2C Interrupt Mode
366
    //Start I2C Interrupt Mode
370
    twi_state = 0;
367
    twi_state = 0;
371
    motor = 0;
368
    motor = 0;
372
    i2c_start();
369
    i2c_start();
373
}
370
}
374
 
371
 
375
 
372
 
376
 
373
 
377
//############################################################################
374
//############################################################################
378
// Trägt ggf. das Poti als Parameter ein
375
// Trägt ggf. das Poti als Parameter ein
379
void ParameterZuordnung(void)
376
void ParameterZuordnung(void)
380
//############################################################################
377
//############################################################################
381
{
378
{
382
 
379
 
383
 #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;}
380
 #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;}
384
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
381
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
385
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
382
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
386
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
383
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
387
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
384
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
388
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
385
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
389
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
386
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
390
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
387
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
391
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
388
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
392
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
389
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
393
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
390
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
394
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
391
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
395
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
392
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
396
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
393
 CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255);
397
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
394
 CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255);
398
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
395
 CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255);
399
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
396
 CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255);
400
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
397
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
401
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
398
 CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255);
402
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
399
 CHK_POTI(Parameter_AchsKopplung1,    EE_Parameter.AchsKopplung1,0,255);
403
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
400
 CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255);
404
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
401
 CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255);
405
 
402
 
406
 Ki = (float)Parameter_I_Faktor * 0.0001;
403
 Ki = (float)Parameter_I_Faktor * 0.0001;
407
 MAX_GAS = EE_Parameter.Gas_Max;
404
 MAX_GAS = EE_Parameter.Gas_Max;
408
 MIN_GAS = EE_Parameter.Gas_Min;
405
 MIN_GAS = EE_Parameter.Gas_Min;
409
}
406
}
410
 
407
 
411
 
408
 
412
//############################################################################
409
//############################################################################
413
//
410
//
414
void MotorRegler(void)
411
void MotorRegler(void)
415
//############################################################################
412
//############################################################################
416
{
413
{
417
         int motorwert,pd_ergebnis,h,tmp_int;
414
         int motorwert,pd_ergebnis,h,tmp_int;
418
         int GierMischanteil,GasMischanteil;
415
         int GierMischanteil,GasMischanteil;
419
     static long SummeNick=0,SummeRoll=0;
416
     static long SummeNick=0,SummeRoll=0;
420
     static long sollGier = 0,tmp_long,tmp_long2;
417
     static long sollGier = 0,tmp_long,tmp_long2;
421
     static long IntegralFehlerNick = 0;
418
     static long IntegralFehlerNick = 0;
422
     static long IntegralFehlerRoll = 0;
419
     static long IntegralFehlerRoll = 0;
423
         static unsigned int RcLostTimer;
420
         static unsigned int RcLostTimer;
424
         static unsigned char delay_neutral = 0;
421
         static unsigned char delay_neutral = 0;
425
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
422
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
426
         static unsigned int  modell_fliegt = 0;
423
         static unsigned int  modell_fliegt = 0;
427
     static int hoehenregler = 0;
424
     static int hoehenregler = 0;
428
     static char TimerWerteausgabe = 0;
425
     static char TimerWerteausgabe = 0;
429
     static char NeueKompassRichtungMerken;
426
     static char NeueKompassRichtungMerken;
430
     static long ausgleichNick, ausgleichRoll;
427
     static long ausgleichNick, ausgleichRoll;
431
     
428
     
432
        Mittelwert();
429
        Mittelwert();
433
 
430
 
434
    //GRN_ON;
431
    //GRN_ON;
435
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
432
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
436
// Gaswert ermitteln
433
// Gaswert ermitteln
437
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
434
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
438
        GasMischanteil = StickGas;
435
        GasMischanteil = StickGas;
439
    if(GasMischanteil < 0) GasMischanteil = 0;
436
    if(GasMischanteil < 0) GasMischanteil = 0;
440
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
437
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
441
// Emfang schlecht
438
// Emfang schlecht
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
439
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
443
   if(SenderOkay < 100)
440
   if(SenderOkay < 100)
444
        {
441
        {
445
        if(!PcZugriff)
442
        if(!PcZugriff)
446
         {
443
         {
447
           if(BeepMuster == 0xffff)
444
           if(BeepMuster == 0xffff)
448
            {
445
            {
449
             beeptime = 15000;
446
             beeptime = 15000;
450
             BeepMuster = 0x0c00;
447
             BeepMuster = 0x0c00;
451
            }
448
            }
452
         }
449
         }
453
        if(RcLostTimer) RcLostTimer--;
450
        if(RcLostTimer) RcLostTimer--;
454
        else
451
        else
455
         {
452
         {
456
          MotorenEin = 0;
453
          MotorenEin = 0;
457
          Notlandung = 0;
454
          Notlandung = 0;
458
         }
455
         }
459
        ROT_ON;
456
        ROT_ON;
460
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
457
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
461
            {
458
                {
462
            GasMischanteil = EE_Parameter.NotGas;
459
                        GasMischanteil = EE_Parameter.NotGas;
463
            Notlandung = 1;
460
                        Notlandung = 1;
-
 
461
                        PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
-
 
462
                        PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
464
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
463
                        PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
465
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
464
                        PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
466
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
465
                        PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
467
            }
466
                }
468
         else MotorenEin = 0;
467
                else MotorenEin = 0;
469
        }
468
        }
470
        else
469
        else
471
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
470
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
472
// Emfang gut
471
// Emfang gut
473
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
472
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
474
        if(SenderOkay > 140)
473
        if(SenderOkay > 140)
475
            {
474
            {
476
            Notlandung = 0;
475
            Notlandung = 0;
477
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
476
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
478
            if(GasMischanteil > 40)
477
            if(GasMischanteil > 40)
479
                {
478
                {
480
                if(modell_fliegt < 0xffff) modell_fliegt++;
479
                if(modell_fliegt < 0xffff) modell_fliegt++;
481
                }
480
                }
482
            if((modell_fliegt < 200) || (GasMischanteil < 40))
481
            if((modell_fliegt < 200) || (GasMischanteil < 40))
483
                {
482
                {
484
                SummeNick = 0;
483
                SummeNick = 0;
485
                SummeRoll = 0;
484
                SummeRoll = 0;
486
                Mess_Integral_Gier = 0;
485
                Mess_Integral_Gier = 0;
487
                Mess_Integral_Gier2 = 0;
486
                Mess_Integral_Gier2 = 0;
488
                }
487
                }
489
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
488
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
490
                {
489
                {
491
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
490
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
492
// auf Nullwerte kalibrieren
491
// auf Nullwerte kalibrieren
493
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
492
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
494
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
493
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
495
                    {
494
                    {
496
                    if(++delay_neutral > 200)  // nicht sofort
495
                    if(++delay_neutral > 200)  // nicht sofort
497
                        {
496
                        {
498
                        //GRN_OFF;
497
                        //GRN_OFF;
499
                        MotorenEin = 0;
498
                        MotorenEin = 0;
500
                        delay_neutral = 0;
499
                        delay_neutral = 0;
501
                        modell_fliegt = 0;
500
                        modell_fliegt = 0;
502
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
501
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
503
                        {
502
                        {
504
                         unsigned char setting=1;
503
                         unsigned char setting=1;
505
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
504
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
506
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
505
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
507
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
506
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
508
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
507
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
509
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
508
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
510
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
509
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
511
                        }
510
                        }
512
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
-
 
513
                          {
-
 
514
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
-
 
515
                          }  
-
 
516
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], sizeof(struct mk_param_struct));
511
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], sizeof(struct mk_param_struct));
517
                        SetNeutral();
512
                        SetNeutral();
518
                        Piep(GetActiveParamSetNumber());
513
                        Piep(GetActiveParamSetNumber());
519
                        }
514
                        }
520
                    }
515
                    }
521
                 else delay_neutral = 0;
516
                 else delay_neutral = 0;
522
                }
517
                }
523
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
518
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
524
// Gas ist unten
519
// Gas ist unten
525
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
520
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
526
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
521
            if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120)
527
                {
522
                {
528
                // Starten
523
                // Starten
529
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
524
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
530
                    {
525
                    {
531
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
526
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
532
// Einschalten
527
// Einschalten
533
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
528
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
534
                    if(++delay_einschalten > 200)
529
                    if(++delay_einschalten > 200)
535
                        {
530
                        {
536
                        delay_einschalten = 200;
531
                        delay_einschalten = 200;
537
                        modell_fliegt = 1;
532
                        modell_fliegt = 1;
538
                        MotorenEin = 1;
533
                        MotorenEin = 1;
539
                        sollGier = 0;
534
                        sollGier = 0;
540
                        Mess_Integral_Gier = 0;
535
                        Mess_Integral_Gier = 0;
541
                        Mess_Integral_Gier2 = 0;
536
                        Mess_Integral_Gier2 = 0;
542
                        Mess_IntegralNick = 0;
537
                        Mess_IntegralNick = 0;
543
                        Mess_IntegralRoll = 0;
538
                        Mess_IntegralRoll = 0;
544
                        Mess_IntegralNick2 = IntegralNick;
539
                        Mess_IntegralNick2 = IntegralNick;
545
                        Mess_IntegralRoll2 = IntegralRoll;
540
                        Mess_IntegralRoll2 = IntegralRoll;
546
                        SummeNick = 0;
541
                        SummeNick = 0;
547
                        SummeRoll = 0;
542
                        SummeRoll = 0;
548
                        }          
543
                        }          
549
                    }  
544
                    }  
550
                    else delay_einschalten = 0;
545
                    else delay_einschalten = 0;
551
                //Auf Neutralwerte setzen
546
                //Auf Neutralwerte setzen
552
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
547
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
553
// Auschalten
548
// Auschalten
554
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
549
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
555
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
550
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
556
                    {
551
                    {
557
                    if(++delay_ausschalten > 200)  // nicht sofort
552
                    if(++delay_ausschalten > 200)  // nicht sofort
558
                        {
553
                        {
559
                        MotorenEin = 0;
554
                        MotorenEin = 0;
560
                        delay_ausschalten = 200;
555
                        delay_ausschalten = 200;
561
                        modell_fliegt = 0;
556
                        modell_fliegt = 0;
562
                        }
557
                        }
563
                    }
558
                    }
564
                else delay_ausschalten = 0;
559
                else delay_ausschalten = 0;
565
                }
560
                }
566
            }
561
            }
567
 
562
 
568
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
563
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
569
// neue Werte von der Funke
564
// neue Werte von der Funke
570
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
565
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
571
 if(!NewPpmData-- || Notlandung)  
566
 if(!NewPpmData-- || Notlandung)  
572
  {
567
  {
573
    int tmp_int;
568
    int tmp_int;
574
    ParameterZuordnung();
569
    ParameterZuordnung();
575
       
570
       
576
    StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
571
    StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
577
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
572
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
578
    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
573
    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
579
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
574
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
580
 
575
 
581
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
576
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
582
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
577
        StickGas  = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
583
 
578
 
584
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick)
579
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick)
585
     MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--;
580
     MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--;
586
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll)
581
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll)
587
     MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--;
582
     MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--;
588
   if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
583
   if(Notlandung)  {MaxStickNick = 0; MaxStickRoll = 0;}
589
 
584
 
590
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
585
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
591
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
586
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
592
 
587
 
593
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
588
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
594
//+ Digitale Steuerung per DubWise
589
//+ Digitale Steuerung per DubWise
595
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
590
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
596
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
591
#define KEY_VALUE (Parameter_UserParam1 * 4)  //(Poti3 * 8)
597
if(DubWiseKeys[1]) beeptime = 10;
592
if(DubWiseKeys[1]) beeptime = 10;
598
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
593
    if(DubWiseKeys[1] & DUB_KEY_UP)    tmp_int = KEY_VALUE;   else
599
    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;
600
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
595
    ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8;
601
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
596
    if(DubWiseKeys[1] & DUB_KEY_LEFT)  tmp_int = KEY_VALUE; else
602
    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;
603
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
598
    ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8;
604
 
599
 
605
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
600
    if(DubWiseKeys[0] & 8)  ExternStickGier = 50;else
606
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
601
    if(DubWiseKeys[0] & 4)  ExternStickGier =-50;else ExternStickGier = 0;
607
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
602
    if(DubWiseKeys[0] & 2)  ExternHoehenValue++;
608
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
603
    if(DubWiseKeys[0] & 16) ExternHoehenValue--;
609
 
604
 
610
    StickNick += ExternStickNick / 8;
605
    StickNick += ExternStickNick / 8;
611
    StickRoll += ExternStickRoll / 8;
606
    StickRoll += ExternStickRoll / 8;
612
    StickGier += ExternStickGier;
607
    StickGier += ExternStickGier;
613
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
608
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
614
//+ Analoge Steuerung per Seriell
609
//+ Analoge Steuerung per Seriell
615
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
610
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
616
   if(ExternControl.Config & 0x01 && Parameter_UserParam1 > 128)
611
   if(ExternControl.Config & 0x01 && Parameter_UserParam1 > 128)
617
    {
612
    {
618
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
613
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
619
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
614
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
620
         StickGier += ExternControl.Gier;
615
         StickGier += ExternControl.Gier;
621
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
616
     ExternHoehenValue =  (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung;
622
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
617
     if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas;
623
    }
618
    }
624
 
619
 
625
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
620
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
626
    if(GyroFaktor < 0) GyroFaktor = 0;
621
    if(GyroFaktor < 0) GyroFaktor = 0;
627
    if(IntegralFaktor < 0) IntegralFaktor = 0;
622
    if(IntegralFaktor < 0) IntegralFaktor = 0;
628
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
623
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
629
// Looping?
624
// Looping?
630
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
625
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
631
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
626
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS)  Looping_Links = 1;
632
  else
627
  else
633
   {
628
   {
634
     {
629
     {
635
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
630
      if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0;  
636
     }  
631
     }  
637
   }
632
   }
638
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
633
  if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1;
639
   else
634
   else
640
   {
635
   {
641
   if(Looping_Rechts) // Hysterese
636
   if(Looping_Rechts) // Hysterese
642
     {
637
     {
643
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
638
      if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0;
644
     }
639
     }
645
   }
640
   }
646
 
641
 
647
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
642
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) Looping_Oben = 1;
648
  else
643
  else
649
   {
644
   {
650
    if(Looping_Oben)  // Hysterese
645
    if(Looping_Oben)  // Hysterese
651
     {
646
     {
652
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
647
      if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0;  
653
     }  
648
     }  
654
   }
649
   }
655
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
650
  if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN) Looping_Unten = 1;
656
   else
651
   else
657
   {
652
   {
658
    if(Looping_Unten) // Hysterese
653
    if(Looping_Unten) // Hysterese
659
     {
654
     {
660
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
655
      if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0;
661
     }
656
     }
662
   }
657
   }
663
 
658
 
664
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
659
   if(Looping_Links || Looping_Rechts)   Looping_Roll = 1; else Looping_Roll = 0;
665
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
660
   if(Looping_Oben  || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0;
666
  } // Ende neue Funken-Werte
661
  } // Ende neue Funken-Werte
667
 
662
 
668
  if(Looping_Roll) beeptime = 100;
663
  if(Looping_Roll) beeptime = 100;
669
  if(Looping_Roll || Looping_Nick)
664
  if(Looping_Roll || Looping_Nick)
670
   {
665
   {
671
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
666
    if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit;
672
   }
667
   }
673
   
668
   
674
 
669
 
675
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
670
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
676
// Bei Empfangsausfall im Flug 
671
// Bei Empfangsausfall im Flug 
677
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
672
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
678
   if(Notlandung)
673
   if(Notlandung)
679
    {
674
    {
680
     StickGier = 0;
675
     StickGier = 0;
681
     StickNick = 0;
676
     StickNick = 0;
682
     StickRoll = 0;
677
     StickRoll = 0;
683
     GyroFaktor  = 0.1;
678
     GyroFaktor  = 0.1;
684
     IntegralFaktor = 0.005;
679
     IntegralFaktor = 0.005;
685
     Looping_Roll = 0;
680
     Looping_Roll = 0;
686
     Looping_Nick = 0;
681
     Looping_Nick = 0;
687
    }  
682
    }  
688
 
683
 
689
 
684
 
690
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
685
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
691
// Integrale auf ACC-Signal abgleichen
686
// Integrale auf ACC-Signal abgleichen
692
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
687
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
693
#define ABGLEICH_ANZAHL 256L
688
#define ABGLEICH_ANZAHL 256L
694
 
689
 
695
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
690
 MittelIntegralNick  += IntegralNick;    // Für die Mittelwertbildung aufsummieren
696
 MittelIntegralRoll  += IntegralRoll;
691
 MittelIntegralRoll  += IntegralRoll;
697
 MittelIntegralNick2 += IntegralNick2;
692
 MittelIntegralNick2 += IntegralNick2;
698
 MittelIntegralRoll2 += IntegralRoll2;
693
 MittelIntegralRoll2 += IntegralRoll2;
699
 
694
 
700
 if(Looping_Nick || Looping_Roll)
695
 if(Looping_Nick || Looping_Roll)
701
  {
696
  {
702
    IntegralAccNick = 0;
697
    IntegralAccNick = 0;
703
    IntegralAccRoll = 0;
698
    IntegralAccRoll = 0;
704
    MittelIntegralNick = 0;
699
    MittelIntegralNick = 0;
705
    MittelIntegralRoll = 0;
700
    MittelIntegralRoll = 0;
706
    MittelIntegralNick2 = 0;
701
    MittelIntegralNick2 = 0;
707
    MittelIntegralRoll2 = 0;
702
    MittelIntegralRoll2 = 0;
708
    Mess_IntegralNick2 = Mess_IntegralNick;
703
    Mess_IntegralNick2 = Mess_IntegralNick;
709
    Mess_IntegralRoll2 = Mess_IntegralRoll;
704
    Mess_IntegralRoll2 = Mess_IntegralRoll;
710
    ZaehlMessungen = 0;
705
    ZaehlMessungen = 0;
711
    LageKorrekturNick = 0;
706
    LageKorrekturNick = 0;
712
    LageKorrekturRoll = 0;
707
    LageKorrekturRoll = 0;
713
  }
708
  }
714
 
709
 
715
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
710
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
716
  if(!Looping_Nick && !Looping_Roll)
711
  if(!Looping_Nick && !Looping_Roll)
717
  {
712
  {
718
   long tmp_long, tmp_long2;
713
   long tmp_long, tmp_long2;
719
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
714
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick);
720
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
715
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll);
721
    tmp_long /= 16;
716
    tmp_long /= 16;
722
    tmp_long2 /= 16;
717
    tmp_long2 /= 16;
723
   if((MaxStickNick > 15) || (MaxStickRoll > 15))
718
   if((MaxStickNick > 15) || (MaxStickRoll > 15))
724
    {
719
    {
725
    tmp_long  /= 3;
720
    tmp_long  /= 3;
726
    tmp_long2 /= 3;
721
    tmp_long2 /= 3;
727
    }
722
    }
728
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
723
   if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
729
    {
724
    {
730
    tmp_long  /= 3;
725
    tmp_long  /= 3;
731
    tmp_long2 /= 3;
726
    tmp_long2 /= 3;
732
    }
727
    }
733
 
728
 
734
 #define AUSGLEICH 32
729
 #define AUSGLEICH 32
735
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
730
    if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
736
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
731
    if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
737
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
732
    if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
738
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
733
    if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
739
 
734
 
740
    Mess_IntegralNick -= tmp_long;
735
    Mess_IntegralNick -= tmp_long;
741
    Mess_IntegralRoll -= tmp_long2;
736
    Mess_IntegralRoll -= tmp_long2;
742
  }
737
  }
743
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
738
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
744
 
739
 
745
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
740
 if(ZaehlMessungen >= ABGLEICH_ANZAHL)
746
 {
741
 {
747
  static int cnt = 0;
742
  static int cnt = 0;
748
  static char last_n_p,last_n_n,last_r_p,last_r_n;
743
  static char last_n_p,last_n_n,last_r_p,last_r_n;
749
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
744
  static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt;
750
  if(!Looping_Nick && !Looping_Roll)
745
  if(!Looping_Nick && !Looping_Roll)
751
  {
746
  {
752
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
747
    MittelIntegralNick  /= ABGLEICH_ANZAHL;
753
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
748
    MittelIntegralRoll  /= ABGLEICH_ANZAHL;
754
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
749
        IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL;
755
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
750
        IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL;
756
    IntegralAccZ    = IntegralAccZ / ABGLEICH_ANZAHL;
-
 
757
#define MAX_I 0//(Poti2/10)
751
#define MAX_I 0//(Poti2/10)
758
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
752
// Nick ++++++++++++++++++++++++++++++++++++++++++++++++
759
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
753
    IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick);
760
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
754
    ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich;
761
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
755
// Roll ++++++++++++++++++++++++++++++++++++++++++++++++     
762
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
756
    IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll);
763
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
757
    ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich;
764
 
758
 
765
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
759
    LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL;
766
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
760
    LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL;
767
 
761
 
768
   if((MaxStickNick > 15) || (MaxStickRoll > 15) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25))
762
   if((MaxStickNick > 15) || (MaxStickRoll > 15) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25))
769
    {
763
    {
770
     LageKorrekturNick /= 2;
764
     LageKorrekturNick /= 2;
771
     LageKorrekturNick /= 2;
765
     LageKorrekturRoll /= 2;
772
    }
766
    }
773
 
767
 
774
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
768
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
775
// Gyro-Drift ermitteln
769
// Gyro-Drift ermitteln
776
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
770
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
777
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
771
    MittelIntegralNick2 /= ABGLEICH_ANZAHL;
778
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
772
    MittelIntegralRoll2 /= ABGLEICH_ANZAHL;
779
    tmp_long  = IntegralNick2 - IntegralNick;
773
    tmp_long  = IntegralNick2 - IntegralNick;
780
    tmp_long2 = IntegralRoll2 - IntegralRoll;
774
    tmp_long2 = IntegralRoll2 - IntegralRoll;
781
 
775
 
782
    IntegralFehlerNick = tmp_long;
776
    IntegralFehlerNick = tmp_long;
783
    IntegralFehlerRoll = tmp_long2;
777
    IntegralFehlerRoll = tmp_long2;
784
    Mess_IntegralNick2 -= IntegralFehlerNick;
778
    Mess_IntegralNick2 -= IntegralFehlerNick;
785
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
779
    Mess_IntegralRoll2 -= IntegralFehlerRoll;
786
 
780
 
787
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
781
//    IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2;
788
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
782
//    IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2;
789
 
783
 
790
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
784
#define FEHLER_LIMIT  (ABGLEICH_ANZAHL * 4)
791
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
785
#define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16)
792
#define BEWEGUNGS_LIMIT 20000
786
#define BEWEGUNGS_LIMIT 20000
793
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
787
// Nick +++++++++++++++++++++++++++++++++++++++++++++++++
794
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
788
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
795
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
789
        if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT)
796
        {
790
        {
797
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
791
        if(IntegralFehlerNick >  FEHLER_LIMIT2)
798
         {
792
         {
799
           if(last_n_p)
793
           if(last_n_p)
800
           {
794
           {
801
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
795
            cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
802
            ausgleichNick = IntegralFehlerNick / 8;
796
            ausgleichNick = IntegralFehlerNick / 8;
803
            if(ausgleichNick > 5000) ausgleichNick = 5000;
797
            if(ausgleichNick > 5000) ausgleichNick = 5000;
804
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
798
            LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
805
           }
799
           }
806
           else last_n_p = 1;
800
           else last_n_p = 1;
807
         } else  last_n_p = 0;
801
         } else  last_n_p = 0;
808
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
802
        if(IntegralFehlerNick < -FEHLER_LIMIT2)
809
         {
803
         {
810
           if(last_n_n)
804
           if(last_n_n)
811
            {
805
            {
812
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
806
             cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2;
813
             ausgleichNick = IntegralFehlerNick / 8;
807
             ausgleichNick = IntegralFehlerNick / 8;
814
             if(ausgleichNick < -5000) ausgleichNick = -5000;
808
             if(ausgleichNick < -5000) ausgleichNick = -5000;
815
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
809
             LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL;
816
            }
810
            }
817
           else last_n_n = 1;
811
           else last_n_n = 1;
818
         } else  last_n_n = 0;
812
         } else  last_n_n = 0;
819
        } else cnt = 0;
813
        } else cnt = 0;
820
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
814
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
821
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
815
        if(IntegralFehlerNick >  FEHLER_LIMIT)   AdNeutralNick += cnt;
822
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
816
        if(IntegralFehlerNick < -FEHLER_LIMIT)   AdNeutralNick -= cnt;
823
 
817
 
824
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
818
// Roll +++++++++++++++++++++++++++++++++++++++++++++++++
825
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
819
        cnt = 1;// + labs(IntegralFehlerNick) / 4096;
826
 
820
 
827
        ausgleichRoll = 0;
821
        ausgleichRoll = 0;
828
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
822
        if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT)
829
        {
823
        {
830
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
824
        if(IntegralFehlerRoll >  FEHLER_LIMIT2)
831
         {
825
         {
832
           if(last_r_p)
826
           if(last_r_p)
833
           {
827
           {
834
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
828
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
835
            ausgleichRoll = IntegralFehlerRoll / 8;
829
            ausgleichRoll = IntegralFehlerRoll / 8;
836
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
830
            if(ausgleichRoll > 5000) ausgleichRoll = 5000;
837
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
831
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
838
           }
832
           }
839
           else last_r_p = 1;
833
           else last_r_p = 1;
840
         } else  last_r_p = 0;
834
         } else  last_r_p = 0;
841
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
835
        if(IntegralFehlerRoll < -FEHLER_LIMIT2)
842
         {
836
         {
843
           if(last_r_n)
837
           if(last_r_n)
844
           {
838
           {
845
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
839
            cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2;
846
            ausgleichRoll = IntegralFehlerRoll / 8;
840
            ausgleichRoll = IntegralFehlerRoll / 8;
847
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
841
            if(ausgleichRoll < -5000) ausgleichRoll = -5000;
848
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
842
            LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL;
849
           }
843
           }
850
           else last_r_n = 1;
844
           else last_r_n = 1;
851
         } else  last_r_n = 0;
845
         } else  last_r_n = 0;
852
        } else
846
        } else
853
        {
847
        {
854
         cnt = 0;
848
         cnt = 0;
855
        }
849
        }
856
 
850
 
857
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
851
        if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp;
858
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
852
        if(IntegralFehlerRoll >  FEHLER_LIMIT)   AdNeutralRoll += cnt;
859
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
853
        if(IntegralFehlerRoll < -FEHLER_LIMIT)   AdNeutralRoll -= cnt;
860
  }
854
  }
861
  else
855
  else
862
  {
856
  {
863
   LageKorrekturRoll = 0;
857
   LageKorrekturRoll = 0;
864
   LageKorrekturNick = 0;
858
   LageKorrekturNick = 0;
865
  }
859
  }
866
 
860
 
867
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
861
  if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH
868
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
862
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
869
   MittelIntegralNick_Alt = MittelIntegralNick;      
863
   MittelIntegralNick_Alt = MittelIntegralNick;      
870
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
864
   MittelIntegralRoll_Alt = MittelIntegralRoll;      
871
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
865
// +++++++++++++++++++++++++++++++++++++++++++++++++++++     
872
    IntegralAccNick = 0;
866
    IntegralAccNick = 0;
873
    IntegralAccRoll = 0;
867
    IntegralAccRoll = 0;
874
    IntegralAccZ = 0;
-
 
875
    MittelIntegralNick = 0;
868
    MittelIntegralNick = 0;
876
    MittelIntegralRoll = 0;
869
    MittelIntegralRoll = 0;
877
    MittelIntegralNick2 = 0;
870
    MittelIntegralNick2 = 0;
878
    MittelIntegralRoll2 = 0;
871
    MittelIntegralRoll2 = 0;
879
    ZaehlMessungen = 0;
872
    ZaehlMessungen = 0;
880
 }
873
 }
881
 
874
 
882
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
875
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
883
//  Gieren
876
//  Gieren
884
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
877
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
885
    if(abs(StickGier) > 15) // war 35 
878
    if(abs(StickGier) > 15) // war 35 
886
     {
879
     {
887
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
880
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
888
     }
881
     }
889
    tmp_int  = (long)EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
882
    tmp_int  = (long)EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
890
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
883
    tmp_int += (EE_Parameter.Gier_P * StickGier) / 4;
891
    sollGier = tmp_int;
884
    sollGier = tmp_int;
892
    Mess_Integral_Gier -= tmp_int;  
885
    Mess_Integral_Gier -= tmp_int;  
893
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
886
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
894
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
887
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
895
 
888
 
896
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
889
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
897
//  Kompass
890
//  Kompass
898
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
891
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
899
        if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
892
        if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)
900
        {
893
        {
901
                if (!updKompass--)              // Aufruf mit ~10 Hz
894
                if (!updKompass--)              // Aufruf mit ~10 Hz
902
                {
895
                {
903
                        updKompass = 50;
896
                        updKompass = 50;
904
                       
897
                       
905
                        if ((MaxStickNick < 50) && (MaxStickRoll < 50))         // Bei extremen Flugmanövern keine Kompassauswertung
898
                        if ((MaxStickNick < 50) && (MaxStickRoll < 50))         // Bei extremen Flugmanövern keine Kompassauswertung
906
                        {
899
                        {
907
                                KompassValue = heading_MM3();
900
                                KompassValue = heading_MM3();
908
                                KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
901
                                KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
909
                                if(NeueKompassRichtungMerken)    
902
                                if(NeueKompassRichtungMerken)    
910
                                {
903
                                {
911
                                        KompassStartwert = KompassValue;
904
                                        KompassStartwert = KompassValue;
912
                                        NeueKompassRichtungMerken = 0;
905
                                        NeueKompassRichtungMerken = 0;
913
                                }
906
                                }
914
                                Mess_Integral_Gier += (KompassRichtung * Parameter_KompassWirkung);     // nach Kompass ausrichten
907
                                Mess_Integral_Gier += (KompassRichtung * Parameter_KompassWirkung);     // nach Kompass ausrichten
915
                        }
908
                        }
916
                }          
909
                }          
917
        }
910
        }
918
 
911
 
919
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
912
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
920
//  GPS
913
//  GPS
921
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
914
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
922
                if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)
915
                if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)
923
                {
916
                {
924
                        GPS_P_Factor = Parameter_UserParam5;
917
                        GPS_P_Factor = Parameter_UserParam5;
925
                        GPS_D_Factor = Parameter_UserParam6;
918
                        GPS_D_Factor = Parameter_UserParam6;
926
                        GPS_Main(); // updates GPS_Pitch and GPS_Roll on new GPS data
919
                        GPS_Main(); // updates GPS_Pitch and GPS_Roll on new GPS data
927
                }
920
                }
928
                else
921
                else
929
                {
922
                {
930
                        GPS_Nick = 0;
923
                        GPS_Nick = 0;
931
                        GPS_Roll = 0;
924
                        GPS_Roll = 0;
932
                }
925
                }
933
 
926
 
934
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
927
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
935
//  Debugwerte zuordnen
928
//  Debugwerte zuordnen
936
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
929
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
937
        if(!TimerWerteausgabe--)
930
        if(!TimerWerteausgabe--)
938
        {
931
        {
939
        TimerWerteausgabe = 24;
932
        TimerWerteausgabe = 24;
940
       
933
       
941
        DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
934
        DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
942
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
935
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
943
    DebugOut.Analog[2] = Mittelwert_AccNick;
936
    DebugOut.Analog[2] = Mittelwert_AccNick;
944
    DebugOut.Analog[3] = Mittelwert_AccRoll;
937
    DebugOut.Analog[3] = Mittelwert_AccRoll;
945
    DebugOut.Analog[4] = MesswertGier;
938
    DebugOut.Analog[4] = MesswertGier;
946
    DebugOut.Analog[5] = HoehenWert;
939
    DebugOut.Analog[5] = HoehenWert;
947
    DebugOut.Analog[6] = Mess_Integral_Hoch / 512;
940
    DebugOut.Analog[6] = Mess_Integral_Hoch / 512;
948
        DebugOut.Analog[7] = GasMischanteil;
941
        DebugOut.Analog[7] = GasMischanteil;
949
    DebugOut.Analog[8] = KompassValue;
942
    DebugOut.Analog[8] = KompassValue;
950
    DebugOut.Analog[9] = UBat;
943
    DebugOut.Analog[9] = UBat;
951
    DebugOut.Analog[10] = SenderOkay;
944
    DebugOut.Analog[10] = SenderOkay;
952
       
945
       
953
        DebugOut.Analog[12] = Motor_Vorne;
946
        DebugOut.Analog[12] = Motor_Vorne;
954
    DebugOut.Analog[13] = Motor_Hinten;
947
    DebugOut.Analog[13] = Motor_Hinten;
955
    DebugOut.Analog[14] = Motor_Links;
948
    DebugOut.Analog[14] = Motor_Links;
956
    DebugOut.Analog[15] = Motor_Rechts;
949
    DebugOut.Analog[15] = Motor_Rechts;
957
    DebugOut.Analog[16] = Mittelwert_AccHoch;
950
    DebugOut.Analog[16] = AdWertAccHoch;
958
 
951
 
959
        DebugOut.Analog[17] = GPSInfo.satfix;
952
        DebugOut.Analog[17] = GPSInfo.satfix;
960
        DebugOut.Analog[18] = GPSInfo.utmnorth;
953
        DebugOut.Analog[18] = GPSInfo.utmnorth;
961
        DebugOut.Analog[19] = GPSInfo.utmeast;
954
        DebugOut.Analog[19] = GPSInfo.utmeast;
962
        DebugOut.Analog[20] = GPSInfo.velground;
955
        DebugOut.Analog[20] = GPSInfo.velground;
963
/*
956
/*
964
        DebugOut.Analog[21] = MittelIntegralNick / 26;
957
        DebugOut.Analog[21] = MittelIntegralNick / 26;
965
        DebugOut.Analog[22] = MittelIntegralRoll / 26;
958
        DebugOut.Analog[22] = MittelIntegralRoll / 26;
966
        DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
959
        DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick);
967
        DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
960
        DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll);
968
        DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
961
        DebugOut.Analog[25] = IntegralRoll * IntegralFaktor;
969
       
962
       
970
        DebugOut.Analog[27] = ausgleichRoll;
963
        DebugOut.Analog[27] = ausgleichRoll;
971
        DebugOut.Analog[28] = MesswertRoll;
964
        DebugOut.Analog[28] = MesswertRoll;
972
        DebugOut.Analog[29] = ausgleichRoll;
965
        DebugOut.Analog[29] = ausgleichRoll;
973
        DebugOut.Analog[30] = LageKorrekturRoll * 10;
966
        DebugOut.Analog[30] = LageKorrekturRoll * 10;
974
        DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
967
        DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor);
975
*/
968
*/
976
        }
969
        }
977
 
970
 
978
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
971
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
979
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
972
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
980
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
973
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
981
 
974
 
982
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
975
    if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor;
983
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
976
    else             MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
984
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
977
    if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor;
985
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
978
    else             MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
986
    MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
979
    MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2;
987
 
980
 
988
    // Maximalwerte abfangen
981
    // Maximalwerte abfangen
989
    #define MAX_SENSOR  2048
982
    #define MAX_SENSOR  2048
990
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
983
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
991
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
984
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
992
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
985
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
993
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
986
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
994
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
987
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
995
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
988
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
996
 
989
 
997
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
990
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
998
// Höhenregelung
991
// Höhenregelung
999
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
992
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
1000
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
993
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1001
//OCR0B = 180 - (Poti1 + 120) / 4;
994
//OCR0B = 180 - (Poti1 + 120) / 4;
1002
//DruckOffsetSetting = OCR0B;
995
//DruckOffsetSetting = OCR0B;
1003
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
996
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
1004
  {
997
  {
1005
    int tmp_int;
998
    int tmp_int;
1006
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
999
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
1007
    {
1000
    {
1008
     if(Parameter_MaxHoehe < 50)
1001
     if(Parameter_MaxHoehe < 50)
1009
      {
1002
      {
1010
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1003
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
1011
       HoehenReglerAktiv = 0;
1004
       HoehenReglerAktiv = 0;
1012
      }
1005
      }
1013
      else  
1006
      else  
1014
        HoehenReglerAktiv = 1;
1007
        HoehenReglerAktiv = 1;
1015
    }
1008
    }
1016
    else
1009
    else
1017
    {
1010
    {
1018
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1011
     SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20;
1019
     HoehenReglerAktiv = 1;
1012
     HoehenReglerAktiv = 1;
1020
    }
1013
    }
1021
 
1014
 
1022
    if(Notlandung) SollHoehe = 0;
1015
    if(Notlandung) SollHoehe = 0;
1023
    h = HoehenWert;
1016
    h = HoehenWert;
1024
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1017
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
1025
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1018
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
1026
      h = GasMischanteil - h;         // vom Gas abziehen
1019
      h = GasMischanteil - h;         // vom Gas abziehen
1027
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1020
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
1028
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1021
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
1029
      if(tmp_int > 50) tmp_int = 50;
1022
      if(tmp_int > 50) tmp_int = 50;
1030
      else if(tmp_int < -50) tmp_int = -50;
1023
      else if(tmp_int < -50) tmp_int = -50;
1031
      h -= tmp_int;
1024
      h -= tmp_int;
1032
      hoehenregler = (hoehenregler*15 + h) / 16;      
1025
      hoehenregler = (hoehenregler*15 + h) / 16;      
1033
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1026
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
1034
       {
1027
       {
1035
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1028
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
1036
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1029
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
1037
       }  
1030
       }  
1038
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1031
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
1039
      GasMischanteil = hoehenregler;
1032
      GasMischanteil = hoehenregler;
1040
     }
1033
     }
1041
  }
1034
  }
1042
  if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20;
1035
  if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20;
1043
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1036
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1044
// + Mischer und PI-Regler
1037
// + Mischer und PI-Regler
1045
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1038
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1046
 
1039
 
1047
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1040
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1048
// Gier-Anteil
1041
// Gier-Anteil
1049
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1042
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1050
#define MUL_G  1.0
1043
#define MUL_G  1.0
1051
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1044
    GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
1052
// GierMischanteil = 0;
1045
// GierMischanteil = 0;
1053
 
1046
 
1054
    if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1047
    if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2;
1055
    if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1048
    if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2);
1056
    if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil));
1049
    if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil));
1057
    if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil));
1050
    if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil));
1058
 
1051
 
1059
    if(GasMischanteil < 20) GierMischanteil = 0;
1052
    if(GasMischanteil < 20) GierMischanteil = 0;
1060
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1053
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1061
// Nick-Achse
1054
// Nick-Achse
1062
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1055
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1063
    DiffNick = MesswertNick - (StickNick - GPS_Nick);   // Differenz bestimmen
1056
    DiffNick = MesswertNick - (StickNick - GPS_Nick);   // Differenz bestimmen
1064
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
1057
    if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung
1065
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1058
    else  SummeNick += DiffNick; // I-Anteil bei HH 
1066
    if(SummeNick >  16000) SummeNick =  16000;
1059
    if(SummeNick >  16000) SummeNick =  16000;
1067
    if(SummeNick < -16000) SummeNick = -16000;
1060
    if(SummeNick < -16000) SummeNick = -16000;
1068
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1061
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
1069
    // Motor Vorn
1062
    // Motor Vorn
1070
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1063
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1071
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1064
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1072
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1065
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1073
 
1066
 
1074
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1067
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
1075
        if ((motorwert < 0)) motorwert = 0;
1068
        if ((motorwert < 0)) motorwert = 0;
1076
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1069
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1077
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1070
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1078
        Motor_Vorne = motorwert;           
1071
        Motor_Vorne = motorwert;           
1079
    // Motor Heck
1072
    // Motor Heck
1080
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1073
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
1081
        if ((motorwert < 0)) motorwert = 0;
1074
        if ((motorwert < 0)) motorwert = 0;
1082
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1075
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
1083
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1076
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1084
        Motor_Hinten = motorwert;              
1077
        Motor_Hinten = motorwert;              
1085
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1078
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1086
// Roll-Achse
1079
// Roll-Achse
1087
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1080
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
1088
        DiffRoll = MesswertRoll - (StickRoll  - GPS_Roll);      // Differenz bestimmen
1081
        DiffRoll = MesswertRoll - (StickRoll  - GPS_Roll);      // Differenz bestimmen
1089
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll  - GPS_Roll);// I-Anteil bei Winkelregelung
1082
    if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll  - GPS_Roll);// I-Anteil bei Winkelregelung
1090
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1083
    else                 SummeRoll += DiffRoll;  // I-Anteil bei HH
1091
    if(SummeRoll >  16000) SummeRoll =  16000;
1084
    if(SummeRoll >  16000) SummeRoll =  16000;
1092
    if(SummeRoll < -16000) SummeRoll = -16000;
1085
    if(SummeRoll < -16000) SummeRoll = -16000;
1093
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1086
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
1094
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1087
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1095
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1088
    if(pd_ergebnis >  tmp_int) pd_ergebnis =  tmp_int;
1096
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1089
    if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int;
1097
    // Motor Links
1090
    // Motor Links
1098
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1091
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
1099
#define GRENZE Poti1
1092
#define GRENZE Poti1
1100
 
1093
 
1101
        if ((motorwert < 0)) motorwert = 0;
1094
        if ((motorwert < 0)) motorwert = 0;
1102
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1095
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1103
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1096
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
1104
    Motor_Links = motorwert;           
1097
    Motor_Links = motorwert;           
1105
    // Motor Rechts
1098
    // Motor Rechts
1106
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1099
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
1107
 
1100
 
1108
        if ((motorwert < 0)) motorwert = 0;
1101
        if ((motorwert < 0)) motorwert = 0;
1109
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1102
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
1110
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1103
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
1111
    Motor_Rechts = motorwert;          
1104
    Motor_Rechts = motorwert;          
1112
   // +++++++++++++++++++++++++++++++++++++++++++++++
1105
   // +++++++++++++++++++++++++++++++++++++++++++++++
1113
}
1106
}
1114
 
1107
 
1115
 
1108