Subversion Repositories FlightCtrl

Rev

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

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