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