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