Rev 1742 | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1338 | ingob | 5 | // + Copyright (c) Holger Buss, Ingo Busker |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
||
1 | ingob | 7 | // + www.MikroKopter.com |
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 9 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
11 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
12 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
1 | ingob | 13 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Verkauf von Luftbildaufnahmen, usw. |
||
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
1 | ingob | 17 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
20 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
21 | // + eindeutig als Ursprung verlinkt werden |
||
22 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
23 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
24 | // + Benutzung auf eigene Gefahr |
||
25 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1338 | ingob | 27 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
1 | ingob | 28 | // + mit unserer Zustimmung zulässig |
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1051 | killagreg | 32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
1 | ingob | 33 | // + this list of conditions and the following disclaimer. |
34 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
35 | // + from this software without specific prior written permission. |
||
1051 | killagreg | 36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
1 | ingob | 37 | // + for non-commercial use (directly or indirectly) |
1051 | killagreg | 38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
1 | ingob | 39 | // + with our written permission |
1051 | killagreg | 40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + clearly linked as origin |
||
1338 | ingob | 42 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
1 | ingob | 43 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
44 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
1322 | hbuss | 50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
1 | ingob | 52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
1051 | killagreg | 53 | // + POSSIBILITY OF SUCH DAMAGE. |
1 | ingob | 54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | |||
56 | #include "main.h" |
||
1320 | hbuss | 57 | #include "mymath.h" |
1330 | killagreg | 58 | #include "isqrt.h" |
1 | ingob | 59 | |
1749 | - | 60 | #ifdef NODISPLAY // main.h |
61 | |||
62 | |||
63 | |||
64 | #endif |
||
65 | unsigned char loop1, loop2, loop3, loop4; |
||
66 | int keynumber=-7; |
||
67 | |||
68 | |||
69 | unsigned char pos1, pos2, pos3, pos4=0; |
||
70 | unsigned char Motors0,Motors1,Motors2,Motors3,Motors4,Motors5,Motors6,Motors7; |
||
71 | unsigned char updatemotors=5; |
||
1352 | hbuss | 72 | unsigned char h,m,s; |
73 | unsigned int BaroExpandActive = 0; |
||
1153 | hbuss | 74 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
1166 | hbuss | 75 | int TrimNick, TrimRoll; |
927 | hbuss | 76 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
1703 | holgerb | 77 | int Mittelwert_AccNick, Mittelwert_AccRoll; |
1643 | holgerb | 78 | unsigned int NeutralAccX=0, NeutralAccY=0; |
805 | hbuss | 79 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
1639 | holgerb | 80 | int NeutralAccZ = 0; |
1683 | killagreg | 81 | unsigned char ControlHeading = 0;// in 2° |
693 | hbuss | 82 | long IntegralNick = 0,IntegralNick2 = 0; |
83 | long IntegralRoll = 0,IntegralRoll2 = 0; |
||
84 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
||
85 | long Integral_Gier = 0; |
||
86 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
||
87 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
||
88 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
||
89 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
||
1685 | holgerb | 90 | long SummeNick=0,SummeRoll=0; |
1 | ingob | 91 | volatile long Mess_Integral_Hoch = 0; |
1153 | hbuss | 92 | int KompassValue = 0; |
93 | int KompassStartwert = 0; |
||
94 | int KompassRichtung = 0; |
||
693 | hbuss | 95 | unsigned int KompassSignalSchlecht = 500; |
855 | hbuss | 96 | unsigned char MAX_GAS,MIN_GAS; |
1 | ingob | 97 | unsigned char HoehenReglerAktiv = 0; |
880 | hbuss | 98 | unsigned char TrichterFlug = 0; |
395 | hbuss | 99 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
693 | hbuss | 100 | long ErsatzKompass; |
101 | int ErsatzKompassInGrad; // Kompasswert in Grad |
||
102 | int GierGyroFehler = 0; |
||
1211 | hbuss | 103 | char GyroFaktor,GyroFaktorGier; |
104 | char IntegralFaktor,IntegralFaktorGier; |
||
1153 | hbuss | 105 | int DiffNick,DiffRoll; |
1377 | hbuss | 106 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
1391 | killagreg | 107 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
1 | ingob | 108 | volatile unsigned char SenderOkay = 0; |
595 | hbuss | 109 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
1698 | holgerb | 110 | char MotorenEin = 0,StartTrigger = 0; |
1246 | killagreg | 111 | long HoehenWert = 0; |
112 | long SollHoehe = 0; |
||
1692 | holgerb | 113 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
1153 | hbuss | 114 | //float Ki = FAKTOR_I; |
1676 | holgerb | 115 | int Ki = 10300 / 33; |
395 | hbuss | 116 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
117 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
||
1 | ingob | 118 | |
119 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
||
120 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
||
121 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
||
122 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
||
123 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
||
1283 | hbuss | 124 | unsigned char Parameter_Hoehe_GPS_Z = 64; // Wert : 0-250 |
1111 | hbuss | 125 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
173 | holgerb | 126 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
1 | ingob | 127 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
1322 | hbuss | 128 | unsigned char Parameter_Gyro_Gier_P = 150; // Wert : 10-250 |
129 | unsigned char Parameter_Gyro_Gier_I = 150; // Wert : 10-250 |
||
1 | ingob | 130 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
131 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
||
132 | unsigned char Parameter_UserParam1 = 0; |
||
133 | unsigned char Parameter_UserParam2 = 0; |
||
134 | unsigned char Parameter_UserParam3 = 0; |
||
135 | unsigned char Parameter_UserParam4 = 0; |
||
499 | hbuss | 136 | unsigned char Parameter_UserParam5 = 0; |
137 | unsigned char Parameter_UserParam6 = 0; |
||
138 | unsigned char Parameter_UserParam7 = 0; |
||
139 | unsigned char Parameter_UserParam8 = 0; |
||
1 | ingob | 140 | unsigned char Parameter_ServoNickControl = 100; |
1232 | hbuss | 141 | unsigned char Parameter_ServoRollControl = 100; |
173 | holgerb | 142 | unsigned char Parameter_LoopGasLimit = 70; |
1120 | hbuss | 143 | unsigned char Parameter_AchsKopplung1 = 90; |
144 | unsigned char Parameter_AchsKopplung2 = 65; |
||
145 | unsigned char Parameter_CouplingYawCorrection = 64; |
||
146 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
||
499 | hbuss | 147 | unsigned char Parameter_DynamicStability = 100; |
921 | hbuss | 148 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
149 | unsigned char Parameter_J16Timing; // for the J16 Output |
||
150 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
||
151 | unsigned char Parameter_J17Timing; // for the J17 Output |
||
152 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
||
1051 | killagreg | 153 | unsigned char Parameter_NaviGpsGain; |
154 | unsigned char Parameter_NaviGpsP; |
||
155 | unsigned char Parameter_NaviGpsI; |
||
156 | unsigned char Parameter_NaviGpsD; |
||
157 | unsigned char Parameter_NaviGpsACC; |
||
993 | hbuss | 158 | unsigned char Parameter_NaviOperatingRadius; |
159 | unsigned char Parameter_NaviWindCorrection; |
||
160 | unsigned char Parameter_NaviSpeedCompensation; |
||
921 | hbuss | 161 | unsigned char Parameter_ExternalControl; |
1403 | hbuss | 162 | unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
1668 | holgerb | 163 | unsigned char CareFree = 0; |
1622 | killagreg | 164 | |
492 | hbuss | 165 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
614 | hbuss | 166 | int MaxStickNick = 0,MaxStickRoll = 0; |
871 | hbuss | 167 | unsigned int modell_fliegt = 0; |
1420 | killagreg | 168 | volatile unsigned char FCFlags = 0; |
1121 | hbuss | 169 | long GIER_GRAD_FAKTOR = 1291; |
1153 | hbuss | 170 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
1209 | hbuss | 171 | signed int tmp_motorwert[MAX_MOTORS]; |
1591 | holgerb | 172 | char VarioCharacter = ' '; |
173 | |||
1391 | killagreg | 174 | #define LIMIT_MIN(value, min) {if(value <= min) value = min;} |
175 | #define LIMIT_MAX(value, max) {if(value >= max) value = max;} |
||
176 | #define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;} |
||
1155 | hbuss | 177 | |
1622 | killagreg | 178 | |
1639 | holgerb | 179 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
180 | // Debugwerte zuordnen |
||
181 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
182 | void CopyDebugValues(void) |
||
183 | { |
||
184 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
||
185 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
||
186 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
||
187 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
||
1660 | holgerb | 188 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
1639 | holgerb | 189 | DebugOut.Analog[5] = HoehenWert/5; |
1703 | holgerb | 190 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
1639 | holgerb | 191 | DebugOut.Analog[8] = KompassValue; |
192 | DebugOut.Analog[9] = UBat; |
||
193 | DebugOut.Analog[10] = SenderOkay; |
||
194 | DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR; |
||
1702 | holgerb | 195 | DebugOut.Analog[12] = Motor[0].SetPoint; |
196 | DebugOut.Analog[13] = Motor[1].SetPoint; |
||
197 | DebugOut.Analog[14] = Motor[2].SetPoint; |
||
198 | DebugOut.Analog[15] = Motor[3].SetPoint; |
||
1739 | - | 199 | |
200 | DebugOut.Analog[16] = Motor[4].SetPoint; |
||
201 | DebugOut.Analog[17] = Motor[5].SetPoint; |
||
202 | |||
203 | DebugOut.Analog[24] = Motor[6].SetPoint; |
||
204 | DebugOut.Analog[25] = Motor[7].SetPoint; |
||
205 | DebugOut.Analog[26] = Motor[8].SetPoint; |
||
206 | DebugOut.Analog[27] = Motor[9].SetPoint; |
||
207 | |||
1639 | holgerb | 208 | DebugOut.Analog[20] = ServoNickValue; |
209 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
||
210 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
||
211 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
||
1682 | holgerb | 212 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
213 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
||
1639 | holgerb | 214 | DebugOut.Analog[30] = GPS_Nick; |
215 | DebugOut.Analog[31] = GPS_Roll; |
||
1702 | holgerb | 216 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
1639 | holgerb | 217 | } |
218 | |||
1232 | hbuss | 219 | void Piep(unsigned char Anzahl, unsigned int dauer) |
1 | ingob | 220 | { |
1232 | hbuss | 221 | if(MotorenEin) return; //auf keinen Fall im Flug! |
1 | ingob | 222 | while(Anzahl--) |
223 | { |
||
1232 | hbuss | 224 | beeptime = dauer; |
225 | while(beeptime); |
||
226 | Delay_ms(dauer * 2); |
||
1 | ingob | 227 | } |
228 | } |
||
229 | |||
230 | //############################################################################ |
||
1622 | killagreg | 231 | // Messwerte beim Ermitteln der Nullage |
232 | void CalibrierMittelwert(void) |
||
233 | //############################################################################ |
||
234 | { |
||
235 | unsigned char i; |
||
236 | if(PlatinenVersion == 13) SucheGyroOffset(); |
||
237 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
||
238 | ANALOG_OFF; |
||
239 | MesswertNick = AdWertNick; |
||
240 | MesswertRoll = AdWertRoll; |
||
241 | MesswertGier = AdWertGier; |
||
1703 | holgerb | 242 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
243 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
||
1622 | killagreg | 244 | // ADC einschalten |
245 | ANALOG_ON; |
||
246 | for(i=0;i<8;i++) |
||
247 | { |
||
248 | int tmp; |
||
249 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
||
250 | LIMIT_MIN_MAX(tmp, 0, 255); |
||
251 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
||
252 | } |
||
253 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
254 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
255 | } |
||
256 | |||
257 | //############################################################################ |
||
1 | ingob | 258 | // Nullwerte ermitteln |
1622 | killagreg | 259 | void SetNeutral(unsigned char AccAdjustment) |
1 | ingob | 260 | //############################################################################ |
261 | { |
||
1622 | killagreg | 262 | unsigned char i; |
263 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
||
1702 | holgerb | 264 | VersionInfo.HardwareError[0] = 0; |
1320 | hbuss | 265 | HEF4017R_ON; |
1051 | killagreg | 266 | NeutralAccX = 0; |
1 | ingob | 267 | NeutralAccY = 0; |
268 | NeutralAccZ = 0; |
||
1622 | killagreg | 269 | |
1051 | killagreg | 270 | AdNeutralNick = 0; |
271 | AdNeutralRoll = 0; |
||
1 | ingob | 272 | AdNeutralGier = 0; |
1622 | killagreg | 273 | |
395 | hbuss | 274 | Parameter_AchsKopplung1 = 0; |
1120 | hbuss | 275 | Parameter_AchsKopplung2 = 0; |
1622 | killagreg | 276 | |
1036 | hbuss | 277 | ExpandBaro = 0; |
1622 | killagreg | 278 | |
1051 | killagreg | 279 | CalibrierMittelwert(); |
395 | hbuss | 280 | Delay_ms_Mess(100); |
1622 | killagreg | 281 | |
1 | ingob | 282 | CalibrierMittelwert(); |
1622 | killagreg | 283 | |
1 | ingob | 284 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
1051 | killagreg | 285 | { |
1 | ingob | 286 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
287 | } |
||
1166 | hbuss | 288 | #define NEUTRAL_FILTER 32 |
289 | for(i=0; i<NEUTRAL_FILTER; i++) |
||
1111 | hbuss | 290 | { |
291 | Delay_ms_Mess(10); |
||
1216 | killagreg | 292 | gier_neutral += AdWertGier; |
1166 | hbuss | 293 | nick_neutral += AdWertNick; |
294 | roll_neutral += AdWertRoll; |
||
1111 | hbuss | 295 | } |
1173 | hbuss | 296 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
297 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
||
298 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
||
1622 | killagreg | 299 | |
401 | hbuss | 300 | StartNeutralRoll = AdNeutralRoll; |
301 | StartNeutralNick = AdNeutralNick; |
||
1622 | killagreg | 302 | |
303 | if(AccAdjustment) |
||
304 | { |
||
305 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
||
306 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
||
307 | NeutralAccZ = Aktuell_az; |
||
308 | |||
309 | // Save ACC neutral settings to eeprom |
||
1639 | holgerb | 310 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
311 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
||
1622 | killagreg | 312 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
513 | hbuss | 313 | } |
1051 | killagreg | 314 | else |
513 | hbuss | 315 | { |
1622 | killagreg | 316 | // restore from eeprom |
317 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
||
318 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
||
319 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
||
320 | // strange settings? |
||
1638 | holgerb | 321 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
1622 | killagreg | 322 | { |
323 | printf("\n\rACC not calibrated!\r\n"); |
||
324 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
||
325 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
||
326 | NeutralAccZ = Aktuell_az; |
||
327 | } |
||
513 | hbuss | 328 | } |
1051 | killagreg | 329 | |
1 | ingob | 330 | MesswertNick = 0; |
331 | MesswertRoll = 0; |
||
332 | MesswertGier = 0; |
||
1111 | hbuss | 333 | Delay_ms_Mess(100); |
1703 | holgerb | 334 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
335 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
||
1173 | hbuss | 336 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
337 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
||
338 | Mess_IntegralNick2 = IntegralNick; |
||
339 | Mess_IntegralRoll2 = IntegralRoll; |
||
340 | Mess_Integral_Gier = 0; |
||
1 | ingob | 341 | StartLuftdruck = Luftdruck; |
1253 | killagreg | 342 | VarioMeter = 0; |
1 | ingob | 343 | Mess_Integral_Hoch = 0; |
344 | KompassStartwert = KompassValue; |
||
345 | GPS_Neutral(); |
||
1051 | killagreg | 346 | beeptime = 50; |
882 | hbuss | 347 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
348 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
||
492 | hbuss | 349 | ExternHoehenValue = 0; |
693 | hbuss | 350 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
351 | GierGyroFehler = 0; |
||
723 | hbuss | 352 | SendVersionToNavi = 1; |
921 | hbuss | 353 | LED_Init(); |
1420 | killagreg | 354 | FCFlags |= FCFLAG_CALIBRATE; |
992 | hbuss | 355 | FromNaviCtrl_Value.Kalman_K = -1; |
1173 | hbuss | 356 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
992 | hbuss | 357 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
1391 | killagreg | 358 | |
359 | for(i=0;i<8;i++) |
||
1377 | hbuss | 360 | { |
361 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
||
362 | } |
||
1171 | hbuss | 363 | SenderOkay = 100; |
1320 | hbuss | 364 | if(ServoActive) |
365 | { |
||
366 | HEF4017R_ON; |
||
367 | DDRD |=0x80; // enable J7 -> Servo signal |
||
368 | } |
||
1702 | holgerb | 369 | |
370 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= DEFEKT_G_NICK; }; |
||
371 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= DEFEKT_G_ROLL; }; |
||
372 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= DEFEKT_G_GIER; }; |
||
373 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= DEFEKT_A_NICK; }; |
||
374 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= DEFEKT_A_ROLL; }; |
||
375 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= DEFEKT_A_Z; }; |
||
1 | ingob | 376 | } |
377 | |||
1702 | holgerb | 378 | |
1 | ingob | 379 | //############################################################################ |
395 | hbuss | 380 | // Bearbeitet die Messwerte |
1 | ingob | 381 | void Mittelwert(void) |
382 | //############################################################################ |
||
1051 | killagreg | 383 | { |
1111 | hbuss | 384 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
385 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
||
1153 | hbuss | 386 | signed long winkel_nick, winkel_roll; |
1377 | hbuss | 387 | unsigned char i; |
1111 | hbuss | 388 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
1171 | hbuss | 389 | MesswertNick = (signed int) AdWertNickFilter / 8; |
390 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
||
1153 | hbuss | 391 | RohMesswertNick = MesswertNick; |
392 | RohMesswertRoll = MesswertRoll; |
||
1166 | hbuss | 393 | |
395 | hbuss | 394 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
1703 | holgerb | 395 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
396 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
||
395 | hbuss | 397 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
398 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
||
805 | hbuss | 399 | NaviAccNick += AdWertAccNick; |
400 | NaviAccRoll += AdWertAccRoll; |
||
401 | NaviCntAcc++; |
||
1153 | hbuss | 402 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
403 | |||
1155 | hbuss | 404 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
405 | // ADC einschalten |
||
1171 | hbuss | 406 | ANALOG_ON; |
1155 | hbuss | 407 | AdReady = 0; |
408 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
||
409 | |||
1216 | killagreg | 410 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
411 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
||
1153 | hbuss | 412 | else winkel_roll = Mess_IntegralRoll; |
413 | |||
1216 | killagreg | 414 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
415 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
||
1153 | hbuss | 416 | else winkel_nick = Mess_IntegralNick; |
417 | |||
1120 | hbuss | 418 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
1153 | hbuss | 419 | Mess_Integral_Gier += MesswertGier; |
420 | ErsatzKompass += MesswertGier; |
||
395 | hbuss | 421 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
422 | if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
||
423 | { |
||
1153 | hbuss | 424 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
1120 | hbuss | 425 | tmpl3 *= Parameter_AchsKopplung2; //65 |
1111 | hbuss | 426 | tmpl3 /= 4096L; |
1153 | hbuss | 427 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
1216 | killagreg | 428 | tmpl4 *= Parameter_AchsKopplung2; //65 |
1111 | hbuss | 429 | tmpl4 /= 4096L; |
1153 | hbuss | 430 | KopplungsteilNickRoll = tmpl3; |
431 | KopplungsteilRollNick = tmpl4; |
||
1111 | hbuss | 432 | tmpl4 -= tmpl3; |
433 | ErsatzKompass += tmpl4; |
||
1166 | hbuss | 434 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
1111 | hbuss | 435 | |
1153 | hbuss | 436 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
1111 | hbuss | 437 | tmpl *= Parameter_AchsKopplung1; // 90 |
880 | hbuss | 438 | tmpl /= 4096L; |
1153 | hbuss | 439 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
395 | hbuss | 440 | tmpl2 *= Parameter_AchsKopplung1; |
1662 | killagreg | 441 | tmpl2 /= 4096L; |
1225 | hbuss | 442 | if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
1153 | hbuss | 443 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
395 | hbuss | 444 | } |
1166 | hbuss | 445 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
1658 | holgerb | 446 | TrimRoll = tmpl - tmpl2 / 100L; |
447 | TrimNick = -tmpl2 + tmpl / 100L; |
||
1111 | hbuss | 448 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
449 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
||
450 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
||
395 | hbuss | 451 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | hbuss | 452 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
453 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
||
1051 | killagreg | 454 | if(Mess_IntegralRoll > Umschlag180Roll) |
395 | hbuss | 455 | { |
882 | hbuss | 456 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
395 | hbuss | 457 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1051 | killagreg | 458 | } |
395 | hbuss | 459 | if(Mess_IntegralRoll <-Umschlag180Roll) |
460 | { |
||
882 | hbuss | 461 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
395 | hbuss | 462 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1051 | killagreg | 463 | } |
395 | hbuss | 464 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | hbuss | 465 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
466 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
||
1051 | killagreg | 467 | if(Mess_IntegralNick > Umschlag180Nick) |
882 | hbuss | 468 | { |
469 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
||
470 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
1051 | killagreg | 471 | } |
472 | if(Mess_IntegralNick <-Umschlag180Nick) |
||
395 | hbuss | 473 | { |
882 | hbuss | 474 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
395 | hbuss | 475 | Mess_IntegralNick2 = Mess_IntegralNick; |
1051 | killagreg | 476 | } |
1111 | hbuss | 477 | |
1 | ingob | 478 | Integral_Gier = Mess_Integral_Gier; |
479 | IntegralNick = Mess_IntegralNick; |
||
480 | IntegralRoll = Mess_IntegralRoll; |
||
1051 | killagreg | 481 | IntegralNick2 = Mess_IntegralNick2; |
1 | ingob | 482 | IntegralRoll2 = Mess_IntegralRoll2; |
483 | |||
1166 | hbuss | 484 | #define D_LIMIT 128 |
485 | |||
1171 | hbuss | 486 | MesswertNick = HiResNick / 8; |
487 | MesswertRoll = HiResRoll / 8; |
||
1166 | hbuss | 488 | |
1167 | hbuss | 489 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
490 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
||
491 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
||
492 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
||
493 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
||
494 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
||
495 | |||
1216 | killagreg | 496 | if(Parameter_Gyro_D) |
1111 | hbuss | 497 | { |
1166 | hbuss | 498 | d2Nick = HiResNick - oldNick; |
499 | oldNick = (oldNick + HiResNick)/2; |
||
1111 | hbuss | 500 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
501 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
||
1166 | hbuss | 502 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
503 | d2Roll = HiResRoll - oldRoll; |
||
504 | oldRoll = (oldRoll + HiResRoll)/2; |
||
1111 | hbuss | 505 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
506 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
||
1166 | hbuss | 507 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
508 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
||
509 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
||
1216 | killagreg | 510 | } |
1111 | hbuss | 511 | |
1166 | hbuss | 512 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
513 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
||
514 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
||
515 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
||
1153 | hbuss | 516 | |
517 | if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
||
518 | { |
||
519 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
||
520 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
||
521 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
||
522 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
||
523 | } |
||
1377 | hbuss | 524 | for(i=0;i<8;i++) |
525 | { |
||
526 | int tmp; |
||
527 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
||
528 | if(tmp > 255) tmp = 255; else if(tmp < 0) tmp = 0; |
||
1406 | hbuss | 529 | if(tmp != Poti[i]) |
530 | { |
||
531 | Poti[i] += (tmp - Poti[i]) / 8; |
||
1413 | killagreg | 532 | if(Poti[i] > tmp) Poti[i]--; |
1406 | hbuss | 533 | else Poti[i]++; |
1413 | killagreg | 534 | } |
1377 | hbuss | 535 | } |
1 | ingob | 536 | } |
537 | |||
538 | //############################################################################ |
||
539 | // Senden der Motorwerte per I2C-Bus |
||
540 | void SendMotorData(void) |
||
541 | //############################################################################ |
||
1051 | killagreg | 542 | { |
1209 | hbuss | 543 | unsigned char i; |
921 | hbuss | 544 | if(!MotorenEin) |
1 | ingob | 545 | { |
1420 | killagreg | 546 | FCFlags &= ~(FCFLAG_MOTOR_RUN | FCFLAG_FLY); |
1216 | killagreg | 547 | for(i=0;i<MAX_MOTORS;i++) |
548 | { |
||
549 | if(!PC_MotortestActive) MotorTest[i] = 0; |
||
1638 | holgerb | 550 | Motor[i].SetPoint = MotorTest[i]; |
551 | Motor[i].SetPointLowerBits = 0; |
||
552 | /* |
||
553 | Motor[i].SetPoint = MotorTest[i] / 4; |
||
554 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
||
555 | */ |
||
1216 | killagreg | 556 | } |
1212 | hbuss | 557 | if(PC_MotortestActive) PC_MotortestActive--; |
1216 | killagreg | 558 | } |
1420 | killagreg | 559 | else FCFlags |= FCFLAG_MOTOR_RUN; |
1 | ingob | 560 | //Start I2C Interrupt Mode |
1662 | killagreg | 561 | motor_write = 0; |
562 | I2C_Start(TWI_STATE_MOTOR_TX); |
||
1 | ingob | 563 | } |
564 | |||
565 | |||
566 | |||
567 | //############################################################################ |
||
568 | // Trägt ggf. das Poti als Parameter ein |
||
1051 | killagreg | 569 | void ParameterZuordnung(void) |
1 | ingob | 570 | //############################################################################ |
571 | { |
||
1668 | holgerb | 572 | unsigned char tmp; |
1391 | killagreg | 573 | #define CHK_POTI(b,a) {if(a < 248) b = a; else b = Poti[255 - a];} |
574 | #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max);} |
||
575 | |||
921 | hbuss | 576 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
577 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
||
578 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
||
579 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255); |
||
580 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255); |
||
1403 | hbuss | 581 | CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3); |
582 | CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4); |
||
583 | CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5); |
||
1377 | hbuss | 584 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe); |
1403 | hbuss | 585 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe); |
1377 | hbuss | 586 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung); |
587 | CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z); |
||
588 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung); |
||
589 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I); |
||
590 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D); |
||
591 | CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P); |
||
592 | CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I); |
||
593 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor); |
||
594 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1); |
||
595 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2); |
||
596 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3); |
||
597 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4); |
||
598 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5); |
||
599 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6); |
||
600 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7); |
||
601 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
||
602 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
||
603 | CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
||
604 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
||
1668 | holgerb | 605 | CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
606 | CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
||
1377 | hbuss | 607 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection); |
608 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
||
609 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability); |
||
610 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl); |
||
1676 | holgerb | 611 | Ki = 10300 / (Parameter_I_Faktor + 1); |
1 | ingob | 612 | MAX_GAS = EE_Parameter.Gas_Max; |
1662 | killagreg | 613 | MIN_GAS = EE_Parameter.Gas_Min; |
1668 | holgerb | 614 | |
615 | tmp = EE_Parameter.OrientationModeControl; |
||
1690 | holgerb | 616 | if(tmp > 50) |
1668 | holgerb | 617 | { |
1682 | holgerb | 618 | #ifdef SWITCH_LEARNS_CAREFREE |
619 | if(!CareFree) ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
||
620 | #endif |
||
621 | CareFree = 1; |
||
1668 | holgerb | 622 | if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; |
1702 | holgerb | 623 | if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= DEFEKT_CAREFREE_ERR; else VersionInfo.HardwareError[0] &= ~DEFEKT_CAREFREE_ERR; |
1669 | killagreg | 624 | } |
1668 | holgerb | 625 | else CareFree = 0; |
626 | |||
1691 | holgerb | 627 | if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert |
1690 | holgerb | 628 | { |
629 | beeptime = 15000; |
||
630 | BeepMuster = 0xA400; |
||
631 | CareFree = 0; |
||
1702 | holgerb | 632 | } |
633 | |||
1668 | holgerb | 634 | if(CareFree) {if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} |
1 | ingob | 635 | } |
636 | |||
637 | //############################################################################ |
||
638 | // |
||
639 | void MotorRegler(void) |
||
640 | //############################################################################ |
||
641 | { |
||
1330 | killagreg | 642 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
1 | ingob | 643 | int GierMischanteil,GasMischanteil; |
644 | static long sollGier = 0,tmp_long,tmp_long2; |
||
395 | hbuss | 645 | static long IntegralFehlerNick = 0; |
646 | static long IntegralFehlerRoll = 0; |
||
1 | ingob | 647 | static unsigned int RcLostTimer; |
648 | static unsigned char delay_neutral = 0; |
||
649 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
1622 | killagreg | 650 | static unsigned char calibration_done = 0; |
1 | ingob | 651 | static char NeueKompassRichtungMerken = 0; |
395 | hbuss | 652 | static long ausgleichNick, ausgleichRoll; |
1153 | hbuss | 653 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
1209 | hbuss | 654 | unsigned char i; |
1051 | killagreg | 655 | Mittelwert(); |
1 | ingob | 656 | GRN_ON; |
1051 | killagreg | 657 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 658 | // Gaswert ermitteln |
1051 | killagreg | 659 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
660 | GasMischanteil = StickGas; |
||
831 | hbuss | 661 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
1330 | killagreg | 662 | |
1051 | killagreg | 663 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | hbuss | 664 | // Empfang schlecht |
1051 | killagreg | 665 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 666 | if(SenderOkay < 100) |
667 | { |
||
1051 | killagreg | 668 | if(RcLostTimer) RcLostTimer--; |
669 | else |
||
1 | ingob | 670 | { |
671 | MotorenEin = 0; |
||
1420 | killagreg | 672 | FCFlags &= ~FCFLAG_NOTLANDUNG; |
1051 | killagreg | 673 | } |
1 | ingob | 674 | ROT_ON; |
693 | hbuss | 675 | if(modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
1 | ingob | 676 | { |
677 | GasMischanteil = EE_Parameter.NotGas; |
||
1420 | killagreg | 678 | FCFlags |= FCFLAG_NOTLANDUNG; |
744 | hbuss | 679 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
1051 | killagreg | 680 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
1 | ingob | 681 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
682 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
683 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
||
173 | holgerb | 684 | } |
1 | ingob | 685 | else MotorenEin = 0; |
686 | } |
||
1051 | killagreg | 687 | else |
688 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 689 | // Emfang gut |
1051 | killagreg | 690 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 691 | if(SenderOkay > 140) |
692 | { |
||
1420 | killagreg | 693 | FCFlags &= ~FCFLAG_NOTLANDUNG; |
1 | ingob | 694 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
921 | hbuss | 695 | if(GasMischanteil > 40 && MotorenEin) |
1 | ingob | 696 | { |
697 | if(modell_fliegt < 0xffff) modell_fliegt++; |
||
698 | } |
||
871 | hbuss | 699 | if((modell_fliegt < 256)) |
1 | ingob | 700 | { |
701 | SummeNick = 0; |
||
702 | SummeRoll = 0; |
||
1682 | holgerb | 703 | sollGier = 0; |
704 | Mess_Integral_Gier = 0; |
||
1051 | killagreg | 705 | if(modell_fliegt == 250) |
918 | hbuss | 706 | { |
1051 | killagreg | 707 | NeueKompassRichtungMerken = 1; |
708 | } |
||
1420 | killagreg | 709 | } else FCFlags |= FCFLAG_FLY; |
1051 | killagreg | 710 | |
595 | hbuss | 711 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
1 | ingob | 712 | { |
1051 | killagreg | 713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 714 | // auf Nullwerte kalibrieren |
1051 | killagreg | 715 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 716 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
717 | { |
||
718 | if(++delay_neutral > 200) // nicht sofort |
||
719 | { |
||
720 | GRN_OFF; |
||
721 | MotorenEin = 0; |
||
722 | delay_neutral = 0; |
||
723 | modell_fliegt = 0; |
||
724 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
||
725 | { |
||
304 | ingob | 726 | unsigned char setting=1; |
1 | ingob | 727 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
728 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
||
729 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
||
730 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
||
731 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
||
1622 | killagreg | 732 | SetActiveParamSet(setting); // aktiven Datensatz merken |
1 | ingob | 733 | } |
1051 | killagreg | 734 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
735 | { |
||
819 | hbuss | 736 | WinkelOut.CalcState = 1; |
737 | beeptime = 1000; |
||
738 | } |
||
739 | else |
||
1 | ingob | 740 | { |
1622 | killagreg | 741 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
1413 | killagreg | 742 | LipoDetection(0); |
1626 | killagreg | 743 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
819 | hbuss | 744 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
745 | { |
||
1 | ingob | 746 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
1051 | killagreg | 747 | } |
1330 | killagreg | 748 | ServoActive = 0; |
1622 | killagreg | 749 | SetNeutral(0); |
1702 | holgerb | 750 | calibration_done = 1; |
1232 | hbuss | 751 | ServoActive = 1; |
752 | DDRD |=0x80; // enable J7 -> Servo signal |
||
1622 | killagreg | 753 | Piep(GetActiveParamSet(),120); |
819 | hbuss | 754 | } |
1051 | killagreg | 755 | } |
1 | ingob | 756 | } |
1051 | killagreg | 757 | else |
513 | hbuss | 758 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
759 | { |
||
760 | if(++delay_neutral > 200) // nicht sofort |
||
761 | { |
||
762 | GRN_OFF; |
||
763 | MotorenEin = 0; |
||
764 | delay_neutral = 0; |
||
765 | modell_fliegt = 0; |
||
1622 | killagreg | 766 | SetNeutral(1); |
767 | calibration_done = 1; |
||
768 | Piep(GetActiveParamSet(),120); |
||
1051 | killagreg | 769 | } |
513 | hbuss | 770 | } |
1 | ingob | 771 | else delay_neutral = 0; |
772 | } |
||
1051 | killagreg | 773 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 774 | // Gas ist unten |
1051 | killagreg | 775 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
595 | hbuss | 776 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
1 | ingob | 777 | { |
1521 | killagreg | 778 | // Motoren Starten |
779 | if(!MotorenEin) |
||
780 | { |
||
781 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
||
782 | { |
||
1051 | killagreg | 783 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 784 | // Einschalten |
1051 | killagreg | 785 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1521 | killagreg | 786 | if(++delay_einschalten > 200) |
787 | { |
||
788 | delay_einschalten = 0; |
||
1702 | holgerb | 789 | if(!VersionInfo.HardwareError[0] && calibration_done) |
1622 | killagreg | 790 | { |
791 | modell_fliegt = 1; |
||
792 | MotorenEin = 1; |
||
793 | sollGier = 0; |
||
794 | Mess_Integral_Gier = 0; |
||
795 | Mess_Integral_Gier2 = 0; |
||
796 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
||
797 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
||
798 | Mess_IntegralNick2 = IntegralNick; |
||
799 | Mess_IntegralRoll2 = IntegralRoll; |
||
800 | SummeNick = 0; |
||
801 | SummeRoll = 0; |
||
802 | FCFlags |= FCFLAG_START; |
||
1669 | killagreg | 803 | ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
1622 | killagreg | 804 | } |
805 | else |
||
806 | { |
||
807 | beeptime = 1500; // indicate missing calibration |
||
808 | } |
||
1521 | killagreg | 809 | } |
810 | } |
||
811 | else delay_einschalten = 0; |
||
812 | } |
||
1051 | killagreg | 813 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 814 | // Auschalten |
1051 | killagreg | 815 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1521 | killagreg | 816 | else // only if motors are running |
817 | { |
||
818 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
||
819 | { |
||
820 | if(++delay_ausschalten > 200) // nicht sofort |
||
821 | { |
||
822 | MotorenEin = 0; |
||
823 | delay_ausschalten = 0; |
||
824 | modell_fliegt = 0; |
||
825 | } |
||
826 | } |
||
827 | else delay_ausschalten = 0; |
||
828 | } |
||
1 | ingob | 829 | } |
830 | } |
||
1051 | killagreg | 831 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 832 | // neue Werte von der Funke |
1051 | killagreg | 833 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1216 | killagreg | 834 | |
1420 | killagreg | 835 | if(!NewPpmData-- || (FCFlags & FCFLAG_NOTLANDUNG)) |
1 | ingob | 836 | { |
604 | hbuss | 837 | static int stick_nick,stick_roll; |
1 | ingob | 838 | ParameterZuordnung(); |
1051 | killagreg | 839 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
723 | hbuss | 840 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
841 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
||
842 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
||
843 | |||
1707 | holgerb | 844 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
845 | // CareFree und freie Wahl der vorderen Richtung |
||
846 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1668 | holgerb | 847 | 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}; |
848 | |||
849 | if(CareFree) |
||
1658 | holgerb | 850 | { |
1664 | holgerb | 851 | signed int nick, roll; |
852 | nick = stick_nick / 4; |
||
853 | roll = stick_roll / 4; |
||
854 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
||
855 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
||
1658 | holgerb | 856 | } |
1662 | killagreg | 857 | else |
1658 | holgerb | 858 | { |
1668 | holgerb | 859 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
860 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
||
861 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
||
862 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
||
1658 | holgerb | 863 | } |
1662 | killagreg | 864 | |
1669 | killagreg | 865 | |
1 | ingob | 866 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
1120 | hbuss | 867 | if(StickGier > 2) StickGier -= 2; else |
868 | if(StickGier < -2) StickGier += 2; else StickGier = 0; |
||
869 | |||
1658 | holgerb | 870 | StickNick -= (GPS_Nick + GPS_Nick2); |
871 | StickRoll -= (GPS_Roll + GPS_Roll2); |
||
1350 | hbuss | 872 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
1330 | killagreg | 873 | |
1153 | hbuss | 874 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
875 | IntegralFaktor = Parameter_Gyro_I; |
||
1322 | hbuss | 876 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
877 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
||
1 | ingob | 878 | |
595 | hbuss | 879 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
880 | //+ Analoge Steuerung per Seriell |
||
881 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
921 | hbuss | 882 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
595 | hbuss | 883 | { |
884 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
||
885 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
||
886 | StickGier += ExternControl.Gier; |
||
887 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
||
888 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
||
889 | } |
||
855 | hbuss | 890 | if(StickGas < 0) StickGas = 0; |
1330 | killagreg | 891 | |
1 | ingob | 892 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
723 | hbuss | 893 | |
1051 | killagreg | 894 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
928 | hbuss | 895 | { |
1051 | killagreg | 896 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
928 | hbuss | 897 | if(MaxStickNick > 100) MaxStickNick = 100; |
1051 | killagreg | 898 | } |
928 | hbuss | 899 | else MaxStickNick--; |
1051 | killagreg | 900 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
928 | hbuss | 901 | { |
1051 | killagreg | 902 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
928 | hbuss | 903 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
1051 | killagreg | 904 | } |
928 | hbuss | 905 | else MaxStickRoll--; |
1420 | killagreg | 906 | if(FCFlags & FCFLAG_NOTLANDUNG) {MaxStickNick = 0; MaxStickRoll = 0;} |
723 | hbuss | 907 | |
1051 | killagreg | 908 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 909 | // Looping? |
1051 | killagreg | 910 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
993 | hbuss | 911 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
1051 | killagreg | 912 | else |
913 | { |
||
395 | hbuss | 914 | { |
1051 | killagreg | 915 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
916 | } |
||
917 | } |
||
993 | hbuss | 918 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
1051 | killagreg | 919 | else |
395 | hbuss | 920 | { |
921 | if(Looping_Rechts) // Hysterese |
||
922 | { |
||
923 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
||
924 | } |
||
1051 | killagreg | 925 | } |
173 | holgerb | 926 | |
993 | hbuss | 927 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
1051 | killagreg | 928 | else |
929 | { |
||
395 | hbuss | 930 | if(Looping_Oben) // Hysterese |
931 | { |
||
1051 | killagreg | 932 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
933 | } |
||
934 | } |
||
993 | hbuss | 935 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
1051 | killagreg | 936 | else |
395 | hbuss | 937 | { |
938 | if(Looping_Unten) // Hysterese |
||
939 | { |
||
940 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
||
941 | } |
||
1051 | killagreg | 942 | } |
395 | hbuss | 943 | |
944 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
||
1153 | hbuss | 945 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
395 | hbuss | 946 | } // Ende neue Funken-Werte |
947 | |||
948 | if(Looping_Roll || Looping_Nick) |
||
949 | { |
||
173 | holgerb | 950 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
1153 | hbuss | 951 | TrichterFlug = 1; |
173 | holgerb | 952 | } |
953 | |||
1051 | killagreg | 954 | |
955 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
956 | // Bei Empfangsausfall im Flug |
||
957 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1420 | killagreg | 958 | if(FCFlags & FCFLAG_NOTLANDUNG) |
1 | ingob | 959 | { |
960 | StickGier = 0; |
||
961 | StickNick = 0; |
||
962 | StickRoll = 0; |
||
1211 | hbuss | 963 | GyroFaktor = 90; |
964 | IntegralFaktor = 120; |
||
965 | GyroFaktorGier = 90; |
||
966 | IntegralFaktorGier = 120; |
||
173 | holgerb | 967 | Looping_Roll = 0; |
968 | Looping_Nick = 0; |
||
1051 | killagreg | 969 | } |
395 | hbuss | 970 | |
971 | |||
1051 | killagreg | 972 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 973 | // Integrale auf ACC-Signal abgleichen |
1051 | killagreg | 974 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 975 | #define ABGLEICH_ANZAHL 256L |
976 | |||
977 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
||
978 | MittelIntegralRoll += IntegralRoll; |
||
979 | MittelIntegralNick2 += IntegralNick2; |
||
980 | MittelIntegralRoll2 += IntegralRoll2; |
||
981 | |||
982 | if(Looping_Nick || Looping_Roll) |
||
983 | { |
||
984 | IntegralAccNick = 0; |
||
985 | IntegralAccRoll = 0; |
||
986 | MittelIntegralNick = 0; |
||
987 | MittelIntegralRoll = 0; |
||
988 | MittelIntegralNick2 = 0; |
||
989 | MittelIntegralRoll2 = 0; |
||
990 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
991 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
||
992 | ZaehlMessungen = 0; |
||
498 | hbuss | 993 | LageKorrekturNick = 0; |
994 | LageKorrekturRoll = 0; |
||
395 | hbuss | 995 | } |
996 | |||
1051 | killagreg | 997 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1224 | hbuss | 998 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
469 | hbuss | 999 | { |
1000 | long tmp_long, tmp_long2; |
||
1171 | hbuss | 1001 | if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/) |
992 | hbuss | 1002 | { |
1003 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
||
1051 | killagreg | 1004 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1005 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
1006 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
||
992 | hbuss | 1007 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1008 | { |
||
1009 | tmp_long /= 2; |
||
1010 | tmp_long2 /= 2; |
||
1011 | } |
||
1012 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
||
1013 | { |
||
1014 | tmp_long /= 3; |
||
1015 | tmp_long2 /= 3; |
||
1016 | } |
||
1017 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1018 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1019 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1020 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
||
1021 | } |
||
1051 | killagreg | 1022 | else |
992 | hbuss | 1023 | { |
1024 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
||
1051 | killagreg | 1025 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
992 | hbuss | 1026 | tmp_long /= 16; |
1027 | tmp_long2 /= 16; |
||
1028 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
||
1029 | { |
||
1030 | tmp_long /= 3; |
||
1031 | tmp_long2 /= 3; |
||
1216 | killagreg | 1032 | } |
1033 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
||
992 | hbuss | 1034 | { |
1035 | tmp_long /= 3; |
||
1036 | tmp_long2 /= 3; |
||
1037 | } |
||
1155 | hbuss | 1038 | |
1039 | #define AUSGLEICH 32 |
||
992 | hbuss | 1040 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
1041 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
||
1042 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
||
1043 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
||
1044 | } |
||
1166 | hbuss | 1045 | |
1111 | hbuss | 1046 | Mess_IntegralNick -= tmp_long; |
1047 | Mess_IntegralRoll -= tmp_long2; |
||
469 | hbuss | 1048 | } |
1051 | killagreg | 1049 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1050 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
1051 | { |
||
1052 | static int cnt = 0; |
||
1053 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
||
1054 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
||
1173 | hbuss | 1055 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
173 | holgerb | 1056 | { |
395 | hbuss | 1057 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
1058 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
||
1059 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
||
1060 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
||
1061 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
||
1707 | holgerb | 1062 | #define MAX_I 0 |
395 | hbuss | 1063 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1064 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
||
1065 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
||
1051 | killagreg | 1066 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1067 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
||
395 | hbuss | 1068 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
614 | hbuss | 1069 | |
1070 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
||
498 | hbuss | 1071 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 1072 | |
992 | hbuss | 1073 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
614 | hbuss | 1074 | { |
1075 | LageKorrekturNick /= 2; |
||
720 | ingob | 1076 | LageKorrekturRoll /= 2; |
614 | hbuss | 1077 | } |
498 | hbuss | 1078 | |
1051 | killagreg | 1079 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1080 | // Gyro-Drift ermitteln |
1051 | killagreg | 1081 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 1082 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1083 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
||
1051 | killagreg | 1084 | tmp_long = IntegralNick2 - IntegralNick; |
1085 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
||
395 | hbuss | 1086 | |
1087 | IntegralFehlerNick = tmp_long; |
||
1088 | IntegralFehlerRoll = tmp_long2; |
||
1089 | Mess_IntegralNick2 -= IntegralFehlerNick; |
||
1090 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
||
1091 | |||
1111 | hbuss | 1092 | if(EE_Parameter.Driftkomp) |
1093 | { |
||
1622 | killagreg | 1094 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
1095 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
||
1111 | hbuss | 1096 | } |
693 | hbuss | 1097 | GierGyroFehler = 0; |
720 | ingob | 1098 | |
1243 | killagreg | 1099 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
1100 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
||
1225 | hbuss | 1101 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
492 | hbuss | 1102 | #define BEWEGUNGS_LIMIT 20000 |
395 | hbuss | 1103 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1104 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
||
1225 | hbuss | 1105 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
1173 | hbuss | 1106 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
492 | hbuss | 1107 | { |
1051 | killagreg | 1108 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
395 | hbuss | 1109 | { |
1051 | killagreg | 1110 | if(last_n_p) |
395 | hbuss | 1111 | { |
1173 | hbuss | 1112 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1113 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1114 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
498 | hbuss | 1115 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1116 | } |
395 | hbuss | 1117 | else last_n_p = 1; |
1118 | } else last_n_p = 0; |
||
1051 | killagreg | 1119 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
395 | hbuss | 1120 | { |
1121 | if(last_n_n) |
||
1051 | killagreg | 1122 | { |
1173 | hbuss | 1123 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1124 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 1125 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
498 | hbuss | 1126 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1051 | killagreg | 1127 | } |
395 | hbuss | 1128 | else last_n_n = 1; |
1129 | } else last_n_n = 0; |
||
1051 | killagreg | 1130 | } |
1131 | else |
||
847 | hbuss | 1132 | { |
1133 | cnt = 0; |
||
921 | hbuss | 1134 | KompassSignalSchlecht = 1000; |
1051 | killagreg | 1135 | } |
499 | hbuss | 1136 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1173 | hbuss | 1137 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
395 | hbuss | 1138 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1139 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
||
401 | hbuss | 1140 | |
395 | hbuss | 1141 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1695 | holgerb | 1142 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
1225 | hbuss | 1143 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
1173 | hbuss | 1144 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
492 | hbuss | 1145 | { |
1051 | killagreg | 1146 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
395 | hbuss | 1147 | { |
1051 | killagreg | 1148 | if(last_r_p) |
395 | hbuss | 1149 | { |
1173 | hbuss | 1150 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1151 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1152 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
498 | hbuss | 1153 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1051 | killagreg | 1154 | } |
395 | hbuss | 1155 | else last_r_p = 1; |
1156 | } else last_r_p = 0; |
||
1051 | killagreg | 1157 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
395 | hbuss | 1158 | { |
1051 | killagreg | 1159 | if(last_r_n) |
395 | hbuss | 1160 | { |
1173 | hbuss | 1161 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
492 | hbuss | 1162 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 1163 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
498 | hbuss | 1164 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 1165 | } |
1166 | else last_r_n = 1; |
||
1167 | } else last_r_n = 0; |
||
1051 | killagreg | 1168 | } else |
492 | hbuss | 1169 | { |
1170 | cnt = 0; |
||
921 | hbuss | 1171 | KompassSignalSchlecht = 1000; |
1051 | killagreg | 1172 | } |
499 | hbuss | 1173 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1173 | hbuss | 1174 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
395 | hbuss | 1175 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1176 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
||
173 | holgerb | 1177 | } |
1051 | killagreg | 1178 | else |
498 | hbuss | 1179 | { |
1180 | LageKorrekturRoll = 0; |
||
1181 | LageKorrekturNick = 0; |
||
880 | hbuss | 1182 | TrichterFlug = 0; |
498 | hbuss | 1183 | } |
1051 | killagreg | 1184 | |
498 | hbuss | 1185 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1051 | killagreg | 1186 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1187 | MittelIntegralNick_Alt = MittelIntegralNick; |
||
1188 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
||
1189 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
395 | hbuss | 1190 | IntegralAccNick = 0; |
1191 | IntegralAccRoll = 0; |
||
1192 | IntegralAccZ = 0; |
||
1193 | MittelIntegralNick = 0; |
||
1194 | MittelIntegralRoll = 0; |
||
1195 | MittelIntegralNick2 = 0; |
||
1196 | MittelIntegralRoll2 = 0; |
||
1197 | ZaehlMessungen = 0; |
||
1173 | hbuss | 1198 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
395 | hbuss | 1199 | |
1051 | killagreg | 1200 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1201 | // Gieren |
1051 | killagreg | 1202 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1203 | if(abs(StickGier) > 15) // war 35 |
||
1 | ingob | 1204 | { |
921 | hbuss | 1205 | KompassSignalSchlecht = 1000; |
1051 | killagreg | 1206 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) |
1207 | { |
||
1208 | NeueKompassRichtungMerken = 1; |
||
824 | hbuss | 1209 | }; |
1 | ingob | 1210 | } |
395 | hbuss | 1211 | tmp_int = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1051 | killagreg | 1212 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
173 | holgerb | 1213 | sollGier = tmp_int; |
1051 | killagreg | 1214 | Mess_Integral_Gier -= tmp_int; |
395 | hbuss | 1215 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1216 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
||
1051 | killagreg | 1217 | |
1218 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1219 | // Kompass |
1051 | killagreg | 1220 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1221 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
||
1 | ingob | 1222 | { |
819 | hbuss | 1223 | int w,v,r,fehler,korrektur; |
1 | ingob | 1224 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1225 | v = abs(IntegralRoll /512); |
||
1226 | if(v > w) w = v; // grösste Neigung ermitteln |
||
1658 | holgerb | 1227 | korrektur = w / 8 + 2; |
921 | hbuss | 1228 | fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180; |
1664 | holgerb | 1229 | //fehler += MesswertGier / 12; |
1662 | killagreg | 1230 | |
921 | hbuss | 1231 | if(!KompassSignalSchlecht && w < 25) |
1232 | { |
||
1233 | GierGyroFehler += fehler; |
||
1051 | killagreg | 1234 | if(NeueKompassRichtungMerken) |
1235 | { |
||
1171 | hbuss | 1236 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
921 | hbuss | 1237 | KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR); |
1238 | NeueKompassRichtungMerken = 0; |
||
1239 | } |
||
1 | ingob | 1240 | } |
1658 | holgerb | 1241 | ErsatzKompass += (fehler * 16) / korrektur; |
921 | hbuss | 1242 | w = (w * Parameter_KompassWirkung) / 32; // auf die Wirkung normieren |
1 | ingob | 1243 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
921 | hbuss | 1244 | if(w >= 0) |
1 | ingob | 1245 | { |
1051 | killagreg | 1246 | if(!KompassSignalSchlecht) |
693 | hbuss | 1247 | { |
1051 | killagreg | 1248 | v = 64 + ((MaxStickNick + MaxStickRoll)) / 8; |
847 | hbuss | 1249 | r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180; |
819 | hbuss | 1250 | v = (r * w) / v; // nach Kompass ausrichten |
1251 | w = 3 * Parameter_KompassWirkung; |
||
693 | hbuss | 1252 | if(v > w) v = w; // Begrenzen |
1051 | killagreg | 1253 | else |
693 | hbuss | 1254 | if(v < -w) v = -w; |
1255 | Mess_Integral_Gier += v; |
||
1051 | killagreg | 1256 | } |
693 | hbuss | 1257 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1051 | killagreg | 1258 | } |
921 | hbuss | 1259 | else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
1051 | killagreg | 1260 | } |
1 | ingob | 1261 | |
1051 | killagreg | 1262 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1263 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1051 | killagreg | 1264 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1216 | killagreg | 1265 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
604 | hbuss | 1266 | |
1171 | hbuss | 1267 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1268 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
||
1153 | hbuss | 1269 | |
1167 | hbuss | 1270 | #define TRIM_MAX 200 |
1166 | hbuss | 1271 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1272 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
||
1153 | hbuss | 1273 | |
1166 | hbuss | 1274 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1275 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
||
1211 | hbuss | 1276 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1166 | hbuss | 1277 | |
1 | ingob | 1278 | // Maximalwerte abfangen |
1153 | hbuss | 1279 | // #define MAX_SENSOR (4096*STICK_GAIN) |
1685 | holgerb | 1280 | #define MAX_SENSOR (4096) |
1216 | killagreg | 1281 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1 | ingob | 1282 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1283 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
||
1284 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
||
1285 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
||
1286 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
||
1287 | |||
1051 | killagreg | 1288 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1289 | // Höhenregelung |
1290 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
||
1051 | killagreg | 1291 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1374 | hbuss | 1292 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
855 | hbuss | 1293 | GasMischanteil *= STICK_GAIN; |
1309 | hbuss | 1294 | // if height control is activated |
1322 | hbuss | 1295 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1309 | hbuss | 1296 | { |
1698 | holgerb | 1297 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1332 | hbuss | 1298 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1638 | holgerb | 1299 | |
1300 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
||
1301 | #define OPA_OFFSET_STEP 15 |
||
1642 | killagreg | 1302 | #else |
1638 | holgerb | 1303 | #define OPA_OFFSET_STEP 10 |
1304 | #endif |
||
1697 | holgerb | 1305 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
1309 | hbuss | 1306 | static int HeightTrimming = 0; // rate for change of height setpoint |
1307 | static int FilterHCGas = 0; |
||
1692 | holgerb | 1308 | static int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023; |
1587 | killagreg | 1309 | static unsigned long HoverGasFilter = 0; |
1322 | hbuss | 1310 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1320 | hbuss | 1311 | int CosAttitude; // for projection of hoover gas |
1330 | killagreg | 1312 | |
1309 | hbuss | 1313 | // get the current hooverpoint |
1587 | killagreg | 1314 | DebugOut.Analog[21] = HoverGas; |
1642 | killagreg | 1315 | |
1322 | hbuss | 1316 | // Expand the measurement |
1317 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
||
1318 | if(!BaroExpandActive) |
||
1319 | { |
||
1320 | if(MessLuftdruck > 920) |
||
1321 | { // increase offset |
||
1330 | killagreg | 1322 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
1322 | hbuss | 1323 | { |
1324 | ExpandBaro -= 1; |
||
1325 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
||
1326 | beeptime = 300; |
||
1352 | hbuss | 1327 | BaroExpandActive = 350; |
1330 | killagreg | 1328 | } |
1329 | else |
||
1322 | hbuss | 1330 | { |
1331 | BaroAtLowerLimit = 1; |
||
1332 | } |
||
1333 | } |
||
1334 | // measurement of air pressure close to lower limit and |
||
1330 | killagreg | 1335 | else |
1322 | hbuss | 1336 | if(MessLuftdruck < 100) |
1337 | { // decrease offset |
||
1330 | killagreg | 1338 | if(OCR0A > OPA_OFFSET_STEP) |
1322 | hbuss | 1339 | { |
1340 | ExpandBaro += 1; |
||
1341 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
||
1342 | beeptime = 300; |
||
1352 | hbuss | 1343 | BaroExpandActive = 350; |
1330 | killagreg | 1344 | } |
1345 | else |
||
1322 | hbuss | 1346 | { |
1347 | BaroAtUpperLimit = 1; |
||
1348 | } |
||
1349 | } |
||
1330 | killagreg | 1350 | else |
1322 | hbuss | 1351 | { |
1352 | BaroAtUpperLimit = 0; |
||
1353 | BaroAtLowerLimit = 0; |
||
1354 | } |
||
1355 | } |
||
1356 | else // delay, because of expanding the Baro-Range |
||
1357 | { |
||
1358 | // now clear the D-values |
||
1359 | SummenHoehe = HoehenWert * SM_FILTER; |
||
1360 | VarioMeter = 0; |
||
1361 | BaroExpandActive--; |
||
1362 | } |
||
1328 | hbuss | 1363 | |
1364 | // if height control is activated by an rc channel |
||
1365 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
||
1366 | { // check if parameter is less than activation threshold |
||
1367 | if(Parameter_MaxHoehe < 50) // for 3 or 2-state switch height control is disabled in lowest position |
||
1368 | { //height control not active |
||
1369 | if(!delay--) |
||
1370 | { |
||
1371 | HoehenReglerAktiv = 0; // disable height control |
||
1372 | SollHoehe = HoehenWert; // update SetPoint with current reading |
||
1373 | delay = 1; |
||
1374 | } |
||
1375 | } |
||
1376 | else |
||
1377 | { //height control is activated |
||
1378 | HoehenReglerAktiv = 1; // enable height control |
||
1334 | killagreg | 1379 | delay = 200; |
1328 | hbuss | 1380 | } |
1051 | killagreg | 1381 | } |
1309 | hbuss | 1382 | else // no switchable height control |
1383 | { |
||
1384 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung; |
||
1385 | HoehenReglerAktiv = 1; |
||
1051 | killagreg | 1386 | } |
1322 | hbuss | 1387 | |
1320 | hbuss | 1388 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1330 | killagreg | 1389 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1390 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
||
1391 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
||
1320 | hbuss | 1392 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1393 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
||
1591 | holgerb | 1394 | VarioCharacter = ' '; |
1420 | killagreg | 1395 | if(HoehenReglerAktiv && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1309 | hbuss | 1396 | { |
1397 | #define HEIGHT_TRIM_UP 0x01 |
||
1398 | #define HEIGHT_TRIM_DOWN 0x02 |
||
1399 | static unsigned char HeightTrimmingFlag = 0x00; |
||
1400 | |||
1330 | killagreg | 1401 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1309 | hbuss | 1402 | // Holger original version |
1403 | // start of height control algorithm |
||
1404 | // the height control is only an attenuation of the actual gas stick. |
||
1405 | // I.e. it will work only if the gas stick is higher than the hover gas |
||
1406 | // and the hover height will be allways larger than height setpoint. |
||
1314 | killagreg | 1407 | if((EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) || !(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1408 | { // old version |
||
1309 | hbuss | 1409 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1410 | HeightTrimming = 0; |
||
1411 | } |
||
1314 | killagreg | 1412 | else |
1309 | hbuss | 1413 | { |
1414 | // alternative height control |
||
1415 | // PD-Control with respect to hoover point |
||
1416 | // the thrust loss out of horizontal attitude is compensated |
||
1417 | // the setpoint will be fine adjusted with the gas stick position |
||
1420 | killagreg | 1418 | if(FCFlags & FCFLAG_FLY) // trim setpoint only when flying |
1309 | hbuss | 1419 | { // gas stick is above hoover point |
1587 | killagreg | 1420 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1309 | hbuss | 1421 | { |
1422 | if(HeightTrimmingFlag & HEIGHT_TRIM_DOWN) |
||
1423 | { |
||
1424 | HeightTrimmingFlag &= ~HEIGHT_TRIM_DOWN; |
||
1425 | SollHoehe = HoehenWert; // update setpoint to current heigth |
||
1426 | } |
||
1427 | HeightTrimmingFlag |= HEIGHT_TRIM_UP; |
||
1587 | killagreg | 1428 | HeightTrimming += abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1591 | holgerb | 1429 | VarioCharacter = '+'; |
1309 | hbuss | 1430 | } // gas stick is below hoover point |
1587 | killagreg | 1431 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) |
1309 | hbuss | 1432 | { |
1433 | if(HeightTrimmingFlag & HEIGHT_TRIM_UP) |
||
1434 | { |
||
1435 | HeightTrimmingFlag &= ~HEIGHT_TRIM_UP; |
||
1436 | SollHoehe = HoehenWert; // update setpoint to current heigth |
||
1437 | } |
||
1438 | HeightTrimmingFlag |= HEIGHT_TRIM_DOWN; |
||
1587 | killagreg | 1439 | HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1591 | holgerb | 1440 | VarioCharacter = '-'; |
1309 | hbuss | 1441 | } |
1587 | killagreg | 1442 | else // Gas Stick in Hover Range |
1309 | hbuss | 1443 | { |
1352 | hbuss | 1444 | if(HeightTrimmingFlag & (HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN)) |
1309 | hbuss | 1445 | { |
1352 | hbuss | 1446 | HeightTrimmingFlag &= ~(HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN); |
1309 | hbuss | 1447 | HeightTrimming = 0; |
1448 | SollHoehe = HoehenWert; // update setpoint to current height |
||
1449 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
||
1698 | holgerb | 1450 | if(!StartTrigger && HoehenWert > 50) |
1451 | { |
||
1452 | StartTrigger = 1; |
||
1453 | } |
||
1309 | hbuss | 1454 | } |
1591 | holgerb | 1455 | VarioCharacter = '='; |
1309 | hbuss | 1456 | } |
1457 | // Trim height set point |
||
1334 | killagreg | 1458 | if(abs(HeightTrimming) > 512) |
1309 | hbuss | 1459 | { |
1332 | hbuss | 1460 | SollHoehe += (HeightTrimming * EE_Parameter.Hoehe_Verstaerkung)/(5 * 512 / 2); // move setpoint |
1309 | hbuss | 1461 | HeightTrimming = 0; |
1587 | killagreg | 1462 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1720 | holgerb | 1463 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1320 | hbuss | 1464 | //update hoover gas stick value when setpoint is shifted |
1332 | hbuss | 1465 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1466 | { |
||
1587 | killagreg | 1467 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1468 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
||
1469 | if(StickGasHover < 70) StickGasHover = 70; |
||
1470 | else if(StickGasHover > 150) StickGasHover = 150; |
||
1332 | hbuss | 1471 | } |
1309 | hbuss | 1472 | } |
1352 | hbuss | 1473 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1420 | killagreg | 1474 | } //if FCFlags & MKFCFLAG_FLY |
1330 | killagreg | 1475 | else |
1476 | { |
||
1322 | hbuss | 1477 | SollHoehe = HoehenWert - 400; |
1587 | killagreg | 1478 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1479 | else StickGasHover = 120; |
||
1698 | holgerb | 1480 | HoverGas = GasMischanteil; |
1320 | hbuss | 1481 | } |
1590 | killagreg | 1482 | HCGas = HoverGas; // take hover gas (neutral point) |
1483 | } |
||
1314 | killagreg | 1484 | if(HoehenWert > SollHoehe || !(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1283 | hbuss | 1485 | { |
1590 | killagreg | 1486 | // from this point the Heigth Control Algorithm is identical for both versions |
1487 | if(BaroExpandActive) // baro range expanding active |
||
1488 | { |
||
1489 | HCGas = HoverGas; // hover while expanding baro adc range |
||
1490 | HeightDeviation = 0; |
||
1491 | } // EOF // baro range expanding active |
||
1492 | else // valid data from air pressure sensor |
||
1493 | { |
||
1494 | // ------------------------- P-Part ---------------------------- |
||
1495 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
||
1496 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
||
1497 | HeightDeviation = (int)(tmp_long); // positive when too high |
||
1695 | holgerb | 1498 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1698 | holgerb | 1499 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1500 | GasReduction = tmp_long; |
||
1590 | killagreg | 1501 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1502 | tmp_int = VarioMeter / 8; |
||
1695 | holgerb | 1503 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1705 | holgerb | 1504 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1505 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
||
1506 | if(HeightTrimmingFlag) tmp_int /= 4; // reduce d-part while trimming setpoint |
||
1720 | holgerb | 1507 | else |
1722 | holgerb | 1508 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1698 | holgerb | 1509 | GasReduction += tmp_int; |
1590 | killagreg | 1510 | } // EOF no baro range expanding |
1309 | hbuss | 1511 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1698 | holgerb | 1512 | if(Parameter_Hoehe_ACC_Wirkung) |
1513 | { |
||
1514 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
||
1515 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
||
1516 | GasReduction += tmp_long; |
||
1517 | } |
||
1587 | killagreg | 1518 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1588 | killagreg | 1519 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1520 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
||
1698 | holgerb | 1521 | GasReduction += tmp_int; |
1701 | holgerb | 1522 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1523 | // ------------------------ ---------------------------------- |
||
1524 | HCGas -= GasReduction; |
||
1309 | hbuss | 1525 | // limit deviation from hoover point within the target region |
1692 | holgerb | 1526 | if(!HeightTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1309 | hbuss | 1527 | { |
1705 | holgerb | 1528 | unsigned int tmp; |
1529 | tmp = abs(HeightDeviation); |
||
1530 | if(tmp <= 60) |
||
1531 | { |
||
1532 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
||
1533 | } |
||
1534 | else |
||
1535 | { |
||
1536 | tmp = (tmp - 60) / 32; |
||
1692 | holgerb | 1537 | if(tmp > 15) tmp = 15; |
1705 | holgerb | 1538 | if(HeightDeviation > 0) |
1693 | holgerb | 1539 | { |
1705 | holgerb | 1540 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1541 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
||
1693 | holgerb | 1542 | } |
1705 | holgerb | 1543 | else |
1544 | { |
||
1545 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
||
1546 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
||
1547 | } |
||
1548 | } |
||
1309 | hbuss | 1549 | } |
1322 | hbuss | 1550 | // strech control output by inverse attitude projection 1/cos |
1551 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
||
1330 | killagreg | 1552 | tmp_long2 = (int32_t)HCGas; |
1553 | tmp_long2 *= 8192L; |
||
1554 | tmp_long2 /= CosAttitude; |
||
1555 | HCGas = (int16_t)tmp_long2; |
||
1309 | hbuss | 1556 | // update height control gas averaging |
1557 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
||
1558 | // limit height control gas pd-control output |
||
1559 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
||
1560 | // set GasMischanteil to HeightControlGasFilter |
||
1314 | killagreg | 1561 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) |
1587 | killagreg | 1562 | { // old version |
1563 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
||
1719 | holgerb | 1564 | GasMischanteil = FilterHCGas; |
1565 | } |
||
1566 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
||
1314 | killagreg | 1567 | } |
1309 | hbuss | 1568 | }// EOF height control active |
1320 | hbuss | 1569 | else // HC not active |
1570 | { |
||
1571 | //update hoover gas stick value when HC is not active |
||
1587 | killagreg | 1572 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1573 | { |
||
1574 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
||
1575 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
||
1322 | hbuss | 1576 | } |
1587 | killagreg | 1577 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1578 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
||
1328 | hbuss | 1579 | FilterHCGas = GasMischanteil; |
1330 | killagreg | 1580 | } |
1283 | hbuss | 1581 | |
1587 | killagreg | 1582 | // Hover gas estimation by averaging gas control output on small z-velocities |
1309 | hbuss | 1583 | // this is done only if height contol option is selected in global config and aircraft is flying |
1698 | holgerb | 1584 | if((FCFlags & FCFLAG_FLY))// && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1309 | hbuss | 1585 | { |
1698 | holgerb | 1586 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1587 | if(StartTrigger == 1) StartTrigger = 2; |
||
1330 | killagreg | 1588 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1589 | tmp_long2 *= CosAttitude; // apply attitude projection |
||
1590 | tmp_long2 /= 8192; |
||
1309 | hbuss | 1591 | // average vertical projected thrust |
1698 | holgerb | 1592 | if(modell_fliegt < 4000) // the first 8 seconds |
1593 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
||
1594 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
||
1595 | HoverGasFilter += 16L * tmp_long2; |
||
1309 | hbuss | 1596 | } |
1698 | holgerb | 1597 | if(modell_fliegt < 8000) // the first 16 seconds |
1598 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
||
1590 | killagreg | 1599 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1587 | killagreg | 1600 | HoverGasFilter += 4L * tmp_long2; |
1309 | hbuss | 1601 | } |
1698 | holgerb | 1602 | else //later |
1603 | if(abs(VarioMeter) < 100) // only on small vertical speed |
||
1309 | hbuss | 1604 | { |
1590 | killagreg | 1605 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1587 | killagreg | 1606 | HoverGasFilter += tmp_long2; |
1309 | hbuss | 1607 | } |
1590 | killagreg | 1608 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1309 | hbuss | 1609 | if(EE_Parameter.Hoehe_HoverBand) |
1610 | { |
||
1611 | int16_t band; |
||
1587 | killagreg | 1612 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1613 | HoverGasMin = HoverGas - band; |
||
1614 | HoverGasMax = HoverGas + band; |
||
1309 | hbuss | 1615 | } |
1616 | else |
||
1617 | { // no limit |
||
1587 | killagreg | 1618 | HoverGasMin = 0; |
1619 | HoverGasMax = 1023; |
||
1309 | hbuss | 1620 | } |
1698 | holgerb | 1621 | } |
1622 | else |
||
1623 | { |
||
1624 | StartTrigger = 0; |
||
1625 | HoverGasFilter = 0; |
||
1626 | HoverGas = 0; |
||
1627 | } |
||
1309 | hbuss | 1628 | }// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL |
1629 | // limit gas to parameter setting |
||
1320 | hbuss | 1630 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
855 | hbuss | 1631 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1111 | hbuss | 1632 | |
1051 | killagreg | 1633 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1320 | hbuss | 1634 | // all BL-Ctrl connected? |
1635 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1675 | holgerb | 1636 | if(MissingMotor || Capacity.MinOfMaxPWM != 255) |
1320 | hbuss | 1637 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) |
1638 | { |
||
1639 | modell_fliegt = 1; |
||
1675 | holgerb | 1640 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
1320 | hbuss | 1641 | } |
1642 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1643 | // + Mischer und PI-Regler |
1051 | killagreg | 1644 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 1645 | DebugOut.Analog[7] = GasMischanteil; |
1051 | killagreg | 1646 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1647 | // Gier-Anteil |
1051 | killagreg | 1648 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
855 | hbuss | 1649 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1650 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
||
693 | hbuss | 1651 | if(GasMischanteil > MIN_GIERGAS) |
1652 | { |
||
1051 | killagreg | 1653 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1654 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
||
693 | hbuss | 1655 | } |
1051 | killagreg | 1656 | else |
693 | hbuss | 1657 | { |
1051 | killagreg | 1658 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1659 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
||
693 | hbuss | 1660 | } |
855 | hbuss | 1661 | tmp_int = MAX_GAS*STICK_GAIN; |
1051 | killagreg | 1662 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
855 | hbuss | 1663 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
513 | hbuss | 1664 | |
1051 | killagreg | 1665 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1666 | // Nick-Achse |
1051 | killagreg | 1667 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
723 | hbuss | 1668 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1153 | hbuss | 1669 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1051 | killagreg | 1670 | else SummeNick += DiffNick; // I-Anteil bei HH |
855 | hbuss | 1671 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1672 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
||
1685 | holgerb | 1673 | pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8 + SummeNick / Ki; // PI-Regler für Nick |
1 | ingob | 1674 | // Motor Vorn |
1676 | holgerb | 1675 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1153 | hbuss | 1676 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1677 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
||
173 | holgerb | 1678 | |
1153 | hbuss | 1679 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1680 | // Roll-Achse |
||
1681 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1682 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
||
1683 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
||
1684 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
||
1685 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
||
1686 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
||
1685 | holgerb | 1687 | pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8 + SummeRoll / Ki; // PI-Regler für Roll |
1676 | holgerb | 1688 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1153 | hbuss | 1689 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1690 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
||
1691 | |||
1692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1209 | hbuss | 1693 | // Universal Mixer |
1155 | hbuss | 1694 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1642 | killagreg | 1695 | for(i=0; i<MAX_MOTORS; i++) |
1696 | { |
||
1697 | signed int tmp_int; |
||
1698 | if(Mixer.Motor[i][0] > 0) |
||
1699 | { |
||
1652 | holgerb | 1700 | // Gas |
1676 | holgerb | 1701 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1652 | holgerb | 1702 | // Nick |
1703 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
||
1704 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
||
1705 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
||
1706 | // Roll |
||
1707 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
||
1708 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
||
1709 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
||
1710 | // Gier |
||
1676 | holgerb | 1711 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
1712 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
||
1713 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
||
1675 | holgerb | 1714 | |
1693 | holgerb | 1715 | |
1749 | - | 1716 | |
1717 | |||
1718 | |||
1719 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
||
1720 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // MotorSmoothing |
||
1721 | // Arthur P: the original code allowed the motor value to drop to 0 or negative values |
||
1722 | // straight off, i.e. could amplify an intended decrease excessively while upregulation |
||
1723 | // is dampened. The modification would still allow immediate drop below intended value |
||
1724 | // but would dampen this. This would still allow for airbraking of the prop to have effect |
||
1725 | // but it might lead to less sudden excessive drops in rpm with only gradual recovery. |
||
1726 | // 090807 Arthur P: Due to problems with uart.c which still refers to user parameter 1 and 2 and |
||
1727 | // possible timing issues with the shutter interval load, removed the shutter interval functions |
||
1728 | // and switched to use of userparam6 for the motor smoothing. |
||
1729 | // 091114 Inserted modification into 0.76g source code. |
||
1730 | // 20100804 Modified v.0.80d code where motorsmoothing is no longer a separate function. |
||
1731 | // Downsmoothing either uses default v.0.7x+ 150% downstep (user para 7 == 0), |
||
1732 | // 50% downstep (user para 7 == 1 or 2), or downsteps of x% (userpara7 ==): |
||
1733 | // 66.6% (3), 75% (4), 80% (5), 90% (10), 95% (20), 97.5% (40), 98% (50), 99% (100). |
||
1734 | else |
||
1735 | { |
||
1736 | if(Parameter_UserParam7 < 2) |
||
1737 | { // Original function |
||
1738 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; |
||
1739 | } |
||
1740 | else |
||
1741 | { |
||
1742 | // If userpara7 >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
||
1743 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/Parameter_UserParam7); |
||
1744 | } |
||
1745 | } |
||
1746 | |||
1747 | |||
1748 | |||
1677 | killagreg | 1749 | LIMIT_MIN_MAX(tmp_int,MIN_GAS * 4,MAX_GAS * 4); |
1676 | holgerb | 1750 | Motor[i].SetPoint = tmp_int / 4; |
1677 | killagreg | 1751 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
1652 | holgerb | 1752 | tmp_motorwert[i] = tmp_int; |
1642 | killagreg | 1753 | } |
1754 | else |
||
1755 | { |
||
1756 | Motor[i].SetPoint = 0; |
||
1757 | Motor[i].SetPointLowerBits = 0; |
||
1758 | } |
||
1759 | } |
||
1111 | hbuss | 1760 | } |