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