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