Subversion Repositories FlightCtrl

Rev

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

Rev 123 Rev 124
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
50
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53
// +  POSSIBILITY OF SUCH DAMAGE. 
53
// +  POSSIBILITY OF SUCH DAMAGE. 
54
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
 
55
 
56
#include "main.h"
56
#include "main.h"
57
 
57
 
58
unsigned char h,m,s;
58
unsigned char h,m,s;
59
volatile unsigned char Timeout = 0;
59
volatile unsigned char Timeout = 0;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
60
volatile int MesswertNick,MesswertRoll,MesswertGier;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0;
61
volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
62
volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0;
63
volatile float NeutralAccZ = 0;
63
volatile float NeutralAccZ = 0;
64
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
64
unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0;
65
volatile long IntegralNick = 0,IntegralNick2 = 0;
65
volatile long IntegralNick = 0,IntegralNick2 = 0;
66
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
66
volatile long IntegralRoll = 0,IntegralRoll2 = 0;
67
volatile long Integral_Gier = 0;
67
volatile long Integral_Gier = 0;
68
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
68
volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
69
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
69
volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
70
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
70
volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
71
volatile long Mess_Integral_Hoch = 0;
71
volatile long Mess_Integral_Hoch = 0;
72
volatile int  KompassValue = 0;
72
volatile int  KompassValue = 0;
73
volatile int  KompassStartwert = 0;
73
volatile int  KompassStartwert = 0;
74
volatile int  KompassRichtung = 0;
74
volatile int  KompassRichtung = 0;
75
unsigned char MAX_GAS,MIN_GAS;
75
unsigned char MAX_GAS,MIN_GAS;
76
unsigned char Notlandung = 0;
76
unsigned char Notlandung = 0;
77
unsigned char HoehenReglerAktiv = 0;
77
unsigned char HoehenReglerAktiv = 0;
78
static int SignalSchlecht = 0;
78
static int SignalSchlecht = 0;
-
 
79
 //Salvo 2.9.2007 Ersatzkompass
-
 
80
volatile long GyroKomp_Int,GyroKomp_Int2;
79
 
81
// Salvo End
80
float GyroFaktor;
82
float GyroFaktor;
81
float IntegralFaktor;
83
float IntegralFaktor;
82
 
84
 
83
volatile int  DiffNick,DiffRoll;
85
volatile int  DiffNick,DiffRoll;
84
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
86
int  Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0;
85
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
87
volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
86
unsigned char MotorWert[5];
88
unsigned char MotorWert[5];
87
volatile unsigned char SenderOkay = 0;
89
volatile unsigned char SenderOkay = 0;
88
int StickNick = 0,StickRoll = 0,StickGier = 0;
90
int StickNick = 0,StickRoll = 0,StickGier = 0;
89
char MotorenEin = 0;
91
char MotorenEin = 0;
90
int HoehenWert = 0;
92
int HoehenWert = 0;
91
int SollHoehe = 0;
93
int SollHoehe = 0;
92
int w,v;
94
int w,v;
93
 
95
 
94
float Kp =  FAKTOR_P;
96
float Kp =  FAKTOR_P;
95
float Ki =  FAKTOR_I;
97
float Ki =  FAKTOR_I;
96
 
98
 
97
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
99
unsigned char Parameter_Luftdruck_D  = 48;      // Wert : 0-250
98
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
100
unsigned char Parameter_MaxHoehe     = 251;      // Wert : 0-250
99
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
101
unsigned char Parameter_Hoehe_P      = 16;      // Wert : 0-32
100
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
102
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250
101
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
103
unsigned char Parameter_KompassWirkung = 64;    // Wert : 0-250
102
unsigned char Parameter_Gyro_P = 50;            // Wert : 10-250
104
unsigned char Parameter_Gyro_P = 50;            // Wert : 10-250
103
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
105
unsigned char Parameter_Gyro_I = 150;           // Wert : 0-250
104
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
106
unsigned char Parameter_Gier_P = 2;             // Wert : 1-20
105
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
107
unsigned char Parameter_I_Faktor = 10;          // Wert : 1-20
106
unsigned char Parameter_UserParam1 = 0;
108
unsigned char Parameter_UserParam1 = 0;
107
unsigned char Parameter_UserParam2 = 0;
109
unsigned char Parameter_UserParam2 = 0;
108
unsigned char Parameter_UserParam3 = 0;
110
unsigned char Parameter_UserParam3 = 0;
109
unsigned char Parameter_UserParam4 = 0;
111
unsigned char Parameter_UserParam4 = 0;
110
unsigned char Parameter_ServoNickControl = 100;
112
unsigned char Parameter_ServoNickControl = 100;
111
struct mk_param_struct EE_Parameter;
113
struct mk_param_struct EE_Parameter;
112
 
114
 
113
void Piep(unsigned char Anzahl)
115
void Piep(unsigned char Anzahl)
114
{
116
{
115
 while(Anzahl--)
117
 while(Anzahl--)
116
 {
118
 {
117
  if(MotorenEin) return; //auf keinen Fall im Flug!
119
  if(MotorenEin) return; //auf keinen Fall im Flug!
118
  beeptime = 100;
120
  beeptime = 100;
119
  Delay_ms(250);
121
  Delay_ms(250);
120
 }
122
 }
121
}
123
}
122
 
124
 
123
//############################################################################
125
//############################################################################
124
//  Nullwerte ermitteln
126
//  Nullwerte ermitteln
125
void SetNeutral(void)
127
void SetNeutral(void)
126
//############################################################################
128
//############################################################################
127
{
129
{
128
    unsigned int timer;
130
    unsigned int timer;
129
        NeutralAccX = 0;
131
        NeutralAccX = 0;
130
        NeutralAccY = 0;
132
        NeutralAccY = 0;
131
        NeutralAccZ = 0;
133
        NeutralAccZ = 0;
132
    AdNeutralNick = 0; 
134
    AdNeutralNick = 0; 
133
        AdNeutralRoll = 0;     
135
        AdNeutralRoll = 0;     
134
        AdNeutralGier = 0;
136
        AdNeutralGier = 0;
135
    CalibrierMittelwert();     
137
    CalibrierMittelwert();     
136
    timer = SetDelay(5);    
138
    timer = SetDelay(5);    
137
        while (!CheckDelay(timer));
139
        while (!CheckDelay(timer));
138
        CalibrierMittelwert();
140
        CalibrierMittelwert();
139
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
141
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
140
     {    
142
     {    
141
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
143
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
142
     }
144
     }
143
    AdNeutralNick= abs(MesswertNick);  
145
    AdNeutralNick= abs(MesswertNick);  
144
        AdNeutralRoll= abs(MesswertRoll);      
146
        AdNeutralRoll= abs(MesswertRoll);      
145
        AdNeutralGier= abs(MesswertGier);
147
        AdNeutralGier= abs(MesswertGier);
146
// Salvo 1.9.2007 ACC mit festen neutralwerten *****
148
// Salvo 1.9.2007 ACC mit festen neutralwerten *****
147
        if (ACC_NEUTRAL_FIXED > 0)
149
        if (ACC_NEUTRAL_FIXED > 0)
148
        {
150
        {
149
                NeutralAccX     = ACC_X_NEUTRAL;
151
                NeutralAccX     = ACC_X_NEUTRAL;
150
                NeutralAccY     = ACC_Y_NEUTRAL;
152
                NeutralAccY     = ACC_Y_NEUTRAL;
151
        }
153
        }
152
        else
154
        else
153
        { // Automatisch bei Offsetabgleich ermitteln
155
        { // Automatisch bei Offsetabgleich ermitteln
154
        NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
156
        NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY;
155
                NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
157
                NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY;
156
        }
158
        }
157
 // Salvo End   
159
 // Salvo End   
158
        NeutralAccZ = Aktuell_az;      
160
        NeutralAccZ = Aktuell_az;      
159
        Mess_IntegralNick = 0; 
161
        Mess_IntegralNick = 0; 
160
    Mess_IntegralNick2 = 0;
162
    Mess_IntegralNick2 = 0;
161
    Mess_IntegralRoll = 0;     
163
    Mess_IntegralRoll = 0;     
162
    Mess_IntegralRoll2 = 0;
164
    Mess_IntegralRoll2 = 0;
163
    Mess_Integral_Gier = 0;    
165
    Mess_Integral_Gier = 0;    
164
    MesswertNick = 0;
166
    MesswertNick = 0;
165
    MesswertRoll = 0;
167
    MesswertRoll = 0;
166
    MesswertGier = 0;
168
    MesswertGier = 0;
167
    StartLuftdruck = Luftdruck;
169
    StartLuftdruck = Luftdruck;
168
    HoeheD = 0;
170
    HoeheD = 0;
169
    Mess_Integral_Hoch = 0;
171
    Mess_Integral_Hoch = 0;
170
    KompassStartwert = KompassValue;
172
    KompassStartwert = KompassValue;
171
    GPS_Neutral();
173
    GPS_Neutral();
172
    beeptime = 50;  
174
    beeptime = 50;  
-
 
175
//Salvo 2.9.2007 Ersatzkompass
-
 
176
        GyroKomp_Int = 0;
-
 
177
        GyroKomp_Int2 = 0;
-
 
178
// Salvo End
173
}
179
}
174
 
