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