Subversion Repositories FlightCtrl

Rev

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

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