180
 
175
//############################################################################
181
//############################################################################
176
// Bildet den Mittelwert aus den Messwerten
182
// Bildet den Mittelwert aus den Messwerten
177
void Mittelwert(void)
183
void Mittelwert(void)
178
//############################################################################
184
//############################################################################
179
{      
185
{      
180
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
186
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
181
    ANALOG_OFF;
187
    ANALOG_OFF;
182
        if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
188
        if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
183
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
189
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
184
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
190
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
185
        if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L;
191
        if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L;
186
        if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L;
192
        if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L;
187
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L;
193
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L;
188
    AccumulateNick = 0;   MessanzahlNick = 0;
194
    AccumulateNick = 0;   MessanzahlNick = 0;
189
    AccumulateRoll = 0;   MessanzahlRoll = 0;
195
    AccumulateRoll = 0;   MessanzahlRoll = 0;
190
    AccumulateGier = 0;   MessanzahlGier = 0;
196
    AccumulateGier = 0;   MessanzahlGier = 0;
191
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
197
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
192
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
198
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
193
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
199
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
194
    Integral_Gier  = Mess_Integral_Gier;
200
    Integral_Gier  = Mess_Integral_Gier;
195
//    Integral_Gier2 = Mess_Integral_Gier2;
201
//    Integral_Gier2 = Mess_Integral_Gier2;
196
    IntegralNick = Mess_IntegralNick;
202
    IntegralNick = Mess_IntegralNick;
197
    IntegralRoll = Mess_IntegralRoll;
203
    IntegralRoll = Mess_IntegralRoll;
198
    IntegralNick2 = Mess_IntegralNick2;
204
    IntegralNick2 = Mess_IntegralNick2;
199
    IntegralRoll2 = Mess_IntegralRoll2;
205
    IntegralRoll2 = Mess_IntegralRoll2;
200
    // ADC einschalten
206
    // ADC einschalten
201
    ANALOG_ON; 
207
    ANALOG_ON; 
202
 
208
 
203
//------------------------------------------------------------------------------
209
//------------------------------------------------------------------------------
204
    if(MesswertNick > 200)  MesswertNick += 4 * (MesswertNick - 200);
210
    if(MesswertNick > 200)  MesswertNick += 4 * (MesswertNick - 200);
205
    else                                         
211
    else                                         
206
    if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
212
    if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200);
207
 
213
 
208
    if(MesswertRoll > 200)  MesswertRoll += 4 * (MesswertRoll - 200);
214
    if(MesswertRoll > 200)  MesswertRoll += 4 * (MesswertRoll - 200);
209
    else                                         
215
    else                                         
210
    if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
216
    if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200);
211
//------------------------------------------------------------------------------
217
//------------------------------------------------------------------------------
212
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
218
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
213
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
219
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
214
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
220
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
215
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
221
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
216
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
222
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
217
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
223
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
218
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
224
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
219
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
225
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
220
}
226
}
221
 
227
 
222
//############################################################################
228
//############################################################################
223
// Messwerte beim Ermitteln der Nullage
229
// Messwerte beim Ermitteln der Nullage
224
void CalibrierMittelwert(void)
230
void CalibrierMittelwert(void)
225
//############################################################################
231
//############################################################################
226
{                
232
{                
227
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
233
    // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern
228
        ANALOG_OFF;
234
        ANALOG_OFF;
229
    if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
235
    if(MessanzahlNick)    (MesswertNick = AccumulateNick / MessanzahlNick);
230
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
236
        if(MessanzahlRoll)    (MesswertRoll = AccumulateRoll / MessanzahlRoll);
231
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
237
        if(MessanzahlGier)    (MesswertGier = AccumulateGier / MessanzahlGier);
232
        if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick);
238
        if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick);
233
        if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll;
239
        if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll;
234
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch;
240
        if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch;
235
    AccumulateNick = 0;   MessanzahlNick = 0;
241
    AccumulateNick = 0;   MessanzahlNick = 0;
236
    AccumulateRoll = 0;   MessanzahlRoll = 0;
242
    AccumulateRoll = 0;   MessanzahlRoll = 0;
237
    AccumulateGier = 0;   MessanzahlGier = 0;
243
    AccumulateGier = 0;   MessanzahlGier = 0;
238
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
244
    accumulate_AccRoll = 0;messanzahl_AccRoll = 0;
239
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
245
    accumulate_AccNick = 0;messanzahl_AccNick = 0;
240
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
246
    accumulate_AccHoch = 0;messanzahl_AccHoch = 0;
241
    // ADC einschalten
247
    // ADC einschalten
242
    ANALOG_ON; 
248
    ANALOG_ON; 
243
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
249
    if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--;
244
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
250
    if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--;
245
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
251
    if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--;
246
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
252
    if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--;
247
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
253
    if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255;
248
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
254
    if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255;
249
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
255
    if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255;
250
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
256
    if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255;
251
}
257
}
252
 
258
 
