Rev 2191 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
2 | Flight Control |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + 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; |
||
1153 | hbuss | 63 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, 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; |
1683 | killagreg | 70 | unsigned char ControlHeading = 0;// in 2° |
693 | hbuss | 71 | long IntegralNick = 0,IntegralNick2 = 0; |
72 | long IntegralRoll = 0,IntegralRoll2 = 0; |
||
73 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
||
74 | long Integral_Gier = 0; |
||
75 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
||
76 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
||
77 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
||
78 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
||
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; |
92 | int ErsatzKompassInGrad; // Kompasswert in Grad |
||
93 | int GierGyroFehler = 0; |
||
1211 | hbuss | 94 | char GyroFaktor,GyroFaktorGier; |
95 | char IntegralFaktor,IntegralFaktorGier; |
||
1153 | hbuss | 96 | int DiffNick,DiffRoll; |
1916 | holgerb | 97 | int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023; |
1943 | holgerb | 98 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
1377 | hbuss | 99 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
1391 | killagreg | 100 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
1 | ingob | 101 | volatile unsigned char SenderOkay = 0; |
1698 | holgerb | 102 | char MotorenEin = 0,StartTrigger = 0; |
1246 | killagreg | 103 | long HoehenWert = 0; |
104 | long SollHoehe = 0; |
||
1942 | holgerb | 105 | signed int AltitudeSetpointTrimming = 0; |
1855 | holgerb | 106 | long FromNC_AltitudeSetpoint = 0; |
107 | unsigned char FromNC_AltitudeSpeed = 0; |
||
1862 | holgerb | 108 | unsigned char carefree_old = 50; // to make the Beep when switching |
1942 | holgerb | 109 | signed char WaypointTrimming = 0; |
1840 | holgerb | 110 | int CompassGierSetpoint = 0; |
2009 | holgerb | 111 | unsigned char CalibrationDone = 0; |
2061 | holgerb | 112 | char NeueKompassRichtungMerken = 0; |
1692 | holgerb | 113 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
1153 | hbuss | 114 | //float Ki = FAKTOR_I; |
1676 | holgerb | 115 | int Ki = 10300 / 33; |
395 | hbuss | 116 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
117 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
||
1 | ingob | 118 | |
119 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
||
1916 | holgerb | 120 | unsigned char Parameter_HoehenSchalter = 251; // Wert : 0-250 |
1 | ingob | 121 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
122 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
||
123 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
||
1283 | hbuss | 124 | unsigned char Parameter_Hoehe_GPS_Z = 64; // Wert : 0-250 |
1111 | hbuss | 125 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
173 | holgerb | 126 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
1 | ingob | 127 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
1322 | hbuss | 128 | unsigned char Parameter_Gyro_Gier_P = 150; // Wert : 10-250 |
129 | unsigned char Parameter_Gyro_Gier_I = 150; // Wert : 10-250 |
||
1 | ingob | 130 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
131 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
||
132 | unsigned char Parameter_UserParam1 = 0; |
||
133 | unsigned char Parameter_UserParam2 = 0; |
||
134 | unsigned char Parameter_UserParam3 = 0; |
||
135 | unsigned char Parameter_UserParam4 = 0; |
||
499 | hbuss | 136 | unsigned char Parameter_UserParam5 = 0; |
137 | unsigned char Parameter_UserParam6 = 0; |
||
138 | unsigned char Parameter_UserParam7 = 0; |
||
139 | unsigned char Parameter_UserParam8 = 0; |
||
1 | ingob | 140 | unsigned char Parameter_ServoNickControl = 100; |
1232 | hbuss | 141 | unsigned char Parameter_ServoRollControl = 100; |
173 | holgerb | 142 | unsigned char Parameter_LoopGasLimit = 70; |
1120 | hbuss | 143 | unsigned char Parameter_AchsKopplung1 = 90; |
144 | unsigned char Parameter_AchsKopplung2 = 65; |
||
145 | unsigned char Parameter_CouplingYawCorrection = 64; |
||
146 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
||
499 | hbuss | 147 | unsigned char Parameter_DynamicStability = 100; |
921 | hbuss | 148 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
149 | unsigned char Parameter_J16Timing; // for the J16 Output |
||
150 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
||
151 | unsigned char Parameter_J17Timing; // for the J17 Output |
||
152 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
||
1051 | killagreg | 153 | unsigned char Parameter_NaviGpsGain; |
154 | unsigned char Parameter_NaviGpsP; |
||
155 | unsigned char Parameter_NaviGpsI; |
||
156 | unsigned char Parameter_NaviGpsD; |
||
157 | unsigned char Parameter_NaviGpsACC; |
||
993 | hbuss | 158 | unsigned char Parameter_NaviOperatingRadius; |
159 | unsigned char Parameter_NaviWindCorrection; |
||
160 | unsigned char Parameter_NaviSpeedCompensation; |
||
921 | hbuss | 161 | unsigned char Parameter_ExternalControl; |
1916 | holgerb | 162 | unsigned char Parameter_GlobalConfig; |
163 | unsigned char Parameter_ExtraConfig; |
||
1966 | holgerb | 164 | unsigned char Parameter_MaximumAltitude; |
1403 | hbuss | 165 | unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
1668 | holgerb | 166 | unsigned char CareFree = 0; |
1876 | holgerb | 167 | 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 | 168 | |
492 | hbuss | 169 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
614 | hbuss | 170 | int MaxStickNick = 0,MaxStickRoll = 0; |
871 | hbuss | 171 | unsigned int modell_fliegt = 0; |
1861 | holgerb | 172 | volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0; |
1121 | hbuss | 173 | long GIER_GRAD_FAKTOR = 1291; |
1153 | hbuss | 174 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
1209 | hbuss | 175 | signed int tmp_motorwert[MAX_MOTORS]; |
1591 | holgerb | 176 | char VarioCharacter = ' '; |
2028 | holgerb | 177 | unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing |
2230 | holgerb | 178 | unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while |
1591 | holgerb | 179 | |
1639 | holgerb | 180 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
181 | // Debugwerte zuordnen |
||
182 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
183 | void CopyDebugValues(void) |
||
184 | { |
||
185 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
||
186 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
||
187 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
||
188 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
||
1660 | holgerb | 189 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
1639 | holgerb | 190 | DebugOut.Analog[5] = HoehenWert/5; |
1703 | holgerb | 191 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
1639 | holgerb | 192 | DebugOut.Analog[8] = KompassValue; |
193 | DebugOut.Analog[9] = UBat; |
||
194 | DebugOut.Analog[10] = SenderOkay; |
||
1941 | holgerb | 195 | DebugOut.Analog[11] = ErsatzKompassInGrad; |
1702 | holgerb | 196 | DebugOut.Analog[12] = Motor[0].SetPoint; |
197 | DebugOut.Analog[13] = Motor[1].SetPoint; |
||
198 | DebugOut.Analog[14] = Motor[2].SetPoint; |
||
199 | DebugOut.Analog[15] = Motor[3].SetPoint; |
||
1639 | holgerb | 200 | DebugOut.Analog[20] = ServoNickValue; |
201 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
||
202 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
||
1879 | holgerb | 203 | DebugOut.Analog[24] = SollHoehe/5; |
1639 | holgerb | 204 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
1682 | holgerb | 205 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
1839 | holgerb | 206 | DebugOut.Analog[27] = KompassSollWert; |
1682 | holgerb | 207 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
1639 | holgerb | 208 | DebugOut.Analog[30] = GPS_Nick; |
209 | DebugOut.Analog[31] = GPS_Roll; |
||
1702 | holgerb | 210 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
1639 | holgerb | 211 | } |
212 | |||
1760 | holgerb | 213 | |
214 | |||
1232 | hbuss | 215 | void Piep(unsigned char Anzahl, unsigned int dauer) |
1 | ingob | 216 | { |
1232 | hbuss | 217 | if(MotorenEin) return; //auf keinen Fall im Flug! |
1966 | holgerb | 218 | GRN_OFF; |
1 | ingob | 219 | while(Anzahl--) |
220 | { |
||
1232 | hbuss | 221 | beeptime = dauer; |
222 | while(beeptime); |
||
223 | Delay_ms(dauer * 2); |
||
1 | ingob | 224 | } |
1966 | holgerb | 225 | GRN_ON; |
1 | ingob | 226 | } |
227 | |||
228 | //############################################################################ |
||
1622 | killagreg | 229 | // Messwerte beim Ermitteln der Nullage |
230 | void CalibrierMittelwert(void) |
||
231 | //############################################################################ |
||
232 | { |
||
233 | unsigned char i; |
||
234 | if(PlatinenVersion == 13) SucheGyroOffset(); |
||
235 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
||
236 | ANALOG_OFF; |
||
237 | MesswertNick = AdWertNick; |
||
238 | MesswertRoll = AdWertRoll; |
||
239 | MesswertGier = AdWertGier; |
||
1703 | holgerb | 240 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
241 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
||
1622 | killagreg | 242 | // ADC einschalten |
243 | ANALOG_ON; |
||
244 | for(i=0;i<8;i++) |
||
245 | { |
||
246 | int tmp; |
||
1876 | holgerb | 247 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
1622 | killagreg | 248 | LIMIT_MIN_MAX(tmp, 0, 255); |
249 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
||
250 | } |
||
251 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
252 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
253 | } |
||
254 | |||
255 | //############################################################################ |
||
1 | ingob | 256 | // Nullwerte ermitteln |
1622 | killagreg | 257 | void SetNeutral(unsigned char AccAdjustment) |
1 | ingob | 258 | //############################################################################ |
259 | { |
||
1622 | killagreg | 260 | unsigned char i; |
261 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
||
1702 | holgerb | 262 | VersionInfo.HardwareError[0] = 0; |
2146 | holgerb | 263 | // HEF4017Reset_ON; |
1051 | killagreg | 264 | NeutralAccX = 0; |
1 | ingob | 265 | NeutralAccY = 0; |
266 | NeutralAccZ = 0; |
||
1622 | killagreg | 267 | |
1051 | killagreg | 268 | AdNeutralNick = 0; |
269 | AdNeutralRoll = 0; |
||
1 | ingob | 270 | AdNeutralGier = 0; |
1622 | killagreg | 271 | |
395 | hbuss | 272 | Parameter_AchsKopplung1 = 0; |
1120 | hbuss | 273 | Parameter_AchsKopplung2 = 0; |
1622 | killagreg | 274 | |
1036 | hbuss | 275 | ExpandBaro = 0; |
1622 | killagreg | 276 | |
1051 | killagreg | 277 | CalibrierMittelwert(); |
395 | hbuss | 278 | Delay_ms_Mess(100); |
1622 | killagreg | 279 | |
1 | ingob | 280 | CalibrierMittelwert(); |
1622 | killagreg | 281 | |
1 | ingob | 282 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
1051 | killagreg | 283 | { |
1 | ingob | 284 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
285 | } |
||
1166 | hbuss | 286 | #define NEUTRAL_FILTER 32 |
287 | for(i=0; i<NEUTRAL_FILTER; i++) |
||
1111 | hbuss | 288 | { |
289 | Delay_ms_Mess(10); |
||
1216 | killagreg | 290 | gier_neutral += AdWertGier; |
1166 | hbuss | 291 | nick_neutral += AdWertNick; |
292 | roll_neutral += AdWertRoll; |
||
1111 | hbuss | 293 | } |
1173 | hbuss | 294 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
295 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
||
296 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
||
1622 | killagreg | 297 | |
401 | hbuss | 298 | StartNeutralRoll = AdNeutralRoll; |
299 | StartNeutralNick = AdNeutralNick; |
||
1622 | killagreg | 300 | |
301 | if(AccAdjustment) |
||
302 | { |
||
303 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
||
304 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
||
305 | NeutralAccZ = Aktuell_az; |
||
306 | |||
307 | // Save ACC neutral settings to eeprom |
||
1639 | holgerb | 308 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
309 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
||
1622 | killagreg | 310 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
513 | hbuss | 311 | } |
1051 | killagreg | 312 | else |
513 | hbuss | 313 | { |
1622 | killagreg | 314 | // restore from eeprom |
315 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
||
316 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
||
317 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
||
318 | // strange settings? |
||
1638 | holgerb | 319 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
1622 | killagreg | 320 | { |
321 | printf("\n\rACC not calibrated!\r\n"); |
||
322 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
||
323 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
||
324 | NeutralAccZ = Aktuell_az; |
||
325 | } |
||
513 | hbuss | 326 | } |
1051 | killagreg | 327 | |
1 | ingob | 328 | MesswertNick = 0; |
329 | MesswertRoll = 0; |
||
330 | MesswertGier = 0; |
||
1111 | hbuss | 331 | Delay_ms_Mess(100); |
1703 | holgerb | 332 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
333 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
||
1173 | hbuss | 334 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
335 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
||
2072 | holgerb | 336 | Mess_IntegralNick = IntegralNick; |
337 | Mess_IntegralRoll = IntegralRoll; |
||
1173 | hbuss | 338 | Mess_Integral_Gier = 0; |
1 | ingob | 339 | StartLuftdruck = Luftdruck; |
1253 | killagreg | 340 | VarioMeter = 0; |
1 | ingob | 341 | Mess_Integral_Hoch = 0; |
1837 | holgerb | 342 | KompassSollWert = KompassValue; |
1839 | holgerb | 343 | KompassSignalSchlecht = 100; |
1051 | killagreg | 344 | beeptime = 50; |
882 | hbuss | 345 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
346 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
||
492 | hbuss | 347 | ExternHoehenValue = 0; |
693 | hbuss | 348 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
349 | GierGyroFehler = 0; |
||
921 | hbuss | 350 | LED_Init(); |
1765 | killagreg | 351 | FC_StatusFlags |= FC_STATUS_CALIBRATE; |
992 | hbuss | 352 | FromNaviCtrl_Value.Kalman_K = -1; |
1173 | hbuss | 353 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
992 | hbuss | 354 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
2191 | holgerb | 355 | |
1391 | killagreg | 356 | for(i=0;i<8;i++) |
1377 | hbuss | 357 | { |
1876 | holgerb | 358 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
1377 | hbuss | 359 | } |
1171 | hbuss | 360 | SenderOkay = 100; |
1320 | hbuss | 361 | if(ServoActive) |
362 | { |
||
363 | DDRD |=0x80; // enable J7 -> Servo signal |
||
364 | } |
||
2191 | holgerb | 365 | else NickServoValue = (128 * 4 * 16); // neutral position |
1702 | holgerb | 366 | |
1765 | killagreg | 367 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
368 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; }; |
||
369 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; }; |
||
370 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; }; |
||
371 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; }; |
||
372 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; }; |
||
1862 | holgerb | 373 | carefree_old = 70; |
1925 | holgerb | 374 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1921 | holgerb | 375 | LIBFC_HoTT_Clear(); |
1925 | holgerb | 376 | #endif |
1 | ingob | 377 | } |
378 | |||
1702 | holgerb | 379 | |
1 | ingob | 380 | //############################################################################ |
395 | hbuss | 381 | // Bearbeitet die Messwerte |
1 | ingob | 382 | void Mittelwert(void) |
383 | //############################################################################ |
||
1051 | killagreg | 384 | { |
1111 | hbuss | 385 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
386 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
||
1153 | hbuss | 387 | signed long winkel_nick, winkel_roll; |
1111 | hbuss | 388 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
1171 | hbuss | 389 | MesswertNick = (signed int) AdWertNickFilter / 8; |
390 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
||
1153 | hbuss | 391 | RohMesswertNick = MesswertNick; |
392 | RohMesswertRoll = MesswertRoll; |
||
1166 | hbuss | 393 | |
395 | hbuss | 394 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
1703 | holgerb | 395 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
396 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
||
395 | hbuss | 397 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
398 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
||
805 | hbuss | 399 | NaviAccNick += AdWertAccNick; |
400 | NaviAccRoll += AdWertAccRoll; |
||
401 | NaviCntAcc++; |
||
1153 | hbuss | 402 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
403 | |||
1155 | hbuss | 404 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
405 | // ADC einschalten |
||
1171 | hbuss | 406 | ANALOG_ON; |
1155 | hbuss | 407 | AdReady = 0; |
408 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
||
409 | |||
1216 | killagreg | 410 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
411 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
||
1153 | hbuss | 412 | else winkel_roll = Mess_IntegralRoll; |
413 | |||
1216 | killagreg | 414 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
415 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
||
1153 | hbuss | 416 | else winkel_nick = Mess_IntegralNick; |
417 | |||
1120 | hbuss | 418 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
1153 | hbuss | 419 | Mess_Integral_Gier += MesswertGier; |
420 | ErsatzKompass += MesswertGier; |
||
395 | hbuss | 421 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
1916 | holgerb | 422 | if(!Looping_Nick && !Looping_Roll && (Parameter_GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
395 | hbuss | 423 | { |
1153 | hbuss | 424 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
1120 | hbuss | 425 | tmpl3 *= Parameter_AchsKopplung2; //65 |
1111 | hbuss | 426 | tmpl3 /= 4096L; |
1153 | hbuss | 427 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
1216 | killagreg | 428 | tmpl4 *= Parameter_AchsKopplung2; //65 |
1111 | hbuss | 429 | tmpl4 /= 4096L; |
1153 | hbuss | 430 | KopplungsteilNickRoll = tmpl3; |
431 | KopplungsteilRollNick = tmpl4; |
||
1111 | hbuss | 432 | tmpl4 -= tmpl3; |
433 | ErsatzKompass += tmpl4; |
||
1166 | hbuss | 434 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
1111 | hbuss | 435 | |
1153 | hbuss | 436 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
1111 | hbuss | 437 | tmpl *= Parameter_AchsKopplung1; // 90 |
880 | hbuss | 438 | tmpl /= 4096L; |
1153 | hbuss | 439 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
395 | hbuss | 440 | tmpl2 *= Parameter_AchsKopplung1; |
1662 | killagreg | 441 | tmpl2 /= 4096L; |
1225 | hbuss | 442 | if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
1153 | hbuss | 443 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
395 | hbuss | 444 | } |
1166 | hbuss | 445 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
1658 | holgerb | 446 | TrimRoll = tmpl - tmpl2 / 100L; |
447 | TrimNick = -tmpl2 + tmpl / 100L; |
||
1111 | hbuss | 448 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
449 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
||
450 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
||
395 | hbuss | 451 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | hbuss | 452 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
453 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
||
1051 | killagreg | 454 | if(Mess_IntegralRoll > Umschlag180Roll) |
395 | hbuss | 455 | { |
882 | hbuss | 456 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
395 | hbuss | 457 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1051 | killagreg | 458 | } |
395 | hbuss | 459 | if(Mess_IntegralRoll <-Umschlag180Roll) |
460 | { |
||
882 | hbuss | 461 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
395 | hbuss | 462 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1051 | killagreg | 463 | } |
395 | hbuss | 464 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | hbuss | 465 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
466 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
||
1051 | killagreg | 467 | if(Mess_IntegralNick > Umschlag180Nick) |
882 | hbuss | 468 | { |
469 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
||
470 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
1051 | killagreg | 471 | } |
472 | if(Mess_IntegralNick <-Umschlag180Nick) |
||
395 | hbuss | 473 | { |
882 | hbuss | 474 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
395 | hbuss | 475 | Mess_IntegralNick2 = Mess_IntegralNick; |
1051 | killagreg | 476 | } |
1111 | hbuss | 477 | |
1 | ingob | 478 | Integral_Gier = Mess_Integral_Gier; |
479 | IntegralNick = Mess_IntegralNick; |
||
480 | IntegralRoll = Mess_IntegralRoll; |
||
1051 | killagreg | 481 | IntegralNick2 = Mess_IntegralNick2; |
1 | ingob | 482 | IntegralRoll2 = Mess_IntegralRoll2; |
483 | |||
1166 | hbuss | 484 | #define D_LIMIT 128 |
485 | |||
1171 | hbuss | 486 | MesswertNick = HiResNick / 8; |
487 | MesswertRoll = HiResRoll / 8; |
||
1166 | hbuss | 488 | |
1167 | hbuss | 489 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
490 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
||
491 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
||
492 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
||
493 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
||
494 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
||
495 | |||
1216 | killagreg | 496 | if(Parameter_Gyro_D) |
1111 | hbuss | 497 | { |
1166 | hbuss | 498 | d2Nick = HiResNick - oldNick; |
499 | oldNick = (oldNick + HiResNick)/2; |
||
1111 | hbuss | 500 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
501 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
||
1791 | holgerb | 502 | |
1166 | hbuss | 503 | d2Roll = HiResRoll - oldRoll; |
504 | oldRoll = (oldRoll + HiResRoll)/2; |
||
1111 | hbuss | 505 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
506 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
||
1791 | holgerb | 507 | |
508 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
||
1166 | hbuss | 509 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
510 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
||
511 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
||
1216 | killagreg | 512 | } |
1111 | hbuss | 513 | |
1166 | hbuss | 514 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
515 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
||
516 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
||
517 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
||
1153 | hbuss | 518 | |
1916 | holgerb | 519 | if(Parameter_GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
1153 | hbuss | 520 | { |
521 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
||
522 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
||
523 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
||
524 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
||
525 | } |
||
1 | ingob | 526 | } |
527 | |||
528 | //############################################################################ |
||
529 | // Senden der Motorwerte per I2C-Bus |
||
530 | void SendMotorData(void) |
||
531 | //############################################################################ |
||
1051 | killagreg | 532 | { |
1209 | hbuss | 533 | unsigned char i; |
921 | hbuss | 534 | if(!MotorenEin) |
1 | ingob | 535 | { |
1765 | killagreg | 536 | FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY); |
1216 | killagreg | 537 | for(i=0;i<MAX_MOTORS;i++) |
538 | { |
||
539 | if(!PC_MotortestActive) MotorTest[i] = 0; |
||
1638 | holgerb | 540 | Motor[i].SetPoint = MotorTest[i]; |
541 | Motor[i].SetPointLowerBits = 0; |
||
542 | /* |
||
1760 | holgerb | 543 | Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution |
544 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
||
1638 | holgerb | 545 | */ |
1216 | killagreg | 546 | } |
1212 | hbuss | 547 | if(PC_MotortestActive) PC_MotortestActive--; |
1216 | killagreg | 548 | } |
1765 | killagreg | 549 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
1744 | holgerb | 550 | |
1765 | killagreg | 551 | if(I2C_TransferActive) |
1744 | holgerb | 552 | { |
1760 | holgerb | 553 | I2C_TransferActive = 0; // enable for the next time |
1765 | killagreg | 554 | } |
555 | else |
||
1744 | holgerb | 556 | { |
557 | motor_write = 0; |
||
1760 | holgerb | 558 | I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode |
1765 | killagreg | 559 | } |
1 | ingob | 560 | } |
561 | |||
562 | |||
563 | |||
564 | //############################################################################ |
||
565 | // Trägt ggf. das Poti als Parameter ein |
||
1051 | killagreg | 566 | void ParameterZuordnung(void) |
1 | ingob | 567 | //############################################################################ |
568 | { |
||
1787 | holgerb | 569 | unsigned char tmp,i; |
570 | for(i=0;i<8;i++) |
||
571 | { |
||
572 | int tmp2; |
||
1933 | holgerb | 573 | tmp = EE_Parameter.Kanalbelegung[K_POTI1 + i]; |
574 | tmp2 = PPM_in[tmp] + 127; |
||
1787 | holgerb | 575 | if(tmp2 > 255) tmp2 = 255; else if(tmp2 < 0) tmp2 = 0; |
1933 | holgerb | 576 | |
577 | if(tmp == 25) Poti[i] = tmp2; // 25 = WaypointEvent channel -> no filter |
||
578 | else |
||
1787 | holgerb | 579 | if(tmp2 != Poti[i]) |
580 | { |
||
581 | Poti[i] += (tmp2 - Poti[i]) / 4; |
||
582 | if(Poti[i] > tmp2) Poti[i]--; |
||
583 | else Poti[i]++; |
||
584 | } |
||
585 | } |
||
921 | hbuss | 586 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
587 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
||
588 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
||
1933 | holgerb | 589 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,5,255); |
590 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,5,255); |
||
2012 | holgerb | 591 | |
2040 | holgerb | 592 | if(EE_Parameter.Servo3 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;} // Out1 (J16) |
593 | else if(EE_Parameter.Servo3 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo3 = 140; else Parameter_Servo3 = 70;} |
||
2012 | holgerb | 594 | else CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3); |
595 | |||
2040 | holgerb | 596 | if(EE_Parameter.Servo4 == 247) { if(PORTC & (1<<PORTC2)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;} |
597 | else if(EE_Parameter.Servo4 == 246) { if(PORTC & (1<<PORTC3)) Parameter_Servo4 = 140; else Parameter_Servo4 = 70;} // Out2 (J17) |
||
2012 | holgerb | 598 | else CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4); |
599 | |||
2043 | holgerb | 600 | CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5); |
1916 | holgerb | 601 | CHK_POTI(Parameter_HoehenSchalter,EE_Parameter.MaxHoehe); |
1377 | hbuss | 602 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung); |
603 | CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z); |
||
604 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung); |
||
605 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I); |
||
606 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D); |
||
607 | CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P); |
||
608 | CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I); |
||
609 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor); |
||
610 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1); |
||
611 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2); |
||
612 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3); |
||
613 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4); |
||
614 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5); |
||
615 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6); |
||
616 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7); |
||
617 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
||
618 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
||
619 | CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
||
620 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
||
1668 | holgerb | 621 | CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
622 | CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
||
1377 | hbuss | 623 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection); |
1936 | holgerb | 624 | CHK_POTI(Parameter_MaximumAltitude,EE_Parameter.MaxAltitude); |
2034 | holgerb | 625 | if((NC_To_FC_MaxAltitude && NC_To_FC_MaxAltitude < Parameter_MaximumAltitude) || Parameter_MaximumAltitude == 0) Parameter_MaximumAltitude = NC_To_FC_MaxAltitude; |
1916 | holgerb | 626 | Parameter_GlobalConfig = EE_Parameter.GlobalConfig; |
627 | Parameter_ExtraConfig = EE_Parameter.ExtraConfig; |
||
1377 | hbuss | 628 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
629 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability); |
||
630 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl); |
||
1676 | holgerb | 631 | Ki = 10300 / (Parameter_I_Faktor + 1); |
1 | ingob | 632 | MAX_GAS = EE_Parameter.Gas_Max; |
1662 | killagreg | 633 | MIN_GAS = EE_Parameter.Gas_Min; |
1668 | holgerb | 634 | |
1921 | holgerb | 635 | tmp = EE_Parameter.CareFreeModeControl; |
1690 | holgerb | 636 | if(tmp > 50) |
1668 | holgerb | 637 | { |
1682 | holgerb | 638 | CareFree = 1; |
1839 | holgerb | 639 | if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; |
1862 | holgerb | 640 | if(carefree_old != CareFree) |
641 | { |
||
642 | if(carefree_old < 3) |
||
643 | { |
||
2090 | holgerb | 644 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
645 | if(CareFree) { beeptime = 1500; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; } |
||
646 | else { beeptime = 200; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; } |
||
647 | #else |
||
2063 | holgerb | 648 | if(CareFree) beeptime = 1500; |
1862 | holgerb | 649 | else beeptime = 200; |
2090 | holgerb | 650 | #endif |
2063 | holgerb | 651 | NeueKompassRichtungMerken = 5; |
1862 | holgerb | 652 | carefree_old = CareFree; |
653 | } else carefree_old--; |
||
654 | } |
||
1937 | holgerb | 655 | if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= FC_ERROR0_CAREFREE; //else VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; |
1669 | killagreg | 656 | } |
1839 | holgerb | 657 | else |
658 | { |
||
659 | CareFree = 0; |
||
1862 | holgerb | 660 | carefree_old = 10; |
1839 | holgerb | 661 | } |
1668 | holgerb | 662 | |
1691 | holgerb | 663 | if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert |
1690 | holgerb | 664 | { |
665 | beeptime = 15000; |
||
666 | BeepMuster = 0xA400; |
||
667 | CareFree = 0; |
||
1765 | killagreg | 668 | } |
1861 | holgerb | 669 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
1 | ingob | 670 | } |
671 | |||
672 | //############################################################################ |
||
673 | // |
||
674 | void MotorRegler(void) |
||
675 | //############################################################################ |
||
676 | { |
||
1330 | killagreg | 677 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
1 | ingob | 678 | int GierMischanteil,GasMischanteil; |
679 | static long sollGier = 0,tmp_long,tmp_long2; |
||
395 | hbuss | 680 | static long IntegralFehlerNick = 0; |
681 | static long IntegralFehlerRoll = 0; |
||
1 | ingob | 682 | static unsigned int RcLostTimer; |
683 | static unsigned char delay_neutral = 0; |
||
684 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
2146 | holgerb | 685 | static signed char move_safety_switch = 0; |
395 | hbuss | 686 | static long ausgleichNick, ausgleichRoll; |
1153 | hbuss | 687 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
1209 | hbuss | 688 | unsigned char i; |
1051 | killagreg | 689 | Mittelwert(); |
690 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 691 | // Gaswert ermitteln |
1051 | killagreg | 692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2230 | holgerb | 693 | if(!(FC_StatusFlags & (FC_STATUS_EMERGENCY_LANDING | FC_STATUS2_RC_FAILSAVE_ACTIVE))) |
694 | { |
||
695 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
||
2028 | holgerb | 696 | { |
697 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
||
698 | { |
||
699 | HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
||
700 | } |
||
701 | else HooverGasEmergencyPercent = 45; // default if the Hoovergas was could not calculated yet |
||
702 | } else HooverGasEmergencyPercent = EE_Parameter.NotGas; |
||
2230 | holgerb | 703 | } |
704 | if(GasIsZeroCnt == 30000) // in that case we have RC-Lost, but the MK is probably landed |
||
705 | { |
||
706 | StickGas = 0; // Hold Gas down in that case |
||
707 | HooverGasEmergencyPercent = MIN_GAS; |
||
708 | } |
||
1051 | killagreg | 709 | GasMischanteil = StickGas; |
831 | hbuss | 710 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
1051 | killagreg | 711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | hbuss | 712 | // Empfang schlecht |
1051 | killagreg | 713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1916 | holgerb | 714 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
1 | ingob | 715 | { |
1051 | killagreg | 716 | if(RcLostTimer) RcLostTimer--; |
717 | else |
||
1 | ingob | 718 | { |
719 | MotorenEin = 0; |
||
1954 | holgerb | 720 | modell_fliegt = 0; |
721 | FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY); |
||
1051 | killagreg | 722 | } |
1 | ingob | 723 | ROT_ON; |
2008 | holgerb | 724 | if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100) // wahrscheinlich in der Luft --> langsam absenken |
1 | ingob | 725 | { |
2028 | holgerb | 726 | GasMischanteil = HooverGasEmergencyPercent; |
1765 | killagreg | 727 | FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING; |
744 | hbuss | 728 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
1051 | killagreg | 729 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
1 | ingob | 730 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
731 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
732 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
||
173 | holgerb | 733 | } |
1954 | holgerb | 734 | else |
735 | { |
||
736 | MotorenEin = 0; |
||
737 | } |
||
1 | ingob | 738 | } |
1051 | killagreg | 739 | else |
740 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 741 | // Emfang gut |
1051 | killagreg | 742 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 743 | if(SenderOkay > 140) |
744 | { |
||
1765 | killagreg | 745 | FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING; |
1 | ingob | 746 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
921 | hbuss | 747 | if(GasMischanteil > 40 && MotorenEin) |
1 | ingob | 748 | { |
749 | if(modell_fliegt < 0xffff) modell_fliegt++; |
||
750 | } |
||
871 | hbuss | 751 | if((modell_fliegt < 256)) |
1 | ingob | 752 | { |
753 | SummeNick = 0; |
||
754 | SummeRoll = 0; |
||
1682 | holgerb | 755 | sollGier = 0; |
756 | Mess_Integral_Gier = 0; |
||
1765 | killagreg | 757 | } else FC_StatusFlags |= FC_STATUS_FLY; |
1051 | killagreg | 758 | |
595 | hbuss | 759 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
1 | ingob | 760 | { |
1051 | killagreg | 761 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 762 | // auf Nullwerte kalibrieren |
1051 | killagreg | 763 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 764 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
765 | { |
||
766 | if(++delay_neutral > 200) // nicht sofort |
||
767 | { |
||
2090 | holgerb | 768 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
769 | SpeakHoTT = SPEAK_CALIBRATE; |
||
770 | #endif |
||
1 | ingob | 771 | delay_neutral = 0; |
772 | modell_fliegt = 0; |
||
773 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
||
774 | { |
||
304 | ingob | 775 | unsigned char setting=1; |
1 | ingob | 776 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
777 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
||
778 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
||
779 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
||
780 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
||
1622 | killagreg | 781 | SetActiveParamSet(setting); // aktiven Datensatz merken |
1 | ingob | 782 | } |
1051 | killagreg | 783 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
784 | { |
||
819 | hbuss | 785 | WinkelOut.CalcState = 1; |
2009 | holgerb | 786 | CalibrationDone = 0; |
819 | hbuss | 787 | beeptime = 1000; |
788 | } |
||
789 | else |
||
1 | ingob | 790 | { |
1622 | killagreg | 791 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
1413 | killagreg | 792 | LipoDetection(0); |
1626 | killagreg | 793 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
1916 | holgerb | 794 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
819 | hbuss | 795 | { |
1 | ingob | 796 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
1051 | killagreg | 797 | } |
2146 | holgerb | 798 | // ServoActive = 0; |
1622 | killagreg | 799 | SetNeutral(0); |
2009 | holgerb | 800 | CalibrationDone = 1; |
1232 | hbuss | 801 | ServoActive = 1; |
802 | DDRD |=0x80; // enable J7 -> Servo signal |
||
1622 | killagreg | 803 | Piep(GetActiveParamSet(),120); |
819 | hbuss | 804 | } |
1051 | killagreg | 805 | } |
1 | ingob | 806 | } |
1051 | killagreg | 807 | else |
513 | hbuss | 808 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
809 | { |
||
810 | if(++delay_neutral > 200) // nicht sofort |
||
811 | { |
||
812 | MotorenEin = 0; |
||
813 | delay_neutral = 0; |
||
814 | modell_fliegt = 0; |
||
1622 | killagreg | 815 | SetNeutral(1); |
2009 | holgerb | 816 | CalibrationDone = 1; |
1622 | killagreg | 817 | Piep(GetActiveParamSet(),120); |
1051 | killagreg | 818 | } |
513 | hbuss | 819 | } |
1 | ingob | 820 | else delay_neutral = 0; |
821 | } |
||
1051 | killagreg | 822 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 823 | // Gas ist unten |
1051 | killagreg | 824 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
595 | hbuss | 825 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
1 | ingob | 826 | { |
2146 | holgerb | 827 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100; |
828 | else |
||
829 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100; |
||
1521 | killagreg | 830 | // Motoren Starten |
831 | if(!MotorenEin) |
||
832 | { |
||
2146 | holgerb | 833 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
834 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100))) |
||
1521 | killagreg | 835 | { |
1051 | killagreg | 836 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 837 | // Einschalten |
1051 | killagreg | 838 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2146 | holgerb | 839 | if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START; |
840 | if(++delay_einschalten > 253) |
||
1521 | killagreg | 841 | { |
842 | delay_einschalten = 0; |
||
2009 | holgerb | 843 | if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode) |
1622 | killagreg | 844 | { |
845 | modell_fliegt = 1; |
||
846 | MotorenEin = 1; |
||
847 | sollGier = 0; |
||
848 | Mess_Integral_Gier = 0; |
||
849 | Mess_Integral_Gier2 = 0; |
||
850 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
||
851 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
||
852 | Mess_IntegralNick2 = IntegralNick; |
||
853 | Mess_IntegralRoll2 = IntegralRoll; |
||
854 | SummeNick = 0; |
||
855 | SummeRoll = 0; |
||
1913 | holgerb | 856 | // ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
1840 | holgerb | 857 | NeueKompassRichtungMerken = 100; // 2 sekunden |
2090 | holgerb | 858 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
859 | SpeakHoTT = SPEAK_STARTING; |
||
860 | #endif |
||
1622 | killagreg | 861 | } |
862 | else |
||
863 | { |
||
864 | beeptime = 1500; // indicate missing calibration |
||
2090 | holgerb | 865 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2146 | holgerb | 866 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
2090 | holgerb | 867 | #endif |
1622 | killagreg | 868 | } |
1521 | killagreg | 869 | } |
870 | } |
||
871 | else delay_einschalten = 0; |
||
872 | } |
||
1051 | killagreg | 873 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 874 | // Auschalten |
1051 | killagreg | 875 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1521 | killagreg | 876 | else // only if motors are running |
877 | { |
||
2146 | holgerb | 878 | // if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0)) |
879 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
||
880 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100))) |
||
1521 | killagreg | 881 | { |
2146 | holgerb | 882 | if(++delay_ausschalten > 250) // nicht sofort |
1521 | killagreg | 883 | { |
884 | MotorenEin = 0; |
||
885 | delay_ausschalten = 0; |
||
886 | modell_fliegt = 0; |
||
2090 | holgerb | 887 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
888 | SpeakHoTT = SPEAK_MK_OFF; |
||
889 | #endif |
||
1521 | killagreg | 890 | } |
891 | } |
||
892 | else delay_ausschalten = 0; |
||
893 | } |
||
2230 | holgerb | 894 | if(GasIsZeroCnt < 1000) GasIsZeroCnt++; |
895 | } |
||
2146 | holgerb | 896 | else // gas not at minimum |
2230 | holgerb | 897 | { |
898 | move_safety_switch = 0; |
||
899 | GasIsZeroCnt = 0; |
||
900 | } |
||
1 | ingob | 901 | } |
2230 | holgerb | 902 | else // Empfang zwischen 100 und 140 -> schlecht |
903 | { |
||
904 | if(GasIsZeroCnt >= 750) // gas-stick was down for 1.5 seconds before RC-Lost |
||
905 | { |
||
906 | if((GPSInfo.HomeDistance < 40 * 10) && (HoehenWert < 15 * 100)) // and we are at the starting point -> maybe landed? |
||
907 | { |
||
908 | GasIsZeroCnt = 30000; |
||
909 | if(modell_fliegt > 1001) modell_fliegt = 1001; |
||
910 | } |
||
911 | } |
||
912 | } |
||
1051 | killagreg | 913 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 914 | // neue Werte von der Funke |
1051 | killagreg | 915 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1216 | killagreg | 916 | |
1765 | killagreg | 917 | if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1 | ingob | 918 | { |
604 | hbuss | 919 | static int stick_nick,stick_roll; |
1912 | holgerb | 920 | unsigned char stick_p; |
1 | ingob | 921 | ParameterZuordnung(); |
1912 | holgerb | 922 | stick_p = EE_Parameter.Stick_P; |
923 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4; |
||
723 | hbuss | 924 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
1912 | holgerb | 925 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4; |
723 | hbuss | 926 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
927 | |||
1707 | holgerb | 928 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
929 | // CareFree und freie Wahl der vorderen Richtung |
||
930 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1865 | holgerb | 931 | if(CareFree) |
932 | { |
||
933 | signed int nick, roll; |
||
934 | nick = stick_nick / 4; |
||
935 | roll = stick_roll / 4; |
||
936 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
||
937 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
||
938 | } |
||
939 | else |
||
940 | { |
||
941 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
||
942 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
||
943 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
||
944 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
||
945 | } |
||
1662 | killagreg | 946 | |
1 | ingob | 947 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
1840 | holgerb | 948 | if(StickGier > 4) StickGier -= 4; else |
949 | if(StickGier < -4) StickGier += 4; else StickGier = 0; |
||
1120 | hbuss | 950 | |
1945 | holgerb | 951 | if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger |
952 | { |
||
953 | StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16; |
||
954 | StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16; |
||
955 | } |
||
1912 | holgerb | 956 | |
957 | StickNick -= GPS_Nick; |
||
958 | StickRoll -= GPS_Roll; |
||
1933 | holgerb | 959 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127; |
1330 | killagreg | 960 | |
1153 | hbuss | 961 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
962 | IntegralFaktor = Parameter_Gyro_I; |
||
1322 | hbuss | 963 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
964 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
||
1 | ingob | 965 | |
595 | hbuss | 966 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
967 | //+ Analoge Steuerung per Seriell |
||
968 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
921 | hbuss | 969 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
595 | hbuss | 970 | { |
971 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
||
972 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
||
973 | StickGier += ExternControl.Gier; |
||
974 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
||
975 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
||
976 | } |
||
855 | hbuss | 977 | if(StickGas < 0) StickGas = 0; |
1330 | killagreg | 978 | |
1916 | holgerb | 979 | if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
723 | hbuss | 980 | |
1051 | killagreg | 981 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
928 | hbuss | 982 | { |
1051 | killagreg | 983 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
928 | hbuss | 984 | if(MaxStickNick > 100) MaxStickNick = 100; |
1051 | killagreg | 985 | } |
928 | hbuss | 986 | else MaxStickNick--; |
1051 | killagreg | 987 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
928 | hbuss | 988 | { |
1051 | killagreg | 989 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
928 | hbuss | 990 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
1051 | killagreg | 991 | } |
928 | hbuss | 992 | else MaxStickRoll--; |
1765 | killagreg | 993 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) {MaxStickNick = 0; MaxStickRoll = 0;} |
723 | hbuss | 994 | |
1051 | killagreg | 995 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 996 | // Looping? |
1051 | killagreg | 997 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
993 | hbuss | 998 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
1051 | killagreg | 999 | else |
1000 | { |
||
395 | hbuss | 1001 | { |
1051 | killagreg | 1002 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
1003 | } |
||
1004 | } |
||
993 | hbuss | 1005 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
1051 | killagreg | 1006 | else |
395 | hbuss | 1007 | { |
1008 | if(Looping_Rechts) // Hysterese |
||
1009 | { |
||
1010 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
||
1011 | } |
||
1051 | killagreg | 1012 | } |
173 | holgerb | 1013 | |
993 | hbuss | 1014 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
1051 | killagreg | 1015 | else |
1016 | { |
||
395 | hbuss | 1017 | if(Looping_Oben) // Hysterese |
1018 | { |
||
1051 | killagreg | 1019 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
1020 | } |
||
1021 | } |
||
993 | hbuss | 1022 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
1051 | killagreg | 1023 | else |
395 | hbuss | 1024 | { |
1025 | if(Looping_Unten) // Hysterese |
||
1026 | { |
||
1027 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
||
1028 | } |
||
1051 | killagreg | 1029 | } |
395 | hbuss | 1030 | |
1031 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
||
1153 | hbuss | 1032 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
395 | hbuss | 1033 | } // Ende neue Funken-Werte |
1034 | |||
1035 | if(Looping_Roll || Looping_Nick) |
||
1036 | { |
||
173 | holgerb | 1037 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
1153 | hbuss | 1038 | TrichterFlug = 1; |
173 | holgerb | 1039 | } |
1040 | |||
1051 | killagreg | 1041 | |
1042 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1043 | // Bei Empfangsausfall im Flug |
||
1044 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
2230 | holgerb | 1045 | DebugOut.Analog[16] = GasIsZeroCnt; |
1046 | DebugOut.Analog[17] = VarioMeter; |
||
1047 | |||
1916 | holgerb | 1048 | if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE) |
1049 | { |
||
1050 | StickNick = -GPS_Nick; |
||
1051 | StickRoll = -GPS_Roll; |
||
2230 | holgerb | 1052 | StickGas = StickGasHover; |
1916 | holgerb | 1053 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1054 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
||
1055 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
||
1056 | Parameter_HoehenSchalter = 200; // switch on |
||
1057 | } |
||
1058 | else |
||
1765 | killagreg | 1059 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) |
1 | ingob | 1060 | { |
1061 | StickGier = 0; |
||
1062 | StickNick = 0; |
||
1063 | StickRoll = 0; |
||
1211 | hbuss | 1064 | GyroFaktor = 90; |
1065 | IntegralFaktor = 120; |
||
1066 | GyroFaktorGier = 90; |
||
1067 | IntegralFaktorGier = 120; |
||
173 | holgerb | 1068 | Looping_Roll = 0; |
1069 | Looping_Nick = 0; |
||
1051 | killagreg | 1070 | } |
395 | hbuss | 1071 | |
1051 | killagreg | 1072 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1073 | // Integrale auf ACC-Signal abgleichen |
1051 | killagreg | 1074 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1075 | #define ABGLEICH_ANZAHL 256L |
1076 | |||
1077 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
||
1078 | MittelIntegralRoll += IntegralRoll; |
||
1079 | MittelIntegralNick2 += IntegralNick2; |
||
1080 | MittelIntegralRoll2 += IntegralRoll2; |
||
1081 | |||
1082 | if(Looping_Nick || Looping_Roll) |
||
1083 | { |
||
1084 | IntegralAccNick = 0; |
||
1085 | IntegralAccRoll = 0; |
||
1086 | MittelIntegralNick = 0; |
||
1087 | MittelIntegralRoll = 0; |
||
1088 | MittelIntegralNick2 = 0; |
||
1089 | MittelIntegralRoll2 = 0; |
||
1090 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
1091 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
||
1092 | ZaehlMessungen = 0; |
||
498 | hbuss | 1093 | LageKorrekturNick = 0; |
1094 | LageKorrekturRoll = 0; |
||
395 | hbuss | 1095 | } |
1096 | |||
1051 | killagreg | 1097 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1224 | hbuss | 1098 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
469 | hbuss | 1099 | { |
1100 | long tmp_long, tmp_long2; |
||
1839 | holgerb | 1101 | if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/) |
992 | hbuss | 1102 | { |
1944 | holgerb | 1103 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN)); |
1104 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR)); |
||
1105 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
1106 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
1107 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
||
1108 | { |
||
1109 | tmp_long /= 2; |
||
1110 | tmp_long2 /= 2; |
||
1111 | } |
||
1112 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
||
1113 | { |
||
1114 | tmp_long /= 3; |
||
1115 | tmp_long2 /= 3; |
||
1116 | } |
||
1117 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1118 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1119 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1120 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
||
992 | hbuss | 1121 | } |
1051 | killagreg | 1122 | else |
992 | hbuss | 1123 | { |
1944 | holgerb | 1124 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1125 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
||
1126 | tmp_long /= 16; |
||
1127 | tmp_long2 /= 16; |
||
1128 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
||
1129 | { |
||
1130 | tmp_long /= 3; |
||
1131 | tmp_long2 /= 3; |
||
1132 | } |
||
1133 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
||
1134 | { |
||
1135 | tmp_long /= 3; |
||
1136 | tmp_long2 /= 3; |
||
1137 | } |
||
1138 | KompassFusion = 25; |
||
1155 | hbuss | 1139 | #define AUSGLEICH 32 |
1944 | holgerb | 1140 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
1141 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
||
1142 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
||
1143 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
||
992 | hbuss | 1144 | } |
1166 | hbuss | 1145 | |
1111 | hbuss | 1146 | Mess_IntegralNick -= tmp_long; |
1147 | Mess_IntegralRoll -= tmp_long2; |
||
469 | hbuss | 1148 | } |
1051 | killagreg | 1149 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1150 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
1151 | { |
||
1152 | static int cnt = 0; |
||
1153 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
||
1154 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
||
1173 | hbuss | 1155 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
173 | holgerb | 1156 | { |
395 | hbuss | 1157 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
1158 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
||
1159 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
||
1160 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
||
1161 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
||
1707 | holgerb | 1162 | #define MAX_I 0 |
395 | hbuss | 1163 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1164 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
||
1165 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
||
1051 | killagreg | 1166 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1167 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
||
395 | hbuss | 1168 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
614 | hbuss | 1169 | |
1170 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
||
498 | hbuss | 1171 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 1172 | |
992 | hbuss | 1173 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
614 | hbuss | 1174 | { |
1175 | LageKorrekturNick /= 2; |
||
720 | ingob | 1176 | LageKorrekturRoll /= 2; |
614 | hbuss | 1177 | } |
498 | hbuss | 1178 | |
1051 | killagreg | 1179 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1180 | // Gyro-Drift ermitteln |
1051 | killagreg | 1181 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1182 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1183 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
||
1051 | killagreg | 1184 | tmp_long = IntegralNick2 - IntegralNick; |
1185 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
||
395 | hbuss | 1186 | |
1187 | IntegralFehlerNick = tmp_long; |
||
1188 | IntegralFehlerRoll = tmp_long2; |
||
1189 | Mess_IntegralNick2 -= IntegralFehlerNick; |
||
1190 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
||
1191 | |||
1111 | hbuss | 1192 | if(EE_Parameter.Driftkomp) |
1193 | { |
||
1622 | killagreg | 1194 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
1195 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
||
1111 | hbuss | 1196 | } |
693 | hbuss | 1197 | GierGyroFehler = 0; |
720 | ingob | 1198 | |
1243 | killagreg | 1199 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
1200 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
||
1225 | hbuss | 1201 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
492 | hbuss | 1202 | #define BEWEGUNGS_LIMIT 20000 |
395 | hbuss | 1203 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1204 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
||
1225 | hbuss | 1205 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
1173 | hbuss | 1206 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
492 | hbuss | 1207 | { |
1051 | killagreg | 1208 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
395 | hbuss | 1209 | { |
1051 | killagreg | 1210 | if(last_n_p) |
395 | hbuss | 1211 | { |
1173 | hbuss | 1212 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1213 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1214 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
498 | hbuss | 1215 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1216 | } |
395 | hbuss | 1217 | else last_n_p = 1; |
1218 | } else last_n_p = 0; |
||
1051 | killagreg | 1219 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
395 | hbuss | 1220 | { |
1221 | if(last_n_n) |
||
1051 | killagreg | 1222 | { |
1173 | hbuss | 1223 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1224 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1225 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
498 | hbuss | 1226 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1227 | } |
395 | hbuss | 1228 | else last_n_n = 1; |
1229 | } else last_n_n = 0; |
||
1051 | killagreg | 1230 | } |
1231 | else |
||
847 | hbuss | 1232 | { |
1233 | cnt = 0; |
||
1839 | holgerb | 1234 | KompassSignalSchlecht = 100; |
1051 | killagreg | 1235 | } |
499 | hbuss | 1236 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1173 | hbuss | 1237 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
395 | hbuss | 1238 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1239 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
||
401 | hbuss | 1240 | |
395 | hbuss | 1241 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1695 | holgerb | 1242 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
1225 | hbuss | 1243 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
1173 | hbuss | 1244 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
492 | hbuss | 1245 | { |
1051 | killagreg | 1246 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
395 | hbuss | 1247 | { |
1051 | killagreg | 1248 | if(last_r_p) |
395 | hbuss | 1249 | { |
1173 | hbuss | 1250 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1251 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1252 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
498 | hbuss | 1253 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1051 | killagreg | 1254 | } |
395 | hbuss | 1255 | else last_r_p = 1; |
1256 | } else last_r_p = 0; |
||
1051 | killagreg | 1257 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
395 | hbuss | 1258 | { |
1051 | killagreg | 1259 | if(last_r_n) |
395 | hbuss | 1260 | { |
1173 | hbuss | 1261 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1262 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1263 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
498 | hbuss | 1264 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 1265 | } |
1266 | else last_r_n = 1; |
||
1267 | } else last_r_n = 0; |
||
1051 | killagreg | 1268 | } else |
492 | hbuss | 1269 | { |
1270 | cnt = 0; |
||
1839 | holgerb | 1271 | KompassSignalSchlecht = 100; |
1051 | killagreg | 1272 | } |
499 | hbuss | 1273 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1173 | hbuss | 1274 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
395 | hbuss | 1275 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1276 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
||
173 | holgerb | 1277 | } |
1051 | killagreg | 1278 | else |
498 | hbuss | 1279 | { |
1280 | LageKorrekturRoll = 0; |
||
1281 | LageKorrekturNick = 0; |
||
880 | hbuss | 1282 | TrichterFlug = 0; |
498 | hbuss | 1283 | } |
1051 | killagreg | 1284 | |
498 | hbuss | 1285 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1051 | killagreg | 1286 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1287 | MittelIntegralNick_Alt = MittelIntegralNick; |
||
1288 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
||
1289 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
395 | hbuss | 1290 | IntegralAccNick = 0; |
1291 | IntegralAccRoll = 0; |
||
1292 | IntegralAccZ = 0; |
||
1293 | MittelIntegralNick = 0; |
||
1294 | MittelIntegralRoll = 0; |
||
1295 | MittelIntegralNick2 = 0; |
||
1296 | MittelIntegralRoll2 = 0; |
||
1297 | ZaehlMessungen = 0; |
||
1173 | hbuss | 1298 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
395 | hbuss | 1299 | |
1051 | killagreg | 1300 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1301 | // Gieren |
1051 | killagreg | 1302 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1840 | holgerb | 1303 | if(abs(StickGier) > 3) // war 15 |
1 | ingob | 1304 | { |
1839 | holgerb | 1305 | // KompassSignalSchlecht = 1000; |
1916 | holgerb | 1306 | if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX)) |
1051 | killagreg | 1307 | { |
1840 | holgerb | 1308 | NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen |
824 | hbuss | 1309 | }; |
1 | ingob | 1310 | } |
1944 | holgerb | 1311 | tmp_int = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1312 | tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4; |
||
1840 | holgerb | 1313 | tmp_int += CompassGierSetpoint; |
173 | holgerb | 1314 | sollGier = tmp_int; |
1051 | killagreg | 1315 | Mess_Integral_Gier -= tmp_int; |
395 | hbuss | 1316 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1317 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
||
1051 | killagreg | 1318 | |
1319 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1320 | // Kompass |
1051 | killagreg | 1321 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1916 | holgerb | 1322 | if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV)) |
1 | ingob | 1323 | { |
1839 | holgerb | 1324 | if(CalculateCompassTimer-- == 1) |
1325 | { |
||
1326 | int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt |
||
1327 | CalculateCompassTimer = 13; // falls keine Navi-Daten |
||
1840 | holgerb | 1328 | // max. Korrekturwert schätzen |
1 | ingob | 1329 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1330 | v = abs(IntegralRoll /512); |
||
1331 | if(v > w) w = v; // grösste Neigung ermitteln |
||
1972 | holgerb | 1332 | // korrektur = w / 4 + 1; |
1333 | korrektur = w / 8 + 2; |
||
1941 | holgerb | 1334 | ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR; |
1840 | holgerb | 1335 | // Kompassfehlerwert bestimmen |
1941 | holgerb | 1336 | fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180; |
1840 | holgerb | 1337 | // GIER_GRAD_FAKTOR ist ca. 1200 |
1338 | // Kompasswert einloggen |
||
1339 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
||
1340 | else |
||
1341 | if(w < 25) |
||
921 | hbuss | 1342 | { |
1343 | GierGyroFehler += fehler; |
||
1051 | killagreg | 1344 | if(NeueKompassRichtungMerken) |
1345 | { |
||
1839 | holgerb | 1346 | if(--NeueKompassRichtungMerken == 0) |
1347 | { |
||
1941 | holgerb | 1348 | KompassSollWert = ErsatzKompassInGrad; |
1839 | holgerb | 1349 | } |
921 | hbuss | 1350 | } |
1 | ingob | 1351 | } |
1840 | holgerb | 1352 | // Kompass fusionieren |
1839 | holgerb | 1353 | if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur; |
1941 | holgerb | 1354 | // MK Gieren |
1355 | if(!NeueKompassRichtungMerken) |
||
1839 | holgerb | 1356 | { |
1941 | holgerb | 1357 | r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180; |
1839 | holgerb | 1358 | v = r * (Parameter_KompassWirkung/2); // nach Kompass ausrichten |
1840 | holgerb | 1359 | CompassGierSetpoint = v / 16; |
1360 | } |
||
1865 | holgerb | 1361 | else CompassGierSetpoint = 0; |
1839 | holgerb | 1362 | } // CalculateCompassTimer |
1051 | killagreg | 1363 | } |
1840 | holgerb | 1364 | else CompassGierSetpoint = 0; |
1972 | holgerb | 1365 | |
1366 | //DebugOut.Analog[16] = KompassFusion; |
||
1051 | killagreg | 1367 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1368 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1051 | killagreg | 1369 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1216 | killagreg | 1370 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
604 | hbuss | 1371 | |
1171 | hbuss | 1372 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1373 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
||
1153 | hbuss | 1374 | |
1167 | hbuss | 1375 | #define TRIM_MAX 200 |
1166 | hbuss | 1376 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1377 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
||
1153 | hbuss | 1378 | |
1166 | hbuss | 1379 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1380 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
||
1211 | hbuss | 1381 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1166 | hbuss | 1382 | |
1 | ingob | 1383 | // Maximalwerte abfangen |
1685 | holgerb | 1384 | #define MAX_SENSOR (4096) |
1216 | killagreg | 1385 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1 | ingob | 1386 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1387 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
||
1388 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
||
1389 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
||
1390 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
||
1391 | |||
1051 | killagreg | 1392 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1393 | // Höhenregelung |
1394 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
||
1051 | killagreg | 1395 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1374 | hbuss | 1396 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
855 | hbuss | 1397 | GasMischanteil *= STICK_GAIN; |
1309 | hbuss | 1398 | // if height control is activated |
1916 | holgerb | 1399 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1309 | hbuss | 1400 | { |
1698 | holgerb | 1401 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1332 | hbuss | 1402 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1638 | holgerb | 1403 | |
1404 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
1405 | #define OPA_OFFSET_STEP 15 |
||
1642 | killagreg | 1406 | #else |
1638 | holgerb | 1407 | #define OPA_OFFSET_STEP 10 |
1408 | #endif |
||
1697 | holgerb | 1409 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
1309 | hbuss | 1410 | static int HeightTrimming = 0; // rate for change of height setpoint |
1411 | static int FilterHCGas = 0; |
||
1587 | killagreg | 1412 | static unsigned long HoverGasFilter = 0; |
1322 | hbuss | 1413 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1320 | hbuss | 1414 | int CosAttitude; // for projection of hoover gas |
1330 | killagreg | 1415 | |
1309 | hbuss | 1416 | // get the current hooverpoint |
1587 | killagreg | 1417 | DebugOut.Analog[21] = HoverGas; |
1642 | killagreg | 1418 | |
1322 | hbuss | 1419 | // Expand the measurement |
1420 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
||
1421 | if(!BaroExpandActive) |
||
1422 | { |
||
1423 | if(MessLuftdruck > 920) |
||
1424 | { // increase offset |
||
1330 | killagreg | 1425 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
1322 | hbuss | 1426 | { |
1427 | ExpandBaro -= 1; |
||
1428 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
||
1429 | beeptime = 300; |
||
1352 | hbuss | 1430 | BaroExpandActive = 350; |
1330 | killagreg | 1431 | } |
1432 | else |
||
1322 | hbuss | 1433 | { |
1434 | BaroAtLowerLimit = 1; |
||
1435 | } |
||
1436 | } |
||
1437 | // measurement of air pressure close to lower limit and |
||
1330 | killagreg | 1438 | else |
1322 | hbuss | 1439 | if(MessLuftdruck < 100) |
1440 | { // decrease offset |
||
1330 | killagreg | 1441 | if(OCR0A > OPA_OFFSET_STEP) |
1322 | hbuss | 1442 | { |
1443 | ExpandBaro += 1; |
||
1444 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
||
1445 | beeptime = 300; |
||
1352 | hbuss | 1446 | BaroExpandActive = 350; |
1330 | killagreg | 1447 | } |
1448 | else |
||
1322 | hbuss | 1449 | { |
1450 | BaroAtUpperLimit = 1; |
||
1451 | } |
||
1452 | } |
||
1330 | killagreg | 1453 | else |
1322 | hbuss | 1454 | { |
1455 | BaroAtUpperLimit = 0; |
||
1456 | BaroAtLowerLimit = 0; |
||
1457 | } |
||
1458 | } |
||
1459 | else // delay, because of expanding the Baro-Range |
||
1460 | { |
||
1461 | // now clear the D-values |
||
1462 | SummenHoehe = HoehenWert * SM_FILTER; |
||
1463 | VarioMeter = 0; |
||
1464 | BaroExpandActive--; |
||
1465 | } |
||
1328 | hbuss | 1466 | |
1467 | // if height control is activated by an rc channel |
||
1916 | holgerb | 1468 | if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1328 | hbuss | 1469 | { // check if parameter is less than activation threshold |
1916 | holgerb | 1470 | if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position |
1328 | hbuss | 1471 | { //height control not active |
1472 | if(!delay--) |
||
1473 | { |
||
2090 | holgerb | 1474 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1475 | if(HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
||
1476 | #endif |
||
1328 | hbuss | 1477 | HoehenReglerAktiv = 0; // disable height control |
1478 | SollHoehe = HoehenWert; // update SetPoint with current reading |
||
1479 | delay = 1; |
||
1480 | } |
||
1481 | } |
||
1482 | else |
||
2090 | holgerb | 1483 | if(Parameter_HoehenSchalter > 70) |
1328 | hbuss | 1484 | { //height control is activated |
2090 | holgerb | 1485 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1486 | if(!HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_ON; |
||
1487 | #endif |
||
1328 | hbuss | 1488 | HoehenReglerAktiv = 1; // enable height control |
1334 | killagreg | 1489 | delay = 200; |
1328 | hbuss | 1490 | } |
1051 | killagreg | 1491 | } |
1309 | hbuss | 1492 | else // no switchable height control |
1493 | { |
||
1916 | holgerb | 1494 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1309 | hbuss | 1495 | HoehenReglerAktiv = 1; |
1051 | killagreg | 1496 | } |
1322 | hbuss | 1497 | |
1320 | hbuss | 1498 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1330 | killagreg | 1499 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1500 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
||
1501 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
||
1320 | hbuss | 1502 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1503 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
||
1591 | holgerb | 1504 | VarioCharacter = ' '; |
1942 | holgerb | 1505 | AltitudeSetpointTrimming = 0; |
1765 | killagreg | 1506 | if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1309 | hbuss | 1507 | { |
1330 | killagreg | 1508 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1309 | hbuss | 1509 | // Holger original version |
1510 | // start of height control algorithm |
||
1511 | // the height control is only an attenuation of the actual gas stick. |
||
1512 | // I.e. it will work only if the gas stick is higher than the hover gas |
||
1513 | // and the hover height will be allways larger than height setpoint. |
||
1861 | holgerb | 1514 | FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL; |
1916 | holgerb | 1515 | if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1314 | killagreg | 1516 | { // old version |
1309 | hbuss | 1517 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1518 | HeightTrimming = 0; |
||
1942 | holgerb | 1519 | AltitudeSetpointTrimming = 0; |
1773 | killagreg | 1520 | // set both flags to indicate no vario mode |
1521 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
||
1309 | hbuss | 1522 | } |
1314 | killagreg | 1523 | else |
1309 | hbuss | 1524 | { |
1525 | // alternative height control |
||
1526 | // PD-Control with respect to hoover point |
||
1527 | // the thrust loss out of horizontal attitude is compensated |
||
1528 | // the setpoint will be fine adjusted with the gas stick position |
||
1943 | holgerb | 1529 | if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying |
1309 | hbuss | 1530 | { // gas stick is above hoover point |
1587 | killagreg | 1531 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1309 | hbuss | 1532 | { |
1767 | killagreg | 1533 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) |
1309 | hbuss | 1534 | { |
1767 | killagreg | 1535 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1309 | hbuss | 1536 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1537 | } |
||
1767 | killagreg | 1538 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1966 | holgerb | 1539 | // Limit the maximum Altitude |
1540 | if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0; |
||
1541 | else |
||
1542 | { |
||
1543 | // SollHoehe = (long) Parameter_MaximumAltitude * 100L; |
||
1544 | // HeightTrimming += abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
||
1942 | holgerb | 1545 | AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1591 | holgerb | 1546 | VarioCharacter = '+'; |
1966 | holgerb | 1547 | } |
1865 | holgerb | 1548 | WaypointTrimming = 0; |
1309 | hbuss | 1549 | } // gas stick is below hoover point |
1587 | killagreg | 1550 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) |
1309 | hbuss | 1551 | { |
1767 | killagreg | 1552 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) |
1309 | hbuss | 1553 | { |
1767 | killagreg | 1554 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1309 | hbuss | 1555 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1556 | } |
||
1767 | killagreg | 1557 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1942 | holgerb | 1558 | AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1559 | // HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
||
1591 | holgerb | 1560 | VarioCharacter = '-'; |
1865 | holgerb | 1561 | WaypointTrimming = 0; |
1309 | hbuss | 1562 | } |
1587 | killagreg | 1563 | else // Gas Stick in Hover Range |
1309 | hbuss | 1564 | { |
1855 | holgerb | 1565 | VarioCharacter = '='; |
1857 | holgerb | 1566 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen |
1855 | holgerb | 1567 | { |
1568 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
||
1942 | holgerb | 1569 | AltitudeSetpointTrimming = FromNC_AltitudeSpeed; |
1570 | //HeightTrimming += FromNC_AltitudeSpeed; |
||
1857 | holgerb | 1571 | WaypointTrimming = 10; |
1572 | VarioCharacter = '^'; |
||
1865 | holgerb | 1573 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) // changed from sinking to rising |
1574 | { |
||
1575 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
||
1576 | SollHoehe = HoehenWert; // update setpoint to current heigth |
||
1577 | } |
||
1855 | holgerb | 1578 | } |
1579 | else |
||
1857 | holgerb | 1580 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
1855 | holgerb | 1581 | { |
1582 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
||
1942 | holgerb | 1583 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
1584 | //HeightTrimming -= FromNC_AltitudeSpeed; |
||
1857 | holgerb | 1585 | WaypointTrimming = -10; |
1586 | VarioCharacter = 'v'; |
||
1865 | holgerb | 1587 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
1588 | { |
||
1589 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
||
1590 | SollHoehe = HoehenWert; // update setpoint to current heigth |
||
1591 | } |
||
1855 | holgerb | 1592 | } |
1593 | else |
||
1767 | killagreg | 1594 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
1309 | hbuss | 1595 | { |
1933 | holgerb | 1596 | if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied |
1597 | else WaypointTrimming = 0; |
||
1767 | killagreg | 1598 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1309 | hbuss | 1599 | HeightTrimming = 0; |
1916 | holgerb | 1600 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1698 | holgerb | 1601 | if(!StartTrigger && HoehenWert > 50) |
1602 | { |
||
1603 | StartTrigger = 1; |
||
1765 | killagreg | 1604 | } |
1309 | hbuss | 1605 | } |
1606 | } |
||
1607 | // Trim height set point |
||
1942 | holgerb | 1608 | HeightTrimming += AltitudeSetpointTrimming; |
1609 | if(abs(HeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz |
||
1309 | hbuss | 1610 | { |
1857 | holgerb | 1611 | if(WaypointTrimming) |
1612 | { |
||
1613 | if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) SollHoehe = FromNC_AltitudeSetpoint; |
||
1614 | else SollHoehe += WaypointTrimming; |
||
1615 | } |
||
1616 | else |
||
1966 | holgerb | 1617 | { |
1618 | if(HeightTrimming > 0) SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3; |
||
1619 | else SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3; |
||
1620 | } |
||
1309 | hbuss | 1621 | HeightTrimming = 0; |
1932 | holgerb | 1622 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1916 | holgerb | 1623 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1320 | hbuss | 1624 | //update hoover gas stick value when setpoint is shifted |
1857 | holgerb | 1625 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1332 | hbuss | 1626 | { |
1587 | killagreg | 1627 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1628 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
||
1629 | if(StickGasHover < 70) StickGasHover = 70; |
||
1630 | else if(StickGasHover > 150) StickGasHover = 150; |
||
1332 | hbuss | 1631 | } |
1309 | hbuss | 1632 | } |
1352 | hbuss | 1633 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1420 | killagreg | 1634 | } //if FCFlags & MKFCFLAG_FLY |
1330 | killagreg | 1635 | else |
1636 | { |
||
1322 | hbuss | 1637 | SollHoehe = HoehenWert - 400; |
1587 | killagreg | 1638 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1639 | else StickGasHover = 120; |
||
1698 | holgerb | 1640 | HoverGas = GasMischanteil; |
1972 | holgerb | 1641 | VarioCharacter = '.'; |
1320 | hbuss | 1642 | } |
1590 | killagreg | 1643 | HCGas = HoverGas; // take hover gas (neutral point) |
1644 | } |
||
1916 | holgerb | 1645 | if(HoehenWert > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1283 | hbuss | 1646 | { |
1590 | killagreg | 1647 | // from this point the Heigth Control Algorithm is identical for both versions |
1648 | if(BaroExpandActive) // baro range expanding active |
||
1649 | { |
||
1650 | HCGas = HoverGas; // hover while expanding baro adc range |
||
1651 | HeightDeviation = 0; |
||
1652 | } // EOF // baro range expanding active |
||
1653 | else // valid data from air pressure sensor |
||
1654 | { |
||
1655 | // ------------------------- P-Part ---------------------------- |
||
1656 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
||
1657 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
||
1658 | HeightDeviation = (int)(tmp_long); // positive when too high |
||
1695 | holgerb | 1659 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1698 | holgerb | 1660 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1661 | GasReduction = tmp_long; |
||
1590 | killagreg | 1662 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1663 | tmp_int = VarioMeter / 8; |
||
1765 | killagreg | 1664 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1705 | holgerb | 1665 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1666 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
||
1767 | killagreg | 1667 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) tmp_int /= 4; // reduce d-part while trimming setpoint |
1765 | killagreg | 1668 | else |
1916 | holgerb | 1669 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1698 | holgerb | 1670 | GasReduction += tmp_int; |
1590 | killagreg | 1671 | } // EOF no baro range expanding |
1309 | hbuss | 1672 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1698 | holgerb | 1673 | if(Parameter_Hoehe_ACC_Wirkung) |
1674 | { |
||
1675 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
||
1676 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
||
1677 | GasReduction += tmp_long; |
||
1765 | killagreg | 1678 | } |
1587 | killagreg | 1679 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1588 | killagreg | 1680 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1681 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
||
1698 | holgerb | 1682 | GasReduction += tmp_int; |
1701 | holgerb | 1683 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1684 | // ------------------------ ---------------------------------- |
||
1685 | HCGas -= GasReduction; |
||
1309 | hbuss | 1686 | // limit deviation from hoover point within the target region |
1942 | holgerb | 1687 | if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1309 | hbuss | 1688 | { |
1765 | killagreg | 1689 | unsigned int tmp; |
1705 | holgerb | 1690 | tmp = abs(HeightDeviation); |
1691 | if(tmp <= 60) |
||
1692 | { |
||
1693 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
||
1694 | } |
||
1695 | else |
||
1765 | killagreg | 1696 | { |
1705 | holgerb | 1697 | tmp = (tmp - 60) / 32; |
1692 | holgerb | 1698 | if(tmp > 15) tmp = 15; |
1705 | holgerb | 1699 | if(HeightDeviation > 0) |
1693 | holgerb | 1700 | { |
1705 | holgerb | 1701 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1702 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
||
1693 | holgerb | 1703 | } |
1705 | holgerb | 1704 | else |
1705 | { |
||
1706 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
||
1707 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
||
1708 | } |
||
1709 | } |
||
1309 | hbuss | 1710 | } |
1322 | hbuss | 1711 | // strech control output by inverse attitude projection 1/cos |
1712 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
||
1330 | killagreg | 1713 | tmp_long2 = (int32_t)HCGas; |
1714 | tmp_long2 *= 8192L; |
||
1715 | tmp_long2 /= CosAttitude; |
||
1716 | HCGas = (int16_t)tmp_long2; |
||
1309 | hbuss | 1717 | // update height control gas averaging |
1718 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
||
1719 | // limit height control gas pd-control output |
||
1720 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
||
1721 | // set GasMischanteil to HeightControlGasFilter |
||
1916 | holgerb | 1722 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
1587 | killagreg | 1723 | { // old version |
1724 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
||
1719 | holgerb | 1725 | GasMischanteil = FilterHCGas; |
1765 | killagreg | 1726 | } |
1719 | holgerb | 1727 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
1314 | killagreg | 1728 | } |
1309 | hbuss | 1729 | }// EOF height control active |
1320 | hbuss | 1730 | else // HC not active |
1731 | { |
||
1732 | //update hoover gas stick value when HC is not active |
||
1587 | killagreg | 1733 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1734 | { |
||
1735 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
||
1736 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
||
1322 | hbuss | 1737 | } |
1587 | killagreg | 1738 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1739 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
||
1328 | hbuss | 1740 | FilterHCGas = GasMischanteil; |
1773 | killagreg | 1741 | // set both flags to indicate no vario mode |
1742 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
||
1861 | holgerb | 1743 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
1330 | killagreg | 1744 | } |
1587 | killagreg | 1745 | // Hover gas estimation by averaging gas control output on small z-velocities |
1309 | hbuss | 1746 | // this is done only if height contol option is selected in global config and aircraft is flying |
1765 | killagreg | 1747 | if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1309 | hbuss | 1748 | { |
1698 | holgerb | 1749 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1750 | if(StartTrigger == 1) StartTrigger = 2; |
||
1330 | killagreg | 1751 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1752 | tmp_long2 *= CosAttitude; // apply attitude projection |
||
1753 | tmp_long2 /= 8192; |
||
1309 | hbuss | 1754 | // average vertical projected thrust |
1698 | holgerb | 1755 | if(modell_fliegt < 4000) // the first 8 seconds |
1756 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
||
1757 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
||
1758 | HoverGasFilter += 16L * tmp_long2; |
||
1309 | hbuss | 1759 | } |
1698 | holgerb | 1760 | if(modell_fliegt < 8000) // the first 16 seconds |
1761 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
||
1590 | killagreg | 1762 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1587 | killagreg | 1763 | HoverGasFilter += 4L * tmp_long2; |
1309 | hbuss | 1764 | } |
1698 | holgerb | 1765 | else //later |
1865 | holgerb | 1766 | if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
1309 | hbuss | 1767 | { |
1590 | killagreg | 1768 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1587 | killagreg | 1769 | HoverGasFilter += tmp_long2; |
1309 | hbuss | 1770 | } |
1590 | killagreg | 1771 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1309 | hbuss | 1772 | if(EE_Parameter.Hoehe_HoverBand) |
1773 | { |
||
1774 | int16_t band; |
||
1587 | killagreg | 1775 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1776 | HoverGasMin = HoverGas - band; |
||
1777 | HoverGasMax = HoverGas + band; |
||
1309 | hbuss | 1778 | } |
1779 | else |
||
1780 | { // no limit |
||
1587 | killagreg | 1781 | HoverGasMin = 0; |
1782 | HoverGasMax = 1023; |
||
1309 | hbuss | 1783 | } |
1765 | killagreg | 1784 | } |
1785 | else |
||
1698 | holgerb | 1786 | { |
1787 | StartTrigger = 0; |
||
1788 | HoverGasFilter = 0; |
||
1789 | HoverGas = 0; |
||
1765 | killagreg | 1790 | } |
1916 | holgerb | 1791 | }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL |
1773 | killagreg | 1792 | else |
1793 | { |
||
1794 | // set undefined state to indicate vario off |
||
1795 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
||
1796 | } // EOF no height control |
||
1797 | |||
2028 | holgerb | 1798 | // Linits the maximum gas in case of "Out of Range emergency landing" |
2009 | holgerb | 1799 | if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING) |
1800 | { |
||
2028 | holgerb | 1801 | if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN; |
2034 | holgerb | 1802 | SollHoehe = HoehenWert; // update setpoint to current heigth |
2009 | holgerb | 1803 | beeptime = 15000; |
1804 | BeepMuster = 0x0E00; |
||
1805 | } |
||
2028 | holgerb | 1806 | // limit gas to parameter setting |
1320 | hbuss | 1807 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
855 | hbuss | 1808 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1111 | hbuss | 1809 | |
1051 | killagreg | 1810 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1320 | hbuss | 1811 | // all BL-Ctrl connected? |
1812 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1944 | holgerb | 1813 | if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode) // wait until all BL-Ctrls started and no Errors |
1931 | holgerb | 1814 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) // only during start-phase |
1320 | hbuss | 1815 | { |
1816 | modell_fliegt = 1; |
||
1675 | holgerb | 1817 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
1320 | hbuss | 1818 | } |
1819 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1820 | // + Mischer und PI-Regler |
1051 | killagreg | 1821 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 1822 | DebugOut.Analog[7] = GasMischanteil; |
1051 | killagreg | 1823 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1824 | // Gier-Anteil |
1051 | killagreg | 1825 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
855 | hbuss | 1826 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1827 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
||
693 | hbuss | 1828 | if(GasMischanteil > MIN_GIERGAS) |
1829 | { |
||
1051 | killagreg | 1830 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1831 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
||
693 | hbuss | 1832 | } |
1051 | killagreg | 1833 | else |
693 | hbuss | 1834 | { |
1051 | killagreg | 1835 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1836 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
||
693 | hbuss | 1837 | } |
855 | hbuss | 1838 | tmp_int = MAX_GAS*STICK_GAIN; |
1051 | killagreg | 1839 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
855 | hbuss | 1840 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
513 | hbuss | 1841 | |
1051 | killagreg | 1842 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1843 | // Nick-Achse |
1051 | killagreg | 1844 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
723 | hbuss | 1845 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1153 | hbuss | 1846 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1051 | killagreg | 1847 | else SummeNick += DiffNick; // I-Anteil bei HH |
855 | hbuss | 1848 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1849 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
||
1791 | holgerb | 1850 | |
1851 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick |
||
1852 | else pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern |
||
1853 | pd_ergebnis_nick += SummeNick / Ki; |
||
1854 | |||
1676 | holgerb | 1855 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1153 | hbuss | 1856 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1857 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
||
173 | holgerb | 1858 | |
1153 | hbuss | 1859 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1860 | // Roll-Achse |
||
1861 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1862 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
||
1863 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
||
1864 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
||
1865 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
||
1866 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
||
1791 | holgerb | 1867 | |
1868 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8; // PI-Regler für Roll |
||
1869 | else pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4; // Überlauf verhindern |
||
1870 | pd_ergebnis_roll += SummeRoll / Ki; |
||
1871 | |||
1676 | holgerb | 1872 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1153 | hbuss | 1873 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1874 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
||
1875 | |||
1876 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1209 | hbuss | 1877 | // Universal Mixer |
1155 | hbuss | 1878 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1642 | killagreg | 1879 | for(i=0; i<MAX_MOTORS; i++) |
1880 | { |
||
1881 | signed int tmp_int; |
||
1882 | if(Mixer.Motor[i][0] > 0) |
||
1883 | { |
||
1652 | holgerb | 1884 | // Gas |
1676 | holgerb | 1885 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1652 | holgerb | 1886 | // Nick |
1887 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
||
1888 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
||
1889 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
||
1890 | // Roll |
||
1891 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
||
1892 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
||
1893 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
||
1894 | // Gier |
||
1676 | holgerb | 1895 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
1896 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
||
1897 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
||
1675 | holgerb | 1898 | |
1913 | holgerb | 1899 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
1900 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
||
1901 | else |
||
1902 | { |
||
1903 | if(EE_Parameter.MotorSmooth == 0) |
||
1904 | { |
||
1931 | holgerb | 1905 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
1913 | holgerb | 1906 | } |
1907 | else // 1 means tmp_int = tmp_int; |
||
1908 | if(EE_Parameter.MotorSmooth > 1) |
||
1909 | { |
||
1910 | // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
||
1925 | holgerb | 1911 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/EE_Parameter.MotorSmooth); |
1913 | holgerb | 1912 | } |
1913 | } |
||
1931 | holgerb | 1914 | |
1760 | holgerb | 1915 | LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4); |
1676 | holgerb | 1916 | Motor[i].SetPoint = tmp_int / 4; |
1677 | killagreg | 1917 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
1652 | holgerb | 1918 | tmp_motorwert[i] = tmp_int; |
1642 | killagreg | 1919 | } |
1920 | else |
||
1921 | { |
||
1922 | Motor[i].SetPoint = 0; |
||
1923 | Motor[i].SetPointLowerBits = 0; |
||
1924 | } |
||
1925 | } |
||
1111 | hbuss | 1926 | } |
2090 | holgerb | 1927 | //DebugOut.Analog[16] |