Subversion Repositories FlightCtrl

Rev

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

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