253
//############################################################################
259
//############################################################################
254
// Senden der Motorwerte per I2C-Bus
260
// Senden der Motorwerte per I2C-Bus
255
void SendMotorData(void)
261
void SendMotorData(void)
256
//############################################################################
262
//############################################################################
257
{
263
{
258
    if(MOTOR_OFF || !MotorenEin)
264
    if(MOTOR_OFF || !MotorenEin)
259
        {
265
        {
260
        Motor_Hinten = 0;
266
        Motor_Hinten = 0;
261
        Motor_Vorne = 0;
267
        Motor_Vorne = 0;
262
        Motor_Rechts = 0;
268
        Motor_Rechts = 0;
263
        Motor_Links = 0;
269
        Motor_Links = 0;
264
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
270
        if(MotorTest[0]) Motor_Vorne = MotorTest[0];
265
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
271
        if(MotorTest[1]) Motor_Hinten = MotorTest[1];
266
        if(MotorTest[2]) Motor_Links = MotorTest[2];
272
        if(MotorTest[2]) Motor_Links = MotorTest[2];
267
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
273
        if(MotorTest[3]) Motor_Rechts = MotorTest[3];
268
        }
274
        }
269
 
275
 
270
    DebugOut.Analog[12] = Motor_Vorne;
276
    DebugOut.Analog[12] = Motor_Vorne;
271
    DebugOut.Analog[13] = Motor_Hinten;
277
    DebugOut.Analog[13] = Motor_Hinten;
272
    DebugOut.Analog[14] = Motor_Links;
278
    DebugOut.Analog[14] = Motor_Links;
273
    DebugOut.Analog[15] = Motor_Rechts;  
279
    DebugOut.Analog[15] = Motor_Rechts;  
274
 
280
 
275
    //Start I2C Interrupt Mode
281
    //Start I2C Interrupt Mode
276
    twi_state = 0;
282
    twi_state = 0;
277
    motor = 0;
283
    motor = 0;
278
    i2c_start();
284
    i2c_start();
279
}
285
}
280
 
286
 
281
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
287
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
282
// + Konstanten 
288
// + Konstanten 
283
// + 0-250 -> normale Werte
289
// + 0-250 -> normale Werte
284
// + 251 -> Poti1
290
// + 251 -> Poti1
285
// + 252 -> Poti2
291
// + 252 -> Poti2
286
// + 253 -> Poti3
292
// + 253 -> Poti3
287
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
293
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
288
void DefaultKonstanten1(void)
294
void DefaultKonstanten1(void)
289
{
295
{
290
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
296
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
291
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
297
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
292
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
298
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
293
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
299
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
294
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
300
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
295
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
301
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
296
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
302
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
297
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
303
 EE_Parameter.Kanalbelegung[K_POTI4] = 8;
298
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01;    
304
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01;    
299
 EE_Parameter.Hoehe_MinGas = 30;
305
 EE_Parameter.Hoehe_MinGas = 30;
300
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
306
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
301
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
307
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
302
 EE_Parameter.Luftdruck_D  = 70;      // Wert : 0-250
308
 EE_Parameter.Luftdruck_D  = 70;      // Wert : 0-250
303
 EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250
309
 EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250
304
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
310
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
305
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
311
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
306
 EE_Parameter.Stick_D = 8; //8           // Wert : 0-64
312
 EE_Parameter.Stick_D = 8; //8           // Wert : 0-64
307
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
313
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
308
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
314
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
309
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
315
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
310
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
316
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
311
 EE_Parameter.KompassWirkung = 64;    // Wert : 0-250
317
 EE_Parameter.KompassWirkung = 64;    // Wert : 0-250
312
 EE_Parameter.Gyro_P = 120; //80          // Wert : 0-250
318
 EE_Parameter.Gyro_P = 120; //80          // Wert : 0-250
313
 EE_Parameter.Gyro_I = 150;               // Wert : 0-250
319
 EE_Parameter.Gyro_I = 150;               // Wert : 0-250
314
 EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250
320
 EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250
315
 EE_Parameter.NotGas = 80;                // Wert : 0-250     // Gaswert bei Empangsverlust
321
 EE_Parameter.NotGas = 80;                // Wert : 0-250     // Gaswert bei Empangsverlust
316
 EE_Parameter.NotGasZeit = 50;            // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
322
 EE_Parameter.NotGasZeit = 50;            // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
317
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
323
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
318
 EE_Parameter.I_Faktor = 5;
324
 EE_Parameter.I_Faktor = 5;
319
 EE_Parameter.UserParam1 = 0;             //zur freien Verwendung
325
 EE_Parameter.UserParam1 = 0;             //zur freien Verwendung
320
 EE_Parameter.UserParam2 = 0;             //zur freien Verwendung
326
 EE_Parameter.UserParam2 = 0;             //zur freien Verwendung
321
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
327
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
322
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
328
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
323
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
329
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
324
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
330
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
325
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
331
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
326
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
332
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
327
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
333
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
328
 EE_Parameter.ServoNickRefresh = 5;
334
 EE_Parameter.ServoNickRefresh = 5;
329
 memcpy(EE_Parameter.Name, "Normal\0", 12);  
335
 memcpy(EE_Parameter.Name, "Normal\0", 12);  
330
}
336
}
331
 
337
 
332
void DefaultKonstanten2(void)
338
void DefaultKonstanten2(void)
333
{
339
{
334
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
340
 EE_Parameter.Kanalbelegung[K_NICK]  = 1;
335
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
341
 EE_Parameter.Kanalbelegung[K_ROLL]  = 2;
336
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
342
 EE_Parameter.Kanalbelegung[K_GAS]   = 3;
337
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
343
 EE_Parameter.Kanalbelegung[K_GIER]  = 4;
338
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
344
 EE_Parameter.Kanalbelegung[K_POTI1] = 5;
339
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
345
 EE_Parameter.Kanalbelegung[K_POTI2] = 6;
340
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
346
 EE_Parameter.Kanalbelegung[K_POTI3] = 7;
341
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01;    
347
 EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01;    
342
 EE_Parameter.Hoehe_MinGas = 30;
348
 EE_Parameter.Hoehe_MinGas = 30;
343
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
349
 EE_Parameter.MaxHoehe     = 251;     // Wert : 0-32   251 -> Poti1
344
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
350
 EE_Parameter.Hoehe_P      = 10;      // Wert : 0-32
345
 EE_Parameter.Luftdruck_D  = 50;      // Wert : 0-250
351
 EE_Parameter.Luftdruck_D  = 50;      // Wert : 0-250
346
 EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250
352
 EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250
347
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
353
 EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50
348
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
354
 EE_Parameter.Stick_P = 4; //2           // Wert : 1-6
349
 EE_Parameter.Stick_D = 0; //8           // Wert : 0-64
355
 EE_Parameter.Stick_D = 0; //8           // Wert : 0-64
350
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
356
 EE_Parameter.Gier_P = 16;            // Wert : 1-20
351
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
357
 EE_Parameter.Gas_Min = 15;            // Wert : 0-32
352
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
358
 EE_Parameter.Gas_Max = 250;          // Wert : 33-250
353
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
359
 EE_Parameter.GyroAccFaktor = 26;     // Wert : 1-64
354
 EE_Parameter.KompassWirkung = 64;    // Wert : 0-250
360
 EE_Parameter.KompassWirkung = 64;    // Wert : 0-250
355
 EE_Parameter.Gyro_P = 175; //80           // Wert : 0-250
361
 EE_Parameter.Gyro_P = 175; //80           // Wert : 0-250
356
 EE_Parameter.Gyro_I = 175;           // Wert : 0-250
362
 EE_Parameter.Gyro_I = 175;           // Wert : 0-250
357
 EE_Parameter.UnterspannungsWarnung = 100;  // Wert : 0-250
363
 EE_Parameter.UnterspannungsWarnung = 100;  // Wert : 0-250
358
 EE_Parameter.NotGas = 80;                 // Wert : 0-250     // Gaswert bei Empangsverlust
364
 EE_Parameter.NotGas = 80;                 // Wert : 0-250     // Gaswert bei Empangsverlust
359
 EE_Parameter.NotGasZeit = 50;             // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
365
 EE_Parameter.NotGasZeit = 50;             // Wert : 0-250     // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen
360
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
366
 EE_Parameter.UfoAusrichtung = 0;         // X oder + Formation
361
 EE_Parameter.I_Faktor = 5;
367
 EE_Parameter.I_Faktor = 5;
362
 EE_Parameter.UserParam1 = 0;   //zur freien Verwendung
368
 EE_Parameter.UserParam1 = 0;   //zur freien Verwendung
363
 EE_Parameter.UserParam2 = 0;   //zur freien Verwendung
369
 EE_Parameter.UserParam2 = 0;   //zur freien Verwendung
364
 EE_Parameter.UserParam3 = 0;   //zur freien Verwendung
370
 EE_Parameter.UserParam3 = 0;   //zur freien Verwendung
365
 EE_Parameter.UserParam4 = 0;   //zur freien Verwendung
371
 EE_Parameter.UserParam4 = 0;   //zur freien Verwendung
366
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
372
 EE_Parameter.UserParam3 = 0;             //zur freien Verwendung
367
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
373
 EE_Parameter.UserParam4 = 0;             //zur freien Verwendung
368
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
374
 EE_Parameter.ServoNickControl = 100;     // Wert : 0-250     // Stellung des Servos
369
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
375
 EE_Parameter.ServoNickComp = 40;         // Wert : 0-250     // Einfluss Gyro/Servo
370
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
376
 EE_Parameter.ServoNickCompInvert = 0;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
371
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
377
 EE_Parameter.ServoNickMin = 50;           // Wert : 0-250     // Anschlag
372
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
378
 EE_Parameter.ServoNickMax = 150;         // Wert : 0-250     // Anschlag
373
 EE_Parameter.ServoNickRefresh = 5;
379
 EE_Parameter.ServoNickRefresh = 5;
374
 memcpy(EE_Parameter.Name, "Kamera\0", 12);  
380
 memcpy(EE_Parameter.Name, "Kamera\0", 12);  
375
}
381
}
376
 
