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