Rev 273 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 273 | Rev 277 | ||
---|---|---|---|
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 int I2CTimeout = 100; |
59 | volatile unsigned int I2CTimeout = 100; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
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 | 78 | ||
79 | unsigned char blinkcount_LED1 = 0;//Hilfszähler für die blinkende LED (310807Kr) |
79 | unsigned char blinkcount_LED1 = 0;//Hilfszähler für die blinkende LED (310807Kr) |
80 | unsigned int modell_fliegt_gps = 0;//(030907Kr) |
80 | unsigned int modell_fliegt_gps = 0;//(030907Kr) |
81 | unsigned char Limit_D_Anteil = 0;//(210907Kr) |
81 | unsigned char Limit_D_Anteil = 0;//(210907Kr) |
82 | 82 | ||
83 | float GyroFaktor; |
83 | float GyroFaktor; |
84 | float IntegralFaktor; |
84 | float IntegralFaktor; |
85 | 85 | ||
86 | volatile int DiffNick,DiffRoll; |
86 | volatile int DiffNick,DiffRoll; |
87 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; //PPM24-Erweiterung (121007Kr) |
87 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; //PPM24-Erweiterung (121007Kr) |
88 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
88 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
89 | unsigned char MotorWert[5]; |
89 | unsigned char MotorWert[5]; |
90 | volatile unsigned char SenderOkay = 0; |
90 | volatile unsigned char SenderOkay = 0; |
91 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
91 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
92 | char MotorenEin = 0; |
92 | char MotorenEin = 0; |
93 | int HoehenWert = 0; |
93 | int HoehenWert = 0; |
94 | int SollHoehe = 0; |
94 | int SollHoehe = 0; |
95 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
95 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
96 | 96 | ||
97 | float Kp = FAKTOR_P; |
97 | float Kp = FAKTOR_P; |
98 | float Ki = FAKTOR_I; |
98 | float Ki = FAKTOR_I; |
99 | 99 | ||
100 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
100 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
101 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
101 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
102 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
102 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
103 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
103 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
104 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
104 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
105 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
105 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
106 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
106 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
107 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
107 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
108 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
108 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
109 | unsigned char Parameter_UserParam1 = 0; |
109 | unsigned char Parameter_UserParam1 = 0; |
110 | unsigned char Parameter_UserParam2 = 0; |
110 | unsigned char Parameter_UserParam2 = 0; |
111 | unsigned char Parameter_UserParam3 = 0; |
111 | unsigned char Parameter_UserParam3 = 0; |
112 | unsigned char Parameter_UserParam4 = 0; |
112 | unsigned char Parameter_UserParam4 = 0; |
113 | unsigned char Parameter_ServoNickControl = 100; |
113 | unsigned char Parameter_ServoNickControl = 100; |
114 | unsigned char Parameter_LoopGasLimit = 70; |
114 | unsigned char Parameter_LoopGasLimit = 70; |
115 | struct mk_param_struct EE_Parameter; |
115 | struct mk_param_struct EE_Parameter; |
116 | 116 | ||
117 | void Piep(unsigned char Anzahl) |
117 | void Piep(unsigned char Anzahl) |
118 | { |
118 | { |
119 | while(Anzahl--) |
119 | while(Anzahl--) |
120 | { |
120 | { |
121 | if(MotorenEin) return; //auf keinen Fall im Flug! |
121 | if(MotorenEin) return; //auf keinen Fall im Flug! |
122 | beeptime = 100; |
122 | beeptime = 100; |
123 | Delay_ms(250); |
123 | Delay_ms(250); |
124 | } |
124 | } |
125 | } |
125 | } |
126 | 126 | ||
127 | //############################################################################ |
127 | //############################################################################ |
128 | // Nullwerte ermitteln |
128 | // Nullwerte ermitteln |
129 | void SetNeutral(void) |
129 | void SetNeutral(void) |
130 | //############################################################################ |
130 | //############################################################################ |
131 | { |
131 | { |
132 | unsigned int timer; |
132 | unsigned int timer; |
133 | NeutralAccX = 0; |
133 | NeutralAccX = 0; |
134 | NeutralAccY = 0; |
134 | NeutralAccY = 0; |
135 | NeutralAccZ = 0; |
135 | NeutralAccZ = 0; |
136 | AdNeutralNick = 0; |
136 | AdNeutralNick = 0; |
137 | AdNeutralRoll = 0; |
137 | AdNeutralRoll = 0; |
138 | AdNeutralGier = 0; |
138 | AdNeutralGier = 0; |
139 | CalibrierMittelwert(); |
139 | CalibrierMittelwert(); |
140 | timer = SetDelay(5); |
140 | timer = SetDelay(5); |
141 | while (!CheckDelay(timer)); |
141 | while (!CheckDelay(timer)); |
142 | CalibrierMittelwert(); |
142 | CalibrierMittelwert(); |
143 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
143 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
144 | { |
144 | { |
145 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
145 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
146 | } |
146 | } |
147 | 147 | ||
148 | if(PlatinenVersion == 10) |
148 | if(PlatinenVersion == 10) |
149 | { |
149 | { |
150 | AdNeutralNick= abs(MesswertNick); |
150 | AdNeutralNick= abs(MesswertNick); |
151 | AdNeutralRoll= abs(MesswertRoll); |
151 | AdNeutralRoll= abs(MesswertRoll); |
152 | AdNeutralGier= abs(MesswertGier); |
152 | AdNeutralGier= abs(MesswertGier); |
153 | } |
153 | } |
154 | else |
154 | else |
155 | { |
155 | { |
156 | AdNeutralNick= abs(MesswertNick) / 2; |
156 | AdNeutralNick= abs(MesswertNick) / 2; |
157 | AdNeutralRoll= abs(MesswertRoll) / 2; |
157 | AdNeutralRoll= abs(MesswertRoll) / 2; |
158 | AdNeutralGier= abs(MesswertGier) / 2; |
158 | AdNeutralGier= abs(MesswertGier) / 2; |
159 | } |
159 | } |
160 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
160 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
161 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
161 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
162 | NeutralAccZ = Aktuell_az; |
162 | NeutralAccZ = Aktuell_az; |
163 | 163 | ||
164 | Mess_IntegralNick = 0; |
164 | Mess_IntegralNick = 0; |
165 | Mess_IntegralNick2 = 0; |
165 | Mess_IntegralNick2 = 0; |
166 | Mess_IntegralRoll = 0; |
166 | Mess_IntegralRoll = 0; |
167 | Mess_IntegralRoll2 = 0; |
167 | Mess_IntegralRoll2 = 0; |
168 | Mess_Integral_Gier = 0; |
168 | Mess_Integral_Gier = 0; |
169 | MesswertNick = 0; |
169 | MesswertNick = 0; |
170 | MesswertRoll = 0; |
170 | MesswertRoll = 0; |
171 | MesswertGier = 0; |
171 | MesswertGier = 0; |
172 | StartLuftdruck = Luftdruck; |
172 | StartLuftdruck = Luftdruck; |
173 | HoeheD = 0; |
173 | HoeheD = 0; |
174 | Mess_Integral_Hoch = 0; |
174 | Mess_Integral_Hoch = 0; |
175 | KompassStartwert = KompassValue; |
175 | KompassStartwert = KompassValue; |
176 | beeptime = 50; |
176 | beeptime = 50; |
177 | } |
177 | } |
178 | 178 | ||
179 | //############################################################################ |
179 | //############################################################################ |
180 | // Bildet den Mittelwert aus den Messwerten |
180 | // Bildet den Mittelwert aus den Messwerten |
181 | void Mittelwert(void) |
181 | void Mittelwert(void) |
182 | //############################################################################ |
182 | //############################################################################ |
183 | { |
183 | { |
184 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
184 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
185 | ANALOG_OFF; |
185 | ANALOG_OFF; |
186 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
186 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
187 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
187 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
188 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
188 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
189 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
189 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
190 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
190 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
191 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
191 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
192 | AccumulateNick = 0; MessanzahlNick = 0; |
192 | AccumulateNick = 0; MessanzahlNick = 0; |
193 | AccumulateRoll = 0; MessanzahlRoll = 0; |
193 | AccumulateRoll = 0; MessanzahlRoll = 0; |
194 | AccumulateGier = 0; MessanzahlGier = 0; |
194 | AccumulateGier = 0; MessanzahlGier = 0; |
195 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
195 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
196 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
196 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
197 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
197 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
198 | Integral_Gier = Mess_Integral_Gier; |
198 | Integral_Gier = Mess_Integral_Gier; |
199 | // Integral_Gier2 = Mess_Integral_Gier2; |
199 | // Integral_Gier2 = Mess_Integral_Gier2; |
200 | IntegralNick = Mess_IntegralNick; |
200 | IntegralNick = Mess_IntegralNick; |
201 | IntegralRoll = Mess_IntegralRoll; |
201 | IntegralRoll = Mess_IntegralRoll; |
202 | IntegralNick2 = Mess_IntegralNick2; |
202 | IntegralNick2 = Mess_IntegralNick2; |
203 | IntegralRoll2 = Mess_IntegralRoll2; |
203 | IntegralRoll2 = Mess_IntegralRoll2; |
204 | // ADC einschalten |
204 | // ADC einschalten |
205 | ANALOG_ON; |
205 | ANALOG_ON; |
206 | 206 | ||
207 | /* |
207 | /* |
208 | //------------------------------------------------------------------------------ |
208 | //------------------------------------------------------------------------------ |
209 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
209 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
210 | else |
210 | else |
211 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
211 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
212 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
212 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
213 | else |
213 | else |
214 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
214 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
215 | //------------------------------------------------------------------------------ |
215 | //------------------------------------------------------------------------------ |
216 | */ |
216 | */ |
217 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
217 | 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(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
218 | 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(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
219 | 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(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
220 | 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 | //PPM24-Erweiterung (121007Kr) |
221 | //PPM24-Erweiterung (121007Kr) |
222 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
222 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
223 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
223 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
224 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
224 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
225 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
225 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
226 | 226 | ||
227 | 227 | ||
228 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
228 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
229 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
229 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
230 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
230 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
231 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
231 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
232 | //PPM24-Erweiterung (121007Kr) |
232 | //PPM24-Erweiterung (121007Kr) |
233 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
233 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
234 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
234 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
235 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
235 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
236 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
236 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
237 | } |
237 | } |
238 | 238 | ||
239 | //############################################################################ |
239 | //############################################################################ |
240 | // Messwerte beim Ermitteln der Nullage |
240 | // Messwerte beim Ermitteln der Nullage |
241 | void CalibrierMittelwert(void) |
241 | void CalibrierMittelwert(void) |
242 | //############################################################################ |
242 | //############################################################################ |
243 | { |
243 | { |
244 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
244 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
245 | ANALOG_OFF; |
245 | ANALOG_OFF; |
246 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
246 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
247 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
247 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
248 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
248 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
249 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
249 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
250 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
250 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
251 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
251 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
252 | AccumulateNick = 0; MessanzahlNick = 0; |
252 | AccumulateNick = 0; MessanzahlNick = 0; |
253 | AccumulateRoll = 0; MessanzahlRoll = 0; |
253 | AccumulateRoll = 0; MessanzahlRoll = 0; |
254 | AccumulateGier = 0; MessanzahlGier = 0; |
254 | AccumulateGier = 0; MessanzahlGier = 0; |
255 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
255 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
256 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
256 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
257 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
257 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
258 | // ADC einschalten |
258 | // ADC einschalten |
259 | ANALOG_ON; |
259 | ANALOG_ON; |
260 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
260 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
261 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
261 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
262 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
262 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
263 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
263 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
264 | //PPM24-Erweiterung (121007Kr) |
264 | //PPM24-Erweiterung (121007Kr) |
265 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
265 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
266 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
266 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
267 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
267 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
268 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
268 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
269 | 269 | ||
270 | 270 | ||
271 | 271 | ||
272 | 272 | ||
273 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
273 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
274 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
274 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
275 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
275 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
276 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
276 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
277 | //PPM24-Erweiterung (121007Kr) |
277 | //PPM24-Erweiterung (121007Kr) |
278 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
278 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
279 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
279 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
280 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
280 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
281 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
281 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
282 | } |
282 | } |
283 | 283 | ||
284 | //############################################################################ |
284 | //############################################################################ |
285 | // Senden der Motorwerte per I2C-Bus |
285 | // Senden der Motorwerte per I2C-Bus |
286 | void SendMotorData(void) |
286 | void SendMotorData(void) |
287 | //############################################################################ |
287 | //############################################################################ |
288 | { |
288 | { |
289 | if(MOTOR_OFF || !MotorenEin) |
289 | if(MOTOR_OFF || !MotorenEin) |
290 | { |
290 | { |
291 | Motor_Hinten = 0; |
291 | Motor_Hinten = 0; |
292 | Motor_Vorne = 0; |
292 | Motor_Vorne = 0; |
293 | Motor_Rechts = 0; |
293 | Motor_Rechts = 0; |
294 | Motor_Links = 0; |
294 | Motor_Links = 0; |
295 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
295 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
296 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
296 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
297 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
297 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
298 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
298 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
299 | } |
299 | } |
300 | 300 | ||
301 | // DebugOut.Analog[12] = Motor_Vorne; |
301 | // DebugOut.Analog[12] = Motor_Vorne; |
302 | // DebugOut.Analog[13] = Motor_Hinten; |
302 | // DebugOut.Analog[13] = Motor_Hinten; |
303 | // DebugOut.Analog[14] = Motor_Links; |
303 | // DebugOut.Analog[14] = Motor_Links; |
304 | // DebugOut.Analog[15] = Motor_Rechts; |
304 | // DebugOut.Analog[15] = Motor_Rechts; |
305 | 305 | ||
306 | // DebugOut.Analog[12] = motor_rx[0]; //Motorstrom vorne |
306 | // DebugOut.Analog[12] = motor_rx[0]; //Motorstrom vorne |
307 | // DebugOut.Analog[13] = motor_rx[1]; //Motorstrom hinten |
307 | // DebugOut.Analog[13] = motor_rx[1]; //Motorstrom hinten |
308 | // DebugOut.Analog[14] = motor_rx[2]; //Motorstrom links |
308 | // DebugOut.Analog[14] = motor_rx[2]; //Motorstrom links |
309 | // DebugOut.Analog[15] = motor_rx[3]; //Motorstrom rechts |
309 | // DebugOut.Analog[15] = motor_rx[3]; //Motorstrom rechts |
310 | 310 | ||
311 | 311 | ||
312 | //Start I2C Interrupt Mode |
312 | //Start I2C Interrupt Mode |
313 | twi_state = 0; |
313 | twi_state = 0; |
314 | motor = 0; |
314 | motor = 0; |
315 | i2c_start(); |
315 | i2c_start(); |
316 | } |
316 | } |
317 | 317 | ||
318 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
318 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
319 | // + Konstanten |
319 | // + Konstanten |
320 | // + 0-250 -> normale Werte |
320 | // + 0-250 -> normale Werte |
321 | // + 251 -> Poti1 |
321 | // + 251 -> Poti1 |
322 | // + 252 -> Poti2 |
322 | // + 252 -> Poti2 |
323 | // + 253 -> Poti3 |
323 | // + 253 -> Poti3 |
324 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
324 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
325 | void DefaultKonstanten1(void) |
325 | void DefaultKonstanten1(void) |
326 | { |
326 | { |
327 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
327 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
328 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
328 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
329 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
329 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
330 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
330 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
331 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
331 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
332 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
332 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
333 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
333 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
334 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
334 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
335 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
335 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
336 | EE_Parameter.Hoehe_MinGas = 30; |
336 | EE_Parameter.Hoehe_MinGas = 30; |
337 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
337 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
338 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
338 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
339 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
339 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
340 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
340 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
341 | EE_Parameter.Hoehe_Verstaerkung = 4; // Wert : 0-50 |
341 | EE_Parameter.Hoehe_Verstaerkung = 4; // Wert : 0-50 |
342 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
342 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
343 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
343 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
344 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
344 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
345 | EE_Parameter.Gas_Min = 5; // Wert : 0-32 // (160607Kr) |
345 | EE_Parameter.Gas_Min = 5; // Wert : 0-32 // (160607Kr) |
346 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
346 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
347 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
347 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
348 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
348 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
349 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
349 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
350 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
350 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
351 | EE_Parameter.UnterspannungsWarnung = 95; // Wert : 0-250 // (160607Kr) |
351 | EE_Parameter.UnterspannungsWarnung = 95; // Wert : 0-250 // (160607Kr) |
352 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
352 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
353 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
353 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
354 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
354 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
355 | EE_Parameter.I_Faktor = 0; |
355 | EE_Parameter.I_Faktor = 0; |
356 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
356 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
357 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
357 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
358 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
358 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
359 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
359 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
360 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
360 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
361 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
361 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
362 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
362 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
363 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
363 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
364 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
364 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
365 | EE_Parameter.ServoNickRefresh = 5; |
365 | EE_Parameter.ServoNickRefresh = 5; |
366 | EE_Parameter.LoopGasLimit = 50; |
366 | EE_Parameter.LoopGasLimit = 50; |
367 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
367 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
368 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
368 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
369 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
369 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
370 | } |
370 | } |
371 | 371 | ||
372 | void DefaultKonstanten2(void) |
372 | void DefaultKonstanten2(void) |
373 | { |
373 | { |
374 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
374 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
375 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
375 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
376 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
376 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
377 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
377 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
378 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
378 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
379 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
379 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
380 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
380 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
381 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
381 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
382 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
382 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
383 | EE_Parameter.Hoehe_MinGas = 30; |
383 | EE_Parameter.Hoehe_MinGas = 30; |
384 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
384 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
385 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
385 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
386 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
386 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
387 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
387 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
388 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
388 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
389 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
389 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
390 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
390 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
391 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
391 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
392 | EE_Parameter.Gas_Min = 5; // Wert : 0-32 // (160607Kr) |
392 | EE_Parameter.Gas_Min = 5; // Wert : 0-32 // (160607Kr) |
393 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
393 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
394 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
394 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
395 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
395 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
396 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
396 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
397 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
397 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
398 | EE_Parameter.UnterspannungsWarnung = 95; // Wert : 0-250 // (160607Kr) |
398 | EE_Parameter.UnterspannungsWarnung = 95; // Wert : 0-250 // (160607Kr) |
399 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
399 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
400 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
400 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
401 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
401 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
402 | EE_Parameter.I_Faktor = 0; |
402 | EE_Parameter.I_Faktor = 0; |
403 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
403 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
404 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
404 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
405 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
405 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
406 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
406 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
407 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
407 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
408 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
408 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
409 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
409 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
410 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
410 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
411 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
411 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
412 | EE_Parameter.ServoNickRefresh = 5; |
412 | EE_Parameter.ServoNickRefresh = 5; |
413 | EE_Parameter.LoopGasLimit = 50; |
413 | EE_Parameter.LoopGasLimit = 50; |
414 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
414 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
415 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
415 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
416 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
416 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
417 | } |
417 | } |
418 | 418 | ||
419 | 419 | ||
420 | //############################################################################ |
420 | //############################################################################ |
421 | // Trägt ggf. das Poti als Parameter ein |
421 | // Trägt ggf. das Poti als Parameter ein |
422 | void ParameterZuordnung(void) |
422 | void ParameterZuordnung(void) |
423 | //############################################################################ |
423 | //############################################################################ |
424 | { |
424 | { |
425 | 425 | ||
426 | #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;} |
426 | #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;} |
427 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
427 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
428 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
428 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
429 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
429 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
430 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
430 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
431 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
431 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
432 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
432 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
433 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
433 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
434 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
434 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
435 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
435 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
436 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
436 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
437 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
437 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
438 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
438 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
439 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
439 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
440 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
440 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
441 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
441 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
442 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
442 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
443 | 443 | ||
444 | Ki = (float) Parameter_I_Faktor * 0.0001; |
444 | Ki = (float) Parameter_I_Faktor * 0.0001; |
445 | MAX_GAS = EE_Parameter.Gas_Max; |
445 | MAX_GAS = EE_Parameter.Gas_Max; |
446 | MIN_GAS = EE_Parameter.Gas_Min; |
446 | MIN_GAS = EE_Parameter.Gas_Min; |
447 | } |
447 | } |
448 | 448 | ||
449 | 449 | ||
450 | //############################################################################ |
450 | //############################################################################ |
451 | // |
451 | // |
452 | void MotorRegler(void) |
452 | void MotorRegler(void) |
453 | //############################################################################ |
453 | //############################################################################ |
454 | { |
454 | { |
455 | int motorwert,pd_ergebnis,h,tmp_int; |
455 | int motorwert,pd_ergebnis,h,tmp_int; |
456 | int GierMischanteil,GasMischanteil; |
456 | int GierMischanteil,GasMischanteil; |
457 | static long SummeNick=0,SummeRoll=0; |
457 | static long SummeNick=0,SummeRoll=0; |
458 | static long sollGier = 0,tmp_long,tmp_long2; |
458 | static long sollGier = 0,tmp_long,tmp_long2; |
459 | long IntegralFehlerNick = 0; |
459 | long IntegralFehlerNick = 0; |
460 | long IntegralFehlerRoll = 0; |
460 | long IntegralFehlerRoll = 0; |
461 | static unsigned int RcLostTimer; |
461 | static unsigned int RcLostTimer; |
462 | static unsigned char delay_neutral = 0; |
462 | static unsigned char delay_neutral = 0; |
463 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
463 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
464 | static unsigned int modell_fliegt = 0; |
464 | static unsigned int modell_fliegt = 0; |
465 | static int hoehenregler = 0; |
465 | static int hoehenregler = 0; |
466 | static char TimerWerteausgabe = 0; |
466 | static char TimerWerteausgabe = 0; |
467 | static char NeueKompassRichtungMerken = 0; |
467 | static char NeueKompassRichtungMerken = 0; |
468 | Mittelwert(); |
468 | Mittelwert(); |
469 | 469 | ||
470 | GRN_ON; |
470 | GRN_ON; |
471 | 471 | ||
472 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
472 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
473 | // Gaswert ermitteln |
473 | // Gaswert ermitteln |
474 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
474 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
475 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
475 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
476 | if(GasMischanteil < 0) GasMischanteil = 0; |
476 | if(GasMischanteil < 0) GasMischanteil = 0; |
477 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
477 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
478 | // Emfang schlecht |
478 | // Emfang schlecht |
479 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
479 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
480 | if(SenderOkay < 100) |
480 | if(SenderOkay < 100) |
481 | { |
481 | { |
482 | if(!PcZugriff) |
482 | if(!PcZugriff) |
483 | { |
483 | { |
484 | if(BeepMuster == 0xffff) |
484 | if(BeepMuster == 0xffff) |
485 | { |
485 | { |
486 | beeptime = 15000; |
486 | beeptime = 15000; |
487 | BeepMuster = 0x0c00; |
487 | BeepMuster = 0x0c00; |
488 | } |
488 | } |
489 | } |
489 | } |
490 | if(RcLostTimer) RcLostTimer--; |
490 | if(RcLostTimer) RcLostTimer--; |
491 | else |
491 | else |
492 | { |
492 | { |
493 | MotorenEin = 0; |
493 | MotorenEin = 0; |
494 | Notlandung = 0; |
494 | Notlandung = 0; |
495 | } |
495 | } |
496 | ROT_ON; |
496 | ROT_ON; |
497 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
497 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
498 | { |
498 | { |
499 | GasMischanteil = EE_Parameter.NotGas; |
499 | GasMischanteil = EE_Parameter.NotGas; |
500 | Notlandung = 1; |
500 | Notlandung = 1; |
501 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
501 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
502 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
502 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
503 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
503 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
504 | } |
504 | } |
505 | else MotorenEin = 0; |
505 | else MotorenEin = 0; |
506 | } |
506 | } |
507 | else |
507 | else |
508 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
508 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
509 | // Emfang gut |
509 | // Emfang gut |
510 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
510 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
511 | if(SenderOkay > 140) |
511 | if(SenderOkay > 140) |
512 | { |
512 | { |
513 | Notlandung = 0; |
513 | Notlandung = 0; |
514 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
514 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
515 | if(GasMischanteil > 40) |
515 | if(GasMischanteil > 40) |
516 | { |
516 | { |
517 | if(modell_fliegt < 0xffff) modell_fliegt++; |
517 | if(modell_fliegt < 0xffff) modell_fliegt++; |
518 | modell_fliegt_gps = modell_fliegt;// (030907Kr) |
518 | modell_fliegt_gps = modell_fliegt;// (030907Kr) |
519 | } |
519 | } |
520 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
520 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
521 | { |
521 | { |
522 | SummeNick = 0; |
522 | SummeNick = 0; |
523 | SummeRoll = 0; |
523 | SummeRoll = 0; |
524 | Mess_Integral_Gier = 0; |
524 | Mess_Integral_Gier = 0; |
525 | Mess_Integral_Gier2 = 0; |
525 | Mess_Integral_Gier2 = 0; |
526 | } |
526 | } |
527 | if((GasMischanteil > 200) && MotorenEin == 0) |
527 | if((GasMischanteil > 200) && MotorenEin == 0) |
528 | { |
528 | { |
529 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
529 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
530 | // auf Nullwerte kalibrieren |
530 | // auf Nullwerte kalibrieren |
531 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
531 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
532 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
532 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
533 | { |
533 | { |
534 | unsigned char setting; |
534 | unsigned char setting; |
535 | if(++delay_neutral > 200) // nicht sofort |
535 | if(++delay_neutral > 200) // nicht sofort |
536 | { |
536 | { |
537 | GRN_OFF; |
537 | GRN_OFF; |
538 | MotorenEin = 0; |
538 | MotorenEin = 0; |
539 | delay_neutral = 0; |
539 | delay_neutral = 0; |
540 | modell_fliegt = 0; |
540 | modell_fliegt = 0; |
541 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
541 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
542 | { |
542 | { |
543 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
543 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
544 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
544 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
545 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
545 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
546 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
546 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
547 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
547 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
548 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
548 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
549 | } |
549 | } |
550 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
550 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
551 | { |
551 | { |
552 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
552 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
553 | } |
553 | } |
554 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
554 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
555 | SetNeutral(); |
555 | SetNeutral(); |
556 | Piep(GetActiveParamSetNumber()); |
556 | Piep(GetActiveParamSetNumber()); |
557 | } |
557 | } |
558 | } |
558 | } |
559 | else delay_neutral = 0; |
559 | else delay_neutral = 0; |
560 | } |
560 | } |
561 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
561 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
562 | // Gas ist unten |
562 | // Gas ist unten |
563 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
563 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
564 | if(GasMischanteil < 35) |
564 | if(GasMischanteil < 35) |
565 | { |
565 | { |
566 | // Starten |
566 | // Starten |
567 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
567 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
568 | { |
568 | { |
569 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
569 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
570 | // Einschalten |
570 | // Einschalten |
571 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
571 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
572 | if(++delay_einschalten > 200) |
572 | if(++delay_einschalten > 200) |
573 | { |
573 | { |
574 | delay_einschalten = 200; |
574 | delay_einschalten = 200; |
575 | modell_fliegt = 1; |
575 | modell_fliegt = 1; |
576 | MotorenEin = 1; |
576 | MotorenEin = 1; |
577 | sollGier = 0; |
577 | sollGier = 0; |
578 | Mess_Integral_Gier = 0; |
578 | Mess_Integral_Gier = 0; |
579 | Mess_Integral_Gier2 = 0; |
579 | Mess_Integral_Gier2 = 0; |
580 | Mess_IntegralNick = 0; |
580 | Mess_IntegralNick = 0; |
581 | Mess_IntegralRoll = 0; |
581 | Mess_IntegralRoll = 0; |
582 | Mess_IntegralNick2 = IntegralNick; |
582 | Mess_IntegralNick2 = IntegralNick; |
583 | Mess_IntegralRoll2 = IntegralRoll; |
583 | Mess_IntegralRoll2 = IntegralRoll; |
584 | SummeNick = 0; |
584 | SummeNick = 0; |
585 | SummeRoll = 0; |
585 | SummeRoll = 0; |
586 | } |
586 | } |
587 | } |
587 | } |
588 | else delay_einschalten = 0; |
588 | else delay_einschalten = 0; |
589 | //Auf Neutralwerte setzen |
589 | //Auf Neutralwerte setzen |
590 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
590 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
591 | // Auschalten |
591 | // Auschalten |
592 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
592 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
593 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
593 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
594 | { |
594 | { |
595 | if(++delay_ausschalten > 200) // nicht sofort |
595 | if(++delay_ausschalten > 200) // nicht sofort |
596 | { |
596 | { |
597 | MotorenEin = 0; |
597 | MotorenEin = 0; |
598 | delay_ausschalten = 200; |
598 | delay_ausschalten = 200; |
599 | modell_fliegt = 0; |
599 | modell_fliegt = 0; |
600 | } |
600 | } |
601 | } |
601 | } |
602 | else delay_ausschalten = 0; |
602 | else delay_ausschalten = 0; |
603 | } |
603 | } |
604 | } |
604 | } |
605 | 605 | ||
606 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
606 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
607 | // neue Werte von der Funke |
607 | // neue Werte von der Funke |
608 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
608 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
609 | if(!NewPpmData-- || Notlandung) |
609 | if(!NewPpmData-- || Notlandung) |
610 | { |
610 | { |
611 | ParameterZuordnung(); |
611 | ParameterZuordnung(); |
612 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
612 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
613 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
613 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
614 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
614 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
615 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
615 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
616 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
616 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
617 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
617 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
618 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
618 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
619 | 619 | ||
620 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
620 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
621 | if(GyroFaktor < 0) GyroFaktor = 0; |
621 | if(GyroFaktor < 0) GyroFaktor = 0; |
622 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
622 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
623 | // greift in den Stick ein, um ungewolltes überschlagen zu verhindern |
623 | // greift in den Stick ein, um ungewolltes überschlagen zu verhindern |
624 | if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
624 | if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
625 | { |
625 | { |
626 | if(IntegralNick > 60000) |
626 | if(IntegralNick > 60000) |
627 | { |
627 | { |
628 | StickNick -= 8 * EE_Parameter.Stick_P; |
628 | StickNick -= 8 * EE_Parameter.Stick_P; |
629 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
629 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
630 | } |
630 | } |
631 | else |
631 | else |
632 | if(IntegralNick < -60000) |
632 | if(IntegralNick < -60000) |
633 | { |
633 | { |
634 | StickNick += 8 * EE_Parameter.Stick_P; |
634 | StickNick += 8 * EE_Parameter.Stick_P; |
635 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
635 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
636 | } |
636 | } |
637 | if(IntegralRoll > 60000) |
637 | if(IntegralRoll > 60000) |
638 | { |
638 | { |
639 | StickRoll -= 8 * EE_Parameter.Stick_P; |
639 | StickRoll -= 8 * EE_Parameter.Stick_P; |
640 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
640 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
641 | } |
641 | } |
642 | else |
642 | else |
643 | if(IntegralRoll < -60000) |
643 | if(IntegralRoll < -60000) |
644 | { |
644 | { |
645 | StickRoll += 8 * EE_Parameter.Stick_P; |
645 | StickRoll += 8 * EE_Parameter.Stick_P; |
646 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
646 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
647 | } |
647 | } |
648 | } |
648 | } |
649 | 649 | ||
650 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
650 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
651 | // LED Stuff |
651 | // LED Stuff |
652 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
652 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
653 | 653 | ||
654 | LED1_OFF; |
654 | LED1_OFF; |
655 | 655 | ||
656 | if(blinkcount_LED1 >= Parameter_UserParam4 && Parameter_UserParam4 > 0) |
656 | if(blinkcount_LED1 >= Parameter_UserParam4 && Parameter_UserParam4 > 0) |
657 | { |
657 | { |
658 | LED1_FLASH; |
658 | LED1_FLASH; |
659 | blinkcount_LED1 = 0; |
659 | blinkcount_LED1 = 0; |
660 | } |
660 | } |
661 | 661 | ||
662 | blinkcount_LED1++; |
662 | blinkcount_LED1++; |
663 | 663 | ||
664 | //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] > 75) LED1_ON; else LED1_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr) |
664 | //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] > 75) LED1_ON; else LED1_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr) |
665 | //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 75) LED2_ON; else LED2_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr) |
665 | //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 75) LED2_ON; else LED2_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr) |
666 | } |
666 | } |
667 | 667 | ||
668 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
668 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
669 | // Looping? |
669 | // Looping? |
670 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
670 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
671 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) || |
671 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) || |
672 | ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
672 | ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
673 | { |
673 | { |
674 | Looping_Roll = 1; |
674 | Looping_Roll = 1; |
675 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
675 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
676 | } |
676 | } |
677 | else Looping_Roll = 0; |
677 | else Looping_Roll = 0; |
678 | 678 | ||
679 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) || |
679 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) || |
680 | ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN)) |
680 | ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN)) |
681 | { |
681 | { |
682 | Looping_Nick = 1; |
682 | Looping_Nick = 1; |
683 | Looping_Roll = 0; |
683 | Looping_Roll = 0; |
684 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
684 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
685 | } |
685 | } |
686 | else Looping_Nick = 0; |
686 | else Looping_Nick = 0; |
687 | 687 | ||
688 | 688 | ||
689 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
689 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
690 | // Bei Empfangsausfall im Flug |
690 | // Bei Empfangsausfall im Flug |
691 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
691 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
692 | if(Notlandung) |
692 | if(Notlandung) |
693 | { |
693 | { |
694 | StickGier = 0; |
694 | StickGier = 0; |
695 | StickNick = 0; |
695 | StickNick = 0; |
696 | StickRoll = 0; |
696 | StickRoll = 0; |
697 | GyroFaktor = 0.1; |
697 | GyroFaktor = 0.1; |
698 | IntegralFaktor = 0.005; |
698 | IntegralFaktor = 0.005; |
699 | Looping_Roll = 0; |
699 | Looping_Roll = 0; |
700 | Looping_Nick = 0; |
700 | Looping_Nick = 0; |
701 | } |
701 | } |
702 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
702 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
703 | // Gyro-Drift kompensieren |
703 | // Gyro-Drift kompensieren |
704 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
704 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
705 | #define DRIFT_FAKTOR 3 |
705 | #define DRIFT_FAKTOR 3 |
706 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
706 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
707 | { |
707 | { |
708 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
708 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
709 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
709 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
710 | ZaehlMessungen = 0; |
710 | ZaehlMessungen = 0; |
711 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
711 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
712 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
712 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
713 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
713 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
714 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
714 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
715 | // if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; // macht nur mit Referenz (Kompass Sinn) |
715 | // if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; // macht nur mit Referenz (Kompass Sinn) |
716 | // if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; // macht nur mit Referenz (Kompass Sinn) |
716 | // if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; // macht nur mit Referenz (Kompass Sinn) |
717 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
717 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
718 | Mess_IntegralNick2 = IntegralNick; |
718 | Mess_IntegralNick2 = IntegralNick; |
719 | Mess_IntegralRoll2 = IntegralRoll; |
719 | Mess_IntegralRoll2 = IntegralRoll; |
720 | Mess_Integral_Gier2 = Integral_Gier; |
720 | Mess_Integral_Gier2 = Integral_Gier; |
721 | ANALOG_ON; // ADC einschalten |
721 | ANALOG_ON; // ADC einschalten |
722 | } |
722 | } |
723 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
723 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
724 | // Integrale auf ACC-Signal abgleichen |
724 | // Integrale auf ACC-Signal abgleichen |
725 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
725 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
726 | 726 | ||
727 | 727 | ||
728 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) |
728 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) |
729 | { |
729 | { |
730 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
730 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
731 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
731 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
732 | #define AUSGLEICH 500 |
732 | #define AUSGLEICH 500 |
733 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
733 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
734 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
734 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
735 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
735 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
736 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
736 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
737 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
737 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
738 | Mess_IntegralNick -= tmp_long; |
738 | Mess_IntegralNick -= tmp_long; |
739 | Mess_IntegralRoll -= tmp_long2; |
739 | Mess_IntegralRoll -= tmp_long2; |
740 | } |
740 | } |
741 | 741 | ||
742 | else |
742 | else |
743 | { |
743 | { |
744 | if(IntegralFaktor && !Looping_Nick && !Looping_Roll) |
744 | if(IntegralFaktor && !Looping_Nick && !Looping_Roll) |
745 | { |
745 | { |
746 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
746 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
747 | if(labs(Mittelwert_AccNick) < 200) tmp_long /= 8; |
747 | if(labs(Mittelwert_AccNick) < 200) tmp_long /= 8; |
748 | else tmp_long /= 16; |
748 | else tmp_long /= 16; |
749 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
749 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
750 | if(labs(Mittelwert_AccRoll) < 200) tmp_long2 /= 8; |
750 | if(labs(Mittelwert_AccRoll) < 200) tmp_long2 /= 8; |
751 | else tmp_long2 /= 16; |
751 | else tmp_long2 /= 16; |
752 | 752 | ||
753 | #define AUSGLEICH 500 |
753 | #define AUSGLEICH 500 |
754 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
754 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
755 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
755 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
756 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
756 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
757 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
757 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
758 | } |
758 | } |
759 | 759 | ||
760 | else |
760 | else |
761 | { |
761 | { |
762 | tmp_long = 0; |
762 | tmp_long = 0; |
763 | tmp_long2 = 0; |
763 | tmp_long2 = 0; |
764 | } |
764 | } |
765 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
765 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
766 | Mess_IntegralNick -= tmp_long; |
766 | Mess_IntegralNick -= tmp_long; |
767 | Mess_IntegralRoll -= tmp_long2; |
767 | Mess_IntegralRoll -= tmp_long2; |
768 | } |
768 | } |
769 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
769 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
770 | // Gieren |
770 | // Gieren |
771 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
771 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
772 | if(abs(StickGier) > 20) // war 35 |
772 | if(abs(StickGier) > 20) // war 35 |
773 | { |
773 | { |
774 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
774 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
775 | } |
775 | } |
776 | tmp_int = EE_Parameter.Gier_P * (StickGier * abs(StickGier)) / 512; // expo y = ax + bx² |
776 | tmp_int = EE_Parameter.Gier_P * (StickGier * abs(StickGier)) / 512; // expo y = ax + bx² |
777 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
777 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
778 | sollGier = tmp_int; |
778 | sollGier = tmp_int; |
779 | Mess_Integral_Gier -= tmp_int; |
779 | Mess_Integral_Gier -= tmp_int; |
780 | if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000; // begrenzen |
780 | if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000; // begrenzen |
781 | if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000; |
781 | if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000; |
782 | 782 | ||
783 | ANALOG_ON; // ADC einschalten |
783 | ANALOG_ON; // ADC einschalten |
784 | 784 | ||
785 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
785 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
786 | // Kompass |
786 | // Kompass |
787 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
787 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
788 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
788 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
789 | { |
789 | { |
790 | int w,v; |
790 | int w,v; |
791 | static int SignalSchlecht = 0; |
791 | static int SignalSchlecht = 0; |
792 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
792 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
793 | v = abs(IntegralRoll /512); |
793 | v = abs(IntegralRoll /512); |
794 | if(v > w) w = v; // grösste Neigung ermitteln |
794 | if(v > w) w = v; // grösste Neigung ermitteln |
795 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
795 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
796 | { |
796 | { |
797 | KompassStartwert = KompassValue; |
797 | KompassStartwert = KompassValue; |
798 | NeueKompassRichtungMerken = 0; |
798 | NeueKompassRichtungMerken = 0; |
799 | } |
799 | } |
800 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
800 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
801 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
801 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
802 | if(w > 0) |
802 | if(w > 0) |
803 | { |
803 | { |
804 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
804 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
805 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
805 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
806 | ANALOG_ON; // ADC einschalten |
806 | ANALOG_ON; // ADC einschalten |
807 | if(SignalSchlecht) SignalSchlecht--; |
807 | if(SignalSchlecht) SignalSchlecht--; |
808 | } |
808 | } |
809 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
809 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
810 | } |
810 | } |
811 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
811 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
812 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
812 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
813 | 813 | ||
814 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
814 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
815 | // GPS |
815 | // GPS |
816 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
816 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
817 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) |
817 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) |
818 | { |
818 | { |
819 | P_GPS_Verstaerkung = Parameter_UserParam1; |
819 | P_GPS_Verstaerkung = Parameter_UserParam1; |
820 | D_GPS_Verstaerkung = Parameter_UserParam2; |
820 | D_GPS_Verstaerkung = Parameter_UserParam2; |
821 | Limit_D_Anteil = Parameter_UserParam3; |
821 | Limit_D_Anteil = Parameter_UserParam3; |
822 | gps_main(); |
822 | gps_main(); |
823 | } |
823 | } |
824 | else |
824 | else |
825 | { |
825 | { |
826 | GPS_Nick = 0; |
826 | GPS_Nick = 0; |
827 | GPS_Roll = 0; |
827 | GPS_Roll = 0; |
828 | } |
828 | } |
829 | 829 | ||
830 | 830 | ||
831 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
831 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
832 | // Debugwerte zuordnen |
832 | // Debugwerte zuordnen |
833 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
833 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
834 | if(!TimerWerteausgabe--) |
834 | if(!TimerWerteausgabe--) |
835 | { |
835 | { |
836 | TimerWerteausgabe = 49; |
836 | TimerWerteausgabe = 49; |
837 | 837 | ||
838 | DebugOut.Analog[0] = actualPos.GPSFix; |
838 | DebugOut.Analog[0] = actualPos.GPSFix; |
839 | DebugOut.Analog[1] = GPS_Roll; |
839 | DebugOut.Analog[1] = GPS_Roll; |
840 | DebugOut.Analog[2] = GPS_Nick; |
840 | DebugOut.Analog[2] = GPS_Nick; |
841 | DebugOut.Analog[3] = GPS_Positionsabweichung_North; |
841 | DebugOut.Analog[3] = GPS_Positionsabweichung_North; |
842 | DebugOut.Analog[4] = GPS_Positionsabweichung_East; |
842 | DebugOut.Analog[4] = GPS_Positionsabweichung_East; |
843 | DebugOut.Analog[5] = P_Einfluss_East; |
843 | DebugOut.Analog[5] = P_Einfluss_East; |
844 | DebugOut.Analog[6] = D_Einfluss_East; |
844 | DebugOut.Analog[6] = D_Einfluss_East; |
845 | DebugOut.Analog[7] = P_Einfluss_North; |
845 | DebugOut.Analog[7] = P_Einfluss_North; |
846 | DebugOut.Analog[8] = D_Einfluss_North; |
846 | DebugOut.Analog[8] = D_Einfluss_North; |
847 | DebugOut.Analog[9] = Soll_Position_North; |
847 | DebugOut.Analog[9] = Soll_Position_North; |
848 | DebugOut.Analog[10] = Soll_Position_East; |
848 | DebugOut.Analog[10] = Soll_Position_East; |
849 | DebugOut.Analog[11] = Parameter_UserParam1; |
849 | DebugOut.Analog[11] = Parameter_UserParam1; |
850 | DebugOut.Analog[12] = Parameter_UserParam2; |
850 | DebugOut.Analog[12] = Parameter_UserParam2; |
851 | DebugOut.Analog[13] = Poti3; |
851 | DebugOut.Analog[13] = Poti3; |
852 | DebugOut.Analog[14] = KompassValue; |
852 | DebugOut.Analog[14] = KompassValue; |
853 | DebugOut.Analog[15] = GPS_Home_North; |
853 | DebugOut.Analog[15] = GPS_Home_North; |
854 | DebugOut.Analog[16] = GPS_Home_East; |
854 | DebugOut.Analog[16] = GPS_Home_East; |
855 | DebugOut.Analog[17] = NORTH_MITTEL; |
855 | DebugOut.Analog[17] = NORTH_MITTEL; |
856 | DebugOut.Analog[18] = EAST_MITTEL; |
856 | DebugOut.Analog[18] = EAST_MITTEL; |
857 | DebugOut.Analog[19] = actualPos.northing; |
857 | DebugOut.Analog[19] = actualPos.northing; |
858 | DebugOut.Analog[20] = actualPos.easting; |
858 | DebugOut.Analog[20] = actualPos.easting; |
859 | DebugOut.Analog[21] = actualPos.velNorth; |
859 | DebugOut.Analog[21] = actualPos.velNorth; |
860 | DebugOut.Analog[22] = actualPos.velEast; |
860 | DebugOut.Analog[22] = actualPos.velEast; |
861 | DebugOut.Analog[23] = UBat; |
861 | DebugOut.Analog[23] = UBat; |
862 | DebugOut.Analog[24] = (motor_rx[0]+motor_rx[1]+motor_rx[2]+motor_rx[3])/4; //Mittelwert aller Motorenströme |
862 | DebugOut.Analog[24] = (motor_rx[0]+motor_rx[1]+motor_rx[2]+motor_rx[3]); //Gesamtstrom |
863 | DebugOut.Analog[25] = motor_rx[0]+motor_rx[1]+motor_rx[2]+motor_rx[3]; //Gesamtstrom aller Motoren |
863 | DebugOut.Analog[25] = StickRoll; |
864 | DebugOut.Analog[26] = HoehenWert; |
864 | DebugOut.Analog[26] = HoehenWert; |
865 | DebugOut.Analog[27] = IntegralNick / EE_Parameter.GyroAccFaktor; |
865 | DebugOut.Analog[27] = IntegralNick / EE_Parameter.GyroAccFaktor; |
866 | DebugOut.Analog[28] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
866 | DebugOut.Analog[28] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
867 | DebugOut.Analog[29] = Mittelwert_AccNick; |
867 | DebugOut.Analog[29] = Mittelwert_AccNick; |
868 | DebugOut.Analog[30] = Mittelwert_AccRoll; |
868 | DebugOut.Analog[30] = Mittelwert_AccRoll; |
869 | DebugOut.Analog[31] = 0; |
869 | DebugOut.Analog[31] = StickNick; |
870 | } |
870 | } |
871 | 871 | ||
872 | 872 | ||
873 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
873 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
874 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
874 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
875 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
875 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
876 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
876 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
877 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
877 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
878 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
878 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
879 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
879 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
880 | // MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
880 | // MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
881 | MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2; |
881 | MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2; |
882 | 882 | ||
883 | // Maximalwerte abfangen |
883 | // Maximalwerte abfangen |
884 | #define MAX_SENSOR 2048 |
884 | #define MAX_SENSOR 2048 |
885 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
885 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
886 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
886 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
887 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
887 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
888 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
888 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
889 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
889 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
890 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
890 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
891 | 891 | ||
892 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
892 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
893 | // Höhenregelung |
893 | // Höhenregelung |
894 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
894 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
895 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
895 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
896 | //OCR0B = 180 - (Poti1 + 120) / 4; |
896 | //OCR0B = 180 - (Poti1 + 120) / 4; |
897 | //DruckOffsetSetting = OCR0B; |
897 | //DruckOffsetSetting = OCR0B; |
898 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
898 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
899 | { |
899 | { |
900 | int tmp_int; |
900 | int tmp_int; |
901 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
901 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
902 | { |
902 | { |
903 | if(Parameter_MaxHoehe < 50) |
903 | if(Parameter_MaxHoehe < 50) |
904 | { |
904 | { |
905 | SollHoehe = HoehenWert - 40; // Parameter_MaxHoehe ist der PPM-Wert des Schalters // (160607Kr) |
905 | SollHoehe = HoehenWert - 40; // Parameter_MaxHoehe ist der PPM-Wert des Schalters // (160607Kr) |
906 | HoehenReglerAktiv = 0; |
906 | HoehenReglerAktiv = 0; |
907 | } |
907 | } |
908 | else |
908 | else |
909 | HoehenReglerAktiv = 1; |
909 | HoehenReglerAktiv = 1; |
910 | } |
910 | } |
911 | else |
911 | else |
912 | { |
912 | { |
913 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 40; // (160607Kr) |
913 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 40; // (160607Kr) |
914 | HoehenReglerAktiv = 1; |
914 | HoehenReglerAktiv = 1; |
915 | } |
915 | } |
916 | 916 | ||
917 | if(Notlandung) SollHoehe = 0; |
917 | if(Notlandung) SollHoehe = 0; |
918 | h = HoehenWert; |
918 | h = HoehenWert; |
919 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
919 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
920 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
920 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
921 | h = GasMischanteil - h; // vom Gas abziehen |
921 | h = GasMischanteil - h; // vom Gas abziehen |
922 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
922 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
923 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
923 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
924 | if(tmp_int > 50) tmp_int = 50; |
924 | if(tmp_int > 50) tmp_int = 50; |
925 | else if(tmp_int < -50) tmp_int = -50; |
925 | else if(tmp_int < -50) tmp_int = -50; |
926 | h -= tmp_int; |
926 | h -= tmp_int; |
927 | hoehenregler = (hoehenregler*15 + h) / 16; |
927 | hoehenregler = (hoehenregler*15 + h) / 16; |
928 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
928 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
929 | { |
929 | { |
930 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
930 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
931 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
931 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
932 | } |
932 | } |
933 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
933 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
934 | GasMischanteil = hoehenregler; |
934 | GasMischanteil = hoehenregler; |
935 | } |
935 | } |
936 | } |
936 | } |
937 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
937 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
938 | // + Mischer und PI-Regler |
938 | // + Mischer und PI-Regler |
939 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
939 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
940 | // DebugOut.Analog[7] = GasMischanteil; |
940 | // DebugOut.Analog[7] = GasMischanteil; |
941 | 941 | ||
942 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
942 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
943 | // Gier-Anteil |
943 | // Gier-Anteil |
944 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
944 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
945 | #define MUL_G 1.0 |
945 | #define MUL_G 1.0 |
946 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
946 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
947 | //GierMischanteil = 0; |
947 | //GierMischanteil = 0; |
948 | if(GierMischanteil > (MUL_G * GasMischanteil)) GierMischanteil = MUL_G * GasMischanteil; |
948 | if(GierMischanteil > (MUL_G * GasMischanteil)) GierMischanteil = MUL_G * GasMischanteil; |
949 | if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil); |
949 | if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil); |
950 | if(GierMischanteil > 100) GierMischanteil = 100; |
950 | if(GierMischanteil > 100) GierMischanteil = 100; |
951 | if(GierMischanteil < -100) GierMischanteil = -100; |
951 | if(GierMischanteil < -100) GierMischanteil = -100; |
952 | 952 | ||
953 | if(GasMischanteil < 20) GierMischanteil = 0; |
953 | if(GasMischanteil < 20) GierMischanteil = 0; |
954 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
954 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
955 | // Nick-Achse |
955 | // Nick-Achse |
956 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
956 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
957 | 957 | ||
958 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
958 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
959 | SummeNick += DiffNick; // I-Anteil |
959 | SummeNick += DiffNick; // I-Anteil |
960 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
960 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
961 | if(SummeNick > 16000) SummeNick = 16000; |
961 | if(SummeNick > 16000) SummeNick = 16000; |
962 | if(SummeNick < -16000) SummeNick = -16000; |
962 | if(SummeNick < -16000) SummeNick = -16000; |
963 | pd_ergebnis = DiffNick;// + Ki * SummeNick; // PI-Regler für Nick |
963 | pd_ergebnis = DiffNick;// + Ki * SummeNick; // PI-Regler für Nick |
964 | // Motor Vorn |
964 | // Motor Vorn |
965 | #define MUL 2 |
965 | #define MUL 2 |
966 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
966 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
967 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
967 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
968 | 968 | ||
969 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
969 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
970 | if ((motorwert < 0)) motorwert = 0; |
970 | if ((motorwert < 0)) motorwert = 0; |
971 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
971 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
972 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
972 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
973 | Motor_Vorne = motorwert; |
973 | Motor_Vorne = motorwert; |
974 | // Motor Heck |
974 | // Motor Heck |
975 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
975 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
976 | if ((motorwert < 0)) motorwert = 0; |
976 | if ((motorwert < 0)) motorwert = 0; |
977 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
977 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
978 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
978 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
979 | Motor_Hinten = motorwert; |
979 | Motor_Hinten = motorwert; |
980 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
980 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
981 | // Roll-Achse |
981 | // Roll-Achse |
982 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
982 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
983 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
983 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
984 | SummeRoll += DiffRoll; // I-Anteil |
984 | SummeRoll += DiffRoll; // I-Anteil |
985 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
985 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
986 | if(SummeRoll > 16000) SummeRoll = 16000; |
986 | if(SummeRoll > 16000) SummeRoll = 16000; |
987 | if(SummeRoll < -16000) SummeRoll = -16000; |
987 | if(SummeRoll < -16000) SummeRoll = -16000; |
988 | pd_ergebnis = DiffRoll;// + Ki * SummeRoll; // PI-Regler für Roll |
988 | pd_ergebnis = DiffRoll;// + Ki * SummeRoll; // PI-Regler für Roll |
989 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
989 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
990 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
990 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
991 | // Motor Links |
991 | // Motor Links |
992 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
992 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
993 | if ((motorwert < 0)) motorwert = 0; |
993 | if ((motorwert < 0)) motorwert = 0; |
994 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
994 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
995 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
995 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
996 | Motor_Links = motorwert; |
996 | Motor_Links = motorwert; |
997 | // Motor Rechts |
997 | // Motor Rechts |
998 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
998 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
999 | if ((motorwert < 0)) motorwert = 0; |
999 | if ((motorwert < 0)) motorwert = 0; |
1000 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1000 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1001 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1001 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1002 | Motor_Rechts = motorwert; |
1002 | Motor_Rechts = motorwert; |
1003 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
1003 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
1004 | } |
1004 | } |
1005 | 1005 | ||
1006 | 1006 |