382
 
377
 
383
 
378
//############################################################################
384
//############################################################################
379
// Trägt ggf. das Poti als Parameter ein
385
// Trägt ggf. das Poti als Parameter ein
380
void ParameterZuordnung(void)
386
void ParameterZuordnung(void)
381
//############################################################################
387
//############################################################################
382
{
388
{
383
 
389
 
384
 #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;}
390
 #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;}
385
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
391
 CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255);
386
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
392
 CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100);
387
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
393
 CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100);
388
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
394
 CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255);
389
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
395
 CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255);
390
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
396
 CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255);
391
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
397
 CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255);
392
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
398
 CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255);
393
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
399
 CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255);
394
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
400
 CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255);
395
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
401
 CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255);
396
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
402
 CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255);
397
 
403
 
398
   unsigned char ServoNickComp;          // Wert : 0-250     // Einfluss Gyro/Servo
404
   unsigned char ServoNickComp;          // Wert : 0-250     // Einfluss Gyro/Servo
399
   unsigned char ServoNickCompInvert;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
405
   unsigned char ServoNickCompInvert;    // Wert : 0-250     // Richtung Einfluss Gyro/Servo
400
   unsigned char ServoNickMin;           // Wert : 0-250     // Anschlag
406
   unsigned char ServoNickMin;           // Wert : 0-250     // Anschlag
401
   unsigned char ServoNickMax;           // Wert : 0-250     // Anschlag
407
   unsigned char ServoNickMax;           // Wert : 0-250     // Anschlag
402
 
408
 
403
 
409
 
404
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
410
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
405
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
411
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
406
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
412
 CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255);
407
 
413
 
408
 Ki = (float) Parameter_I_Faktor * 0.0001;
414
 Ki = (float) Parameter_I_Faktor * 0.0001;
409
 MAX_GAS = EE_Parameter.Gas_Max;
415
 MAX_GAS = EE_Parameter.Gas_Max;
410
 MIN_GAS = EE_Parameter.Gas_Min;
416
 MIN_GAS = EE_Parameter.Gas_Min;
411
}
417
}
412
 
418
 
413
 
419
 
