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