Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
2 | Flight Control |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + www.MikroKopter.com |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2050 | holgerb | 7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
||
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
1 | ingob | 13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2050 | holgerb | 14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
22 | // + des Mitverschuldens offen. |
||
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
||
1 | ingob | 31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2050 | holgerb | 32 | // + Software LICENSING TERMS |
1 | ingob | 33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2050 | holgerb | 34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
||
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
||
37 | // + The Software may only be used with the Licensor's products. |
||
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
40 | // + agreement shall be the property of the Licensor. |
||
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
43 | // + The customer shall be responsible for taking reasonable precautions |
||
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
53 | // + #### END OF LICENSING TERMS #### |
||
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
1 | ingob | 55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | |||
57 | #include "main.h" |
||
1320 | hbuss | 58 | #include "mymath.h" |
1330 | killagreg | 59 | #include "isqrt.h" |
1 | ingob | 60 | |
1352 | hbuss | 61 | unsigned char h,m,s; |
62 | unsigned int BaroExpandActive = 0; |
||
2481 | holgerb | 63 | int MesswertNick,MesswertRoll,MesswertGier,RohMesswertNick,RohMesswertRoll; |
1166 | hbuss | 64 | int TrimNick, TrimRoll; |
927 | hbuss | 65 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
1703 | holgerb | 66 | int Mittelwert_AccNick, Mittelwert_AccRoll; |
1643 | holgerb | 67 | unsigned int NeutralAccX=0, NeutralAccY=0; |
805 | hbuss | 68 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
1639 | holgerb | 69 | int NeutralAccZ = 0; |
2316 | holgerb | 70 | signed char NeutralAccZfine = 0; |
1683 | killagreg | 71 | unsigned char ControlHeading = 0;// in 2° |
2481 | holgerb | 72 | long IntegralNick = 0; |
73 | long IntegralRoll = 0; |
||
693 | hbuss | 74 | long Integral_Gier = 0; |
2481 | holgerb | 75 | long Mess_IntegralNick = 0; |
76 | long Mess_IntegralRoll = 0; |
||
693 | hbuss | 77 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
2481 | holgerb | 78 | long MittelIntegralNick,MittelIntegralRoll; |
1685 | holgerb | 79 | long SummeNick=0,SummeRoll=0; |
1 | ingob | 80 | volatile long Mess_Integral_Hoch = 0; |
1840 | holgerb | 81 | int KompassValue = -1; |
1837 | holgerb | 82 | int KompassSollWert = 0; |
1941 | holgerb | 83 | //int KompassRichtung = 0; |
1839 | holgerb | 84 | char CalculateCompassTimer = 100; |
85 | unsigned char KompassFusion = 32; |
||
86 | unsigned int KompassSignalSchlecht = 50; |
||
855 | hbuss | 87 | unsigned char MAX_GAS,MIN_GAS; |
1 | ingob | 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; |
2437 | holgerb | 92 | int ErsatzKompassInGrad, CompassCorrected; // Kompasswert in Grad |
693 | hbuss | 93 | int GierGyroFehler = 0; |
1211 | hbuss | 94 | char GyroFaktor,GyroFaktorGier; |
95 | char IntegralFaktor,IntegralFaktorGier; |
||
1153 | hbuss | 96 | int DiffNick,DiffRoll; |
2427 | holgerb | 97 | unsigned int StickGasHover = 127; |
98 | int HoverGasMin = 0, HoverGasMax = 1023; |
||
1943 | holgerb | 99 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
1377 | hbuss | 100 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
1391 | killagreg | 101 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
1 | ingob | 102 | volatile unsigned char SenderOkay = 0; |
1698 | holgerb | 103 | char MotorenEin = 0,StartTrigger = 0; |
1246 | killagreg | 104 | long HoehenWert = 0; |
105 | long SollHoehe = 0; |
||
1942 | holgerb | 106 | signed int AltitudeSetpointTrimming = 0; |
1855 | holgerb | 107 | long FromNC_AltitudeSetpoint = 0; |
108 | unsigned char FromNC_AltitudeSpeed = 0; |
||
1862 | holgerb | 109 | unsigned char carefree_old = 50; // to make the Beep when switching |
1942 | holgerb | 110 | signed char WaypointTrimming = 0; |
1840 | holgerb | 111 | int CompassGierSetpoint = 0; |
2009 | holgerb | 112 | unsigned char CalibrationDone = 0; |
2061 | holgerb | 113 | char NeueKompassRichtungMerken = 0; |
1692 | holgerb | 114 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
1153 | hbuss | 115 | //float Ki = FAKTOR_I; |
1676 | holgerb | 116 | int Ki = 10300 / 33; |
395 | hbuss | 117 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
118 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
||
1 | ingob | 119 | |
120 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
||
2342 | holgerb | 121 | unsigned char Parameter_HoehenSchalter = 0; // Wert : 0-250 |
1 | ingob | 122 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
123 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
||
124 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
||
1283 | hbuss | 125 | unsigned char Parameter_Hoehe_GPS_Z = 64; // Wert : 0-250 |
1111 | hbuss | 126 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
173 | holgerb | 127 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
1 | ingob | 128 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
1322 | hbuss | 129 | unsigned char Parameter_Gyro_Gier_P = 150; // Wert : 10-250 |
130 | unsigned char Parameter_Gyro_Gier_I = 150; // Wert : 10-250 |
||
1 | ingob | 131 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
132 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
||
133 | unsigned char Parameter_UserParam1 = 0; |
||
134 | unsigned char Parameter_UserParam2 = 0; |
||
135 | unsigned char Parameter_UserParam3 = 0; |
||
136 | unsigned char Parameter_UserParam4 = 0; |
||
499 | hbuss | 137 | unsigned char Parameter_UserParam5 = 0; |
138 | unsigned char Parameter_UserParam6 = 0; |
||
139 | unsigned char Parameter_UserParam7 = 0; |
||
140 | unsigned char Parameter_UserParam8 = 0; |
||
2349 | holgerb | 141 | unsigned char Parameter_NickControl = 100; |
1 | ingob | 142 | unsigned char Parameter_ServoNickControl = 100; |
1232 | hbuss | 143 | unsigned char Parameter_ServoRollControl = 100; |
2296 | holgerb | 144 | unsigned char Parameter_ServoNickComp = 50; |
145 | unsigned char Parameter_ServoRollComp = 85; |
||
173 | holgerb | 146 | unsigned char Parameter_LoopGasLimit = 70; |
1120 | hbuss | 147 | unsigned char Parameter_AchsKopplung1 = 90; |
148 | unsigned char Parameter_AchsKopplung2 = 65; |
||
149 | unsigned char Parameter_CouplingYawCorrection = 64; |
||
150 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
||
499 | hbuss | 151 | unsigned char Parameter_DynamicStability = 100; |
921 | hbuss | 152 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
153 | unsigned char Parameter_J16Timing; // for the J16 Output |
||
154 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
||
155 | unsigned char Parameter_J17Timing; // for the J17 Output |
||
1051 | killagreg | 156 | unsigned char Parameter_NaviGpsGain; |
157 | unsigned char Parameter_NaviGpsP; |
||
158 | unsigned char Parameter_NaviGpsI; |
||
159 | unsigned char Parameter_NaviGpsD; |
||
2344 | holgerb | 160 | unsigned char Parameter_NaviGpsA; |
2447 | holgerb | 161 | //unsigned char Parameter_NaviOperatingRadius; |
993 | hbuss | 162 | unsigned char Parameter_NaviWindCorrection; |
163 | unsigned char Parameter_NaviSpeedCompensation; |
||
921 | hbuss | 164 | unsigned char Parameter_ExternalControl; |
1916 | holgerb | 165 | unsigned char Parameter_GlobalConfig; |
166 | unsigned char Parameter_ExtraConfig; |
||
1966 | holgerb | 167 | unsigned char Parameter_MaximumAltitude; |
1403 | hbuss | 168 | unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
1668 | holgerb | 169 | unsigned char CareFree = 0; |
1876 | holgerb | 170 | const signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8}; // 15° steps |
1622 | killagreg | 171 | |
492 | hbuss | 172 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
614 | hbuss | 173 | int MaxStickNick = 0,MaxStickRoll = 0; |
871 | hbuss | 174 | unsigned int modell_fliegt = 0; |
1861 | holgerb | 175 | volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0; |
2481 | holgerb | 176 | unsigned char FC_StatusFlags3 = 0; |
1121 | hbuss | 177 | long GIER_GRAD_FAKTOR = 1291; |
1153 | hbuss | 178 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
1209 | hbuss | 179 | signed int tmp_motorwert[MAX_MOTORS]; |
1591 | holgerb | 180 | char VarioCharacter = ' '; |
2028 | holgerb | 181 | unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing |
2230 | holgerb | 182 | unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while |
2309 | holgerb | 183 | signed int Variance = 0; |
184 | signed int CosAttitude; // for projection of hoover gas |
||
185 | unsigned char ACC_AltitudeControl = 0; |
||
2390 | holgerb | 186 | unsigned char LowVoltageLandingActive = 0; |
2408 | holgerb | 187 | unsigned char LowVoltageHomeActive = 0; |
2481 | holgerb | 188 | signed int DriftNick = 0, DriftRoll = 0; |
1591 | holgerb | 189 | |
2367 | holgerb | 190 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
191 | #define OPA_OFFSET_STEP 5 |
||
192 | #else |
||
193 | #define OPA_OFFSET_STEP 10 |
||
194 | #endif |
||
195 | |||
1639 | holgerb | 196 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
197 | // Debugwerte zuordnen |
||
198 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
199 | void CopyDebugValues(void) |
||
200 | { |
||
2373 | holgerb | 201 | DebugOut.Analog[0] = ToNaviCtrl.IntegralNick;//IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
202 | DebugOut.Analog[1] = ToNaviCtrl.IntegralRoll;//IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
||
1639 | holgerb | 203 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
204 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
||
1660 | holgerb | 205 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
2367 | holgerb | 206 | DebugOut.Analog[5] = HoehenWert/10; |
2309 | holgerb | 207 | DebugOut.Analog[6] = Aktuell_az;//AdWertAccHoch;//(Mess_Integral_Hoch / 512); |
1639 | holgerb | 208 | DebugOut.Analog[8] = KompassValue; |
209 | DebugOut.Analog[9] = UBat; |
||
210 | DebugOut.Analog[10] = SenderOkay; |
||
1941 | holgerb | 211 | DebugOut.Analog[11] = ErsatzKompassInGrad; |
1702 | holgerb | 212 | DebugOut.Analog[12] = Motor[0].SetPoint; |
213 | DebugOut.Analog[13] = Motor[1].SetPoint; |
||
214 | DebugOut.Analog[14] = Motor[2].SetPoint; |
||
215 | DebugOut.Analog[15] = Motor[3].SetPoint; |
||
1639 | holgerb | 216 | DebugOut.Analog[20] = ServoNickValue; |
2322 | holgerb | 217 | DebugOut.Analog[21] = HoverGas; |
1639 | holgerb | 218 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
219 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
||
2309 | holgerb | 220 | DebugOut.Analog[24] = SollHoehe/10; |
2437 | holgerb | 221 | // DebugOut.Analog[27] = KompassSollWert; |
1682 | holgerb | 222 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
1639 | holgerb | 223 | DebugOut.Analog[30] = GPS_Nick; |
224 | DebugOut.Analog[31] = GPS_Roll; |
||
1702 | holgerb | 225 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
2373 | holgerb | 226 | //DebugOut.Analog[16] = MinBlTemperture; |
227 | //DebugOut.Analog[17] = MaxBlTemperture; |
||
2316 | holgerb | 228 | //DebugOut.Analog[16] = Variance; |
229 | //DebugOut.Analog[17] = VarioMeter; |
||
2369 | holgerb | 230 | //DebugOut.Analog[16] = GasIsZeroCnt; |
2316 | holgerb | 231 | //DebugOut.Analog[18] = HoehenWertF; |
232 | //DebugOut.Analog[25] = Parameter_Hoehe_P; |
||
233 | //DebugOut.Analog[26] = Parameter_Luftdruck_D; |
||
1639 | holgerb | 234 | } |
235 | |||
1760 | holgerb | 236 | |
1232 | hbuss | 237 | void Piep(unsigned char Anzahl, unsigned int dauer) |
1 | ingob | 238 | { |
2263 | holgerb | 239 | unsigned int wait = 0; |
1232 | hbuss | 240 | if(MotorenEin) return; //auf keinen Fall im Flug! |
1966 | holgerb | 241 | GRN_OFF; |
1 | ingob | 242 | while(Anzahl--) |
243 | { |
||
1232 | hbuss | 244 | beeptime = dauer; |
2263 | holgerb | 245 | wait = dauer; |
246 | while(beeptime || wait) |
||
247 | { |
||
248 | if(UpdateMotor) |
||
249 | { |
||
250 | UpdateMotor = 0; |
||
251 | if(!beeptime) wait--; |
||
252 | LIBFC_Polling(); |
||
253 | }; |
||
254 | } |
||
1 | ingob | 255 | } |
1966 | holgerb | 256 | GRN_ON; |
1 | ingob | 257 | } |
258 | |||
259 | //############################################################################ |
||
1622 | killagreg | 260 | // Messwerte beim Ermitteln der Nullage |
261 | void CalibrierMittelwert(void) |
||
262 | //############################################################################ |
||
263 | { |
||
2426 | holgerb | 264 | // if(PlatinenVersion == 13) SucheGyroOffset(); |
1622 | killagreg | 265 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
266 | ANALOG_OFF; |
||
267 | MesswertNick = AdWertNick; |
||
268 | MesswertRoll = AdWertRoll; |
||
269 | MesswertGier = AdWertGier; |
||
1703 | holgerb | 270 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
271 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
||
1622 | killagreg | 272 | // ADC einschalten |
273 | ANALOG_ON; |
||
274 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
275 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
276 | } |
||
277 | |||
278 | //############################################################################ |
||
1 | ingob | 279 | // Nullwerte ermitteln |
2319 | holgerb | 280 | // Parameter: 0 -> after switch on (ignore ACC-Z fault) |
281 | // Parameter: 1 -> before Start |
||
282 | // Parameter: 2 -> calibrate and store ACC |
||
2481 | holgerb | 283 | // Parameter: 3 -> use stored Gyro calibration Data from EEPROM |
2319 | holgerb | 284 | unsigned char SetNeutral(unsigned char AdjustmentMode) // retuns: "sucess" |
1 | ingob | 285 | //############################################################################ |
286 | { |
||
2316 | holgerb | 287 | unsigned char i, sucess = 1; |
2367 | holgerb | 288 | unsigned int gier_neutral = 0, nick_neutral = 0, roll_neutral = 0, acc_z_neutral = 0, barotest; |
1702 | holgerb | 289 | VersionInfo.HardwareError[0] = 0; |
2146 | holgerb | 290 | // HEF4017Reset_ON; |
1051 | killagreg | 291 | NeutralAccX = 0; |
1 | ingob | 292 | NeutralAccY = 0; |
293 | NeutralAccZ = 0; |
||
2316 | holgerb | 294 | NeutralAccZfine = 0; |
1622 | killagreg | 295 | |
1051 | killagreg | 296 | AdNeutralNick = 0; |
297 | AdNeutralRoll = 0; |
||
1 | ingob | 298 | AdNeutralGier = 0; |
1622 | killagreg | 299 | |
395 | hbuss | 300 | Parameter_AchsKopplung1 = 0; |
1120 | hbuss | 301 | Parameter_AchsKopplung2 = 0; |
1622 | killagreg | 302 | |
1036 | hbuss | 303 | ExpandBaro = 0; |
2481 | holgerb | 304 | if(AdjustmentMode == 3) FC_StatusFlags3 |= FC_STATUS3_BOAT; |
305 | // else FC_StatusFlags3 &= ~FC_STATUS3_BOAT; -> do not clear that |
||
1622 | killagreg | 306 | |
1051 | killagreg | 307 | CalibrierMittelwert(); |
395 | hbuss | 308 | Delay_ms_Mess(100); |
1 | ingob | 309 | CalibrierMittelwert(); |
1622 | killagreg | 310 | |
1 | ingob | 311 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
1051 | killagreg | 312 | { |
2367 | holgerb | 313 | if((MessLuftdruck > 950) || (MessLuftdruck < 750) || ExpandBaro) SucheLuftruckOffset(); |
1 | ingob | 314 | } |
2367 | holgerb | 315 | |
316 | barotest = MessLuftdruck; |
||
1166 | hbuss | 317 | #define NEUTRAL_FILTER 32 |
2367 | holgerb | 318 | OCR0A += OPA_OFFSET_STEP; |
319 | OCR0B = 255 - OCR0A; |
||
1166 | hbuss | 320 | for(i=0; i<NEUTRAL_FILTER; i++) |
1111 | hbuss | 321 | { |
322 | Delay_ms_Mess(10); |
||
1216 | killagreg | 323 | gier_neutral += AdWertGier; |
1166 | hbuss | 324 | nick_neutral += AdWertNick; |
325 | roll_neutral += AdWertRoll; |
||
2316 | holgerb | 326 | acc_z_neutral += Aktuell_az; |
1111 | hbuss | 327 | } |
2367 | holgerb | 328 | if(MessLuftdruck < 1010 && MessLuftdruck > 20) BaroStep = barotest - MessLuftdruck; |
329 | OCR0A -= OPA_OFFSET_STEP; |
||
330 | OCR0B = 255 - OCR0A; |
||
2316 | holgerb | 331 | AdNeutralNick = (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
332 | AdNeutralRoll = (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
||
333 | AdNeutralGier = (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
||
334 | NeutralAccZ = (acc_z_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
||
1622 | killagreg | 335 | |
401 | hbuss | 336 | StartNeutralRoll = AdNeutralRoll; |
337 | StartNeutralNick = AdNeutralNick; |
||
1622 | killagreg | 338 | |
2319 | holgerb | 339 | if(AdjustmentMode == 2) |
1622 | killagreg | 340 | { |
341 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
||
342 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
||
343 | // Save ACC neutral settings to eeprom |
||
1639 | holgerb | 344 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
345 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
||
1622 | killagreg | 346 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
2481 | holgerb | 347 | SetParamWord(PID_GYRO_NICK,(uint16_t)AdNeutralNick); |
348 | SetParamWord(PID_GYRO_ROLL,(uint16_t)AdNeutralRoll); |
||
349 | SetParamWord(PID_GYRO_YAW,(uint16_t)AdNeutralGier); |
||
513 | hbuss | 350 | } |
1051 | killagreg | 351 | else |
513 | hbuss | 352 | { |
1622 | killagreg | 353 | // restore from eeprom |
354 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
||
355 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
||
356 | // strange settings? |
||
2316 | holgerb | 357 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048)/* || ((unsigned int) NeutralAccZ > 1024)*/) |
1622 | killagreg | 358 | { |
359 | printf("\n\rACC not calibrated!\r\n"); |
||
360 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
||
361 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
||
2316 | holgerb | 362 | sucess = 0; |
1622 | killagreg | 363 | } |
2481 | holgerb | 364 | if(FC_StatusFlags3 & FC_STATUS3_BOAT) // Read Gyro Data from eeprom |
365 | { |
||
366 | unsigned int nick, roll, gier; |
||
367 | // restore from eeprom |
||
368 | nick = (int16_t)GetParamWord(PID_GYRO_NICK); |
||
369 | roll = (int16_t)GetParamWord(PID_GYRO_ROLL); |
||
370 | gier = (int16_t)GetParamWord(PID_GYRO_YAW); |
||
371 | // strange settings? |
||
372 | if(((unsigned int) nick > (600 * 16)) || ((unsigned int) nick < (400 * 16)) |
||
373 | || ((unsigned int) roll > (600 * 16)) || ((unsigned int) roll < (400 * 16)) |
||
374 | || ((unsigned int) gier > (600 * 2)) || ((unsigned int) gier < (400 * 2))) |
||
375 | { |
||
376 | printf("\n\rGyro calibration data not valid\r\n"); |
||
377 | sucess = 0; |
||
378 | } |
||
379 | else |
||
380 | { |
||
381 | AdNeutralNick = nick; |
||
382 | AdNeutralRoll = roll; |
||
383 | AdNeutralGier = gier; |
||
384 | } |
||
385 | } |
||
513 | hbuss | 386 | } |
2330 | holgerb | 387 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
388 | MesswertNick = 0; |
||
1 | ingob | 389 | MesswertRoll = 0; |
390 | MesswertGier = 0; |
||
2367 | holgerb | 391 | Delay_ms_Mess(200); |
1703 | holgerb | 392 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
393 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
||
1173 | hbuss | 394 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
395 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
||
2072 | holgerb | 396 | Mess_IntegralNick = IntegralNick; |
397 | Mess_IntegralRoll = IntegralRoll; |
||
1173 | hbuss | 398 | Mess_Integral_Gier = 0; |
1837 | holgerb | 399 | KompassSollWert = KompassValue; |
1839 | holgerb | 400 | KompassSignalSchlecht = 100; |
882 | hbuss | 401 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
402 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
||
492 | hbuss | 403 | ExternHoehenValue = 0; |
693 | hbuss | 404 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
405 | GierGyroFehler = 0; |
||
921 | hbuss | 406 | LED_Init(); |
2389 | holgerb | 407 | if(AdjustmentMode != 0) FC_StatusFlags |= FC_STATUS_CALIBRATE; |
992 | hbuss | 408 | FromNaviCtrl_Value.Kalman_K = -1; |
1173 | hbuss | 409 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
992 | hbuss | 410 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
1171 | hbuss | 411 | SenderOkay = 100; |
2349 | holgerb | 412 | |
413 | if(ServoActive) DDRD |=0x80; // enable J7 -> Servo signal |
||
414 | else |
||
1320 | hbuss | 415 | { |
2366 | holgerb | 416 | if((EE_Parameter.ServoCompInvert & SERVO_NICK_INV) && (EE_Parameter.ServoCompInvert & SERVO_RELATIVE)) NickServoValue = 12000;//((128 + 60) * 4 * 16); // neutral position = upper 1/4// else |
417 | else NickServoValue = ((128 - 60) * 4 * 16); // neutral position = lower 1/4 |
||
2349 | holgerb | 418 | CalculateServoSignals = 1; |
419 | CalculateServo(); // nick |
||
420 | CalculateServo(); // roll |
||
2240 | holgerb | 421 | } |
1702 | holgerb | 422 | |
2316 | holgerb | 423 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
424 | signed int tilt1, tilt2; |
||
425 | tilt1 = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
||
426 | tilt2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
||
427 | tilt1 = (int16_t)ihypot(tilt1,tilt2); // tilt angle over all |
||
428 | CosAttitude = c_cos_8192(tilt1); |
||
429 | NeutralAccZ = (long)((long) (NeutralAccZ - 512) * 8192 + 4096) / CosAttitude + 512; |
||
430 | if(tilt1 > 20) sucess = 0; // calibration must be within 20° Tilt angle |
||
2427 | holgerb | 431 | if(AdjustmentMode != 0 && ACC_AltitudeControl) if((NeutralAccZ < 682 - 30) || (NeutralAccZ > 682 + 35)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; sucess = 0;}; |
2316 | holgerb | 432 | #else |
433 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
||
2330 | holgerb | 434 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
2316 | holgerb | 435 | #endif |
1765 | killagreg | 436 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
437 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; }; |
||
438 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; }; |
||
439 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; }; |
||
440 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; }; |
||
441 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; }; |
||
2316 | holgerb | 442 | if(VersionInfo.HardwareError[0]) sucess = 0; |
1862 | holgerb | 443 | carefree_old = 70; |
1925 | holgerb | 444 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1921 | holgerb | 445 | LIBFC_HoTT_Clear(); |
2316 | holgerb | 446 | ACC_AltitudeFusion(2); // initalisation |
1925 | holgerb | 447 | #endif |
2367 | holgerb | 448 | StartLuftdruck = Luftdruck; |
449 | VarioMeter = 0; |
||
450 | SummenHoehe = 0; Mess_Integral_Hoch = 0; |
||
2373 | holgerb | 451 | DebugOut.Analog[28] = 0; // I2C-Counter |
2367 | holgerb | 452 | CalcExpandBaroStep(); |
2481 | holgerb | 453 | if(FC_StatusFlags3 & FC_STATUS3_BOAT && !EE_Parameter.Driftkomp) EE_Parameter.Driftkomp = 4; |
2316 | holgerb | 454 | return(sucess); |
1 | ingob | 455 | } |
456 | |||
1702 | holgerb | 457 | |
1 | ingob | 458 | //############################################################################ |
395 | hbuss | 459 | // Bearbeitet die Messwerte |
1 | ingob | 460 | void Mittelwert(void) |
461 | //############################################################################ |
||
1051 | killagreg | 462 | { |
1111 | hbuss | 463 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
464 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
||
1153 | hbuss | 465 | signed long winkel_nick, winkel_roll; |
1111 | hbuss | 466 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
1171 | hbuss | 467 | MesswertNick = (signed int) AdWertNickFilter / 8; |
468 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
||
1153 | hbuss | 469 | RohMesswertNick = MesswertNick; |
470 | RohMesswertRoll = MesswertRoll; |
||
1166 | hbuss | 471 | |
395 | hbuss | 472 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
1703 | holgerb | 473 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
474 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
||
805 | hbuss | 475 | NaviAccNick += AdWertAccNick; |
476 | NaviAccRoll += AdWertAccRoll; |
||
477 | NaviCntAcc++; |
||
1153 | hbuss | 478 | |
1155 | hbuss | 479 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
2471 | holgerb | 480 | HoehenWert = HoehenWert_Mess; |
481 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
482 | HoehenWertF = HoehenWertF_Mess; |
||
483 | #else |
||
484 | HoehenWertF = HoehenWert; |
||
485 | #endif |
||
486 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1155 | hbuss | 487 | // ADC einschalten |
1171 | hbuss | 488 | ANALOG_ON; |
1155 | hbuss | 489 | AdReady = 0; |
490 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
||
491 | |||
1216 | killagreg | 492 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
493 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
||
1153 | hbuss | 494 | else winkel_roll = Mess_IntegralRoll; |
495 | |||
1216 | killagreg | 496 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
497 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
||
1153 | hbuss | 498 | else winkel_nick = Mess_IntegralNick; |
499 | |||
1120 | hbuss | 500 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
1153 | hbuss | 501 | Mess_Integral_Gier += MesswertGier; |
502 | ErsatzKompass += MesswertGier; |
||
395 | hbuss | 503 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
1916 | holgerb | 504 | if(!Looping_Nick && !Looping_Roll && (Parameter_GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
395 | hbuss | 505 | { |
1153 | hbuss | 506 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
1120 | hbuss | 507 | tmpl3 *= Parameter_AchsKopplung2; //65 |
1111 | hbuss | 508 | tmpl3 /= 4096L; |
1153 | hbuss | 509 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
1216 | killagreg | 510 | tmpl4 *= Parameter_AchsKopplung2; //65 |
1111 | hbuss | 511 | tmpl4 /= 4096L; |
1153 | hbuss | 512 | KopplungsteilNickRoll = tmpl3; |
513 | KopplungsteilRollNick = tmpl4; |
||
1111 | hbuss | 514 | tmpl4 -= tmpl3; |
515 | ErsatzKompass += tmpl4; |
||
1166 | hbuss | 516 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
1111 | hbuss | 517 | |
1153 | hbuss | 518 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
1111 | hbuss | 519 | tmpl *= Parameter_AchsKopplung1; // 90 |
880 | hbuss | 520 | tmpl /= 4096L; |
1153 | hbuss | 521 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
395 | hbuss | 522 | tmpl2 *= Parameter_AchsKopplung1; |
1662 | killagreg | 523 | tmpl2 /= 4096L; |
1225 | hbuss | 524 | if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
1153 | hbuss | 525 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
395 | hbuss | 526 | } |
1166 | hbuss | 527 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
1658 | holgerb | 528 | TrimRoll = tmpl - tmpl2 / 100L; |
529 | TrimNick = -tmpl2 + tmpl / 100L; |
||
1111 | hbuss | 530 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
531 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
||
532 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
||
395 | hbuss | 533 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | hbuss | 534 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
1051 | killagreg | 535 | if(Mess_IntegralRoll > Umschlag180Roll) |
395 | hbuss | 536 | { |
882 | hbuss | 537 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
1051 | killagreg | 538 | } |
395 | hbuss | 539 | if(Mess_IntegralRoll <-Umschlag180Roll) |
540 | { |
||
882 | hbuss | 541 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
1051 | killagreg | 542 | } |
395 | hbuss | 543 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | hbuss | 544 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
1051 | killagreg | 545 | if(Mess_IntegralNick > Umschlag180Nick) |
882 | hbuss | 546 | { |
547 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
||
1051 | killagreg | 548 | } |
549 | if(Mess_IntegralNick <-Umschlag180Nick) |
||
395 | hbuss | 550 | { |
882 | hbuss | 551 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
1051 | killagreg | 552 | } |
1111 | hbuss | 553 | |
1 | ingob | 554 | Integral_Gier = Mess_Integral_Gier; |
555 | IntegralNick = Mess_IntegralNick; |
||
556 | IntegralRoll = Mess_IntegralRoll; |
||
557 | |||
2481 | holgerb | 558 | |
1166 | hbuss | 559 | #define D_LIMIT 128 |
560 | |||
1171 | hbuss | 561 | MesswertNick = HiResNick / 8; |
562 | MesswertRoll = HiResRoll / 8; |
||
1166 | hbuss | 563 | |
1167 | hbuss | 564 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
2426 | holgerb | 565 | // if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
566 | // else |
||
567 | { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
||
1167 | hbuss | 568 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
2426 | holgerb | 569 | // if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
570 | // else |
||
571 | { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
||
1167 | hbuss | 572 | |
1216 | killagreg | 573 | if(Parameter_Gyro_D) |
1111 | hbuss | 574 | { |
1166 | hbuss | 575 | d2Nick = HiResNick - oldNick; |
576 | oldNick = (oldNick + HiResNick)/2; |
||
1111 | hbuss | 577 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
578 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
||
1791 | holgerb | 579 | |
1166 | hbuss | 580 | d2Roll = HiResRoll - oldRoll; |
581 | oldRoll = (oldRoll + HiResRoll)/2; |
||
1111 | hbuss | 582 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
583 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
||
1791 | holgerb | 584 | |
585 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
||
1166 | hbuss | 586 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
587 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
||
588 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
||
1216 | killagreg | 589 | } |
1111 | hbuss | 590 | |
1166 | hbuss | 591 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
592 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
||
593 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
||
594 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
||
1153 | hbuss | 595 | |
1916 | holgerb | 596 | if(Parameter_GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
1153 | hbuss | 597 | { |
598 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
||
599 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
||
600 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
||
601 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
||
602 | } |
||
1 | ingob | 603 | } |
604 | |||
605 | //############################################################################ |
||
606 | // Senden der Motorwerte per I2C-Bus |
||
607 | void SendMotorData(void) |
||
608 | //############################################################################ |
||
1051 | killagreg | 609 | { |
1209 | hbuss | 610 | unsigned char i; |
921 | hbuss | 611 | if(!MotorenEin) |
1 | ingob | 612 | { |
1765 | killagreg | 613 | FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY); |
2309 | holgerb | 614 | FC_StatusFlags2 &= ~FC_STATUS2_WAIT_FOR_TAKEOFF; |
1216 | killagreg | 615 | for(i=0;i<MAX_MOTORS;i++) |
616 | { |
||
617 | if(!PC_MotortestActive) MotorTest[i] = 0; |
||
1638 | holgerb | 618 | Motor[i].SetPoint = MotorTest[i]; |
619 | Motor[i].SetPointLowerBits = 0; |
||
620 | /* |
||
1760 | holgerb | 621 | Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution |
622 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
||
1638 | holgerb | 623 | */ |
1216 | killagreg | 624 | } |
1212 | hbuss | 625 | if(PC_MotortestActive) PC_MotortestActive--; |
1216 | killagreg | 626 | } |
1765 | killagreg | 627 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
1744 | holgerb | 628 | |
2418 | holgerb | 629 | // ++++++++++++++++++++++++++++++++++++++++++ |
630 | |||
631 | // ++++++++++++++++++++++++++++++++++++++++++ |
||
2427 | holgerb | 632 | #ifdef REDUNDANT_FC_SLAVE |
2418 | holgerb | 633 | I2CTimeout = 100; |
634 | return; |
||
2427 | holgerb | 635 | #endif |
636 | |||
637 | #ifdef REDUNDANT_FC_MASTER |
||
638 | if(Parameter_UserParam7 > 150) |
||
2418 | holgerb | 639 | { |
2427 | holgerb | 640 | // Make noise |
641 | if((BeepMuster == 0xffff)) { beeptime = 25000; BeepMuster = 0x0080; } |
||
642 | // Do not send I2C-Data |
||
2481 | holgerb | 643 | if(FC_StatusFlags3 & FC_STATUS3_REDUNDANCE) |
2427 | holgerb | 644 | { |
645 | I2CTimeout = 100; |
||
646 | return; |
||
647 | } |
||
2418 | holgerb | 648 | } |
649 | #endif |
||
650 | |||
1765 | killagreg | 651 | if(I2C_TransferActive) |
1744 | holgerb | 652 | { |
1760 | holgerb | 653 | I2C_TransferActive = 0; // enable for the next time |
1765 | killagreg | 654 | } |
655 | else |
||
1744 | holgerb | 656 | { |
2407 | holgerb | 657 | // motor_write = 0; |
1760 | holgerb | 658 | I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode |
1765 | killagreg | 659 | } |
1 | ingob | 660 | } |
661 | |||
2342 | holgerb | 662 | unsigned char GetChannelValue(unsigned char ch) // gives the unsigned value of the channel |
663 | { |
||
664 | int tmp2; |
||
665 | if(ch == 0) return(0); |
||
666 | tmp2 = PPM_in[ch] + 127; |
||
667 | if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0; |
||
668 | return(tmp2); |
||
669 | } |
||
1 | ingob | 670 | |
671 | //############################################################################ |
||
672 | // Trägt ggf. das Poti als Parameter ein |
||
1051 | killagreg | 673 | void ParameterZuordnung(void) |
1 | ingob | 674 | //############################################################################ |
675 | { |
||
1787 | holgerb | 676 | unsigned char tmp,i; |
677 | for(i=0;i<8;i++) |
||
678 | { |
||
679 | int tmp2; |
||
1933 | holgerb | 680 | tmp = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
681 | tmp2 = PPM_in[tmp] + 127; |
||
1787 | holgerb | 682 | if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0; |
1933 | holgerb | 683 | |
684 | if(tmp == 25) Poti[i] = tmp2; // 25 = WaypointEvent channel -> no filter |
||
685 | else |
||
1787 | holgerb | 686 | if(tmp2 != Poti[i]) |
687 | { |
||
688 | Poti[i] += (tmp2 - Poti[i]) / 4; |
||
689 | if(Poti[i] > tmp2) Poti[i]--; |
||
690 | else Poti[i]++; |
||
691 | } |
||
692 | } |
||
921 | hbuss | 693 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
694 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
||
695 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
||
1933 | holgerb | 696 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,5,255); |
697 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,5,255); |
||
2012 | holgerb | 698 | |
2443 | holgerb | 699 | if(EE_Parameter.Servo3 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo3 = EE_Parameter.Servo3OnValue; else Parameter_Servo3 = EE_Parameter.Servo3OffValue;} // Out1 (J16) |
700 | else if(EE_Parameter.Servo3 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo3 = EE_Parameter.Servo3OnValue; else Parameter_Servo3 = EE_Parameter.Servo3OffValue;} |
||
2349 | holgerb | 701 | else CHK_POTI_MM(Parameter_Servo3,EE_Parameter.Servo3, 24, 255); |
2012 | holgerb | 702 | |
2443 | holgerb | 703 | if(EE_Parameter.Servo4 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo4 = EE_Parameter.Servo4OnValue; else Parameter_Servo4 = EE_Parameter.Servo4OffValue;} |
704 | else if(EE_Parameter.Servo4 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo4 = EE_Parameter.Servo4OnValue; else Parameter_Servo4 = EE_Parameter.Servo4OffValue;} // Out2 (J17) |
||
2349 | holgerb | 705 | else CHK_POTI_MM(Parameter_Servo4,EE_Parameter.Servo4, 24, 255); |
706 | |||
707 | CHK_POTI_MM(Parameter_Servo5,EE_Parameter.Servo5, 24, 255); |
||
2342 | holgerb | 708 | Parameter_HoehenSchalter = GetChannelValue(EE_Parameter.HoeheChannel); |
1377 | hbuss | 709 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung); |
710 | CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z); |
||
711 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung); |
||
712 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I); |
||
713 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D); |
||
714 | CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P); |
||
715 | CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I); |
||
716 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor); |
||
717 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1); |
||
718 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2); |
||
719 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3); |
||
720 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4); |
||
721 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5); |
||
722 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6); |
||
723 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7); |
||
724 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
||
725 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
||
726 | CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
||
2296 | holgerb | 727 | CHK_POTI(Parameter_ServoNickComp,EE_Parameter.ServoNickComp); |
728 | CHK_POTI(Parameter_ServoRollComp,EE_Parameter.ServoRollComp); |
||
1377 | hbuss | 729 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
1668 | holgerb | 730 | CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
731 | CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
||
1377 | hbuss | 732 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection); |
1936 | holgerb | 733 | CHK_POTI(Parameter_MaximumAltitude,EE_Parameter.MaxAltitude); |
2447 | holgerb | 734 | // if((NC_To_FC_MaxAltitude && NC_To_FC_MaxAltitude < Parameter_MaximumAltitude) || Parameter_MaximumAltitude == 0) Parameter_MaximumAltitude = NC_To_FC_MaxAltitude; |
1916 | holgerb | 735 | Parameter_GlobalConfig = EE_Parameter.GlobalConfig; |
736 | Parameter_ExtraConfig = EE_Parameter.ExtraConfig; |
||
1377 | hbuss | 737 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
738 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability); |
||
739 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl); |
||
1676 | holgerb | 740 | Ki = 10300 / (Parameter_I_Faktor + 1); |
1 | ingob | 741 | MAX_GAS = EE_Parameter.Gas_Max; |
1662 | killagreg | 742 | MIN_GAS = EE_Parameter.Gas_Min; |
1668 | holgerb | 743 | |
2342 | holgerb | 744 | if(EE_Parameter.CareFreeChannel) |
1668 | holgerb | 745 | { |
1682 | holgerb | 746 | CareFree = 1; |
2342 | holgerb | 747 | if(PPM_in[EE_Parameter.CareFreeChannel] < -64) CareFree = 0; |
748 | // if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; |
||
1862 | holgerb | 749 | if(carefree_old != CareFree) |
750 | { |
||
751 | if(carefree_old < 3) |
||
752 | { |
||
2090 | holgerb | 753 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
754 | if(CareFree) { beeptime = 1500; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; } |
||
755 | else { beeptime = 200; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; } |
||
756 | #else |
||
2063 | holgerb | 757 | if(CareFree) beeptime = 1500; |
1862 | holgerb | 758 | else beeptime = 200; |
2090 | holgerb | 759 | #endif |
2063 | holgerb | 760 | NeueKompassRichtungMerken = 5; |
1862 | holgerb | 761 | carefree_old = CareFree; |
762 | } else carefree_old--; |
||
763 | } |
||
1937 | holgerb | 764 | if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= FC_ERROR0_CAREFREE; //else VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; |
1669 | killagreg | 765 | } |
1839 | holgerb | 766 | else |
767 | { |
||
768 | CareFree = 0; |
||
1862 | holgerb | 769 | carefree_old = 10; |
1839 | holgerb | 770 | } |
1668 | holgerb | 771 | |
1691 | holgerb | 772 | if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert |
1690 | holgerb | 773 | { |
774 | beeptime = 15000; |
||
775 | BeepMuster = 0xA400; |
||
776 | CareFree = 0; |
||
1765 | killagreg | 777 | } |
2341 | holgerb | 778 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; /*if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;*/} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
1 | ingob | 779 | } |
780 | |||
2427 | holgerb | 781 | void CalcStickGasHover(void) |
782 | { |
||
783 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
||
784 | { |
||
785 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
||
786 | StickGasHover = (unsigned int)((unsigned int) StickGasHover * UBat) / BattLowVoltageWarning; |
||
787 | } |
||
788 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
||
789 | LIMIT_MIN_MAX(StickGasHover, 70, 175); // reserve some range for trim up and down |
||
790 | } |
||
791 | |||
792 | |||
1 | ingob | 793 | //############################################################################ |
794 | // |
||
795 | void MotorRegler(void) |
||
796 | //############################################################################ |
||
797 | { |
||
1330 | killagreg | 798 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
1 | ingob | 799 | int GierMischanteil,GasMischanteil; |
800 | static long sollGier = 0,tmp_long,tmp_long2; |
||
801 | static unsigned int RcLostTimer; |
||
802 | static unsigned char delay_neutral = 0; |
||
803 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
2146 | holgerb | 804 | static signed char move_safety_switch = 0; |
1153 | hbuss | 805 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
1209 | hbuss | 806 | unsigned char i; |
1051 | killagreg | 807 | Mittelwert(); |
808 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 809 | // Gaswert ermitteln |
1051 | killagreg | 810 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2230 | holgerb | 811 | if(!(FC_StatusFlags & (FC_STATUS_EMERGENCY_LANDING | FC_STATUS2_RC_FAILSAVE_ACTIVE))) |
812 | { |
||
813 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
||
2028 | holgerb | 814 | { |
815 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
||
816 | { |
||
817 | HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
||
818 | } |
||
819 | else HooverGasEmergencyPercent = 45; // default if the Hoovergas was could not calculated yet |
||
820 | } else HooverGasEmergencyPercent = EE_Parameter.NotGas; |
||
2230 | holgerb | 821 | } |
822 | if(GasIsZeroCnt == 30000) // in that case we have RC-Lost, but the MK is probably landed |
||
823 | { |
||
824 | StickGas = 0; // Hold Gas down in that case |
||
825 | HooverGasEmergencyPercent = MIN_GAS; |
||
826 | } |
||
1051 | killagreg | 827 | GasMischanteil = StickGas; |
831 | hbuss | 828 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
1051 | killagreg | 829 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | hbuss | 830 | // Empfang schlecht |
1051 | killagreg | 831 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1916 | holgerb | 832 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
1 | ingob | 833 | { |
1051 | killagreg | 834 | if(RcLostTimer) RcLostTimer--; |
835 | else |
||
1 | ingob | 836 | { |
837 | MotorenEin = 0; |
||
1954 | holgerb | 838 | modell_fliegt = 0; |
839 | FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY); |
||
1051 | killagreg | 840 | } |
1 | ingob | 841 | ROT_ON; |
2008 | holgerb | 842 | if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100) // wahrscheinlich in der Luft --> langsam absenken |
1 | ingob | 843 | { |
2028 | holgerb | 844 | GasMischanteil = HooverGasEmergencyPercent; |
1765 | killagreg | 845 | FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING; |
744 | hbuss | 846 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
1051 | killagreg | 847 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
1 | ingob | 848 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
849 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
850 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
||
173 | holgerb | 851 | } |
1954 | holgerb | 852 | else |
853 | { |
||
854 | MotorenEin = 0; |
||
855 | } |
||
1 | ingob | 856 | } |
1051 | killagreg | 857 | else |
858 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 859 | // Emfang gut |
1051 | killagreg | 860 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 861 | if(SenderOkay > 140) |
862 | { |
||
2340 | holgerb | 863 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2345 | holgerb | 864 | static unsigned int trigger = 1000; |
2340 | holgerb | 865 | static unsigned char old_switch = 100; |
866 | if(EE_Parameter.StartLandChannel && EE_Parameter.LandingSpeed) |
||
867 | { |
||
868 | if(PPM_in[EE_Parameter.StartLandChannel] > 50) |
||
869 | { |
||
870 | if(old_switch == 50) if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) { FC_StatusFlags2 |= FC_STATUS2_AUTO_STARTING; SpeakHoTT = SPEAK_RISING;} |
||
2342 | holgerb | 871 | FC_StatusFlags2 &= ~FC_STATUS2_AUTO_LANDING; |
2340 | holgerb | 872 | old_switch = 150; |
873 | } |
||
874 | else |
||
875 | if(PPM_in[EE_Parameter.StartLandChannel] < -50) |
||
876 | { |
||
877 | if(old_switch == 150) { FC_StatusFlags2 |= FC_STATUS2_AUTO_LANDING; SpeakHoTT = SPEAK_SINKING;} |
||
2342 | holgerb | 878 | FC_StatusFlags2 &= ~FC_STATUS2_AUTO_STARTING; |
2340 | holgerb | 879 | old_switch = 50; |
880 | } |
||
881 | else |
||
882 | { |
||
883 | FC_StatusFlags2 &= ~(FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING); |
||
884 | } |
||
885 | } |
||
886 | #endif |
||
1765 | killagreg | 887 | FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING; |
1 | ingob | 888 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
921 | hbuss | 889 | if(GasMischanteil > 40 && MotorenEin) |
1 | ingob | 890 | { |
891 | if(modell_fliegt < 0xffff) modell_fliegt++; |
||
892 | } |
||
871 | hbuss | 893 | if((modell_fliegt < 256)) |
2309 | holgerb | 894 | { |
1 | ingob | 895 | SummeNick = 0; |
896 | SummeRoll = 0; |
||
1682 | holgerb | 897 | sollGier = 0; |
898 | Mess_Integral_Gier = 0; |
||
2309 | holgerb | 899 | FC_StatusFlags2 |= FC_STATUS2_WAIT_FOR_TAKEOFF; |
2340 | holgerb | 900 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
901 | old_switch = 100; |
||
902 | #endif |
||
2309 | holgerb | 903 | } |
904 | else |
||
905 | { |
||
906 | FC_StatusFlags |= FC_STATUS_FLY; |
||
907 | if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) |
||
908 | { |
||
2322 | holgerb | 909 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2340 | holgerb | 910 | if((NC_To_FC_Flags & NC_TO_FC_AUTOSTART || FC_StatusFlags2 & FC_STATUS2_AUTO_STARTING) && (VarioCharacter == '=') && ACC_AltitudeControl) |
2322 | holgerb | 911 | { |
2340 | holgerb | 912 | FromNC_AltitudeSpeed = 80; |
913 | FromNC_AltitudeSetpoint = 500; |
||
914 | SollHoehe = 500; |
||
2322 | holgerb | 915 | trigger = 1000; |
2340 | holgerb | 916 | if(NC_To_FC_Flags & NC_TO_FC_AUTOSTART) SpeakHoTT = SPEAK_NEXT_WP; |
2322 | holgerb | 917 | /* if(StartTrigger != 2) |
918 | { |
||
919 | StartTrigger = 1; |
||
920 | if(HoverGas < STICK_GAIN * 35) HoverGas = STICK_GAIN * 35; |
||
921 | } |
||
922 | */ |
||
923 | } |
||
2340 | holgerb | 924 | // else FC_StatusFlags2 &= ~(FC_STATUS2_AUTO_STARTING); |
2322 | holgerb | 925 | #endif |
2340 | holgerb | 926 | if(HoehenWertF > 150 || HoehenWert < -350 || !(Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) |
2309 | holgerb | 927 | { |
928 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
2322 | holgerb | 929 | trigger = 1000; |
2369 | holgerb | 930 | if(FC_StatusFlags2 & FC_STATUS2_AUTO_STARTING) { FromNC_AltitudeSpeed = 0; SollHoehe = 300;/*HoehenWertF + 100;*/} |
931 | else SpeakHoTT = SPEAK_RISING; |
||
2309 | holgerb | 932 | #endif |
2340 | holgerb | 933 | FC_StatusFlags2 &= ~(FC_STATUS2_WAIT_FOR_TAKEOFF | FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING); |
2309 | holgerb | 934 | } |
935 | SummeNick = 0; |
||
936 | SummeRoll = 0; |
||
937 | Mess_Integral_Gier = 0; |
||
938 | // sollGier = 0; |
||
939 | if(modell_fliegt > 1000) modell_fliegt = 1000; // for the Hooverpoint-Estimation |
||
940 | } |
||
2322 | holgerb | 941 | else // Flying mode |
942 | { |
||
943 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
2340 | holgerb | 944 | if((FC_StatusFlags2 & FC_STATUS2_AUTO_LANDING) && (VarioCharacter == 'v' || VarioCharacter == '=') && ACC_AltitudeControl) |
945 | { |
||
946 | FromNC_AltitudeSpeed = EE_Parameter.LandingSpeed; |
||
947 | FromNC_AltitudeSetpoint = -20000; |
||
948 | } |
||
2322 | holgerb | 949 | if(trigger < 1000) |
950 | { |
||
951 | trigger++; |
||
952 | SummeNick = 0; |
||
953 | SummeRoll = 0; |
||
954 | Mess_Integral_Gier = 0; |
||
955 | SollHoehe = HoehenWertF - 300; |
||
2345 | holgerb | 956 | if(trigger == 1000 && FC_StatusFlags2 & FC_STATUS2_AUTO_LANDING && VarioCharacter != '+') |
957 | { |
||
958 | FC_StatusFlags2 &= ~FC_STATUS2_AUTO_LANDING; |
||
959 | FC_StatusFlags2 |= FC_STATUS2_WAIT_FOR_TAKEOFF; // go back into starting state |
||
960 | } |
||
2322 | holgerb | 961 | } |
962 | else |
||
963 | if(ACC_AltitudeControl && (VarioCharacter == 'v' || VarioCharacter == '-') && HoehenWert < 1000 /*&& FromNC_AltitudeSetpoint < 0*/) |
||
964 | { |
||
2345 | holgerb | 965 | if(Aktuell_az > 940) |
966 | { |
||
967 | trigger = 0; |
||
968 | SpeakHoTT = SPEAK_LANDING; |
||
969 | }; |
||
2322 | holgerb | 970 | } |
971 | #endif |
||
972 | } |
||
973 | } // end of: modell_fliegt > 256 |
||
2481 | holgerb | 974 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0 && !(NC_To_FC_Flags & NC_TO_FC_SIMULATION_ACTIVE)) |
1 | ingob | 975 | { |
1051 | killagreg | 976 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 977 | // auf Nullwerte kalibrieren |
1051 | killagreg | 978 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2481 | holgerb | 979 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 75) // Neutralwerte |
1 | ingob | 980 | { |
981 | if(++delay_neutral > 200) // nicht sofort |
||
982 | { |
||
2481 | holgerb | 983 | unsigned char setting = 0; |
1 | ingob | 984 | delay_neutral = 0; |
985 | modell_fliegt = 0; |
||
986 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
||
987 | { |
||
2481 | holgerb | 988 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -70) setting = 1; |
1 | ingob | 989 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
990 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
||
991 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
||
2481 | holgerb | 992 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -70) setting = 5; |
993 | if(setting) SetActiveParamSet(setting); // aktiven Datensatz merken |
||
1 | ingob | 994 | } |
1051 | killagreg | 995 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
996 | { |
||
819 | hbuss | 997 | WinkelOut.CalcState = 1; |
2009 | holgerb | 998 | CalibrationDone = 0; |
819 | hbuss | 999 | beeptime = 1000; |
1000 | } |
||
1001 | else |
||
1 | ingob | 1002 | { |
2340 | holgerb | 1003 | ParamSet_ReadFromEEProm(ActiveParamSet); |
1413 | killagreg | 1004 | LipoDetection(0); |
1626 | killagreg | 1005 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
1916 | holgerb | 1006 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
819 | hbuss | 1007 | { |
1 | ingob | 1008 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
1051 | killagreg | 1009 | } |
2481 | holgerb | 1010 | if(!setting && PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) CalibrationDone = SetNeutral(3); |
1011 | else |
||
1012 | if(!setting && PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75 && abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) < 70) CalibrationDone = SetNeutral(2); // store ACC values into EEPROM |
||
1013 | else CalibrationDone = SetNeutral(1); |
||
1232 | hbuss | 1014 | ServoActive = 1; |
1015 | DDRD |=0x80; // enable J7 -> Servo signal |
||
2263 | holgerb | 1016 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2309 | holgerb | 1017 | if(VersionInfo.HardwareError[0]) SpeakHoTT = SPEAK_ERR_SENSOR; |
2316 | holgerb | 1018 | else |
1019 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
||
2309 | holgerb | 1020 | else SpeakHoTT = SPEAK_CALIBRATE; |
2481 | holgerb | 1021 | ShowSettingNameTime = 10; // for HoTT & Jeti |
2263 | holgerb | 1022 | #endif |
2332 | holgerb | 1023 | Piep(ActiveParamSet,120); |
819 | hbuss | 1024 | } |
1051 | killagreg | 1025 | } |
1 | ingob | 1026 | } |
2481 | holgerb | 1027 | /* |
1051 | killagreg | 1028 | else |
513 | hbuss | 1029 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
1030 | { |
||
1031 | if(++delay_neutral > 200) // nicht sofort |
||
1032 | { |
||
1033 | MotorenEin = 0; |
||
1034 | delay_neutral = 0; |
||
1035 | modell_fliegt = 0; |
||
2319 | holgerb | 1036 | CalibrationDone = SetNeutral(2); // store ACC values into EEPROM |
2263 | holgerb | 1037 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2316 | holgerb | 1038 | if(VersionInfo.HardwareError[0]) SpeakHoTT = SPEAK_ERR_SENSOR; |
1039 | else |
||
1040 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
||
1041 | else SpeakHoTT = SPEAK_CALIBRATE; |
||
2263 | holgerb | 1042 | #endif |
2332 | holgerb | 1043 | Piep(ActiveParamSet,120); |
1051 | killagreg | 1044 | } |
513 | hbuss | 1045 | } |
2481 | holgerb | 1046 | */ |
1 | ingob | 1047 | else delay_neutral = 0; |
1048 | } |
||
1051 | killagreg | 1049 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1050 | // Gas ist unten |
1051 | killagreg | 1051 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2342 | holgerb | 1052 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < -100) |
1 | ingob | 1053 | { |
2146 | holgerb | 1054 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100; |
1055 | else |
||
1056 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100; |
||
1521 | killagreg | 1057 | // Motoren Starten |
1058 | if(!MotorenEin) |
||
1059 | { |
||
2481 | holgerb | 1060 | if(((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -100) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
1061 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100))) |
||
1062 | && !(NC_To_FC_Flags & NC_TO_FC_SIMULATION_ACTIVE)) |
||
1521 | killagreg | 1063 | { |
1051 | killagreg | 1064 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1065 | // Einschalten |
1051 | killagreg | 1066 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2146 | holgerb | 1067 | if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START; |
2367 | holgerb | 1068 | |
2309 | holgerb | 1069 | StartLuftdruck = Luftdruck; |
1070 | HoehenWert = 0; |
||
2471 | holgerb | 1071 | HoehenWert_Mess = 0; |
2481 | holgerb | 1072 | GasIsZeroCnt = 600; |
2471 | holgerb | 1073 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1074 | HoehenWertF_Mess = 0; |
||
1075 | #endif |
||
2309 | holgerb | 1076 | SummenHoehe = 0; |
2367 | holgerb | 1077 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0) delay_einschalten = 0; |
2146 | holgerb | 1078 | if(++delay_einschalten > 253) |
1521 | killagreg | 1079 | { |
2481 | holgerb | 1080 | if(FC_StatusFlags3 & FC_STATUS3_BOAT) { if((abs(MesswertGier) > 32*2 || abs(MesswertNick) > 20*3) || abs(MesswertRoll) > 20*3) CalibrationDone = 0; } // dann ist der Gyro defekt, schlecht kalibriert oder der MK dreht sich |
1081 | else |
||
2407 | holgerb | 1082 | if((abs(MesswertGier) > 32 || abs(MesswertNick) > 20) || abs(MesswertRoll) > 20) CalibrationDone = 0; // dann ist der Gyro defekt, schlecht kalibriert oder der MK dreht sich |
1521 | killagreg | 1083 | delay_einschalten = 0; |
2009 | holgerb | 1084 | if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode) |
1622 | killagreg | 1085 | { |
1086 | modell_fliegt = 1; |
||
1087 | MotorenEin = 1; |
||
1088 | sollGier = 0; |
||
1089 | Mess_Integral_Gier = 0; |
||
1090 | Mess_Integral_Gier2 = 0; |
||
1091 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
||
1092 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
||
1093 | SummeNick = 0; |
||
1094 | SummeRoll = 0; |
||
1913 | holgerb | 1095 | // ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
1840 | holgerb | 1096 | NeueKompassRichtungMerken = 100; // 2 sekunden |
2090 | holgerb | 1097 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1098 | SpeakHoTT = SPEAK_STARTING; |
||
1099 | #endif |
||
1622 | killagreg | 1100 | } |
1101 | else |
||
1102 | { |
||
1103 | beeptime = 1500; // indicate missing calibration |
||
2090 | holgerb | 1104 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2146 | holgerb | 1105 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
2090 | holgerb | 1106 | #endif |
1622 | killagreg | 1107 | } |
1521 | killagreg | 1108 | } |
1109 | } |
||
1110 | else delay_einschalten = 0; |
||
1111 | } |
||
1051 | killagreg | 1112 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1113 | // Auschalten |
1051 | killagreg | 1114 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1521 | killagreg | 1115 | else // only if motors are running |
1116 | { |
||
2146 | holgerb | 1117 | // if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0)) |
2342 | holgerb | 1118 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 100) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
2146 | holgerb | 1119 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100))) |
1521 | killagreg | 1120 | { |
2349 | holgerb | 1121 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0) |
1122 | { |
||
1123 | delay_ausschalten = 0; |
||
1124 | } |
||
1125 | else |
||
1126 | { |
||
1127 | SummeNick = 0; |
||
1128 | SummeRoll = 0; |
||
1129 | StickNick = 0; |
||
1130 | StickRoll = 0; |
||
1131 | } |
||
2146 | holgerb | 1132 | if(++delay_ausschalten > 250) // nicht sofort |
1521 | killagreg | 1133 | { |
1134 | MotorenEin = 0; |
||
1135 | delay_ausschalten = 0; |
||
1136 | modell_fliegt = 0; |
||
2349 | holgerb | 1137 | FC_StatusFlags2 &= ~(FC_STATUS2_WAIT_FOR_TAKEOFF | FC_STATUS2_AUTO_STARTING | FC_STATUS2_AUTO_LANDING); |
1138 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
1139 | SpeakHoTT = SPEAK_MK_OFF; |
||
1140 | #endif |
||
1521 | killagreg | 1141 | } |
2366 | holgerb | 1142 | else |
1143 | if(delay_ausschalten == 100) beeptime = 3500; |
||
1521 | killagreg | 1144 | } |
1145 | else delay_ausschalten = 0; |
||
1146 | } |
||
2369 | holgerb | 1147 | if(GasIsZeroCnt < 1000) |
1148 | { |
||
1149 | if(VarioMeter > -150) GasIsZeroCnt++; |
||
1150 | else if(GasIsZeroCnt) GasIsZeroCnt--; |
||
1151 | } |
||
2230 | holgerb | 1152 | } |
2146 | holgerb | 1153 | else // gas not at minimum |
2230 | holgerb | 1154 | { |
1155 | move_safety_switch = 0; |
||
1156 | GasIsZeroCnt = 0; |
||
1157 | } |
||
1 | ingob | 1158 | } |
2230 | holgerb | 1159 | else // Empfang zwischen 100 und 140 -> schlecht |
1160 | { |
||
1161 | if(GasIsZeroCnt >= 750) // gas-stick was down for 1.5 seconds before RC-Lost |
||
1162 | { |
||
1163 | if((GPSInfo.HomeDistance < 40 * 10) && (HoehenWert < 15 * 100)) // and we are at the starting point -> maybe landed? |
||
1164 | { |
||
1165 | GasIsZeroCnt = 30000; |
||
1166 | if(modell_fliegt > 1001) modell_fliegt = 1001; |
||
1167 | } |
||
1168 | } |
||
1169 | } |
||
1051 | killagreg | 1170 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1171 | // neue Werte von der Funke |
1051 | killagreg | 1172 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1216 | killagreg | 1173 | |
1765 | killagreg | 1174 | if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1 | ingob | 1175 | { |
604 | hbuss | 1176 | static int stick_nick,stick_roll; |
1912 | holgerb | 1177 | unsigned char stick_p; |
1 | ingob | 1178 | ParameterZuordnung(); |
1912 | holgerb | 1179 | stick_p = EE_Parameter.Stick_P; |
1180 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4; |
||
723 | hbuss | 1181 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
1912 | holgerb | 1182 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4; |
723 | hbuss | 1183 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
1184 | |||
1707 | holgerb | 1185 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1186 | // CareFree und freie Wahl der vorderen Richtung |
||
1187 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1865 | holgerb | 1188 | if(CareFree) |
1189 | { |
||
1190 | signed int nick, roll; |
||
1191 | nick = stick_nick / 4; |
||
1192 | roll = stick_roll / 4; |
||
1193 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
||
1194 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
||
1195 | } |
||
1196 | else |
||
1197 | { |
||
1198 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
||
1199 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
||
1200 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
||
1201 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
||
1202 | } |
||
1662 | killagreg | 1203 | |
1 | ingob | 1204 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
1840 | holgerb | 1205 | if(StickGier > 4) StickGier -= 4; else |
1206 | if(StickGier < -4) StickGier += 4; else StickGier = 0; |
||
1120 | hbuss | 1207 | |
2369 | holgerb | 1208 | if(GasIsZeroCnt > 512) // About to switch - off |
1209 | { |
||
1210 | StickNick = StickNick/8; |
||
1211 | StickRoll = StickRoll/8; |
||
1212 | SummeNick = 0; |
||
1213 | SummeRoll = 0; |
||
1214 | } |
||
1215 | else |
||
1945 | holgerb | 1216 | if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger |
1217 | { |
||
1218 | StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16; |
||
1219 | StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16; |
||
1220 | } |
||
1912 | holgerb | 1221 | StickNick -= GPS_Nick; |
1222 | StickRoll -= GPS_Roll; |
||
1933 | holgerb | 1223 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127; |
1330 | killagreg | 1224 | |
1153 | hbuss | 1225 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
1226 | IntegralFaktor = Parameter_Gyro_I; |
||
1322 | hbuss | 1227 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
1228 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
||
1 | ingob | 1229 | |
595 | hbuss | 1230 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1231 | //+ Analoge Steuerung per Seriell |
||
1232 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
921 | hbuss | 1233 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
595 | hbuss | 1234 | { |
1235 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
||
1236 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
||
1237 | StickGier += ExternControl.Gier; |
||
1238 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
||
1239 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
||
1240 | } |
||
855 | hbuss | 1241 | if(StickGas < 0) StickGas = 0; |
1330 | killagreg | 1242 | |
1916 | holgerb | 1243 | if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
723 | hbuss | 1244 | |
1051 | killagreg | 1245 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
928 | hbuss | 1246 | { |
1051 | killagreg | 1247 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
928 | hbuss | 1248 | if(MaxStickNick > 100) MaxStickNick = 100; |
1051 | killagreg | 1249 | } |
928 | hbuss | 1250 | else MaxStickNick--; |
1051 | killagreg | 1251 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
928 | hbuss | 1252 | { |
1051 | killagreg | 1253 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
928 | hbuss | 1254 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
1051 | killagreg | 1255 | } |
928 | hbuss | 1256 | else MaxStickRoll--; |
1765 | killagreg | 1257 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) {MaxStickNick = 0; MaxStickRoll = 0;} |
723 | hbuss | 1258 | |
1051 | killagreg | 1259 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 1260 | // Looping? |
1051 | killagreg | 1261 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
993 | hbuss | 1262 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
1051 | killagreg | 1263 | else |
1264 | { |
||
395 | hbuss | 1265 | { |
1051 | killagreg | 1266 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
1267 | } |
||
1268 | } |
||
993 | hbuss | 1269 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
1051 | killagreg | 1270 | else |
395 | hbuss | 1271 | { |
1272 | if(Looping_Rechts) // Hysterese |
||
1273 | { |
||
1274 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
||
1275 | } |
||
1051 | killagreg | 1276 | } |
173 | holgerb | 1277 | |
993 | hbuss | 1278 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
1051 | killagreg | 1279 | else |
1280 | { |
||
395 | hbuss | 1281 | if(Looping_Oben) // Hysterese |
1282 | { |
||
1051 | killagreg | 1283 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
1284 | } |
||
1285 | } |
||
993 | hbuss | 1286 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
1051 | killagreg | 1287 | else |
395 | hbuss | 1288 | { |
1289 | if(Looping_Unten) // Hysterese |
||
1290 | { |
||
1291 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
||
1292 | } |
||
1051 | killagreg | 1293 | } |
395 | hbuss | 1294 | |
1295 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
||
1153 | hbuss | 1296 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
395 | hbuss | 1297 | } // Ende neue Funken-Werte |
1298 | |||
1299 | if(Looping_Roll || Looping_Nick) |
||
1300 | { |
||
173 | holgerb | 1301 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
1153 | hbuss | 1302 | TrichterFlug = 1; |
173 | holgerb | 1303 | } |
1304 | |||
1051 | killagreg | 1305 | |
1306 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1307 | // Bei Empfangsausfall im Flug |
||
1308 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1916 | holgerb | 1309 | if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE) |
1310 | { |
||
1311 | StickNick = -GPS_Nick; |
||
1312 | StickRoll = -GPS_Roll; |
||
2230 | holgerb | 1313 | StickGas = StickGasHover; |
2407 | holgerb | 1314 | StickGier = 0; |
1916 | holgerb | 1315 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1316 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
||
1317 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
||
1318 | Parameter_HoehenSchalter = 200; // switch on |
||
1319 | } |
||
1320 | else |
||
1765 | killagreg | 1321 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) |
1 | ingob | 1322 | { |
1323 | StickGier = 0; |
||
1324 | StickNick = 0; |
||
1325 | StickRoll = 0; |
||
1211 | hbuss | 1326 | GyroFaktor = 90; |
1327 | IntegralFaktor = 120; |
||
1328 | GyroFaktorGier = 90; |
||
1329 | IntegralFaktorGier = 120; |
||
173 | holgerb | 1330 | Looping_Roll = 0; |
1331 | Looping_Nick = 0; |
||
1051 | killagreg | 1332 | } |
395 | hbuss | 1333 | |
1051 | killagreg | 1334 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1335 | // Integrale auf ACC-Signal abgleichen |
1051 | killagreg | 1336 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1337 | #define ABGLEICH_ANZAHL 256L |
1338 | |||
1339 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
||
1340 | MittelIntegralRoll += IntegralRoll; |
||
1341 | if(Looping_Nick || Looping_Roll) |
||
1342 | { |
||
1343 | MittelIntegralNick = 0; |
||
1344 | MittelIntegralRoll = 0; |
||
1345 | ZaehlMessungen = 0; |
||
498 | hbuss | 1346 | LageKorrekturNick = 0; |
1347 | LageKorrekturRoll = 0; |
||
395 | hbuss | 1348 | } |
1349 | |||
1051 | killagreg | 1350 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1224 | hbuss | 1351 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
469 | hbuss | 1352 | { |
1353 | long tmp_long, tmp_long2; |
||
1839 | holgerb | 1354 | if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/) |
992 | hbuss | 1355 | { |
1944 | holgerb | 1356 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN)); |
1357 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR)); |
||
1358 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
1359 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
1360 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
||
1361 | { |
||
1362 | tmp_long /= 2; |
||
1363 | tmp_long2 /= 2; |
||
1364 | } |
||
2309 | holgerb | 1365 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1944 | holgerb | 1366 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1367 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1368 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
||
992 | hbuss | 1369 | } |
1051 | killagreg | 1370 | else |
992 | hbuss | 1371 | { |
1944 | holgerb | 1372 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1373 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
||
1374 | tmp_long /= 16; |
||
1375 | tmp_long2 /= 16; |
||
1376 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
||
1377 | { |
||
1378 | tmp_long /= 3; |
||
1379 | tmp_long2 /= 3; |
||
1380 | } |
||
1381 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
||
1382 | { |
||
1383 | tmp_long /= 3; |
||
1384 | tmp_long2 /= 3; |
||
1385 | } |
||
1386 | KompassFusion = 25; |
||
1155 | hbuss | 1387 | #define AUSGLEICH 32 |
1944 | holgerb | 1388 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
1389 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
||
1390 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
||
1391 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
||
992 | hbuss | 1392 | } |
1166 | hbuss | 1393 | |
2481 | holgerb | 1394 | Mess_IntegralNick -= tmp_long; |
1395 | Mess_IntegralRoll -= tmp_long2; |
||
1396 | DriftNick += tmp_long; |
||
1397 | DriftRoll += tmp_long2; |
||
469 | hbuss | 1398 | } |
1051 | killagreg | 1399 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1400 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
1401 | { |
||
2481 | holgerb | 1402 | // static int cnt = 0; |
1403 | // static char last_n_p,last_n_n,last_r_p,last_r_n; |
||
395 | hbuss | 1404 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
2481 | holgerb | 1405 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1406 | // Gyro-Drift ermitteln |
||
1407 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1408 | if(EE_Parameter.Driftkomp && abs(Mittelwert_AccNick) < 200*4 && abs(Mittelwert_AccRoll) < 200*4 && !TrichterFlug && abs(MesswertGier) < 32/* && (FC_StatusFlags & FC_STATUS_FLY)*/) |
||
1409 | { |
||
1410 | DebugOut.Analog[16] = EE_Parameter.Driftkomp; |
||
1411 | DriftNick -= DriftNick / (64 * (unsigned int) EE_Parameter.Driftkomp); |
||
1412 | DriftRoll -= DriftRoll / (64 * (unsigned int) EE_Parameter.Driftkomp); |
||
1413 | GierGyroFehler -= GierGyroFehler / (64 * (unsigned int) EE_Parameter.Driftkomp); |
||
1414 | if((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) |
||
1415 | { |
||
1416 | DriftNick /= 2; |
||
1417 | DriftRoll /= 2; |
||
1418 | GierGyroFehler = 0; |
||
1419 | } |
||
1420 | if(DriftNick > 3000) { DriftNick = 0; AdNeutralNick++;} |
||
1421 | if(DriftNick <-3000) { DriftNick = 0; AdNeutralNick--;} |
||
1422 | if(DriftRoll > 3000) { DriftRoll = 0; AdNeutralRoll++;} |
||
1423 | if(DriftRoll <-3000) { DriftRoll = 0; AdNeutralRoll--;} |
||
1424 | if(GierGyroFehler > 3500) { GierGyroFehler = 0; AdNeutralGier++; } |
||
1425 | if(GierGyroFehler <-3500) { GierGyroFehler = 0; AdNeutralGier--; } |
||
1426 | } |
||
1427 | else |
||
1428 | { |
||
1429 | DriftNick = 0; |
||
1430 | DriftRoll = 0; |
||
1431 | GierGyroFehler = 0; |
||
1432 | } |
||
1433 | TrichterFlug = 0; |
||
1434 | |||
1435 | /* |
||
1173 | hbuss | 1436 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
173 | holgerb | 1437 | { |
395 | hbuss | 1438 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
1439 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
||
1440 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
||
1441 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
||
1442 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
||
1707 | holgerb | 1443 | #define MAX_I 0 |
395 | hbuss | 1444 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1445 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
||
1446 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
||
1051 | killagreg | 1447 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1448 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
||
395 | hbuss | 1449 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
614 | hbuss | 1450 | |
1451 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
||
498 | hbuss | 1452 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 1453 | |
992 | hbuss | 1454 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
614 | hbuss | 1455 | { |
1456 | LageKorrekturNick /= 2; |
||
720 | ingob | 1457 | LageKorrekturRoll /= 2; |
614 | hbuss | 1458 | } |
498 | hbuss | 1459 | |
1051 | killagreg | 1460 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1461 | // Gyro-Drift ermitteln |
1051 | killagreg | 1462 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1463 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1464 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
||
1051 | killagreg | 1465 | tmp_long = IntegralNick2 - IntegralNick; |
1466 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
||
395 | hbuss | 1467 | |
1468 | IntegralFehlerNick = tmp_long; |
||
1469 | IntegralFehlerRoll = tmp_long2; |
||
1470 | Mess_IntegralNick2 -= IntegralFehlerNick; |
||
1471 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
||
1472 | |||
1111 | hbuss | 1473 | if(EE_Parameter.Driftkomp) |
1474 | { |
||
1622 | killagreg | 1475 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
1476 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
||
1111 | hbuss | 1477 | } |
693 | hbuss | 1478 | GierGyroFehler = 0; |
720 | ingob | 1479 | |
1243 | killagreg | 1480 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
1481 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
||
1225 | hbuss | 1482 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
492 | hbuss | 1483 | #define BEWEGUNGS_LIMIT 20000 |
2481 | holgerb | 1484 | |
395 | hbuss | 1485 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1486 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
||
1225 | hbuss | 1487 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
1173 | hbuss | 1488 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
492 | hbuss | 1489 | { |
1051 | killagreg | 1490 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
395 | hbuss | 1491 | { |
1051 | killagreg | 1492 | if(last_n_p) |
395 | hbuss | 1493 | { |
1173 | hbuss | 1494 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1495 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1496 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
498 | hbuss | 1497 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1498 | } |
395 | hbuss | 1499 | else last_n_p = 1; |
1500 | } else last_n_p = 0; |
||
1051 | killagreg | 1501 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
395 | hbuss | 1502 | { |
1503 | if(last_n_n) |
||
1051 | killagreg | 1504 | { |
1173 | hbuss | 1505 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1506 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1507 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
498 | hbuss | 1508 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1509 | } |
395 | hbuss | 1510 | else last_n_n = 1; |
1511 | } else last_n_n = 0; |
||
1051 | killagreg | 1512 | } |
1513 | else |
||
847 | hbuss | 1514 | { |
1515 | cnt = 0; |
||
1839 | holgerb | 1516 | KompassSignalSchlecht = 100; |
1051 | killagreg | 1517 | } |
499 | hbuss | 1518 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1173 | hbuss | 1519 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
395 | hbuss | 1520 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1521 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
||
401 | hbuss | 1522 | |
395 | hbuss | 1523 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1695 | holgerb | 1524 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
1225 | hbuss | 1525 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
1173 | hbuss | 1526 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
492 | hbuss | 1527 | { |
1051 | killagreg | 1528 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
395 | hbuss | 1529 | { |
1051 | killagreg | 1530 | if(last_r_p) |
395 | hbuss | 1531 | { |
1173 | hbuss | 1532 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1533 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1534 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
498 | hbuss | 1535 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1051 | killagreg | 1536 | } |
395 | hbuss | 1537 | else last_r_p = 1; |
1538 | } else last_r_p = 0; |
||
1051 | killagreg | 1539 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
395 | hbuss | 1540 | { |
1051 | killagreg | 1541 | if(last_r_n) |
395 | hbuss | 1542 | { |
1173 | hbuss | 1543 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1544 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1545 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
498 | hbuss | 1546 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 1547 | } |
1548 | else last_r_n = 1; |
||
1549 | } else last_r_n = 0; |
||
1051 | killagreg | 1550 | } else |
492 | hbuss | 1551 | { |
1552 | cnt = 0; |
||
1839 | holgerb | 1553 | KompassSignalSchlecht = 100; |
1051 | killagreg | 1554 | } |
499 | hbuss | 1555 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1173 | hbuss | 1556 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
395 | hbuss | 1557 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1558 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
||
173 | holgerb | 1559 | } |
1051 | killagreg | 1560 | else |
498 | hbuss | 1561 | { |
1562 | LageKorrekturRoll = 0; |
||
1563 | LageKorrekturNick = 0; |
||
880 | hbuss | 1564 | TrichterFlug = 0; |
498 | hbuss | 1565 | } |
2481 | holgerb | 1566 | */ |
498 | hbuss | 1567 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1051 | killagreg | 1568 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1569 | MittelIntegralNick_Alt = MittelIntegralNick; |
||
1570 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
||
1571 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
395 | hbuss | 1572 | MittelIntegralNick = 0; |
1573 | MittelIntegralRoll = 0; |
||
1574 | ZaehlMessungen = 0; |
||
1173 | hbuss | 1575 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
395 | hbuss | 1576 | |
1051 | killagreg | 1577 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1578 | // Gieren |
1051 | killagreg | 1579 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1840 | holgerb | 1580 | if(abs(StickGier) > 3) // war 15 |
1 | ingob | 1581 | { |
1839 | holgerb | 1582 | // KompassSignalSchlecht = 1000; |
1916 | holgerb | 1583 | if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX)) |
1051 | killagreg | 1584 | { |
1840 | holgerb | 1585 | NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen |
824 | hbuss | 1586 | }; |
1 | ingob | 1587 | } |
1944 | holgerb | 1588 | tmp_int = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1589 | tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4; |
||
2309 | holgerb | 1590 | if(GasIsZeroCnt > 512) tmp_int = 0; // disable Yawing when Gas-Stick is to Zero |
1840 | holgerb | 1591 | tmp_int += CompassGierSetpoint; |
173 | holgerb | 1592 | sollGier = tmp_int; |
1051 | killagreg | 1593 | Mess_Integral_Gier -= tmp_int; |
395 | hbuss | 1594 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1595 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
||
1051 | killagreg | 1596 | |
1597 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1598 | // Kompass |
1051 | killagreg | 1599 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1916 | holgerb | 1600 | if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV)) |
1 | ingob | 1601 | { |
1839 | holgerb | 1602 | if(CalculateCompassTimer-- == 1) |
1603 | { |
||
1604 | int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt |
||
1605 | CalculateCompassTimer = 13; // falls keine Navi-Daten |
||
1840 | holgerb | 1606 | // max. Korrekturwert schätzen |
1 | ingob | 1607 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1608 | v = abs(IntegralRoll /512); |
||
1609 | if(v > w) w = v; // grösste Neigung ermitteln |
||
1972 | holgerb | 1610 | // korrektur = w / 4 + 1; |
1611 | korrektur = w / 8 + 2; |
||
1941 | holgerb | 1612 | ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR; |
1840 | holgerb | 1613 | // Kompassfehlerwert bestimmen |
1941 | holgerb | 1614 | fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180; |
1840 | holgerb | 1615 | // GIER_GRAD_FAKTOR ist ca. 1200 |
1616 | // Kompasswert einloggen |
||
2439 | holgerb | 1617 | if(NeueKompassRichtungMerken) KompassSollWert = ErsatzKompassInGrad; |
1618 | |||
1840 | holgerb | 1619 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1620 | else |
||
1621 | if(w < 25) |
||
921 | hbuss | 1622 | { |
1623 | GierGyroFehler += fehler; |
||
2439 | holgerb | 1624 | if(NeueKompassRichtungMerken) NeueKompassRichtungMerken--; |
1625 | /* if(NeueKompassRichtungMerken) |
||
1051 | killagreg | 1626 | { |
1839 | holgerb | 1627 | if(--NeueKompassRichtungMerken == 0) |
1628 | { |
||
1941 | holgerb | 1629 | KompassSollWert = ErsatzKompassInGrad; |
1839 | holgerb | 1630 | } |
921 | hbuss | 1631 | } |
2439 | holgerb | 1632 | */ |
1 | ingob | 1633 | } |
1840 | holgerb | 1634 | // Kompass fusionieren |
1839 | holgerb | 1635 | if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur; |
1941 | holgerb | 1636 | // MK Gieren |
1637 | if(!NeueKompassRichtungMerken) |
||
1839 | holgerb | 1638 | { |
1941 | holgerb | 1639 | r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180; |
1839 | holgerb | 1640 | v = r * (Parameter_KompassWirkung/2); // nach Kompass ausrichten |
1840 | holgerb | 1641 | CompassGierSetpoint = v / 16; |
1642 | } |
||
1865 | holgerb | 1643 | else CompassGierSetpoint = 0; |
1839 | holgerb | 1644 | } // CalculateCompassTimer |
1051 | killagreg | 1645 | } |
1840 | holgerb | 1646 | else CompassGierSetpoint = 0; |
1972 | holgerb | 1647 | |
1648 | //DebugOut.Analog[16] = KompassFusion; |
||
1051 | killagreg | 1649 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1650 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1051 | killagreg | 1651 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1216 | killagreg | 1652 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
604 | hbuss | 1653 | |
1171 | hbuss | 1654 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1655 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
||
1153 | hbuss | 1656 | |
1167 | hbuss | 1657 | #define TRIM_MAX 200 |
1166 | hbuss | 1658 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1659 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
||
1153 | hbuss | 1660 | |
1166 | hbuss | 1661 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1662 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
||
1211 | hbuss | 1663 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1166 | hbuss | 1664 | |
1 | ingob | 1665 | // Maximalwerte abfangen |
1685 | holgerb | 1666 | #define MAX_SENSOR (4096) |
1216 | killagreg | 1667 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1 | ingob | 1668 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1669 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
||
1670 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
||
1671 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
||
1672 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
||
1673 | |||
1051 | killagreg | 1674 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2390 | holgerb | 1675 | // Undervoltage |
1676 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1677 | if(!(FC_StatusFlags & FC_STATUS_LOWBAT)) |
||
1678 | { |
||
1679 | GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
||
1680 | } |
||
1681 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1682 | // Auto-Landing |
||
1683 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1684 | static unsigned char slower; |
||
1685 | if(!slower--) |
||
1686 | { |
||
2402 | holgerb | 1687 | static unsigned int u_filter = 0; |
1688 | if(!u_filter) u_filter = UBat; |
||
1689 | if(UBat > u_filter) u_filter++; else |
||
1690 | if(UBat < u_filter) u_filter--; |
||
1691 | slower = 100; // 5Hz |
||
2416 | holgerb | 1692 | if(u_filter < BattAutoLandingVoltage) |
2390 | holgerb | 1693 | { |
2402 | holgerb | 1694 | LowVoltageLandingActive = 10; // 2 sek |
2390 | holgerb | 1695 | } |
2416 | holgerb | 1696 | else if(u_filter > BattAutoLandingVoltage + LipoCells && LowVoltageLandingActive) LowVoltageLandingActive--; |
2408 | holgerb | 1697 | |
2416 | holgerb | 1698 | if(u_filter < BattComingHomeVoltage) |
2408 | holgerb | 1699 | { |
1700 | LowVoltageHomeActive = 25; // min. 5 sek |
||
1701 | } |
||
2416 | holgerb | 1702 | else if(u_filter > BattComingHomeVoltage + LipoCells && LowVoltageHomeActive) LowVoltageHomeActive--; |
2390 | holgerb | 1703 | } |
1704 | if(LowVoltageLandingActive && FromNC_AltitudeSetpoint >= 0) |
||
1705 | { |
||
1706 | FromNC_AltitudeSpeed = EE_Parameter.LandingSpeed; |
||
1707 | FromNC_AltitudeSetpoint = -20000; |
||
1708 | } |
||
1709 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2427 | holgerb | 1710 | // send SPI pending bytes |
1711 | if(BytegapSPI == 0) SPI_TransmitByte(); |
||
1712 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1713 | // Höhenregelung |
1051 | killagreg | 1714 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
855 | hbuss | 1715 | GasMischanteil *= STICK_GAIN; |
2427 | holgerb | 1716 | // if height control is activated |
2334 | holgerb | 1717 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick) && !(VersionInfo.HardwareError[0] & 0x7F)) // Höhenregelung |
1309 | hbuss | 1718 | { |
1698 | holgerb | 1719 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1332 | hbuss | 1720 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1638 | holgerb | 1721 | |
2309 | holgerb | 1722 | int HCGas, GasReduction = 0; |
1309 | hbuss | 1723 | static int HeightTrimming = 0; // rate for change of height setpoint |
2309 | holgerb | 1724 | static int HeightDeviation = 0, FilterHCGas = 0; |
1587 | killagreg | 1725 | static unsigned long HoverGasFilter = 0; |
1322 | hbuss | 1726 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1727 | // Expand the measurement |
||
1728 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
||
1729 | if(!BaroExpandActive) |
||
1730 | { |
||
1731 | if(MessLuftdruck > 920) |
||
1732 | { // increase offset |
||
1330 | killagreg | 1733 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
1322 | hbuss | 1734 | { |
1735 | ExpandBaro -= 1; |
||
1736 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
||
2367 | holgerb | 1737 | OCR0B = 255 - OCR0A; |
1322 | hbuss | 1738 | beeptime = 300; |
1352 | hbuss | 1739 | BaroExpandActive = 350; |
2367 | holgerb | 1740 | CalcExpandBaroStep(); |
1330 | killagreg | 1741 | } |
1742 | else |
||
1322 | hbuss | 1743 | { |
1744 | BaroAtLowerLimit = 1; |
||
1745 | } |
||
1746 | } |
||
1747 | // measurement of air pressure close to lower limit and |
||
1330 | killagreg | 1748 | else |
1322 | hbuss | 1749 | if(MessLuftdruck < 100) |
1750 | { // decrease offset |
||
1330 | killagreg | 1751 | if(OCR0A > OPA_OFFSET_STEP) |
1322 | hbuss | 1752 | { |
1753 | ExpandBaro += 1; |
||
1754 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
||
2367 | holgerb | 1755 | OCR0B = 255 - OCR0A; |
1322 | hbuss | 1756 | beeptime = 300; |
1352 | hbuss | 1757 | BaroExpandActive = 350; |
2367 | holgerb | 1758 | CalcExpandBaroStep(); |
1330 | killagreg | 1759 | } |
1760 | else |
||
1322 | hbuss | 1761 | { |
1762 | BaroAtUpperLimit = 1; |
||
1763 | } |
||
1764 | } |
||
1330 | killagreg | 1765 | else |
1322 | hbuss | 1766 | { |
1767 | BaroAtUpperLimit = 0; |
||
1768 | BaroAtLowerLimit = 0; |
||
1769 | } |
||
1770 | } |
||
1771 | else // delay, because of expanding the Baro-Range |
||
1772 | { |
||
1773 | // now clear the D-values |
||
2316 | holgerb | 1774 | VarioMeter = 0; |
2309 | holgerb | 1775 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2316 | holgerb | 1776 | if(ACC_AltitudeControl) ACC_AltitudeFusion(1); // init |
2309 | holgerb | 1777 | else SummenHoehe = HoehenWert * SM_FILTER; |
1778 | #else |
||
1779 | SummenHoehe = HoehenWert * SM_FILTER; |
||
1780 | #endif |
||
1322 | hbuss | 1781 | BaroExpandActive--; |
1782 | } |
||
1328 | hbuss | 1783 | // if height control is activated by an rc channel |
1916 | holgerb | 1784 | if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1328 | hbuss | 1785 | { // check if parameter is less than activation threshold |
1916 | holgerb | 1786 | if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position |
1328 | hbuss | 1787 | { //height control not active |
1788 | if(!delay--) |
||
1789 | { |
||
2090 | holgerb | 1790 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2263 | holgerb | 1791 | if(!SpeakHoTT && HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
2090 | holgerb | 1792 | #endif |
1328 | hbuss | 1793 | HoehenReglerAktiv = 0; // disable height control |
1794 | SollHoehe = HoehenWert; // update SetPoint with current reading |
||
1795 | delay = 1; |
||
1796 | } |
||
1797 | } |
||
1798 | else |
||
2090 | holgerb | 1799 | if(Parameter_HoehenSchalter > 70) |
1328 | hbuss | 1800 | { //height control is activated |
2090 | holgerb | 1801 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2263 | holgerb | 1802 | if(!SpeakHoTT && !HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_ON; |
2090 | holgerb | 1803 | #endif |
2263 | holgerb | 1804 | delay = 200; |
1328 | hbuss | 1805 | HoehenReglerAktiv = 1; // enable height control |
1806 | } |
||
1051 | killagreg | 1807 | } |
1309 | hbuss | 1808 | else // no switchable height control |
1809 | { |
||
1916 | holgerb | 1810 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1309 | hbuss | 1811 | HoehenReglerAktiv = 1; |
1051 | killagreg | 1812 | } |
1320 | hbuss | 1813 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1330 | killagreg | 1814 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1815 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
||
1816 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
||
1320 | hbuss | 1817 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1818 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
||
1591 | holgerb | 1819 | VarioCharacter = ' '; |
1942 | holgerb | 1820 | AltitudeSetpointTrimming = 0; |
1765 | killagreg | 1821 | if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1309 | hbuss | 1822 | { |
1823 | // Holger original version |
||
1824 | // start of height control algorithm |
||
1825 | // the height control is only an attenuation of the actual gas stick. |
||
1826 | // I.e. it will work only if the gas stick is higher than the hover gas |
||
1827 | // and the hover height will be allways larger than height setpoint. |
||
1861 | holgerb | 1828 | FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL; |
1916 | holgerb | 1829 | if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1314 | killagreg | 1830 | { // old version |
1309 | hbuss | 1831 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1832 | HeightTrimming = 0; |
||
1942 | holgerb | 1833 | AltitudeSetpointTrimming = 0; |
1773 | killagreg | 1834 | // set both flags to indicate no vario mode |
1835 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
||
1309 | hbuss | 1836 | } |
1314 | killagreg | 1837 | else |
1309 | hbuss | 1838 | { |
1839 | // alternative height control |
||
1840 | // PD-Control with respect to hoover point |
||
1841 | // the thrust loss out of horizontal attitude is compensated |
||
1842 | // the setpoint will be fine adjusted with the gas stick position |
||
2390 | holgerb | 1843 | if(/*1 || */FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying |
1309 | hbuss | 1844 | { // gas stick is above hoover point |
1587 | killagreg | 1845 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1309 | hbuss | 1846 | { |
1767 | killagreg | 1847 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) |
1309 | hbuss | 1848 | { |
1767 | killagreg | 1849 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
2309 | holgerb | 1850 | SollHoehe = HoehenWertF; // update setpoint to current heigth |
1309 | hbuss | 1851 | } |
1966 | holgerb | 1852 | // Limit the maximum Altitude |
2381 | holgerb | 1853 | if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) |
1854 | { |
||
1855 | AltitudeSetpointTrimming = 0; |
||
1856 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
1857 | if(!SpeakHoTT && HoehenWert/95 > Parameter_MaximumAltitude) SpeakHoTT = SPEAK_MAX_ALTITUD; |
||
1858 | #endif |
||
1859 | VarioCharacter = '='; |
||
1860 | } |
||
1966 | holgerb | 1861 | else |
1862 | { |
||
2381 | holgerb | 1863 | if(HeightDeviation > 20) SollHoehe = HoehenWertF; // update setpoint to current heigth |
1864 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
||
1942 | holgerb | 1865 | AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
2390 | holgerb | 1866 | if(LowVoltageLandingActive) AltitudeSetpointTrimming /= 3; // only 33% rising |
1591 | holgerb | 1867 | VarioCharacter = '+'; |
1966 | holgerb | 1868 | } |
1865 | holgerb | 1869 | WaypointTrimming = 0; |
1309 | hbuss | 1870 | } // gas stick is below hoover point |
2390 | holgerb | 1871 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) // Minus |
1309 | hbuss | 1872 | { |
2471 | holgerb | 1873 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP || (HeightDeviation < -300)) |
1309 | hbuss | 1874 | { |
1767 | killagreg | 1875 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
2309 | holgerb | 1876 | SollHoehe = HoehenWertF; // update setpoint to current heigth |
1309 | hbuss | 1877 | } |
1767 | killagreg | 1878 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1942 | holgerb | 1879 | AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1591 | holgerb | 1880 | VarioCharacter = '-'; |
1865 | holgerb | 1881 | WaypointTrimming = 0; |
1309 | hbuss | 1882 | } |
1587 | killagreg | 1883 | else // Gas Stick in Hover Range |
1309 | hbuss | 1884 | { |
1855 | holgerb | 1885 | VarioCharacter = '='; |
1857 | holgerb | 1886 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen |
1855 | holgerb | 1887 | { |
1888 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
||
1942 | holgerb | 1889 | AltitudeSetpointTrimming = FromNC_AltitudeSpeed; |
1890 | //HeightTrimming += FromNC_AltitudeSpeed; |
||
1857 | holgerb | 1891 | WaypointTrimming = 10; |
1892 | VarioCharacter = '^'; |
||
1865 | holgerb | 1893 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) // changed from sinking to rising |
1894 | { |
||
1895 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
||
2309 | holgerb | 1896 | SollHoehe = HoehenWertF; // update setpoint to current heigth |
1865 | holgerb | 1897 | } |
1855 | holgerb | 1898 | } |
1899 | else |
||
1857 | holgerb | 1900 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
1855 | holgerb | 1901 | { |
1902 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
||
1942 | holgerb | 1903 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
1904 | //HeightTrimming -= FromNC_AltitudeSpeed; |
||
1857 | holgerb | 1905 | WaypointTrimming = -10; |
1906 | VarioCharacter = 'v'; |
||
1865 | holgerb | 1907 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
1908 | { |
||
1909 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
||
2309 | holgerb | 1910 | SollHoehe = HoehenWertF; // update setpoint to current heigth |
1865 | holgerb | 1911 | } |
1855 | holgerb | 1912 | } |
1913 | else |
||
1767 | killagreg | 1914 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
1309 | hbuss | 1915 | { |
2309 | holgerb | 1916 | if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWertF-200), (HoehenWertF+200)) // max. 2m Unterschied |
1933 | holgerb | 1917 | else WaypointTrimming = 0; |
1767 | killagreg | 1918 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1309 | hbuss | 1919 | HeightTrimming = 0; |
1916 | holgerb | 1920 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1698 | holgerb | 1921 | if(!StartTrigger && HoehenWert > 50) |
1922 | { |
||
1923 | StartTrigger = 1; |
||
1765 | killagreg | 1924 | } |
1309 | hbuss | 1925 | } |
1926 | } |
||
1927 | // Trim height set point |
||
1942 | holgerb | 1928 | HeightTrimming += AltitudeSetpointTrimming; |
1929 | if(abs(HeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz |
||
1309 | hbuss | 1930 | { |
1857 | holgerb | 1931 | if(WaypointTrimming) |
1932 | { |
||
1933 | if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) SollHoehe = FromNC_AltitudeSetpoint; |
||
1934 | else SollHoehe += WaypointTrimming; |
||
1935 | } |
||
1936 | else |
||
1966 | holgerb | 1937 | { |
1938 | if(HeightTrimming > 0) SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3; |
||
1939 | else SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3; |
||
1940 | } |
||
1309 | hbuss | 1941 | HeightTrimming = 0; |
2471 | holgerb | 1942 | LIMIT_MIN_MAX(HoehenWertF, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1943 | LIMIT_MIN_MAX(SollHoehe, (HoehenWertF-1024), (HoehenWertF+1024)); // max. 10m Unterschied |
||
1916 | holgerb | 1944 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1320 | hbuss | 1945 | //update hoover gas stick value when setpoint is shifted |
2427 | holgerb | 1946 | if(FromNC_AltitudeSpeed == 0) CalcStickGasHover(); |
1947 | /* |
||
1857 | holgerb | 1948 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1332 | hbuss | 1949 | { |
1587 | killagreg | 1950 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
2427 | holgerb | 1951 | StickGasHover = (unsigned int)((unsigned int) StickGasHover * UBat) / BattLowVoltageWarning; |
1587 | killagreg | 1952 | if(StickGasHover < 70) StickGasHover = 70; |
2427 | holgerb | 1953 | else if(StickGasHover > 175) StickGasHover = 175; |
1332 | hbuss | 1954 | } |
2427 | holgerb | 1955 | */ |
1309 | hbuss | 1956 | } |
2309 | holgerb | 1957 | if(BaroExpandActive) SollHoehe = HoehenWertF; // update setpoint to current altitude if Expanding is active |
1420 | killagreg | 1958 | } //if FCFlags & MKFCFLAG_FLY |
1330 | killagreg | 1959 | else |
1960 | { |
||
2466 | holgerb | 1961 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2462 | holgerb | 1962 | ACC_AltitudeFusion(1); // init the ACC and Altitude fusion |
2466 | holgerb | 1963 | #endif |
2471 | holgerb | 1964 | SollHoehe = HoehenWertF - 2000; |
1965 | |||
1587 | killagreg | 1966 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
2427 | holgerb | 1967 | else StickGasHover = 127; |
1698 | holgerb | 1968 | HoverGas = GasMischanteil; |
1972 | holgerb | 1969 | VarioCharacter = '.'; |
1320 | hbuss | 1970 | } |
1590 | killagreg | 1971 | HCGas = HoverGas; // take hover gas (neutral point) |
1972 | } |
||
2309 | holgerb | 1973 | if(HoehenWertF > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1283 | hbuss | 1974 | { |
2316 | holgerb | 1975 | if(!ACC_AltitudeControl) |
1976 | { |
||
1590 | killagreg | 1977 | // from this point the Heigth Control Algorithm is identical for both versions |
1978 | if(BaroExpandActive) // baro range expanding active |
||
1979 | { |
||
1980 | HCGas = HoverGas; // hover while expanding baro adc range |
||
1981 | HeightDeviation = 0; |
||
1982 | } // EOF // baro range expanding active |
||
1983 | else // valid data from air pressure sensor |
||
1984 | { |
||
1985 | // ------------------------- P-Part ---------------------------- |
||
2309 | holgerb | 1986 | tmp_long = (HoehenWertF - SollHoehe); // positive when too high |
1590 | killagreg | 1987 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1988 | HeightDeviation = (int)(tmp_long); // positive when too high |
||
1695 | holgerb | 1989 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1698 | holgerb | 1990 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1991 | GasReduction = tmp_long; |
||
1590 | killagreg | 1992 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1993 | tmp_int = VarioMeter / 8; |
||
1765 | killagreg | 1994 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1705 | holgerb | 1995 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1996 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
||
1767 | killagreg | 1997 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) tmp_int /= 4; // reduce d-part while trimming setpoint |
1765 | killagreg | 1998 | else |
1916 | holgerb | 1999 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1698 | holgerb | 2000 | GasReduction += tmp_int; |
1590 | killagreg | 2001 | } // EOF no baro range expanding |
1309 | hbuss | 2002 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1698 | holgerb | 2003 | if(Parameter_Hoehe_ACC_Wirkung) |
2004 | { |
||
2005 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
||
2006 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
||
2007 | GasReduction += tmp_long; |
||
1765 | killagreg | 2008 | } |
1587 | killagreg | 2009 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1588 | killagreg | 2010 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
2011 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
||
1698 | holgerb | 2012 | GasReduction += tmp_int; |
1701 | holgerb | 2013 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
2309 | holgerb | 2014 | |
1701 | holgerb | 2015 | // ------------------------ ---------------------------------- |
2016 | HCGas -= GasReduction; |
||
1309 | hbuss | 2017 | // limit deviation from hoover point within the target region |
1942 | holgerb | 2018 | if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1309 | hbuss | 2019 | { |
1765 | killagreg | 2020 | unsigned int tmp; |
1705 | holgerb | 2021 | tmp = abs(HeightDeviation); |
2022 | if(tmp <= 60) |
||
2023 | { |
||
2024 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
||
2025 | } |
||
2026 | else |
||
1765 | killagreg | 2027 | { |
1705 | holgerb | 2028 | tmp = (tmp - 60) / 32; |
1692 | holgerb | 2029 | if(tmp > 15) tmp = 15; |
1705 | holgerb | 2030 | if(HeightDeviation > 0) |
1693 | holgerb | 2031 | { |
1705 | holgerb | 2032 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
2033 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
||
1693 | holgerb | 2034 | } |
1705 | holgerb | 2035 | else |
2036 | { |
||
2037 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
||
2038 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
||
2039 | } |
||
2040 | } |
||
1309 | hbuss | 2041 | } |
1322 | hbuss | 2042 | // strech control output by inverse attitude projection 1/cos |
2043 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
||
1330 | killagreg | 2044 | tmp_long2 = (int32_t)HCGas; |
2045 | tmp_long2 *= 8192L; |
||
2046 | tmp_long2 /= CosAttitude; |
||
2047 | HCGas = (int16_t)tmp_long2; |
||
1309 | hbuss | 2048 | // update height control gas averaging |
2049 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
||
2050 | // limit height control gas pd-control output |
||
2051 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
||
2052 | // set GasMischanteil to HeightControlGasFilter |
||
1916 | holgerb | 2053 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
1587 | killagreg | 2054 | { // old version |
2055 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
||
1719 | holgerb | 2056 | GasMischanteil = FilterHCGas; |
1765 | killagreg | 2057 | } |
1719 | holgerb | 2058 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
2316 | holgerb | 2059 | } |
2320 | holgerb | 2060 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2316 | holgerb | 2061 | else // ACC-Altitude control |
2062 | { |
||
2309 | holgerb | 2063 | // from this point the Heigth Control Algorithm is identical for both versions |
2064 | if(BaroExpandActive) // baro range expanding active |
||
2065 | { |
||
2066 | HCGas = HoverGas; // hover while expanding baro adc range |
||
2067 | HeightDeviation = 0; |
||
2068 | } // EOF // baro range expanding active |
||
2069 | else // valid data from air pressure sensor |
||
2070 | { |
||
2071 | // ------------------------- P-Part ---------------------------- |
||
2072 | tmp_long = (HoehenWertF - SollHoehe); // positive when too high |
||
2073 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
||
2074 | HeightDeviation = (int)(tmp_long); // positive when too high |
||
2075 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
||
2076 | LIMIT_MIN_MAX(tmp_long, -511 * STICK_GAIN, 512 * STICK_GAIN); // more than full range makes sense |
||
2077 | GasReduction = tmp_long; |
||
2078 | // ------------------------ D-Part: ACC-Z Integral ------------------------ |
||
2316 | holgerb | 2079 | tmp_long = VarioMeter + (AdWertAccHoch * Parameter_Hoehe_ACC_Wirkung)/256; |
2309 | holgerb | 2080 | // ------------------------- D-Part: Vario Meter ---------------------------- |
2081 | if(WaypointTrimming) { |
||
2082 | Variance = AltitudeSetpointTrimming * 8; |
||
2083 | } else { |
||
2084 | Variance = AltitudeSetpointTrimming * EE_Parameter.Hoehe_Verstaerkung*9/32; |
||
2085 | } |
||
2086 | tmp_long -= (long)Variance; |
||
2087 | tmp_long = (tmp_long * (long)Parameter_Luftdruck_D) / 32; // scale to d-gain parameter |
||
2088 | LIMIT_MIN_MAX(tmp_long,-511 * STICK_GAIN, 512 * STICK_GAIN); |
||
2089 | GasReduction += tmp_long; |
||
2090 | } // EOF no baro range expanding |
||
2091 | HCGas -= GasReduction; |
||
2092 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limits gas around hover point |
||
2093 | // strech control output by inverse attitude projection 1/cos |
||
2094 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
||
2095 | tmp_long2 = (int32_t)HCGas; |
||
2096 | tmp_long2 *= 8192L; |
||
2097 | tmp_long2 /= CosAttitude; |
||
2098 | HCGas = (int16_t)tmp_long2; |
||
2099 | // update height control gas averaging |
||
2100 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
||
2101 | // limit height control gas pd-control output |
||
2471 | holgerb | 2102 | int min; |
2103 | if(GasIsZeroCnt > 400 || (FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF)) min = EE_Parameter.Gas_Min; else min = EE_Parameter.Hoehe_MinGas; |
||
2104 | LIMIT_MIN_MAX(FilterHCGas, min * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN) |
||
2309 | holgerb | 2105 | // set GasMischanteil to HeightControlGasFilter |
2106 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
||
2107 | { // old version |
||
2108 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
||
2109 | GasMischanteil = FilterHCGas; |
||
2110 | } |
||
2316 | holgerb | 2111 | else GasMischanteil = FilterHCGas; |
2112 | } // end of ACC-Altitude control |
||
2320 | holgerb | 2113 | #endif |
1314 | killagreg | 2114 | } |
1309 | hbuss | 2115 | }// EOF height control active |
1320 | hbuss | 2116 | else // HC not active |
2117 | { |
||
2118 | //update hoover gas stick value when HC is not active |
||
2427 | holgerb | 2119 | CalcStickGasHover(); |
2120 | /* if(!EE_Parameter.Hoehe_StickNeutralPoint) |
||
1587 | killagreg | 2121 | { |
2122 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
||
2427 | holgerb | 2123 | StickGasHover = (unsigned int)((unsigned int) StickGasHover * UBat) / BattLowVoltageWarning; |
1322 | hbuss | 2124 | } |
1587 | killagreg | 2125 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
2427 | holgerb | 2126 | LIMIT_MIN_MAX(StickGasHover, 70, 175); // reserve some range for trim up and down |
2127 | */ |
||
1328 | hbuss | 2128 | FilterHCGas = GasMischanteil; |
1773 | killagreg | 2129 | // set both flags to indicate no vario mode |
2130 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
||
1861 | holgerb | 2131 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
1330 | killagreg | 2132 | } |
1587 | killagreg | 2133 | // Hover gas estimation by averaging gas control output on small z-velocities |
1309 | hbuss | 2134 | // this is done only if height contol option is selected in global config and aircraft is flying |
1765 | killagreg | 2135 | if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1309 | hbuss | 2136 | { |
2316 | holgerb | 2137 | //if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
2318 | holgerb | 2138 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(HoverGas); // 0.90f: geändert |
1698 | holgerb | 2139 | if(StartTrigger == 1) StartTrigger = 2; |
1330 | killagreg | 2140 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
2141 | tmp_long2 *= CosAttitude; // apply attitude projection |
||
2142 | tmp_long2 /= 8192; |
||
1309 | hbuss | 2143 | // average vertical projected thrust |
1698 | holgerb | 2144 | if(modell_fliegt < 4000) // the first 8 seconds |
2145 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
||
2146 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
||
2147 | HoverGasFilter += 16L * tmp_long2; |
||
1309 | hbuss | 2148 | } |
1698 | holgerb | 2149 | if(modell_fliegt < 8000) // the first 16 seconds |
2150 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
||
1590 | killagreg | 2151 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1587 | killagreg | 2152 | HoverGasFilter += 4L * tmp_long2; |
1309 | hbuss | 2153 | } |
1698 | holgerb | 2154 | else //later |
2316 | holgerb | 2155 | if(abs(VarioMeter) < 100 && abs(HoehenWertF - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
1309 | hbuss | 2156 | { |
1590 | killagreg | 2157 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1587 | killagreg | 2158 | HoverGasFilter += tmp_long2; |
1309 | hbuss | 2159 | } |
1590 | killagreg | 2160 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1309 | hbuss | 2161 | if(EE_Parameter.Hoehe_HoverBand) |
2162 | { |
||
2163 | int16_t band; |
||
1587 | killagreg | 2164 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
2165 | HoverGasMin = HoverGas - band; |
||
2166 | HoverGasMax = HoverGas + band; |
||
1309 | hbuss | 2167 | } |
2168 | else |
||
2169 | { // no limit |
||
1587 | killagreg | 2170 | HoverGasMin = 0; |
2171 | HoverGasMax = 1023; |
||
1309 | hbuss | 2172 | } |
1765 | killagreg | 2173 | } |
2174 | else |
||
1698 | holgerb | 2175 | { |
2176 | StartTrigger = 0; |
||
2177 | HoverGasFilter = 0; |
||
2178 | HoverGas = 0; |
||
1765 | killagreg | 2179 | } |
1916 | holgerb | 2180 | }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL |
1773 | killagreg | 2181 | else |
2182 | { |
||
2183 | // set undefined state to indicate vario off |
||
2184 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
||
2185 | } // EOF no height control |
||
2186 | |||
2309 | holgerb | 2187 | // Limits the maximum gas in case of "Out of Range emergency landing" |
2009 | holgerb | 2188 | if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING) |
2189 | { |
||
2028 | holgerb | 2190 | if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN; |
2309 | holgerb | 2191 | SollHoehe = HoehenWertF; // update setpoint to current heigth |
2009 | holgerb | 2192 | beeptime = 15000; |
2193 | BeepMuster = 0x0E00; |
||
2194 | } |
||
2028 | holgerb | 2195 | // limit gas to parameter setting |
1320 | hbuss | 2196 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
855 | hbuss | 2197 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1111 | hbuss | 2198 | |
1051 | killagreg | 2199 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1320 | hbuss | 2200 | // all BL-Ctrl connected? |
2201 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2418 | holgerb | 2202 | if(MissingMotor || Capacity.MinOfMaxPWM < 254 || NC_ErrorCode) // wait until all BL-Ctrls started and no Errors |
1931 | holgerb | 2203 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) // only during start-phase |
1320 | hbuss | 2204 | { |
2205 | modell_fliegt = 1; |
||
1675 | holgerb | 2206 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
2382 | holgerb | 2207 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2208 | if(Capacity.MinOfMaxPWM < 40) SpeakHoTT = SPEAK_ERR_MOTOR; |
||
2209 | #endif |
||
1320 | hbuss | 2210 | } |
2407 | holgerb | 2211 | |
2427 | holgerb | 2212 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2213 | // send SPI pending bytes |
||
2407 | holgerb | 2214 | if(BytegapSPI == 0) SPI_TransmitByte(); |
1320 | hbuss | 2215 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 2216 | // + Mischer und PI-Regler |
1051 | killagreg | 2217 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 2218 | DebugOut.Analog[7] = GasMischanteil; |
1051 | killagreg | 2219 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 2220 | // Gier-Anteil |
1051 | killagreg | 2221 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
855 | hbuss | 2222 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
2223 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
||
693 | hbuss | 2224 | if(GasMischanteil > MIN_GIERGAS) |
2225 | { |
||
1051 | killagreg | 2226 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
2227 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
||
693 | hbuss | 2228 | } |
1051 | killagreg | 2229 | else |
693 | hbuss | 2230 | { |
1051 | killagreg | 2231 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
2232 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
||
693 | hbuss | 2233 | } |
855 | hbuss | 2234 | tmp_int = MAX_GAS*STICK_GAIN; |
1051 | killagreg | 2235 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
855 | hbuss | 2236 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
513 | hbuss | 2237 | |
1051 | killagreg | 2238 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 2239 | // Nick-Achse |
1051 | killagreg | 2240 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
723 | hbuss | 2241 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1153 | hbuss | 2242 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1051 | killagreg | 2243 | else SummeNick += DiffNick; // I-Anteil bei HH |
855 | hbuss | 2244 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
2245 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
||
1791 | holgerb | 2246 | |
2247 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick |
||
2248 | else pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern |
||
2249 | pd_ergebnis_nick += SummeNick / Ki; |
||
2250 | |||
1676 | holgerb | 2251 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1153 | hbuss | 2252 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
2253 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
||
173 | holgerb | 2254 | |
1153 | hbuss | 2255 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2256 | // Roll-Achse |
||
2257 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2258 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
||
2259 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
||
2260 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
||
2261 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
||
2262 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
||
1791 | holgerb | 2263 | |
2264 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8; // PI-Regler für Roll |
||
2265 | else pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4; // Überlauf verhindern |
||
2266 | pd_ergebnis_roll += SummeRoll / Ki; |
||
2267 | |||
1676 | holgerb | 2268 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1153 | hbuss | 2269 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
2270 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
||
2271 | |||
2272 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2427 | holgerb | 2273 | // send SPI pending bytes |
2274 | if(BytegapSPI == 0) SPI_TransmitByte(); |
||
2275 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1209 | hbuss | 2276 | // Universal Mixer |
1155 | hbuss | 2277 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1642 | killagreg | 2278 | for(i=0; i<MAX_MOTORS; i++) |
2279 | { |
||
2280 | signed int tmp_int; |
||
2281 | if(Mixer.Motor[i][0] > 0) |
||
2282 | { |
||
1652 | holgerb | 2283 | // Gas |
1676 | holgerb | 2284 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1652 | holgerb | 2285 | // Nick |
2286 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
||
2287 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
||
2288 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
||
2289 | // Roll |
||
2290 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
||
2291 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
||
2292 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
||
2293 | // Gier |
||
1676 | holgerb | 2294 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
2295 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
||
2296 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
||
2427 | holgerb | 2297 | #ifdef REDUNDANT_FC_SLAVE |
2418 | holgerb | 2298 | tmp_int = (tmp_motorwert[i] + tmp_int) / 2; |
2299 | #else |
||
2386 | holgerb | 2300 | if(Motor[i].Version & MOTOR_STATE_FAST_MODE || tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // Beschleunigen |
1913 | holgerb | 2301 | else |
2402 | holgerb | 2302 | { // BL-Ctrl 1.0 or 2.0 |
2386 | holgerb | 2303 | if(EE_Parameter.MotorSmooth == 0) |
1913 | holgerb | 2304 | { |
1931 | holgerb | 2305 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
1913 | holgerb | 2306 | } |
2307 | else // 1 means tmp_int = tmp_int; |
||
2443 | holgerb | 2308 | if(EE_Parameter.MotorSmooth > 1) |
1913 | holgerb | 2309 | { |
2386 | holgerb | 2310 | // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
2311 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int) / EE_Parameter.MotorSmooth); |
||
1913 | holgerb | 2312 | } |
2313 | } |
||
2418 | holgerb | 2314 | #endif |
1760 | holgerb | 2315 | LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4); |
1676 | holgerb | 2316 | Motor[i].SetPoint = tmp_int / 4; |
1677 | killagreg | 2317 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
1652 | holgerb | 2318 | tmp_motorwert[i] = tmp_int; |
1642 | killagreg | 2319 | } |
2320 | else |
||
2321 | { |
||
2322 | Motor[i].SetPoint = 0; |
||
2323 | Motor[i].SetPointLowerBits = 0; |
||
2324 | } |
||
2325 | } |
||
2427 | holgerb | 2326 | #ifdef REDUNDANT_FC_MASTER |
2437 | holgerb | 2327 | if(Parameter_UserParam6 > 230) Motor[0].SetPoint = 0; |
2427 | holgerb | 2328 | #endif |
1111 | hbuss | 2329 | } |
2090 | holgerb | 2330 | //DebugOut.Analog[16] |