414
//############################################################################
420
//############################################################################
415
//
421
//
416
void MotorRegler(void)
422
void MotorRegler(void)
417
//############################################################################
423
//############################################################################
418
{
424
{
419
         int motorwert,pd_ergebnis,h,tmp_int;
425
         int motorwert,pd_ergebnis,h,tmp_int;
420
         int GierMischanteil,GasMischanteil;
426
         int GierMischanteil,GasMischanteil;
421
     static long SummeNick=0,SummeRoll=0;
427
     static long SummeNick=0,SummeRoll=0;
422
     static long sollGier = 0,tmp_long,tmp_long2;
428
     static long sollGier = 0,tmp_long,tmp_long2;
423
     static int IntegralFehlerNick = 0;
429
     static int IntegralFehlerNick = 0;
424
     static int IntegralFehlerRoll = 0;
430
     static int IntegralFehlerRoll = 0;
425
         static unsigned int RcLostTimer;
431
         static unsigned int RcLostTimer;
426
         static unsigned char delay_neutral = 0;
432
         static unsigned char delay_neutral = 0;
427
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
433
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
428
         static unsigned int  modell_fliegt = 0;
434
         static unsigned int  modell_fliegt = 0;
429
     static int hoehenregler = 0;
435
     static int hoehenregler = 0;
430
     static char TimerWerteausgabe = 0;
436
     static char TimerWerteausgabe = 0;
431
     static char NeueKompassRichtungMerken = 0;
437
     static char NeueKompassRichtungMerken = 0;
432
        Mittelwert();
438
        Mittelwert();
433
 
439
 
434
    GRN_ON;
440
    GRN_ON;
435
 
441
 
436
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
437
// Gaswert ermitteln
443
// Gaswert ermitteln
438
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
444
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
439
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
445
        GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
440
    if(GasMischanteil < 0) GasMischanteil = 0;
446
    if(GasMischanteil < 0) GasMischanteil = 0;
441
   
447
   
442
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
448
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
443
// Emfang schlecht
449
// Emfang schlecht
444
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
450
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
445
   if(SenderOkay < 100)
451
   if(SenderOkay < 100)
446
        {
452
        {
447
        if(!PcZugriff)  beeptime = 500;
453
        if(!PcZugriff)  beeptime = 500;
448
        if(RcLostTimer) RcLostTimer--;
454
        if(RcLostTimer) RcLostTimer--;
449
        else
455
        else
450
         {
456
         {
451
          MotorenEin = 0;
457
          MotorenEin = 0;
452
          Notlandung = 0;
458
          Notlandung = 0;
453
         }
459
         }
454
        ROT_ON;
460
        ROT_ON;
455
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
461
        if(modell_fliegt > 2000)  // wahrscheinlich in der Luft --> langsam absenken
456
            {
462
            {
457
            GasMischanteil = EE_Parameter.NotGas;
463
            GasMischanteil = EE_Parameter.NotGas;
458
            Notlandung = 1;
464
            Notlandung = 1;
459
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
465
            PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
460
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
466
            PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
461
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
467
            PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
462
/*          Poti1 = 65;
468
/*          Poti1 = 65;
463
            Poti2 = 48;
469
            Poti2 = 48;
464
            Poti3 = 0;
470
            Poti3 = 0;
465
*/          }
471
*/          }
466
         else MotorenEin = 0;
472
         else MotorenEin = 0;
467
        }
473
        }
468
        else
474
        else
469
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
475
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
470
// Emfang gut
476
// Emfang gut
471
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
477
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
472
        if(SenderOkay > 140)
478
        if(SenderOkay > 140)
473
            {
479
            {
474
            Notlandung = 0;
480
            Notlandung = 0;
475
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
481
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
476
            if(GasMischanteil > 40)
482
            if(GasMischanteil > 40)
477
                {
483
                {
478
                if(modell_fliegt < 0xffff) modell_fliegt++;
484
                if(modell_fliegt < 0xffff) modell_fliegt++;
479
                }
485
                }
480
            if((modell_fliegt < 200) || (GasMischanteil < 40))
486
            if((modell_fliegt < 200) || (GasMischanteil < 40))
481
                {
487
                {
482
                SummeNick = 0;
488
                SummeNick = 0;
483
                SummeRoll = 0;
489
                SummeRoll = 0;
484
                Mess_Integral_Gier = 0;
490
                Mess_Integral_Gier = 0;
485
                Mess_Integral_Gier2 = 0;
491
                Mess_Integral_Gier2 = 0;
486
                }
492
                }
487
            if((GasMischanteil > 200) && MotorenEin == 0)
493
            if((GasMischanteil > 200) && MotorenEin == 0)
488
                {
494
                {
489
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
495
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
490
// auf Nullwerte kalibrieren
496
// auf Nullwerte kalibrieren
491
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
497
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
492
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
498
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
493
                    {
499
                    {
494
                    unsigned char setting;
500
                    unsigned char setting;
495
                    if(++delay_neutral > 200)  // nicht sofort
501
                    if(++delay_neutral > 200)  // nicht sofort
496
                        {
502
                        {
497
                        GRN_OFF;
503
                        GRN_OFF;
498
                        SetNeutral();
504
                        SetNeutral();
499
                        MotorenEin = 0;
505
                        MotorenEin = 0;
500
                        delay_neutral = 0;
506
                        delay_neutral = 0;
501
                        modell_fliegt = 0;
507
                        modell_fliegt = 0;
502
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
508
                        if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70)
503
                        {
509
                        {
504
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
510
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1;
505
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
511
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2;
506
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
512
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3;
507
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
513
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4;
508
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
514
                         if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5;
509
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
515
                         eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting);  // aktiven Datensatz merken
510
                        }
516
                        }
511
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
517
                            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
512
                        Piep(GetActiveParamSetNumber());
518
                        Piep(GetActiveParamSetNumber());
513
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
519
                        if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
514
                          {
520
                          {
515
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
521
                             if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
516
                          }  
522
                          }  
517
                        }
523
                        }
518
                    }
524
                    }
519
                 else delay_neutral = 0;
525
                 else delay_neutral = 0;
520
                }
526
                }
521
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
527
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
522
// Gas ist unten
528
// Gas ist unten
523
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
529
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
524
            if(GasMischanteil < 35)
530
            if(GasMischanteil < 35)
525
                {
531
                {
526
                // Starten
532
                // Starten
527
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
533
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
528
                    {
534
                    {
529
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
535
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
530
// Einschalten
536
// Einschalten
531
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
537
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
532
                    if(++delay_einschalten > 200)
538
                    if(++delay_einschalten > 200)
533
                        {
539
                        {
534
                        delay_einschalten = 200;
540
                        delay_einschalten = 200;
535
                        modell_fliegt = 1;
541
                        modell_fliegt = 1;
536
                        MotorenEin = 1;
542
                        MotorenEin = 1;
537
                        sollGier = 0;
543
                        sollGier = 0;
538
                        Mess_Integral_Gier = 0;
544
                        Mess_Integral_Gier = 0;
539
                        Mess_Integral_Gier2 = 0;
545
                        Mess_Integral_Gier2 = 0;
540
                        Mess_IntegralNick = 0;
546
                        Mess_IntegralNick = 0;
541
                        Mess_IntegralRoll = 0;
547
                        Mess_IntegralRoll = 0;
542
                        Mess_IntegralNick2 = IntegralNick;
548
                        Mess_IntegralNick2 = IntegralNick;
543
                        Mess_IntegralRoll2 = IntegralRoll;
549
                        Mess_IntegralRoll2 = IntegralRoll;
544
                        SummeNick = 0;
550
                        SummeNick = 0;
545
                        SummeRoll = 0;
551
                        SummeRoll = 0;
546
                        }          
552
                        }          
547
                    }  
553
                    }  
548
                    else delay_einschalten = 0;
554
                    else delay_einschalten = 0;
549
                //Auf Neutralwerte setzen
555
                //Auf Neutralwerte setzen
550
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
556
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
551
// Auschalten
557
// Auschalten
552
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
558
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
553
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
559
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
554
                    {
560
                    {
555
                    if(++delay_ausschalten > 200)  // nicht sofort
561
                    if(++delay_ausschalten > 200)  // nicht sofort
556
                        {
562
                        {
557
                        MotorenEin = 0;
563
                        MotorenEin = 0;
558
                        delay_ausschalten = 200;
564
                        delay_ausschalten = 200;
559
                        modell_fliegt = 0;
565
                        modell_fliegt = 0;
560
                        }
566
                        }
561
                    }
567
                    }
562
                else delay_ausschalten = 0;
568
                else delay_ausschalten = 0;
563
                }
569
                }
564
            }
570
            }
565
 
571
 
566
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
572
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
567
// neue Werte von der Funke
573
// neue Werte von der Funke
568
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
574
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
569
 if(!NewPpmData-- || Notlandung)  
575
 if(!NewPpmData-- || Notlandung)  
570
  {
576
  {
571
    ParameterZuordnung();
577
    ParameterZuordnung();
572
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
578
    StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P;
573
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
579
    StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D;
574
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
580
    StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P;
575
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
581
    StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D;
576
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
582
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
577
 
583
 
578
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
584
    GyroFaktor     = ((float)Parameter_Gyro_P + 10.0) / 256.0;
579
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
585
    IntegralFaktor = ((float) Parameter_Gyro_I) / 44000;
580
 
586
 
581
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
587
    if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor =  0;
582
    if(GyroFaktor < 0) GyroFaktor = 0;
588
    if(GyroFaktor < 0) GyroFaktor = 0;
583
    if(IntegralFaktor < 0) IntegralFaktor = 0;
589
    if(IntegralFaktor < 0) IntegralFaktor = 0;
584
  }
590
  }
585
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
591
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
586
// Bei Empfangsausfall im Flug 
592
// Bei Empfangsausfall im Flug 
587
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
593
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
588
   if(Notlandung)
594
   if(Notlandung)
589
    {
595
    {
590
     StickGier = 0;
596
     StickGier = 0;
591
     StickNick = 0;
597
     StickNick = 0;
592
     StickRoll = 0;
598
     StickRoll = 0;
593
     GyroFaktor  = 0.1;
599
     GyroFaktor  = 0.1;
594
     IntegralFaktor = 0.005;
600
     IntegralFaktor = 0.005;
595
    }  
601
    }  
596
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
602
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
597
// Gyro-Drift kompensieren
603
// Gyro-Drift kompensieren
598
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
604
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
599
#define DRIFT_FAKTOR 3
605
#define DRIFT_FAKTOR 3
600
    if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR)
