Subversion Repositories FlightCtrl

Rev

Rev 884 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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