Rev 1086 | Rev 1092 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
2 | Flight Control |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 04.2007 Holger Buss |
||
6 | // + Nur für den privaten Gebrauch |
||
7 | // + www.MikroKopter.com |
||
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 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. |
||
11 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
12 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
1 | ingob | 13 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Verkauf von Luftbildaufnahmen, usw. |
||
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
1 | ingob | 17 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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" |
||
21 | // + eindeutig als Ursprung verlinkt werden |
||
22 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
23 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
24 | // + Benutzung auf eigene Gefahr |
||
25 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 27 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
1 | ingob | 28 | // + mit unserer Zustimmung zulässig |
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
1 | ingob | 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 |
||
35 | // + from this software without specific prior written permission. |
||
1051 | killagreg | 36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
1 | ingob | 37 | // + for non-commercial use (directly or indirectly) |
1051 | killagreg | 38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
1 | ingob | 39 | // + with our written permission |
1051 | killagreg | 40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + clearly linked as origin |
||
831 | hbuss | 42 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
1 | ingob | 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 |
||
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
492 | hbuss | 50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
1 | ingob | 51 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
1051 | killagreg | 52 | // + POSSIBILITY OF SUCH DAMAGE. |
1 | ingob | 53 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1086 | salvo | 54 | // Aenderungen von Peter Muehlenbrock ("Salvo") Stand 9.11.2008 |
55 | /* |
||
56 | Driftkompensation fuer Gyros verbessert |
||
57 | Linearsensor optional mit fixem Neutralwert |
||
58 | Ersatzkompass abgeleitet aus Magnetkompass und Giergyro fuer nahezu neigungsunabhaengige Kompassfunktion |
||
59 | */ |
||
1 | ingob | 60 | |
61 | #include "main.h" |
||
395 | hbuss | 62 | #include "eeprom.c" |
1 | ingob | 63 | |
64 | unsigned char h,m,s; |
||
173 | holgerb | 65 | volatile unsigned int I2CTimeout = 100; |
927 | hbuss | 66 | volatile int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias; |
1051 | killagreg | 67 | int AdNeutralGierBias; |
927 | hbuss | 68 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
69 | int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
||
805 | hbuss | 70 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
1 | ingob | 71 | volatile float NeutralAccZ = 0; |
72 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
||
693 | hbuss | 73 | long IntegralNick = 0,IntegralNick2 = 0; |
74 | long IntegralRoll = 0,IntegralRoll2 = 0; |
||
75 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
||
76 | long Integral_Gier = 0; |
||
77 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
||
78 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
||
79 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
||
80 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
||
1 | ingob | 81 | volatile long Mess_Integral_Hoch = 0; |
82 | volatile int KompassValue = 0; |
||
83 | volatile int KompassStartwert = 0; |
||
84 | volatile int KompassRichtung = 0; |
||
693 | hbuss | 85 | unsigned int KompassSignalSchlecht = 500; |
855 | hbuss | 86 | unsigned char MAX_GAS,MIN_GAS; |
1 | ingob | 87 | unsigned char Notlandung = 0; |
88 | unsigned char HoehenReglerAktiv = 0; |
||
880 | hbuss | 89 | unsigned char TrichterFlug = 0; |
395 | hbuss | 90 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
693 | hbuss | 91 | long ErsatzKompass; |
92 | int ErsatzKompassInGrad; // Kompasswert in Grad |
||
93 | int GierGyroFehler = 0; |
||
1086 | salvo | 94 | //Salvo 12.10.2007 |
95 | uint8_t magkompass_ok=0; |
||
96 | uint8_t gps_cmd = GPS_CMD_STOP; |
||
97 | static int ubat_cnt =0; |
||
98 | static int gas_actual,gas_mittel; //Parameter fuer Gasreduzierung bei unterspannung |
||
99 | int w,v; |
||
100 | //Salvo End |
||
101 | |||
102 | //Salvo 15.12.2007 Ersatzkompass und Giergyrokompensation |
||
103 | long GyroKomp_Int; |
||
104 | long int GyroGier_Comp; |
||
105 | int GyroKomp_Value; // Der ermittelte Kompasswert aus Gyro und Magnetkompass |
||
106 | short int cnt_stickgier_zero =0; |
||
107 | int gyrogier_kompass; |
||
108 | //Salvo End |
||
109 | |||
110 | //Salvo 2.1.2008 Allgemeine Debugvariablen |
||
111 | int debug_gp_0,debug_gp_1,debug_gp_2,debug_gp_3,debug_gp_4,debug_gp_5,debug_gp_6,debug_gp_7; |
||
112 | //Salvo End |
||
1 | ingob | 113 | float GyroFaktor; |
114 | float IntegralFaktor; |
||
115 | volatile int DiffNick,DiffRoll; |
||
1051 | killagreg | 116 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
1 | ingob | 117 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
118 | volatile unsigned char SenderOkay = 0; |
||
595 | hbuss | 119 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
1 | ingob | 120 | char MotorenEin = 0; |
121 | int HoehenWert = 0; |
||
122 | int SollHoehe = 0; |
||
498 | hbuss | 123 | int LageKorrekturRoll = 0,LageKorrekturNick = 0; |
1 | ingob | 124 | float Ki = FAKTOR_I; |
395 | hbuss | 125 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
126 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
||
1 | ingob | 127 | |
128 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
||
129 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
||
130 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
||
131 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
||
132 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
||
173 | holgerb | 133 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
1 | ingob | 134 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
135 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
||
136 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
||
137 | unsigned char Parameter_UserParam1 = 0; |
||
138 | unsigned char Parameter_UserParam2 = 0; |
||
139 | unsigned char Parameter_UserParam3 = 0; |
||
140 | unsigned char Parameter_UserParam4 = 0; |
||
499 | hbuss | 141 | unsigned char Parameter_UserParam5 = 0; |
142 | unsigned char Parameter_UserParam6 = 0; |
||
143 | unsigned char Parameter_UserParam7 = 0; |
||
144 | unsigned char Parameter_UserParam8 = 0; |
||
1 | ingob | 145 | unsigned char Parameter_ServoNickControl = 100; |
173 | holgerb | 146 | unsigned char Parameter_LoopGasLimit = 70; |
395 | hbuss | 147 | unsigned char Parameter_AchsKopplung1 = 0; |
148 | unsigned char Parameter_AchsGegenKopplung1 = 0; |
||
499 | hbuss | 149 | unsigned char Parameter_DynamicStability = 100; |
921 | hbuss | 150 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
151 | unsigned char Parameter_J16Timing; // for the J16 Output |
||
152 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
||
153 | unsigned char Parameter_J17Timing; // for the J17 Output |
||
154 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
||
1051 | killagreg | 155 | unsigned char Parameter_NaviGpsGain; |
156 | unsigned char Parameter_NaviGpsP; |
||
157 | unsigned char Parameter_NaviGpsI; |
||
158 | unsigned char Parameter_NaviGpsD; |
||
159 | unsigned char Parameter_NaviGpsACC; |
||
1086 | salvo | 160 | unsigned char Parameter_NaviStickThreshold; //salvo 16.10.2008 |
993 | hbuss | 161 | unsigned char Parameter_NaviOperatingRadius; |
162 | unsigned char Parameter_NaviWindCorrection; |
||
163 | unsigned char Parameter_NaviSpeedCompensation; |
||
921 | hbuss | 164 | unsigned char Parameter_ExternalControl; |
1 | ingob | 165 | struct mk_param_struct EE_Parameter; |
492 | hbuss | 166 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
614 | hbuss | 167 | int MaxStickNick = 0,MaxStickRoll = 0; |
871 | hbuss | 168 | unsigned int modell_fliegt = 0; |
921 | hbuss | 169 | unsigned char MikroKopterFlags = 0; |
1 | ingob | 170 | |
1086 | salvo | 171 | //Salvo 2.1.2008 Allgemeine Debugvariablen |
172 | int debug_gp_0,debug_gp_1,debug_gp_2,debug_gp_3,debug_gp_4,debug_gp_5,debug_gp_6,debug_gp_7; |
||
173 | //Salvo End |
||
174 | |||
175 | |||
176 | |||
177 | |||
1 | ingob | 178 | void Piep(unsigned char Anzahl) |
179 | { |
||
180 | while(Anzahl--) |
||
181 | { |
||
182 | if(MotorenEin) return; //auf keinen Fall im Flug! |
||
183 | beeptime = 100; |
||
184 | Delay_ms(250); |
||
185 | } |
||
186 | } |
||
187 | |||
188 | //############################################################################ |
||
189 | // Nullwerte ermitteln |
||
190 | void SetNeutral(void) |
||
191 | //############################################################################ |
||
192 | { |
||
1086 | salvo | 193 | // Salvo 9.12.2007 |
194 | RX_SWTCH_ON; //GPS Daten auf RX eingang schalten |
||
195 | // Salvo End |
||
196 | NeutralAccX = 0; |
||
1 | ingob | 197 | NeutralAccY = 0; |
198 | NeutralAccZ = 0; |
||
1051 | killagreg | 199 | AdNeutralNick = 0; |
200 | AdNeutralRoll = 0; |
||
1 | ingob | 201 | AdNeutralGier = 0; |
927 | hbuss | 202 | AdNeutralGierBias = 0; |
395 | hbuss | 203 | Parameter_AchsKopplung1 = 0; |
204 | Parameter_AchsGegenKopplung1 = 0; |
||
1036 | hbuss | 205 | ExpandBaro = 0; |
1051 | killagreg | 206 | CalibrierMittelwert(); |
395 | hbuss | 207 | Delay_ms_Mess(100); |
1 | ingob | 208 | CalibrierMittelwert(); |
209 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
||
1051 | killagreg | 210 | { |
1 | ingob | 211 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
212 | } |
||
173 | holgerb | 213 | |
1051 | killagreg | 214 | AdNeutralNick= AdWertNick; |
215 | AdNeutralRoll= AdWertRoll; |
||
395 | hbuss | 216 | AdNeutralGier= AdWertGier; |
927 | hbuss | 217 | AdNeutralGierBias = AdWertGier; |
401 | hbuss | 218 | StartNeutralRoll = AdNeutralRoll; |
219 | StartNeutralNick = AdNeutralNick; |
||
1051 | killagreg | 220 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
513 | hbuss | 221 | { |
222 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
||
223 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
||
224 | NeutralAccZ = Aktuell_az; |
||
225 | } |
||
1051 | killagreg | 226 | else |
513 | hbuss | 227 | { |
228 | NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]); |
||
229 | NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]); |
||
230 | NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]); |
||
231 | } |
||
1051 | killagreg | 232 | |
233 | Mess_IntegralNick = 0; |
||
1 | ingob | 234 | Mess_IntegralNick2 = 0; |
1051 | killagreg | 235 | Mess_IntegralRoll = 0; |
1 | ingob | 236 | Mess_IntegralRoll2 = 0; |
1051 | killagreg | 237 | Mess_Integral_Gier = 0; |
1 | ingob | 238 | MesswertNick = 0; |
239 | MesswertRoll = 0; |
||
240 | MesswertGier = 0; |
||
927 | hbuss | 241 | Delay_ms_Mess(100); |
1 | ingob | 242 | StartLuftdruck = Luftdruck; |
243 | HoeheD = 0; |
||
244 | Mess_Integral_Hoch = 0; |
||
245 | KompassStartwert = KompassValue; |
||
246 | GPS_Neutral(); |
||
1051 | killagreg | 247 | beeptime = 50; |
882 | hbuss | 248 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
249 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
||
492 | hbuss | 250 | ExternHoehenValue = 0; |
693 | hbuss | 251 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
252 | GierGyroFehler = 0; |
||
723 | hbuss | 253 | SendVersionToNavi = 1; |
921 | hbuss | 254 | LED_Init(); |
255 | MikroKopterFlags |= FLAG_CALIBRATE; |
||
992 | hbuss | 256 | FromNaviCtrl_Value.Kalman_K = -1; |
257 | FromNaviCtrl_Value.Kalman_MaxDrift = EE_Parameter.Driftkomp * 16; |
||
258 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
||
1086 | salvo | 259 | |
260 | //Salvo 13.10.2007 Ersatzkompass und Gas |
||
261 | GyroKomp_Int = KompassValue * GIER_GRAD_FAKTOR; //Neu ab 15.10.2008 |
||
262 | // gas_mittel = 30; |
||
263 | // gas_actual = gas_mittel; |
||
264 | // Salvo End |
||
265 | |||
1 | ingob | 266 | } |
267 | |||
268 | //############################################################################ |
||
395 | hbuss | 269 | // Bearbeitet die Messwerte |
1 | ingob | 270 | void Mittelwert(void) |
271 | //############################################################################ |
||
1051 | killagreg | 272 | { |
273 | static signed long tmpl,tmpl2; |
||
395 | hbuss | 274 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
927 | hbuss | 275 | MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier; |
395 | hbuss | 276 | MesswertRoll = (signed int) AdWertRoll - AdNeutralRoll; |
277 | MesswertNick = (signed int) AdWertNick - AdNeutralNick; |
||
401 | hbuss | 278 | |
604 | hbuss | 279 | //DebugOut.Analog[26] = MesswertNick; |
1086 | salvo | 280 | //DebugOut.Analog[28] = MesswertRoll; |
604 | hbuss | 281 | |
395 | hbuss | 282 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
283 | Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 2L; |
||
284 | Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 2L; |
||
285 | Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdWertAccHoch)) / 2L; |
||
286 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
||
287 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
||
805 | hbuss | 288 | NaviAccNick += AdWertAccNick; |
289 | NaviAccRoll += AdWertAccRoll; |
||
290 | NaviCntAcc++; |
||
513 | hbuss | 291 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
395 | hbuss | 292 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | hbuss | 293 | ErsatzKompass += MesswertGier; |
1086 | salvo | 294 | //Salvo 12.11.2007 |
295 | GyroKomp_Int += (long)MesswertGier; |
||
296 | GyroGier_Comp += (long)MesswertGier; |
||
297 | //Salvo End |
||
395 | hbuss | 298 | Mess_Integral_Gier += MesswertGier; |
927 | hbuss | 299 | // Mess_Integral_Gier2 += MesswertGier; |
693 | hbuss | 300 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
301 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
||
395 | hbuss | 302 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
303 | if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
||
304 | { |
||
927 | hbuss | 305 | tmpl = (MesswertGierBias * Mess_IntegralNick) / 2048L; |
395 | hbuss | 306 | tmpl *= Parameter_AchsKopplung1; //125 |
880 | hbuss | 307 | tmpl /= 4096L; |
927 | hbuss | 308 | tmpl2 = (MesswertGierBias * Mess_IntegralRoll) / 2048L; |
395 | hbuss | 309 | tmpl2 *= Parameter_AchsKopplung1; |
880 | hbuss | 310 | tmpl2 /= 4096L; |
1051 | killagreg | 311 | if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
395 | hbuss | 312 | } |
313 | else tmpl = tmpl2 = 0; |
||
314 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
||
315 | MesswertRoll += tmpl; |
||
316 | MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109 |
||
317 | Mess_IntegralRoll2 += MesswertRoll; |
||
498 | hbuss | 318 | Mess_IntegralRoll += MesswertRoll - LageKorrekturRoll; |
1051 | killagreg | 319 | if(Mess_IntegralRoll > Umschlag180Roll) |
395 | hbuss | 320 | { |
882 | hbuss | 321 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
395 | hbuss | 322 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1051 | killagreg | 323 | } |
395 | hbuss | 324 | if(Mess_IntegralRoll <-Umschlag180Roll) |
325 | { |
||
882 | hbuss | 326 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
395 | hbuss | 327 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1051 | killagreg | 328 | } |
395 | hbuss | 329 | if(AdWertRoll < 15) MesswertRoll = -1000; |
330 | if(AdWertRoll < 7) MesswertRoll = -2000; |
||
401 | hbuss | 331 | if(PlatinenVersion == 10) |
332 | { |
||
333 | if(AdWertRoll > 1010) MesswertRoll = +1000; |
||
334 | if(AdWertRoll > 1017) MesswertRoll = +2000; |
||
335 | } |
||
1051 | killagreg | 336 | else |
401 | hbuss | 337 | { |
338 | if(AdWertRoll > 2020) MesswertRoll = +1000; |
||
339 | if(AdWertRoll > 2034) MesswertRoll = +2000; |
||
340 | } |
||
395 | hbuss | 341 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
342 | MesswertNick -= tmpl2; |
||
343 | MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L; |
||
344 | Mess_IntegralNick2 += MesswertNick; |
||
498 | hbuss | 345 | Mess_IntegralNick += MesswertNick - LageKorrekturNick; |
882 | hbuss | 346 | |
1051 | killagreg | 347 | if(Mess_IntegralNick > Umschlag180Nick) |
882 | hbuss | 348 | { |
349 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
||
350 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
1051 | killagreg | 351 | } |
352 | if(Mess_IntegralNick <-Umschlag180Nick) |
||
395 | hbuss | 353 | { |
882 | hbuss | 354 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
395 | hbuss | 355 | Mess_IntegralNick2 = Mess_IntegralNick; |
1051 | killagreg | 356 | } |
395 | hbuss | 357 | if(AdWertNick < 15) MesswertNick = -1000; |
358 | if(AdWertNick < 7) MesswertNick = -2000; |
||
401 | hbuss | 359 | if(PlatinenVersion == 10) |
360 | { |
||
361 | if(AdWertNick > 1010) MesswertNick = +1000; |
||
362 | if(AdWertNick > 1017) MesswertNick = +2000; |
||
363 | } |
||
1051 | killagreg | 364 | else |
401 | hbuss | 365 | { |
366 | if(AdWertNick > 2020) MesswertNick = +1000; |
||
367 | if(AdWertNick > 2034) MesswertNick = +2000; |
||
368 | } |
||
395 | hbuss | 369 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
370 | // ADC einschalten |
||
1051 | killagreg | 371 | ANALOG_ON; |
395 | hbuss | 372 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
373 | |||
1 | ingob | 374 | Integral_Gier = Mess_Integral_Gier; |
375 | IntegralNick = Mess_IntegralNick; |
||
376 | IntegralRoll = Mess_IntegralRoll; |
||
1051 | killagreg | 377 | IntegralNick2 = Mess_IntegralNick2; |
1 | ingob | 378 | IntegralRoll2 = Mess_IntegralRoll2; |
379 | |||
395 | hbuss | 380 | if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
381 | { |
||
382 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
||
1051 | killagreg | 383 | else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
395 | hbuss | 384 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
1051 | killagreg | 385 | else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
395 | hbuss | 386 | } |
1 | ingob | 387 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
388 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
||
389 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
||
390 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
||
391 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
||
392 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
393 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
394 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
395 | } |
||
396 | |||
397 | //############################################################################ |
||
398 | // Messwerte beim Ermitteln der Nullage |
||
399 | void CalibrierMittelwert(void) |
||
400 | //############################################################################ |
||
1051 | killagreg | 401 | { |
1021 | hbuss | 402 | if(PlatinenVersion == 13) SucheGyroOffset(); |
1 | ingob | 403 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
404 | ANALOG_OFF; |
||
395 | hbuss | 405 | MesswertNick = AdWertNick; |
406 | MesswertRoll = AdWertRoll; |
||
407 | MesswertGier = AdWertGier; |
||
408 | Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick; |
||
409 | Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll; |
||
410 | Mittelwert_AccHoch = (long)AdWertAccHoch; |
||
411 | // ADC einschalten |
||
1051 | killagreg | 412 | ANALOG_ON; |
1 | ingob | 413 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
414 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
||
415 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
||
416 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
||
417 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
||
418 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
419 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
420 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
395 | hbuss | 421 | |
422 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
720 | ingob | 423 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
1 | ingob | 424 | } |
425 | |||
426 | //############################################################################ |
||
427 | // Senden der Motorwerte per I2C-Bus |
||
428 | void SendMotorData(void) |
||
429 | //############################################################################ |
||
1051 | killagreg | 430 | { |
921 | hbuss | 431 | if(!MotorenEin) |
1 | ingob | 432 | { |
433 | Motor_Hinten = 0; |
||
434 | Motor_Vorne = 0; |
||
435 | Motor_Rechts = 0; |
||
436 | Motor_Links = 0; |
||
437 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
||
438 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
||
439 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
||
440 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
||
921 | hbuss | 441 | MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY); |
442 | } else MikroKopterFlags |= FLAG_MOTOR_RUN; |
||
1 | ingob | 443 | |
444 | DebugOut.Analog[12] = Motor_Vorne; |
||
445 | DebugOut.Analog[13] = Motor_Hinten; |
||
446 | DebugOut.Analog[14] = Motor_Links; |
||
1051 | killagreg | 447 | DebugOut.Analog[15] = Motor_Rechts; |
1 | ingob | 448 | |
449 | //Start I2C Interrupt Mode |
||
450 | twi_state = 0; |
||
451 | motor = 0; |
||
1051 | killagreg | 452 | i2c_start(); |
1 | ingob | 453 | } |
454 | |||
455 | |||
456 | |||
457 | //############################################################################ |
||
458 | // Trägt ggf. das Poti als Parameter ein |
||
1051 | killagreg | 459 | void ParameterZuordnung(void) |
1 | ingob | 460 | //############################################################################ |
461 | { |
||
921 | hbuss | 462 | #define CHK_POTI_MM(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;} |
463 | #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; } |
||
1 | ingob | 464 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
921 | hbuss | 465 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
466 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
||
1 | ingob | 467 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
468 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
||
921 | hbuss | 469 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
1 | ingob | 470 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
1051 | killagreg | 471 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
472 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
||
473 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
||
474 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
||
475 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
||
476 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255); |
||
477 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255); |
||
478 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255); |
||
479 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255); |
||
1 | ingob | 480 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
173 | holgerb | 481 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
395 | hbuss | 482 | CHK_POTI(Parameter_AchsKopplung1, EE_Parameter.AchsKopplung1,0,255); |
483 | CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
||
499 | hbuss | 484 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255); |
921 | hbuss | 485 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255); |
486 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255); |
||
993 | hbuss | 487 | |
1086 | salvo | 488 | CHK_POTI(Parameter_NaviGpsModeControl,EE_Parameter.NaviGpsModeControl,0,255); |
489 | CHK_POTI(Parameter_NaviGpsGain,EE_Parameter.NaviGpsGain,0,255); |
||
490 | CHK_POTI(Parameter_NaviGpsP,EE_Parameter.NaviGpsP,0,255); |
||
491 | CHK_POTI(Parameter_NaviGpsI,EE_Parameter.NaviGpsI,0,255); |
||
492 | CHK_POTI(Parameter_NaviGpsD,EE_Parameter.NaviGpsD,0,255); |
||
1091 | salvo | 493 | CHK_POTI(Parameter_NaviStickThreshold,EE_Parameter.NaviStickThreshold,0,255); //Salvo 16.10.2008 |
1086 | salvo | 494 | CHK_POTI(Parameter_NaviGpsACC,EE_Parameter.NaviGpsACC,0,255); |
993 | hbuss | 495 | // CHK_POTI_MM(Parameter_NaviOperatingRadius,EE_Parameter.NaviOperatingRadius,10,255); |
496 | // CHK_POTI(Parameter_NaviWindCorrection,EE_Parameter.NaviWindCorrection,0,255); |
||
497 | // CHK_POTI(Parameter_NaviSpeedCompensation,EE_Parameter.NaviSpeedCompensation,0,255); |
||
498 | |||
921 | hbuss | 499 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255); |
1 | ingob | 500 | |
501 | Ki = (float) Parameter_I_Faktor * 0.0001; |
||
502 | MAX_GAS = EE_Parameter.Gas_Max; |
||
503 | MIN_GAS = EE_Parameter.Gas_Min; |
||
504 | } |
||
505 | |||
506 | |||
819 | hbuss | 507 | |
1 | ingob | 508 | //############################################################################ |
509 | // |
||
510 | void MotorRegler(void) |
||
511 | //############################################################################ |
||
512 | { |
||
513 | int motorwert,pd_ergebnis,h,tmp_int; |
||
514 | int GierMischanteil,GasMischanteil; |
||
515 | static long SummeNick=0,SummeRoll=0; |
||
516 | static long sollGier = 0,tmp_long,tmp_long2; |
||
395 | hbuss | 517 | static long IntegralFehlerNick = 0; |
518 | static long IntegralFehlerRoll = 0; |
||
1 | ingob | 519 | static unsigned int RcLostTimer; |
520 | static unsigned char delay_neutral = 0; |
||
521 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
522 | static int hoehenregler = 0; |
||
523 | static char TimerWerteausgabe = 0; |
||
524 | static char NeueKompassRichtungMerken = 0; |
||
395 | hbuss | 525 | static long ausgleichNick, ausgleichRoll; |
1086 | salvo | 526 | |
527 | Mittelwert(); |
||
528 | //****** GPS Daten holen *************** |
||
529 | short int n; |
||
530 | if (gps_alive_cnt > 0) gps_alive_cnt--; //Dekrementieren. Wenn 0 kommen keine ausreichenden GPS Meldungen (Timeout) |
||
531 | n = Get_Rel_Position(); |
||
532 | if (n == 0) |
||
533 | { |
||
534 | ROT_ON; //led blitzen lassen |
||
535 | } |
||
536 | //******PROVISORISCH*************** |
||
1 | ingob | 537 | GRN_ON; |
1051 | killagreg | 538 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 539 | // Gaswert ermitteln |
1051 | killagreg | 540 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
541 | GasMischanteil = StickGas; |
||
831 | hbuss | 542 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
1051 | killagreg | 543 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | hbuss | 544 | // Empfang schlecht |
1051 | killagreg | 545 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 546 | if(SenderOkay < 100) |
547 | { |
||
1051 | killagreg | 548 | if(!PcZugriff) |
173 | holgerb | 549 | { |
1051 | killagreg | 550 | if(BeepMuster == 0xffff) |
551 | { |
||
173 | holgerb | 552 | beeptime = 15000; |
553 | BeepMuster = 0x0c00; |
||
1051 | killagreg | 554 | } |
173 | holgerb | 555 | } |
1051 | killagreg | 556 | if(RcLostTimer) RcLostTimer--; |
557 | else |
||
1 | ingob | 558 | { |
559 | MotorenEin = 0; |
||
560 | Notlandung = 0; |
||
1051 | killagreg | 561 | } |
1 | ingob | 562 | ROT_ON; |
693 | hbuss | 563 | if(modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
1 | ingob | 564 | { |
565 | GasMischanteil = EE_Parameter.NotGas; |
||
566 | Notlandung = 1; |
||
744 | hbuss | 567 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
1051 | killagreg | 568 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
1 | ingob | 569 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
570 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
571 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
||
173 | holgerb | 572 | } |
1 | ingob | 573 | else MotorenEin = 0; |
574 | } |
||
1051 | killagreg | 575 | else |
576 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 577 | // Emfang gut |
1051 | killagreg | 578 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 579 | if(SenderOkay > 140) |
580 | { |
||
581 | Notlandung = 0; |
||
582 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
||
921 | hbuss | 583 | if(GasMischanteil > 40 && MotorenEin) |
1 | ingob | 584 | { |
585 | if(modell_fliegt < 0xffff) modell_fliegt++; |
||
586 | } |
||
871 | hbuss | 587 | if((modell_fliegt < 256)) |
1 | ingob | 588 | { |
589 | SummeNick = 0; |
||
590 | SummeRoll = 0; |
||
1051 | killagreg | 591 | if(modell_fliegt == 250) |
918 | hbuss | 592 | { |
1051 | killagreg | 593 | NeueKompassRichtungMerken = 1; |
918 | hbuss | 594 | sollGier = 0; |
1051 | killagreg | 595 | Mess_Integral_Gier = 0; |
927 | hbuss | 596 | // Mess_Integral_Gier2 = 0; |
1051 | killagreg | 597 | } |
921 | hbuss | 598 | } else MikroKopterFlags |= FLAG_FLY; |
1051 | killagreg | 599 | |
595 | hbuss | 600 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
1 | ingob | 601 | { |
1051 | killagreg | 602 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 603 | // auf Nullwerte kalibrieren |
1051 | killagreg | 604 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 605 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
606 | { |
||
607 | if(++delay_neutral > 200) // nicht sofort |
||
608 | { |
||
609 | GRN_OFF; |
||
1086 | salvo | 610 | SetNeutral(); |
1 | ingob | 611 | MotorenEin = 0; |
612 | delay_neutral = 0; |
||
613 | modell_fliegt = 0; |
||
614 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
||
615 | { |
||
304 | ingob | 616 | unsigned char setting=1; |
1 | ingob | 617 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
618 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
||
619 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
||
620 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
||
621 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
||
1063 | killagreg | 622 | SetActiveParamSetNumber(setting); // aktiven Datensatz merken |
1 | ingob | 623 | } |
820 | hbuss | 624 | // else |
1051 | killagreg | 625 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
626 | { |
||
819 | hbuss | 627 | WinkelOut.CalcState = 1; |
628 | beeptime = 1000; |
||
629 | } |
||
630 | else |
||
1 | ingob | 631 | { |
819 | hbuss | 632 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
633 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
||
634 | { |
||
1 | ingob | 635 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
1051 | killagreg | 636 | } |
819 | hbuss | 637 | SetNeutral(); |
638 | Piep(GetActiveParamSetNumber()); |
||
1086 | salvo | 639 | GPS_Save_Home(); //Daten sind jetzt hoffentlich verfuegbar |
640 | if (gps_home_position.status > 0 ) |
||
641 | { |
||
642 | Delay_ms(1000); //akustisch verkuenden dass GPS Home Daten da sind |
||
643 | beeptime = 1000; |
||
644 | Delay_ms(500); |
||
645 | } |
||
819 | hbuss | 646 | } |
1051 | killagreg | 647 | } |
1 | ingob | 648 | } |
1051 | killagreg | 649 | else |
513 | hbuss | 650 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
651 | { |
||
652 | if(++delay_neutral > 200) // nicht sofort |
||
653 | { |
||
654 | GRN_OFF; |
||
655 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen |
||
656 | MotorenEin = 0; |
||
657 | delay_neutral = 0; |
||
658 | modell_fliegt = 0; |
||
659 | SetNeutral(); |
||
660 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern |
||
661 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern |
||
662 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256); |
||
663 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256); |
||
664 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256); |
||
665 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256); |
||
666 | Piep(GetActiveParamSetNumber()); |
||
1051 | killagreg | 667 | } |
513 | hbuss | 668 | } |
1 | ingob | 669 | else delay_neutral = 0; |
670 | } |
||
1051 | killagreg | 671 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 672 | // Gas ist unten |
1051 | killagreg | 673 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
595 | hbuss | 674 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
1 | ingob | 675 | { |
676 | // Starten |
||
677 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
||
678 | { |
||
1051 | killagreg | 679 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 680 | // Einschalten |
1051 | killagreg | 681 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 682 | if(++delay_einschalten > 200) |
683 | { |
||
1086 | salvo | 684 | int n; |
685 | // Salvo 9.12.2007 |
||
686 | RX_SWTCH_ON; //GPS Daten auf RX eingang schalten |
||
687 | // Salvo End |
||
1 | ingob | 688 | delay_einschalten = 200; |
689 | modell_fliegt = 1; |
||
690 | MotorenEin = 1; |
||
691 | sollGier = 0; |
||
1051 | killagreg | 692 | Mess_Integral_Gier = 0; |
1 | ingob | 693 | Mess_Integral_Gier2 = 0; |
694 | Mess_IntegralNick = 0; |
||
695 | Mess_IntegralRoll = 0; |
||
696 | Mess_IntegralNick2 = IntegralNick; |
||
697 | Mess_IntegralRoll2 = IntegralRoll; |
||
698 | SummeNick = 0; |
||
699 | SummeRoll = 0; |
||
1086 | salvo | 700 | n= GPS_CRTL(GPS_CMD_STOP); //GPS Lageregelung beenden |
701 | |||
921 | hbuss | 702 | MikroKopterFlags |= FLAG_START; |
1051 | killagreg | 703 | } |
704 | } |
||
1 | ingob | 705 | else delay_einschalten = 0; |
706 | //Auf Neutralwerte setzen |
||
1051 | killagreg | 707 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 708 | // Auschalten |
1051 | killagreg | 709 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 710 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
711 | { |
||
712 | if(++delay_ausschalten > 200) // nicht sofort |
||
713 | { |
||
1086 | salvo | 714 | // Salvo 9.12.2007 |
715 | RX_SWTCH_OFF; //Bluetooth Daten auf RX eingang schalten |
||
716 | // Salvo End |
||
717 | |||
1 | ingob | 718 | MotorenEin = 0; |
719 | delay_ausschalten = 200; |
||
720 | modell_fliegt = 0; |
||
1051 | killagreg | 721 | } |
1 | ingob | 722 | } |
723 | else delay_ausschalten = 0; |
||
724 | } |
||
725 | } |
||
726 | |||
1051 | killagreg | 727 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 728 | // neue Werte von der Funke |
1051 | killagreg | 729 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
730 | if(!NewPpmData-- || Notlandung) |
||
1 | ingob | 731 | { |
492 | hbuss | 732 | int tmp_int; |
604 | hbuss | 733 | static int stick_nick,stick_roll; |
1 | ingob | 734 | ParameterZuordnung(); |
1051 | killagreg | 735 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
723 | hbuss | 736 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
805 | hbuss | 737 | StickNick = stick_nick - (GPS_Nick + GPS_Nick2); |
1051 | killagreg | 738 | // StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
604 | hbuss | 739 | |
723 | hbuss | 740 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
741 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
||
805 | hbuss | 742 | StickRoll = stick_roll - (GPS_Roll + GPS_Roll2); |
723 | hbuss | 743 | |
744 | // StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
||
745 | |||
1 | ingob | 746 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
595 | hbuss | 747 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
748 | |||
1051 | killagreg | 749 | /* if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick) |
614 | hbuss | 750 | MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--; |
1051 | killagreg | 751 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll) |
614 | hbuss | 752 | MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--; |
723 | hbuss | 753 | */ |
855 | hbuss | 754 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN); |
755 | IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN); |
||
1 | ingob | 756 | |
595 | hbuss | 757 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
758 | //+ Analoge Steuerung per Seriell |
||
759 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
921 | hbuss | 760 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
595 | hbuss | 761 | { |
762 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
||
763 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
||
764 | StickGier += ExternControl.Gier; |
||
765 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
||
766 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
||
767 | } |
||
855 | hbuss | 768 | if(StickGas < 0) StickGas = 0; |
492 | hbuss | 769 | |
1 | ingob | 770 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
771 | if(GyroFaktor < 0) GyroFaktor = 0; |
||
772 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
||
723 | hbuss | 773 | |
1051 | killagreg | 774 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
928 | hbuss | 775 | { |
1051 | killagreg | 776 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
928 | hbuss | 777 | if(MaxStickNick > 100) MaxStickNick = 100; |
1051 | killagreg | 778 | } |
928 | hbuss | 779 | else MaxStickNick--; |
1051 | killagreg | 780 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
928 | hbuss | 781 | { |
1051 | killagreg | 782 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
928 | hbuss | 783 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
1051 | killagreg | 784 | } |
928 | hbuss | 785 | else MaxStickRoll--; |
723 | hbuss | 786 | if(Notlandung) {MaxStickNick = 0; MaxStickRoll = 0;} |
787 | |||
1051 | killagreg | 788 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 789 | // Looping? |
1051 | killagreg | 790 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
993 | hbuss | 791 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
1051 | killagreg | 792 | else |
793 | { |
||
395 | hbuss | 794 | { |
1051 | killagreg | 795 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
796 | } |
||
797 | } |
||
993 | hbuss | 798 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
1051 | killagreg | 799 | else |
395 | hbuss | 800 | { |
801 | if(Looping_Rechts) // Hysterese |
||
802 | { |
||
803 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
||
804 | } |
||
1051 | killagreg | 805 | } |
173 | holgerb | 806 | |
993 | hbuss | 807 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
1051 | killagreg | 808 | else |
809 | { |
||
395 | hbuss | 810 | if(Looping_Oben) // Hysterese |
811 | { |
||
1051 | killagreg | 812 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
813 | } |
||
814 | } |
||
993 | hbuss | 815 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
1051 | killagreg | 816 | else |
395 | hbuss | 817 | { |
818 | if(Looping_Unten) // Hysterese |
||
819 | { |
||
820 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
||
821 | } |
||
1051 | killagreg | 822 | } |
395 | hbuss | 823 | |
824 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
||
825 | if(Looping_Oben || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
||
826 | } // Ende neue Funken-Werte |
||
827 | |||
828 | if(Looping_Roll || Looping_Nick) |
||
829 | { |
||
173 | holgerb | 830 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
831 | } |
||
832 | |||
1051 | killagreg | 833 | |
834 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
835 | // Bei Empfangsausfall im Flug |
||
836 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 837 | if(Notlandung) |
838 | { |
||
839 | StickGier = 0; |
||
840 | StickNick = 0; |
||
841 | StickRoll = 0; |
||
855 | hbuss | 842 | GyroFaktor = (float) 100 / (256.0 / STICK_GAIN); |
843 | IntegralFaktor = (float) 120 / (44000 / STICK_GAIN); |
||
173 | holgerb | 844 | Looping_Roll = 0; |
845 | Looping_Nick = 0; |
||
1051 | killagreg | 846 | } |
395 | hbuss | 847 | |
848 | |||
1051 | killagreg | 849 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 850 | // Integrale auf ACC-Signal abgleichen |
1051 | killagreg | 851 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 852 | #define ABGLEICH_ANZAHL 256L |
853 | |||
854 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
||
855 | MittelIntegralRoll += IntegralRoll; |
||
856 | MittelIntegralNick2 += IntegralNick2; |
||
857 | MittelIntegralRoll2 += IntegralRoll2; |
||
858 | |||
859 | if(Looping_Nick || Looping_Roll) |
||
860 | { |
||
861 | IntegralAccNick = 0; |
||
862 | IntegralAccRoll = 0; |
||
863 | MittelIntegralNick = 0; |
||
864 | MittelIntegralRoll = 0; |
||
865 | MittelIntegralNick2 = 0; |
||
866 | MittelIntegralRoll2 = 0; |
||
867 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
868 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
||
869 | ZaehlMessungen = 0; |
||
498 | hbuss | 870 | LageKorrekturNick = 0; |
871 | LageKorrekturRoll = 0; |
||
395 | hbuss | 872 | } |
873 | |||
1051 | killagreg | 874 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
498 | hbuss | 875 | if(!Looping_Nick && !Looping_Roll) |
469 | hbuss | 876 | { |
877 | long tmp_long, tmp_long2; |
||
992 | hbuss | 878 | if(FromNaviCtrl_Value.Kalman_K != -1) |
879 | { |
||
880 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
||
1051 | killagreg | 881 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
882 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
883 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
992 | hbuss | 884 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
885 | { |
||
886 | tmp_long /= 2; |
||
887 | tmp_long2 /= 2; |
||
888 | } |
||
889 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
||
890 | { |
||
891 | tmp_long /= 3; |
||
892 | tmp_long2 /= 3; |
||
893 | } |
||
894 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
||
895 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
||
896 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
||
897 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
||
898 | } |
||
1051 | killagreg | 899 | else |
992 | hbuss | 900 | { |
901 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
||
1051 | killagreg | 902 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
992 | hbuss | 903 | tmp_long /= 16; |
904 | tmp_long2 /= 16; |
||
905 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
||
906 | { |
||
907 | tmp_long /= 3; |
||
908 | tmp_long2 /= 3; |
||
909 | } |
||
910 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
||
911 | { |
||
912 | tmp_long /= 3; |
||
913 | tmp_long2 /= 3; |
||
914 | } |
||
614 | hbuss | 915 | #define AUSGLEICH 32 |
992 | hbuss | 916 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
917 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
||
918 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
||
919 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
||
920 | } |
||
1051 | killagreg | 921 | |
469 | hbuss | 922 | Mess_IntegralNick -= tmp_long; |
923 | Mess_IntegralRoll -= tmp_long2; |
||
924 | } |
||
1051 | killagreg | 925 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 926 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
927 | { |
||
928 | static int cnt = 0; |
||
929 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
||
930 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
||
880 | hbuss | 931 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug) |
173 | holgerb | 932 | { |
395 | hbuss | 933 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
934 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
||
935 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
||
936 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
||
937 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
||
492 | hbuss | 938 | #define MAX_I 0//(Poti2/10) |
395 | hbuss | 939 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
940 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
||
941 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
||
1051 | killagreg | 942 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
943 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
||
395 | hbuss | 944 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
614 | hbuss | 945 | |
946 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
||
498 | hbuss | 947 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 948 | |
992 | hbuss | 949 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
614 | hbuss | 950 | { |
951 | LageKorrekturNick /= 2; |
||
720 | ingob | 952 | LageKorrekturRoll /= 2; |
614 | hbuss | 953 | } |
498 | hbuss | 954 | |
1051 | killagreg | 955 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 956 | // Gyro-Drift ermitteln |
1051 | killagreg | 957 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 958 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
959 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
||
1051 | killagreg | 960 | tmp_long = IntegralNick2 - IntegralNick; |
961 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
||
395 | hbuss | 962 | //DebugOut.Analog[25] = MittelIntegralRoll2 / 26; |
963 | |||
964 | IntegralFehlerNick = tmp_long; |
||
965 | IntegralFehlerRoll = tmp_long2; |
||
966 | Mess_IntegralNick2 -= IntegralFehlerNick; |
||
967 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
||
968 | |||
969 | // IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2; |
||
970 | // IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2; |
||
927 | hbuss | 971 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; } |
972 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; } |
||
395 | hbuss | 973 | |
1086 | salvo | 974 | //DebugOut.Analog[22] = MittelIntegralRoll / 26; |
921 | hbuss | 975 | //DebugOut.Analog[24] = GierGyroFehler; |
693 | hbuss | 976 | GierGyroFehler = 0; |
720 | ingob | 977 | |
1086 | salvo | 978 | //Salvo Ersatzkompass Ueberlauf korrigieren |
979 | if (GyroKomp_Int >= ((long)360 * GIER_GRAD_FAKTOR)) GyroKomp_Int = GyroKomp_Int - (GIER_GRAD_FAKTOR *(long)360); //neu ab 3.11.2007 |
||
980 | if (GyroKomp_Int < 0) GyroKomp_Int = GyroKomp_Int + (GIER_GRAD_FAKTOR *(long)360); //neu ab 3.11.2007 |
||
981 | ROT_OFF; |
||
982 | // Salvo End |
||
720 | ingob | 983 | |
984 | /*DebugOut.Analog[17] = IntegralAccNick / 26; |
||
395 | hbuss | 985 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
986 | DebugOut.Analog[19] = IntegralFehlerNick;// / 26; |
||
987 | DebugOut.Analog[20] = IntegralFehlerRoll;// / 26; |
||
720 | ingob | 988 | */ |
989 | //DebugOut.Analog[21] = MittelIntegralNick / 26; |
||
990 | //MittelIntegralRoll = MittelIntegralRoll; |
||
469 | hbuss | 991 | //DebugOut.Analog[28] = ausgleichNick; |
720 | ingob | 992 | /* |
395 | hbuss | 993 | DebugOut.Analog[29] = ausgleichRoll; |
498 | hbuss | 994 | DebugOut.Analog[30] = LageKorrekturRoll * 10; |
720 | ingob | 995 | */ |
395 | hbuss | 996 | |
492 | hbuss | 997 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
998 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
||
999 | #define BEWEGUNGS_LIMIT 20000 |
||
395 | hbuss | 1000 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1001 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
||
992 | hbuss | 1002 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*16)) |
492 | hbuss | 1003 | { |
1051 | killagreg | 1004 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
395 | hbuss | 1005 | { |
1051 | killagreg | 1006 | if(last_n_p) |
395 | hbuss | 1007 | { |
1051 | killagreg | 1008 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
492 | hbuss | 1009 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1010 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
498 | hbuss | 1011 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1012 | } |
395 | hbuss | 1013 | else last_n_p = 1; |
1014 | } else last_n_p = 0; |
||
1051 | killagreg | 1015 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
395 | hbuss | 1016 | { |
1017 | if(last_n_n) |
||
1051 | killagreg | 1018 | { |
1019 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
||
492 | hbuss | 1020 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1021 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
498 | hbuss | 1022 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1023 | } |
395 | hbuss | 1024 | else last_n_n = 1; |
1025 | } else last_n_n = 0; |
||
1051 | killagreg | 1026 | } |
1027 | else |
||
847 | hbuss | 1028 | { |
1029 | cnt = 0; |
||
921 | hbuss | 1030 | KompassSignalSchlecht = 1000; |
1051 | killagreg | 1031 | } |
499 | hbuss | 1032 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
992 | hbuss | 1033 | if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift/16; |
395 | hbuss | 1034 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1035 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
||
401 | hbuss | 1036 | |
395 | hbuss | 1037 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
492 | hbuss | 1038 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1039 | |||
498 | hbuss | 1040 | ausgleichRoll = 0; |
992 | hbuss | 1041 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*16)) |
492 | hbuss | 1042 | { |
1051 | killagreg | 1043 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
395 | hbuss | 1044 | { |
1051 | killagreg | 1045 | if(last_r_p) |
395 | hbuss | 1046 | { |
1051 | killagreg | 1047 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
492 | hbuss | 1048 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1049 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
498 | hbuss | 1050 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1051 | killagreg | 1051 | } |
395 | hbuss | 1052 | else last_r_p = 1; |
1053 | } else last_r_p = 0; |
||
1051 | killagreg | 1054 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
395 | hbuss | 1055 | { |
1051 | killagreg | 1056 | if(last_r_n) |
395 | hbuss | 1057 | { |
1051 | killagreg | 1058 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
492 | hbuss | 1059 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1060 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
498 | hbuss | 1061 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 1062 | } |
1063 | else last_r_n = 1; |
||
1064 | } else last_r_n = 0; |
||
1051 | killagreg | 1065 | } else |
492 | hbuss | 1066 | { |
1067 | cnt = 0; |
||
921 | hbuss | 1068 | KompassSignalSchlecht = 1000; |
1051 | killagreg | 1069 | } |
499 | hbuss | 1070 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
992 | hbuss | 1071 | if(cnt * 16 > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift/16; |
395 | hbuss | 1072 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1073 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
||
173 | holgerb | 1074 | } |
1051 | killagreg | 1075 | else |
498 | hbuss | 1076 | { |
1077 | LageKorrekturRoll = 0; |
||
1078 | LageKorrekturNick = 0; |
||
880 | hbuss | 1079 | TrichterFlug = 0; |
498 | hbuss | 1080 | } |
1051 | killagreg | 1081 | |
498 | hbuss | 1082 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1051 | killagreg | 1083 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1084 | MittelIntegralNick_Alt = MittelIntegralNick; |
||
1085 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
||
1086 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
395 | hbuss | 1087 | IntegralAccNick = 0; |
1088 | IntegralAccRoll = 0; |
||
1089 | IntegralAccZ = 0; |
||
1090 | MittelIntegralNick = 0; |
||
1091 | MittelIntegralRoll = 0; |
||
1092 | MittelIntegralNick2 = 0; |
||
1093 | MittelIntegralRoll2 = 0; |
||
1094 | ZaehlMessungen = 0; |
||
1095 | } |
||
469 | hbuss | 1096 | //DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor); |
1086 | salvo | 1097 | // Salvo Ersatzkompass und Giergyrokompensation 15.12.2007 ********************** |
1098 | if ((Kompass_Neuer_Wert > 0)) //nur wenn Kompass einen neuen Wert geliefert hat |
||
1099 | { |
||
1100 | Kompass_Neuer_Wert = 0; |
||
1101 | w = (abs(Mittelwert_AccNick)); |
||
1102 | v = (abs(Mittelwert_AccRoll)); |
||
1103 | if ((w < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) //Ersatzkompass und Giergyro nur mit Magnetkompass aktualisieren wenn alles ok |
||
1104 | { |
||
1105 | if ((abs(KompassValue - Kompass_Value_Old)) <= 5) // Aufeinanderfolgende Werte duerfen nur minimal abweichen |
||
1106 | { |
||
395 | hbuss | 1107 | |
1086 | salvo | 1108 | if ((abs(StickGier) < 20)) //Giergyroabgleich mit Kompass |
1109 | { |
||
1110 | if (cnt_stickgier_zero < 255) cnt_stickgier_zero += 1; |
||
1111 | if (cnt_stickgier_zero > 2) // nur Abgleichen wenn keine Stickbewegung da |
||
1112 | { |
||
1113 | w = (int) (GyroGier_Comp/(long)GIER_GRAD_FAKTOR); |
||
1114 | v = KompassValue - gyrogier_kompass; // realen Drehwinkel seit letztem Ruecksetzen von GyroGier_Comp bestimmen |
||
1115 | if (v <-180) v +=360; // Uberlaufkorrektur |
||
1116 | if (v > 180) v -=360; // Uberlaufkorrektur |
||
1117 | |||
1118 | v = w-v; //Differenz Gyro zu Kompass ist der Driftfehler |
||
1119 | |||
1120 | #define GIER_COMP_MAX 4 |
||
1121 | if (v > GIER_COMP_MAX) v= GIER_COMP_MAX; |
||
1122 | if (v < -GIER_COMP_MAX) v= - GIER_COMP_MAX; |
||
1123 | if (abs(w) > 1) |
||
1124 | { |
||
1125 | GyroGier_Comp = 0; |
||
1126 | gyrogier_kompass = KompassValue; // Kompasswert merken |
||
1127 | AdNeutralGier -= v; |
||
1128 | } |
||
1129 | } |
||
1130 | } |
||
1131 | else |
||
1132 | { |
||
1133 | gyrogier_kompass = KompassValue; // Kompasswert merken |
||
1134 | cnt_stickgier_zero = 0; |
||
1135 | GyroGier_Comp = 0; |
||
1136 | } |
||
1137 | |||
1138 | magkompass_ok = 1; // Flag dass Magnetkompass stabil arbeitet |
||
1139 | GyroKomp_Int = (GyroKomp_Int )/(long)GIER_GRAD_FAKTOR; |
||
1140 | |||
1141 | w = KompassValue - GyroKomp_Int; |
||
1142 | if ((w > 0) && (w < 180)) |
||
1143 | { |
||
1144 | ++GyroKomp_Int; |
||
1145 | } |
||
1146 | else if ((w > 0) && (w >= 180)) |
||
1147 | { |
||
1148 | --GyroKomp_Int; |
||
1149 | } |
||
1150 | else if ((w < 0) && (w >= -180)) |
||
1151 | { |
||
1152 | --GyroKomp_Int; |
||
1153 | } |
||
1154 | else if ((w < 0) && (w < -180)) |
||
1155 | { |
||
1156 | ++GyroKomp_Int; |
||
1157 | } |
||
1158 | if (GyroKomp_Int < 0) GyroKomp_Int = GyroKomp_Int + 360L; |
||
1159 | GyroKomp_Int = (GyroKomp_Int%360L) * (long)GIER_GRAD_FAKTOR; // An Magnetkompasswert annaehern |
||
1160 | } |
||
1161 | } |
||
1162 | else //Kompassfehler |
||
1163 | { |
||
1164 | magkompass_ok = 0; |
||
1165 | GyroGier_Comp = 0; |
||
1166 | } |
||
1167 | Kompass_Value_Old = KompassValue; |
||
1168 | } |
||
1169 | // Salvo End ************************* |
||
1170 | |||
1171 | // Salvo 6.10.2007 |
||
1172 | // GPS Home aktivieren wenn Knueppel in Ruhelage und Hoehenschalter aktiviert ist |
||
1173 | //GPS Hold Aktiveren wenn Knueppel in Ruhelage sind |
||
1174 | if ((abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) < Parameter_NaviStickThreshold) |
||
1175 | && (abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < Parameter_NaviStickThreshold) && (gps_alive_cnt > 0)) |
||
1176 | { |
||
1177 | if ((Parameter_NaviGpsModeControl > 170) && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) //Hoehenschalter und GPS Flag aktiv |
||
1178 | { |
||
1179 | if ( gps_cmd == GPS_CMD_REQ_HOLD) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet |
||
1180 | else gps_cmd = GPS_CMD_REQ_HOME; |
||
1181 | n = GPS_CRTL(gps_cmd); |
||
1182 | } |
||
1183 | else if ((Parameter_NaviGpsModeControl < 170) && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) //Hoehenschalter Mittelstellung und GPS Flag aktiv |
||
1184 | { |
||
1185 | if ( gps_cmd == GPS_CMD_REQ_HOME) gps_cmd = GPS_CMD_STOP; // erst mal stoppen, denn altes Kommando wurde noch nicht beendet |
||
1186 | else gps_cmd = GPS_CMD_REQ_HOLD; |
||
1187 | n= GPS_CRTL(gps_cmd); |
||
1188 | } |
||
1189 | else // GPS komplett aus |
||
1190 | { |
||
1191 | if (gps_cmd != GPS_CMD_STOP) |
||
1192 | { |
||
1193 | gps_cmd = GPS_CMD_STOP; |
||
1194 | n= GPS_CRTL(gps_cmd); //GPS Lageregelung beenden |
||
1195 | } |
||
1196 | } |
||
1197 | } |
||
1198 | else |
||
1199 | { |
||
1200 | if (gps_cmd != GPS_CMD_STOP) |
||
1201 | { |
||
1202 | gps_cmd = GPS_CMD_STOP; |
||
1203 | n= GPS_CRTL(gps_cmd); //GPS Lageregelung beenden |
||
1204 | } |
||
1205 | } |
||
1206 | if (gps_state != GPS_CRTL_IDLE) if (TimerWerteausgabe == 12) LED_J16_OFF; //led im GPS Mode schnell blinken lassen |
||
1207 | |||
1208 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1209 | // Gieren |
1051 | killagreg | 1210 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | hbuss | 1211 | // if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;}; |
1051 | killagreg | 1212 | if(abs(StickGier) > 15) // war 35 |
1 | ingob | 1213 | { |
921 | hbuss | 1214 | KompassSignalSchlecht = 1000; |
1051 | killagreg | 1215 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) |
1216 | { |
||
1217 | NeueKompassRichtungMerken = 1; |
||
824 | hbuss | 1218 | }; |
1 | ingob | 1219 | } |
395 | hbuss | 1220 | tmp_int = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1051 | killagreg | 1221 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
173 | holgerb | 1222 | sollGier = tmp_int; |
1051 | killagreg | 1223 | Mess_Integral_Gier -= tmp_int; |
395 | hbuss | 1224 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1225 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
||
1051 | killagreg | 1226 | |
1227 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1228 | // Kompass |
1051 | killagreg | 1229 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
846 | hbuss | 1230 | //DebugOut.Analog[29] = (MaxStickNick + MaxStickRoll); |
819 | hbuss | 1231 | |
1086 | salvo | 1232 | // Salvo 13.9.2007 Nur wenn Magnetkompass ordentliche Werte liefert |
1233 | if ((magkompass_ok > 0) && NeueKompassRichtungMerken) |
||
1234 | { |
||
1235 | KompassStartwert = KompassValue; |
||
1236 | NeueKompassRichtungMerken = 0; |
||
1 | ingob | 1237 | } |
1086 | salvo | 1238 | // Salvo 13.9.2007 |
1239 | w=0; |
||
1240 | // Salvo End |
||
1241 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
||
1 | ingob | 1242 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
921 | hbuss | 1243 | if(w >= 0) |
1 | ingob | 1244 | { |
1086 | salvo | 1245 | // Salvo Kompasssteuerung ********************** |
1246 | if (magkompass_ok > 0) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
||
1247 | // Salvo End |
||
1248 | } |
||
1249 | |||
1 | ingob | 1250 | |
1086 | salvo | 1251 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1252 | |||
1051 | killagreg | 1253 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1254 | // Debugwerte zuordnen |
1051 | killagreg | 1255 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1256 | if(!TimerWerteausgabe--) |
1257 | { |
||
395 | hbuss | 1258 | TimerWerteausgabe = 24; |
1086 | salvo | 1259 | // Salvo 13.12.2007 Beleuchtung steuern |
1260 | if (!(beeptime & BeepMuster)) LED_J16_FLASH; |
||
1261 | else if (MotorenEin) LED_J16_ON; |
||
1262 | else LED_J16_OFF; |
||
1263 | // Salvo End |
||
805 | hbuss | 1264 | |
1 | ingob | 1265 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
1266 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
||
1267 | DebugOut.Analog[2] = Mittelwert_AccNick; |
||
1268 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
||
1269 | DebugOut.Analog[4] = MesswertGier; |
||
1270 | DebugOut.Analog[5] = HoehenWert; |
||
1086 | salvo | 1271 | // DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
1272 | |||
1 | ingob | 1273 | DebugOut.Analog[8] = KompassValue; |
297 | holgerb | 1274 | DebugOut.Analog[9] = UBat; |
1086 | salvo | 1275 | DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
1276 | // DebugOut.Analog[10] = SenderOkay; |
||
1277 | DebugOut.Analog[11] = GyroKomp_Int / GIER_GRAD_FAKTOR; |
||
929 | hbuss | 1278 | //DebugOut.Analog[16] = Mittelwert_AccHoch; |
1086 | salvo | 1279 | // DebugOut.Analog[17] = FromNaviCtrl_Value.Distance; |
1280 | // DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar; |
||
1281 | // DebugOut.Analog[19] = WinkelOut.CalcState; |
||
1282 | // DebugOut.Analog[20] = ServoValue; |
||
720 | ingob | 1283 | |
805 | hbuss | 1284 | |
1285 | // DebugOut.Analog[19] -= DebugOut.Analog[19]/128; |
||
1286 | // if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++; |
||
1086 | salvo | 1287 | DebugOut.Analog[23] = debug_gp_0; |
1288 | DebugOut.Analog[24] = debug_gp_1; |
||
1289 | DebugOut.Analog[25] = debug_gp_2; |
||
1290 | DebugOut.Analog[26] = gps_rel_act_position.utm_east; //in 10cm ausgeben |
||
1291 | DebugOut.Analog[27] = gps_rel_act_position.utm_north; |
||
1292 | DebugOut.Analog[28] = gps_rel_act_position.utm_alt; |
||
1293 | DebugOut.Analog[29] = gps_state + (gps_sub_state*10)+(50*gps_cmd); |
||
805 | hbuss | 1294 | |
1086 | salvo | 1295 | DebugOut.Analog[30] = GPS_Nick; |
1296 | DebugOut.Analog[31] = GPS_Roll; |
||
1297 | |||
1298 | |||
173 | holgerb | 1299 | /* DebugOut.Analog[16] = motor_rx[0]; |
1300 | DebugOut.Analog[17] = motor_rx[1]; |
||
1301 | DebugOut.Analog[18] = motor_rx[2]; |
||
1302 | DebugOut.Analog[19] = motor_rx[3]; |
||
1303 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
||
1304 | DebugOut.Analog[20] /= 14; |
||
1305 | DebugOut.Analog[21] = motor_rx[4]; |
||
1306 | DebugOut.Analog[22] = motor_rx[5]; |
||
1307 | DebugOut.Analog[23] = motor_rx[6]; |
||
1308 | DebugOut.Analog[24] = motor_rx[7]; |
||
1309 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
||
1310 | */ |
||
1311 | // DebugOut.Analog[9] = MesswertNick; |
||
1 | ingob | 1312 | // DebugOut.Analog[9] = SollHoehe; |
1313 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
||
1314 | // DebugOut.Analog[11] = KompassStartwert; |
||
1051 | killagreg | 1315 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
1316 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
||
1317 | // DebugOut.Analog[9] = KompassRichtung; |
||
1 | ingob | 1318 | // DebugOut.Analog[10] = GasMischanteil; |
1319 | // DebugOut.Analog[3] = HoeheD * 32; |
||
1320 | // DebugOut.Analog[4] = hoehenregler; |
||
1321 | } |
||
1322 | |||
1051 | killagreg | 1323 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1324 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1051 | killagreg | 1325 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
604 | hbuss | 1326 | |
173 | holgerb | 1327 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
1328 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
||
1329 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
||
1330 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
||
855 | hbuss | 1331 | MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2; |
1 | ingob | 1332 | |
854 | hbuss | 1333 | DebugOut.Analog[21] = MesswertNick; |
1334 | DebugOut.Analog[22] = MesswertRoll; |
||
1335 | |||
1 | ingob | 1336 | // Maximalwerte abfangen |
882 | hbuss | 1337 | #define MAX_SENSOR (4096*STICK_GAIN) |
1 | ingob | 1338 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1339 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
||
1340 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
||
1341 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
||
1342 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
||
1343 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
||
1344 | |||
1051 | killagreg | 1345 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1346 | // Höhenregelung |
1347 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
||
1051 | killagreg | 1348 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1349 | //OCR0B = 180 - (Poti1 + 120) / 4; |
1350 | //DruckOffsetSetting = OCR0B; |
||
855 | hbuss | 1351 | GasMischanteil *= STICK_GAIN; |
1036 | hbuss | 1352 | /* |
1353 | if(Poti1 > 200) {OCR0A = DruckOffsetSetting - 16; ExpandBaro = 16; }else |
||
1354 | if(Poti1 > 150) {OCR0A = DruckOffsetSetting - 8; ExpandBaro = 8; }else |
||
1355 | if(Poti1 > 100) {OCR0A = DruckOffsetSetting - 4; ExpandBaro = 4; }else |
||
1356 | if(Poti1 > 50) {OCR0A = DruckOffsetSetting - 2; ExpandBaro = 1; }else |
||
1357 | {OCR0A = DruckOffsetSetting; ExpandBaro = 0;} |
||
1358 | */ |
||
1 | ingob | 1359 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
1360 | { |
||
1361 | int tmp_int; |
||
1036 | hbuss | 1362 | static char delay = 100; |
1 | ingob | 1363 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1364 | { |
||
1036 | hbuss | 1365 | if(((EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && ((Parameter_MaxHoehe > 80) && (Parameter_MaxHoehe < 140))) || |
993 | hbuss | 1366 | (!(EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && (Parameter_MaxHoehe < 50))) |
1 | ingob | 1367 | { |
1036 | hbuss | 1368 | if(!delay--) |
1369 | { |
||
1051 | killagreg | 1370 | if(MessLuftdruck > 1000) |
1036 | hbuss | 1371 | { |
1372 | ExpandBaro -= 10; |
||
1051 | killagreg | 1373 | OCR0A = DruckOffsetSetting - ExpandBaro; |
1036 | hbuss | 1374 | beeptime = 300; |
1375 | delay = 250; |
||
1376 | } |
||
1377 | else |
||
1051 | killagreg | 1378 | if(MessLuftdruck < 100) |
1036 | hbuss | 1379 | { |
1380 | ExpandBaro += 10; |
||
1051 | killagreg | 1381 | OCR0A = DruckOffsetSetting - ExpandBaro; |
1036 | hbuss | 1382 | beeptime = 300; |
1383 | delay = 250; |
||
1384 | } |
||
1385 | else |
||
1051 | killagreg | 1386 | { |
1036 | hbuss | 1387 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
1388 | HoehenReglerAktiv = 0; |
||
1389 | delay = 1; |
||
1390 | } |
||
1051 | killagreg | 1391 | } |
1 | ingob | 1392 | } |
1051 | killagreg | 1393 | else |
1394 | { |
||
1036 | hbuss | 1395 | HoehenReglerAktiv = 1; |
1396 | delay = 200; |
||
1051 | killagreg | 1397 | } |
1 | ingob | 1398 | } |
1051 | killagreg | 1399 | else |
1 | ingob | 1400 | { |
492 | hbuss | 1401 | SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20; |
1 | ingob | 1402 | HoehenReglerAktiv = 1; |
1403 | } |
||
1404 | |||
1405 | if(Notlandung) SollHoehe = 0; |
||
1406 | h = HoehenWert; |
||
1407 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
||
1051 | killagreg | 1408 | { |
855 | hbuss | 1409 | h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil |
1 | ingob | 1410 | h = GasMischanteil - h; // vom Gas abziehen |
871 | hbuss | 1411 | // h -= (HoeheD * Parameter_Luftdruck_D)/(8/STICK_GAIN); // D-Anteil |
1412 | h -= (HoeheD)/(8/STICK_GAIN); // D-Anteil |
||
1413 | tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN); |
||
1414 | if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN; |
||
1415 | else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN); |
||
1 | ingob | 1416 | h -= tmp_int; |
1051 | killagreg | 1417 | hoehenregler = (hoehenregler*15 + h) / 16; |
855 | hbuss | 1418 | if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN |
1 | ingob | 1419 | { |
855 | hbuss | 1420 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN; |
1421 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil; |
||
1051 | killagreg | 1422 | } |
1 | ingob | 1423 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
1424 | GasMischanteil = hoehenregler; |
||
1051 | killagreg | 1425 | } |
1 | ingob | 1426 | } |
855 | hbuss | 1427 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1051 | killagreg | 1428 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1429 | // + Mischer und PI-Regler |
1051 | killagreg | 1430 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 1431 | DebugOut.Analog[7] = GasMischanteil; |
1051 | killagreg | 1432 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1433 | // Gier-Anteil |
1051 | killagreg | 1434 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
188 | holgerb | 1435 | #define MUL_G 1.0 |
855 | hbuss | 1436 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
604 | hbuss | 1437 | // GierMischanteil = 0; |
855 | hbuss | 1438 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
693 | hbuss | 1439 | if(GasMischanteil > MIN_GIERGAS) |
1440 | { |
||
1051 | killagreg | 1441 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1442 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
||
693 | hbuss | 1443 | } |
1051 | killagreg | 1444 | else |
693 | hbuss | 1445 | { |
1051 | killagreg | 1446 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1447 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
||
693 | hbuss | 1448 | } |
855 | hbuss | 1449 | tmp_int = MAX_GAS*STICK_GAIN; |
1051 | killagreg | 1450 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
855 | hbuss | 1451 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
513 | hbuss | 1452 | |
1051 | killagreg | 1453 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1454 | // Nick-Achse |
1051 | killagreg | 1455 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
723 | hbuss | 1456 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1457 | if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - StickNick; // I-Anteil bei Winkelregelung |
||
1051 | killagreg | 1458 | else SummeNick += DiffNick; // I-Anteil bei HH |
855 | hbuss | 1459 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1460 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
||
1051 | killagreg | 1461 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
1 | ingob | 1462 | // Motor Vorn |
499 | hbuss | 1463 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1051 | killagreg | 1464 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1465 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
||
173 | holgerb | 1466 | |
1 | ingob | 1467 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
855 | hbuss | 1468 | motorwert /= STICK_GAIN; |
173 | holgerb | 1469 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1470 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1051 | killagreg | 1471 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1472 | Motor_Vorne = motorwert; |
||
1 | ingob | 1473 | // Motor Heck |
1474 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
||
855 | hbuss | 1475 | motorwert /= STICK_GAIN; |
173 | holgerb | 1476 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1477 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1478 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
1051 | killagreg | 1479 | Motor_Hinten = motorwert; |
1480 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1481 | // Roll-Achse |
1051 | killagreg | 1482 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
723 | hbuss | 1483 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1484 | if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - StickRoll;// I-Anteil bei Winkelregelung |
||
498 | hbuss | 1485 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
918 | hbuss | 1486 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1487 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
||
297 | holgerb | 1488 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
499 | hbuss | 1489 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1051 | killagreg | 1490 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1491 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
||
1 | ingob | 1492 | // Motor Links |
1493 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
||
855 | hbuss | 1494 | motorwert /= STICK_GAIN; |
173 | holgerb | 1495 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1496 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1497 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
1051 | killagreg | 1498 | Motor_Links = motorwert; |
1 | ingob | 1499 | // Motor Rechts |
1500 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
||
855 | hbuss | 1501 | motorwert /= STICK_GAIN; |
173 | holgerb | 1502 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1503 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1051 | killagreg | 1504 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1505 | Motor_Rechts = motorwert; |
||
1 | ingob | 1506 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
1507 | } |
||
1508 |