606
    if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR)
601
        {
607
                {
602
        IntegralFehlerNick = IntegralNick2 - IntegralNick;
608
               IntegralFehlerNick = IntegralNick2 - IntegralNick;
603
        IntegralFehlerRoll = IntegralRoll2 - IntegralRoll;
609
           IntegralFehlerRoll = IntegralRoll2 - IntegralRoll;
604
        ZaehlMessungen = 0;
610
           ZaehlMessungen = 0;
605
// Salvo 1.9.2007 *************************
611
// Salvo 1.9.2007 *************************
606
// Abgleich Roll und Nick Gyro nur, wenn nahezu waagrechte Lage
612
// Abgleich Roll und Nick Gyro vollsteandig nur, wenn nahezu waagrechte Lage, ansonsten abschwaechen
607
            ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
613
                   ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
608
                w = (abs(Mittelwert_AccNick));
614
                        w = (abs(Mittelwert_AccNick));
609
                v = (abs(Mittelwert_AccRoll));
615
                        v = (abs(Mittelwert_AccRoll));
610
        ANALOG_ON;      // ADC einschalten
616
                ANALOG_ON;      // ADC einschalten
611
                if ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT))
617
                        if ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT))
612
                {              
618
                        {              
613
         if(IntegralFehlerNick > 500/DRIFT_FAKTOR)   AdNeutralNick++;
619
                 if(IntegralFehlerNick > 500/DRIFT_FAKTOR)   AdNeutralNick++;
614
         if(IntegralFehlerNick < -500/DRIFT_FAKTOR)  AdNeutralNick--;
620
                 if(IntegralFehlerNick < -500/DRIFT_FAKTOR)  AdNeutralNick--;
615
         if(IntegralFehlerRoll > 500/DRIFT_FAKTOR)   AdNeutralRoll++;
621
                 if(IntegralFehlerRoll > 500/DRIFT_FAKTOR)   AdNeutralRoll++;
616
         if(IntegralFehlerRoll < -500/DRIFT_FAKTOR)  AdNeutralRoll--;
622
                 if(IntegralFehlerRoll < -500/DRIFT_FAKTOR)  AdNeutralRoll--;
-
 
623
                        }
-
 
624
                        else if ((w  < 2*ACC_WAAGRECHT_LIMIT) && (v < 2*ACC_WAAGRECHT_LIMIT)) // langsamer kompensieren, weil ACC Werte unsicherer sind, was die Neigung angeht
-
 
625
                        {
-
 
626
                 if(IntegralFehlerNick > 500*2/DRIFT_FAKTOR)   AdNeutralNick++;
-
 
627
                 if(IntegralFehlerNick < -500*2/DRIFT_FAKTOR)  AdNeutralNick--;
-
 
628
                 if(IntegralFehlerRoll > 500*2/DRIFT_FAKTOR)   AdNeutralRoll++;
-
 
629
                 if(IntegralFehlerRoll < -500*2/DRIFT_FAKTOR)  AdNeutralRoll--;
-
 
630
                        }
-
 
631
                        else  // noch langsamer kompensieren, weil ACC Werte unsicherer sind, was die Neigung angeht
-
 
632
                        {
-
 
633
                 if(IntegralFehlerNick > 500*4/DRIFT_FAKTOR)   AdNeutralNick++;
-
 
634
                 if(IntegralFehlerNick < -500*4/DRIFT_FAKTOR)  AdNeutralNick--;
-
 
635
                 if(IntegralFehlerRoll > 500*4/DRIFT_FAKTOR)   AdNeutralRoll++;
-
 
636
                 if(IntegralFehlerRoll < -500*4/DRIFT_FAKTOR)  AdNeutralRoll--;
617
                }
637
                        }
618
// Salvo End
638
// Salvo End
619
 
639
 
620
// Salvo 31.8.2007 Abgleich Giergyro nur wenn Kompass aktiv und ok ist ***********************
640
// Salvo 31.8.2007 Abgleich Giergyro nur wenn Kompass aktiv und ok ist ***********************
621
// Ohne Kompass wird die Pseudo-Gyrodrift durch die Driftkompensation nur verschlimmert
641
// Ohne Kompass wird die Pseudo-Gyrodrift durch die Driftkompensation nur verschlimmert
622
// Ohne Driftkompensation ist die Gierachse wesentlich stabiler
642
// Ohne Driftkompensation ist die Gierachse wesentlich stabiler
623
                if ((EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (!SignalSchlecht))
643
                        if ((EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (!SignalSchlecht))
624
                {
644
                        {
625
         if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR)  AdNeutralGier--;        
645
                 if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR)  AdNeutralGier--;        
626
         if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR)  AdNeutralGier++;  
646
                 if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR)  AdNeutralGier++;  
627
                }  
647
                        }  
628
                else
648
                        else
629
                {
649
                        {
630
                  Mess_Integral_Gier2 = 0;     
650
                         Mess_Integral_Gier2 = 0;      
631
                }
651
                        }
632
// Salvo End ***********************
652
// Salvo End ***********************
633
    ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
653
                        ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
634
        Mess_IntegralNick2 = IntegralNick;
654
                Mess_IntegralNick2 = IntegralNick;
635
        Mess_IntegralRoll2 = IntegralRoll;
655
                Mess_IntegralRoll2 = IntegralRoll;
636
        Mess_Integral_Gier2 = Integral_Gier;
656
                Mess_Integral_Gier2 = Integral_Gier;
637
    ANALOG_ON;  // ADC einschalten
657
                ANALOG_ON;      // ADC einschalten
638
        }
658
        }
639
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
659
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
640
// Integrale auf ACC-Signal abgleichen
660
// Integrale auf ACC-Signal abgleichen
641
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
661
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
642
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16;  
662
    tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16;  
643
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16;  
663
    tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16;  
644
#define AUSGLEICH 500
664
#define AUSGLEICH 500
645
        if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
665
        if(tmp_long >  AUSGLEICH)  tmp_long  = AUSGLEICH;
646
        if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
666
        if(tmp_long < -AUSGLEICH)  tmp_long  =-AUSGLEICH;
647
        if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
667
        if(tmp_long2 > AUSGLEICH)  tmp_long2 = AUSGLEICH;
648
        if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
668
        if(tmp_long2 <-AUSGLEICH)  tmp_long2 =-AUSGLEICH;
649
 
669
 
650
 ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
670
 ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
651
 // Salvo 1.9.2007 Volle Korrektur nur wenn waagrechte Lage, sonst abgeschawecht *****************
671
 // Salvo 1.9.2007 Volle Korrektur nur wenn waagrechte Lage, sonst abgeschawecht *****************
652
        w = (abs(Mittelwert_AccNick));
672
        w = (abs(Mittelwert_AccNick));
653
        v = (abs(Mittelwert_AccRoll));
673
        v = (abs(Mittelwert_AccRoll));
654
        if ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT))
674
        if ((w  < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT))
655
        {
675
        {
656
        Mess_IntegralNick -= tmp_long;
676
        Mess_IntegralNick -= tmp_long;
657
        Mess_IntegralRoll -= tmp_long2;
677
        Mess_IntegralRoll -= tmp_long2;
658
        }
678
        }
659
        else if ((w  < 2 * ACC_WAAGRECHT_LIMIT) && (v < 2 * ACC_WAAGRECHT_LIMIT))
