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