Subversion Repositories FlightCtrl

Rev

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

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