679
        else if ((w  < 2 * ACC_WAAGRECHT_LIMIT) && (v < 2 * ACC_WAAGRECHT_LIMIT))
660
        {
680
        {
661
        Mess_IntegralNick -= tmp_long/8;
681
        Mess_IntegralNick -= tmp_long/2; //Vorher 8
662
        Mess_IntegralRoll -= tmp_long/8;
682
        Mess_IntegralRoll -= tmp_long2/2;
663
        }
683
        }
664
        else if ((w  < 4 * ACC_WAAGRECHT_LIMIT) && (v < 4 * ACC_WAAGRECHT_LIMIT))
684
        else if ((w  < 4 * ACC_WAAGRECHT_LIMIT) && (v < 4 * ACC_WAAGRECHT_LIMIT))
665
        {
685
        {
666
        Mess_IntegralNick -= tmp_long/16;
686
        Mess_IntegralNick -= tmp_long/4;
667
        Mess_IntegralRoll -= tmp_long/16;
687
        Mess_IntegralRoll -= tmp_long2/4;
668
        }
688
        }
669
        else
689
        else
670
        {
690
        {
671
        Mess_IntegralNick -= tmp_long/32;
691
        Mess_IntegralNick -= tmp_long/8;
672
        Mess_IntegralRoll -= tmp_long2/32;             
692
        Mess_IntegralRoll -= tmp_long2/8;              
673
        }
693
        }
674
// Salvo End ***********************
694
// Salvo End ***********************
675
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
695
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
676
//  Gieren
696
//  Gieren
677
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
697
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
678
    sollGier = StickGier;
698
    sollGier = StickGier;
679
    if(abs(StickGier) > 35)
699
    if(abs(StickGier) > 35)
680
     {
700
     {
681
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
701
      if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1;
682
     }
702
     }
683
    tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo
703
    tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo
684
    Mess_Integral_Gier -= tmp_int;  
704
    Mess_Integral_Gier -= tmp_int;  
685
    if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000;  // begrenzen
705
    if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000;  // begrenzen
686
    if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000;
706
    if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000;
687
// Salvo Gewolltes Gieren ignorieren 30.8.2007 **********************
707
// Salvo Gewolltes Gieren ignorieren 30.8.2007 **********************
688
    Mess_Integral_Gier2  -= tmp_int;  
708
    Mess_Integral_Gier2  -= tmp_int;  
689
// Salvo End *************************
709
// Salvo End *************************
690
 ANALOG_ON;     // ADC einschalten
710
 ANALOG_ON;     // ADC einschalten
691
 
711
 
692
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
712
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
693
//  Kompass
713
//  Kompass
694
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
714
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
695
 //KompassValue = 12;
715
 //KompassValue = 12;
696
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
716
    if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV))
697
     {
717
     {
698
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
718
       w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln
699
       v = abs(IntegralRoll /512);
719
       v = abs(IntegralRoll /512);
700
       if(v > w) w = v; // grösste Neigung ermitteln
720
       if(v > w) w = v; // grösste Neigung ermitteln
701
       if(w < 20 && NeueKompassRichtungMerken && !SignalSchlecht)    
721
       if(w < 20 && NeueKompassRichtungMerken && !SignalSchlecht)    
702
        {
722
        {
703
         KompassStartwert = KompassValue;
723
         KompassStartwert = KompassValue;
704
         NeueKompassRichtungMerken = 0;
724
         NeueKompassRichtungMerken = 0;
705
        }
725
        }
706
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
726
       w = (w * Parameter_KompassWirkung) / 64;           // auf die Wirkung normieren
707
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
727
       w = Parameter_KompassWirkung - w;                  // Wirkung ggf drosseln
708
       if(w > 0)
728
       if(w > 0)
709
        {
729
        {
710
          ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
730
          ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern
711
 
731
 
712
// Salvo 30.8.2007 Winkelbegrenzung **********************
732
// Salvo 30.8.2007 Winkelbegrenzung **********************
713
         if ((!SignalSchlecht) )
733
         if ((!SignalSchlecht) )
714
                 {
734
                 {
715
                        if (abs(KompassRichtung) < 135 )
735
                        if (abs(KompassRichtung) < 135 )
716
                        {
736
                        {
717
                                Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
737
                                Mess_Integral_Gier += (KompassRichtung * w) / 32;  // nach Kompass ausrichten
718
                        }
738
                        }
719
                 }
739
                 }
720
 // Salvo End *************************
740
 // Salvo End *************************
721
 
741
 
722
          ANALOG_ON;  // ADC einschalten
742
          ANALOG_ON;  // ADC einschalten
723
          if(SignalSchlecht) SignalSchlecht--;
743
          if(SignalSchlecht) SignalSchlecht--;
724
        }  
744
        }  
725
        else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
745
        else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek
726
     }
746
     }
727
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
747
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
728
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
748
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
729
 
749
 
730
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
750
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
731
//  Debugwerte zuordnen
751
//  Debugwerte zuordnen
732
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
752
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
733
DebugOut.Sekunden++;
753
DebugOut.Sekunden++;
734
  if(!TimerWerteausgabe--)
754
  if(!TimerWerteausgabe--)
735
   {
755
   {
736
    TimerWerteausgabe = 49;
756
    TimerWerteausgabe = 49;
737
//    DebugOut.Analog[0] = MesswertNick;
757
//    DebugOut.Analog[0] = MesswertNick;
738
//    DebugOut.Analog[1] = MesswertRoll;
758
//    DebugOut.Analog[1] = MesswertRoll;
739
//    DebugOut.Analog[2] = MesswertGier;
759
//    DebugOut.Analog[2] = MesswertGier;
740
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
760
    DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor;
741
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
761
    DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor;
742
    DebugOut.Analog[2] = Mittelwert_AccNick;
762
    DebugOut.Analog[2] = Mittelwert_AccNick;
743
    DebugOut.Analog[3] = Mittelwert_AccRoll;
763
    DebugOut.Analog[3] = Mittelwert_AccRoll;
744
    DebugOut.Analog[4] = MesswertGier;
764
    DebugOut.Analog[4] = MesswertGier;
745
    DebugOut.Analog[5] = HoehenWert;
765
    DebugOut.Analog[5] = HoehenWert;
746
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
766
    DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);
747
    DebugOut.Analog[7] = GasMischanteil;
767
    DebugOut.Analog[7] = GasMischanteil;
748
    DebugOut.Analog[8] = KompassValue;
768
    DebugOut.Analog[8] = KompassValue;
749
    DebugOut.Analog[9] = tmp_long;
769
    DebugOut.Analog[9] = GyroKomp_Int;
750
    DebugOut.Analog[10] = tmp_long2;
770
    DebugOut.Analog[10] = GyroKomp_Int2;
-
 
771
 
751
//    DebugOut.Analog[9] = SollHoehe;
772
//    DebugOut.Analog[9] = SollHoehe;
752
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
773
//    DebugOut.Analog[10] = Mess_Integral_Gier / 128;
753
//    DebugOut.Analog[11] = KompassStartwert;
774
//    DebugOut.Analog[11] = KompassStartwert;
754
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
775
//    DebugOut.Analog[10] = Parameter_Gyro_I;    
755
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
776
//    DebugOut.Analog[10] = EE_Parameter.Gyro_I;    
756
//    DebugOut.Analog[9] = KompassRichtung;    
777
//    DebugOut.Analog[9] = KompassRichtung;    
757
//    DebugOut.Analog[10] = GasMischanteil;
778
//    DebugOut.Analog[10] = GasMischanteil;
758
//    DebugOut.Analog[3] = HoeheD * 32;
779
//    DebugOut.Analog[3] = HoeheD * 32;
759
//    DebugOut.Analog[4] = hoehenregler;
780
//    DebugOut.Analog[4] = hoehenregler;
760
  }
