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