Subversion Repositories FlightCtrl

Rev

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

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