781
  }
761
 
782
 
762
 
783
 
763
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
784
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
764
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
785
//  Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen
765
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
786
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
766
    MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
787
    MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor;
767
    MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
788
    MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor;
768
    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
789
    MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor;
769
 
790
 
770
    // Maximalwerte abfangen
791
    // Maximalwerte abfangen
771
    #define MAX_SENSOR  2048
792
    #define MAX_SENSOR  2048
772
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
793
    if(MesswertNick >  MAX_SENSOR) MesswertNick =  MAX_SENSOR;
773
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
794
    if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR;
774
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
795
    if(MesswertRoll >  MAX_SENSOR) MesswertRoll =  MAX_SENSOR;
775
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
796
    if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR;
776
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
797
    if(MesswertGier >  MAX_SENSOR) MesswertGier =  MAX_SENSOR;
777
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
798
    if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR;
778
 
799
 
779
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
800
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
780
// Höhenregelung
801
// Höhenregelung
781
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
802
// Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht
782
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
803
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
783
//OCR0B = 180 - (Poti1 + 120) / 4;
804
//OCR0B = 180 - (Poti1 + 120) / 4;
784
//DruckOffsetSetting = OCR0B;
805
//DruckOffsetSetting = OCR0B;
785
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
806
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung
786
  {
807
  {
787
    int tmp_int;
808
    int tmp_int;
788
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
809
    if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)  // Regler wird über Schalter gesteuert
789
    {
810
    {
790
     if(Parameter_MaxHoehe < 50)
811
     if(Parameter_MaxHoehe < 50)
791
      {
812
      {
792
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
813
       SollHoehe = HoehenWert - 20;  // Parameter_MaxHoehe ist der PPM-Wert des Schalters
793
       HoehenReglerAktiv = 0;
814
       HoehenReglerAktiv = 0;
794
      }
815
      }
795
      else  
816
      else  
796
        HoehenReglerAktiv = 1;
817
        HoehenReglerAktiv = 1;
797
    }
818
    }
798
    else
819
    else
799
    {
820
    {
800
     SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20;
821
     SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20;
801
     HoehenReglerAktiv = 1;
822
     HoehenReglerAktiv = 1;
802
    }
823
    }
803
 
824
 
804
    if(Notlandung) SollHoehe = 0;
825
    if(Notlandung) SollHoehe = 0;
805
    h = HoehenWert;
826
    h = HoehenWert;
806
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
827
    if((h > SollHoehe) && HoehenReglerAktiv)      // zu hoch --> drosseln
807
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
828
     {      h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil
808
      h = GasMischanteil - h;         // vom Gas abziehen
829
      h = GasMischanteil - h;         // vom Gas abziehen
809
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
830
      h -= (HoeheD * Parameter_Luftdruck_D)/8;    // D-Anteil
810
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
831
      tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32;
811
      if(tmp_int > 50) tmp_int = 50;
832
      if(tmp_int > 50) tmp_int = 50;
812
      else if(tmp_int < -50) tmp_int = -50;
833
      else if(tmp_int < -50) tmp_int = -50;
813
      h -= tmp_int;
834
      h -= tmp_int;
814
      hoehenregler = (hoehenregler*15 + h) / 16;      
835
      hoehenregler = (hoehenregler*15 + h) / 16;      
815
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
836
      if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN
816
       {
837
       {
817
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
838
         if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas;
818
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
839
         if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil;
819
       }  
840
       }  
820
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
841
      if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas
821
      GasMischanteil = hoehenregler;
842
      GasMischanteil = hoehenregler;
822
     }
843
     }
823
  }
844
  }
824
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
845
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
825
// + Mischer und PI-Regler
846
// + Mischer und PI-Regler
826
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
847
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
827
 
848
 
828
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
849
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
829
// Gier-Anteil
850
// Gier-Anteil
830
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
851
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
831
        GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
852
        GierMischanteil = MesswertGier - sollGier;     // Regler für Gier
832
    if(GierMischanteil > 100)  GierMischanteil = 100;
853
    if(GierMischanteil > 100)  GierMischanteil = 100;
833
    if(GierMischanteil < -100) GierMischanteil = -100;
854
    if(GierMischanteil < -100) GierMischanteil = -100;
834
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
855
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
835
// Nick-Achse
856
// Nick-Achse
836
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
857
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
837
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
858
    DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick));    // Differenz bestimmen
838
    SummeNick += DiffNick;                                   // I-Anteil
859
    SummeNick += DiffNick;                                   // I-Anteil
839
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
860
    if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1;
840
    if(SummeNick >  16000) SummeNick =  16000;
861
    if(SummeNick >  16000) SummeNick =  16000;
841
    if(SummeNick < -16000) SummeNick = -16000;
862
    if(SummeNick < -16000) SummeNick = -16000;
842
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
863
    pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick                                      
843
    // Motor Vorn
864
    // Motor Vorn
844
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
865
    motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;   // Mischer
845
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
866
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
846
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
867
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
847
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
868
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
848
        Motor_Vorne = motorwert;           
869
        Motor_Vorne = motorwert;           
849
    // Motor Heck
870
    // Motor Heck
850
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
871
        motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
851
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
872
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
852
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
873
        else if(motorwert > MAX_GAS)        motorwert = MAX_GAS;
853
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
874
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
854
        Motor_Hinten = motorwert;              
875
        Motor_Hinten = motorwert;              
855
 
876
 
856
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
877
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
857
// Roll-Achse
878
// Roll-Achse
858
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
879
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                
859
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
880
        DiffRoll = Kp * (MesswertRoll - (StickRoll  - GPS_Roll));       // Differenz bestimmen
860
        SummeRoll += DiffRoll;                                                              // I-Anteil
881
        SummeRoll += DiffRoll;                                                              // I-Anteil
861
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
882
    if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1;
862
    if(SummeRoll >  16000) SummeRoll =  16000;
883
    if(SummeRoll >  16000) SummeRoll =  16000;
863
    if(SummeRoll < -16000) SummeRoll = -16000;
884
    if(SummeRoll < -16000) SummeRoll = -16000;
864
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
885
    pd_ergebnis = DiffRoll + Ki * SummeRoll;    // PI-Regler für Roll
865
    // Motor Links
886
    // Motor Links
866
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
887
    motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
867
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
888
        if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0;
868
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
889
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
869
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
890
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;
870
        Motor_Links = motorwert;               
891
        Motor_Links = motorwert;               
871
    // Motor Rechts
892
    // Motor Rechts
872
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
893
        motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
873
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
894
        if ((motorwert < 0) | (GasMischanteil < 10))    motorwert = 0;
874
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
895
        else if(motorwert > MAX_GAS)            motorwert = MAX_GAS;
875
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
896
        if (motorwert < MIN_GAS)            motorwert = MIN_GAS;       
876
        Motor_Rechts = motorwert;
897
        Motor_Rechts = motorwert;
877
   // +++++++++++++++++++++++++++++++++++++++++++++++
898
   // +++++++++++++++++++++++++++++++++++++++++++++++
878
 
899
 
879
}
900
}
880
 
901
 
881
 
902