Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
2 | Flight Control |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 04.2007 Holger Buss |
||
6 | // + Nur für den privaten Gebrauch |
||
7 | // + www.MikroKopter.com |
||
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | killagreg | 27 | // + Die Portierung 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | 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. |
||
683 | 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) |
683 | killagreg | 38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
1 | ingob | 39 | // + with our written permission |
683 | killagreg | 40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + clearly linked as origin |
||
1 | ingob | 42 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
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 |
||
492 | hbuss | 50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
1 | ingob | 51 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
683 | killagreg | 52 | // + POSSIBILITY OF SUCH DAMAGE. |
1 | ingob | 53 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
687 | killagreg | 54 | #include <stdlib.h> |
55 | #include <avr/io.h> |
||
1 | ingob | 56 | |
57 | #include "main.h" |
||
685 | killagreg | 58 | #include "eeprom.h" |
59 | #include "timer0.h" |
||
60 | #include "_Settings.h" |
||
61 | #include "analog.h" |
||
62 | #include "fc.h" |
||
63 | #include "gps.h" |
||
64 | #include "uart.h" |
||
65 | #include "rc.h" |
||
66 | #include "twimaster.h" |
||
694 | killagreg | 67 | #include "mm3.h" |
1 | ingob | 68 | |
69 | unsigned char h,m,s; |
||
173 | holgerb | 70 | volatile unsigned int I2CTimeout = 100; |
1 | ingob | 71 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
401 | hbuss | 72 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
1 | ingob | 73 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
74 | volatile float NeutralAccZ = 0; |
||
75 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
||
76 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
||
395 | hbuss | 77 | volatile long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
1 | ingob | 78 | volatile long Integral_Gier = 0; |
79 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
||
80 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
||
81 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
||
395 | hbuss | 82 | volatile long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
1 | ingob | 83 | volatile long Mess_Integral_Hoch = 0; |
84 | volatile int KompassValue = 0; |
||
85 | volatile int KompassStartwert = 0; |
||
86 | volatile int KompassRichtung = 0; |
||
87 | unsigned char MAX_GAS,MIN_GAS; |
||
88 | unsigned char Notlandung = 0; |
||
89 | unsigned char HoehenReglerAktiv = 0; |
||
395 | hbuss | 90 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
1 | ingob | 91 | |
92 | float GyroFaktor; |
||
93 | float IntegralFaktor; |
||
94 | volatile int DiffNick,DiffRoll; |
||
683 | killagreg | 95 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
1 | ingob | 96 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
97 | unsigned char MotorWert[5]; |
||
595 | hbuss | 98 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
1 | ingob | 99 | char MotorenEin = 0; |
100 | int HoehenWert = 0; |
||
101 | int SollHoehe = 0; |
||
498 | hbuss | 102 | int LageKorrekturRoll = 0,LageKorrekturNick = 0; |
1 | ingob | 103 | float Ki = FAKTOR_I; |
395 | hbuss | 104 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
105 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
||
1 | ingob | 106 | |
107 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
||
108 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
||
109 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
||
110 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
||
111 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
||
173 | holgerb | 112 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
1 | ingob | 113 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
114 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
||
690 | killagreg | 115 | unsigned char Parameter_I_Factor = 10; // Wert : 1-20 |
1 | ingob | 116 | unsigned char Parameter_UserParam1 = 0; |
117 | unsigned char Parameter_UserParam2 = 0; |
||
118 | unsigned char Parameter_UserParam3 = 0; |
||
119 | unsigned char Parameter_UserParam4 = 0; |
||
499 | hbuss | 120 | unsigned char Parameter_UserParam5 = 0; |
121 | unsigned char Parameter_UserParam6 = 0; |
||
122 | unsigned char Parameter_UserParam7 = 0; |
||
123 | unsigned char Parameter_UserParam8 = 0; |
||
1 | ingob | 124 | unsigned char Parameter_ServoNickControl = 100; |
173 | holgerb | 125 | unsigned char Parameter_LoopGasLimit = 70; |
395 | hbuss | 126 | unsigned char Parameter_AchsKopplung1 = 0; |
127 | unsigned char Parameter_AchsGegenKopplung1 = 0; |
||
499 | hbuss | 128 | unsigned char Parameter_DynamicStability = 100; |
687 | killagreg | 129 | |
492 | hbuss | 130 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
614 | hbuss | 131 | int MaxStickNick = 0,MaxStickRoll = 0; |
1 | ingob | 132 | |
133 | void Piep(unsigned char Anzahl) |
||
134 | { |
||
135 | while(Anzahl--) |
||
136 | { |
||
137 | if(MotorenEin) return; //auf keinen Fall im Flug! |
||
683 | killagreg | 138 | BeepTime = 100; |
1 | ingob | 139 | Delay_ms(250); |
140 | } |
||
141 | } |
||
142 | |||
143 | //############################################################################ |
||
144 | // Nullwerte ermitteln |
||
145 | void SetNeutral(void) |
||
146 | //############################################################################ |
||
147 | { |
||
683 | killagreg | 148 | NeutralAccX = 0; |
1 | ingob | 149 | NeutralAccY = 0; |
150 | NeutralAccZ = 0; |
||
683 | killagreg | 151 | AdNeutralNick = 0; |
152 | AdNeutralRoll = 0; |
||
1 | ingob | 153 | AdNeutralGier = 0; |
395 | hbuss | 154 | Parameter_AchsKopplung1 = 0; |
155 | Parameter_AchsGegenKopplung1 = 0; |
||
683 | killagreg | 156 | CalibrierMittelwert(); |
395 | hbuss | 157 | Delay_ms_Mess(100); |
1 | ingob | 158 | CalibrierMittelwert(); |
690 | killagreg | 159 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung aktiviert? |
683 | killagreg | 160 | { |
1 | ingob | 161 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
162 | } |
||
173 | holgerb | 163 | |
683 | killagreg | 164 | AdNeutralNick= AdValueGyrNick; |
165 | AdNeutralRoll= AdValueGyrRoll; |
||
166 | AdNeutralGier= AdValueGyrGier; |
||
401 | hbuss | 167 | StartNeutralRoll = AdNeutralRoll; |
168 | StartNeutralNick = AdNeutralNick; |
||
687 | killagreg | 169 | if(GetParamByte(PID_ACC_NICK) > 4) |
513 | hbuss | 170 | { |
171 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
||
172 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
||
683 | killagreg | 173 | NeutralAccZ = Current_AccZ; |
513 | hbuss | 174 | } |
683 | killagreg | 175 | else |
513 | hbuss | 176 | { |
687 | killagreg | 177 | NeutralAccX = (int)GetParamByte(PID_ACC_NICK) * 256 + (int)GetParamByte(PID_ACC_NICK+1); |
178 | NeutralAccY = (int)GetParamByte(PID_ACC_ROLL) * 256 + (int)GetParamByte(PID_ACC_ROLL+1); |
||
179 | NeutralAccZ = (int)GetParamByte(PID_ACC_Z) * 256 + (int)GetParamByte(PID_ACC_Z+1); |
||
513 | hbuss | 180 | } |
683 | killagreg | 181 | |
182 | Mess_IntegralNick = 0; |
||
1 | ingob | 183 | Mess_IntegralNick2 = 0; |
683 | killagreg | 184 | Mess_IntegralRoll = 0; |
1 | ingob | 185 | Mess_IntegralRoll2 = 0; |
683 | killagreg | 186 | Mess_Integral_Gier = 0; |
1 | ingob | 187 | MesswertNick = 0; |
188 | MesswertRoll = 0; |
||
189 | MesswertGier = 0; |
||
190 | StartLuftdruck = Luftdruck; |
||
191 | HoeheD = 0; |
||
192 | Mess_Integral_Hoch = 0; |
||
193 | KompassStartwert = KompassValue; |
||
194 | GPS_Neutral(); |
||
683 | killagreg | 195 | BeepTime = 50; |
687 | killagreg | 196 | Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L; |
197 | Umschlag180Roll = (long) ParamSet.WinkelUmschlagRoll * 2500L; |
||
492 | hbuss | 198 | ExternHoehenValue = 0; |
1 | ingob | 199 | } |
200 | |||
201 | //############################################################################ |
||
395 | hbuss | 202 | // Bearbeitet die Messwerte |
1 | ingob | 203 | void Mittelwert(void) |
204 | //############################################################################ |
||
683 | killagreg | 205 | { |
206 | static signed long tmpl,tmpl2; |
||
207 | MesswertGier = (signed int) AdNeutralGier - AdValueGyrGier; |
||
208 | MesswertRoll = (signed int) AdValueGyrRoll - AdNeutralRoll; |
||
209 | MesswertNick = (signed int) AdValueGyrNick - AdNeutralNick; |
||
401 | hbuss | 210 | |
604 | hbuss | 211 | //DebugOut.Analog[26] = MesswertNick; |
212 | DebugOut.Analog[28] = MesswertRoll; |
||
213 | |||
395 | hbuss | 214 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
683 | killagreg | 215 | Mittelwert_AccNick = ((long)Mittelwert_AccNick * 1 + ((ACC_AMPLIFY * (long)AdValueAccNick))) / 2L; |
216 | Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 1 + ((ACC_AMPLIFY * (long)AdValueAccRoll))) / 2L; |
||
217 | Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 1 + ((long)AdValueAccTop)) / 2L; |
||
218 | IntegralAccNick += ACC_AMPLIFY * AdValueAccNick; |
||
219 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
||
220 | IntegralAccZ += Current_AccZ - NeutralAccZ; |
||
395 | hbuss | 221 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
222 | Mess_Integral_Gier += MesswertGier; |
||
223 | Mess_Integral_Gier2 += MesswertGier; |
||
224 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
||
690 | killagreg | 225 | if(!Looping_Nick && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
395 | hbuss | 226 | { |
227 | tmpl = Mess_IntegralNick / 4096L; |
||
228 | tmpl *= MesswertGier; |
||
229 | tmpl *= Parameter_AchsKopplung1; //125 |
||
230 | tmpl /= 2048L; |
||
231 | tmpl2 = Mess_IntegralRoll / 4096L; |
||
232 | tmpl2 *= MesswertGier; |
||
233 | tmpl2 *= Parameter_AchsKopplung1; |
||
234 | tmpl2 /= 2048L; |
||
235 | } |
||
236 | else tmpl = tmpl2 = 0; |
||
237 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
||
238 | MesswertRoll += tmpl; |
||
239 | MesswertRoll += (tmpl2*Parameter_AchsGegenKopplung1)/512L; //109 |
||
240 | Mess_IntegralRoll2 += MesswertRoll; |
||
498 | hbuss | 241 | Mess_IntegralRoll += MesswertRoll - LageKorrekturRoll; |
683 | killagreg | 242 | if(Mess_IntegralRoll > Umschlag180Roll) |
395 | hbuss | 243 | { |
244 | Mess_IntegralRoll = -(Umschlag180Roll - 10000L); |
||
245 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
||
683 | killagreg | 246 | } |
395 | hbuss | 247 | if(Mess_IntegralRoll <-Umschlag180Roll) |
248 | { |
||
249 | Mess_IntegralRoll = (Umschlag180Roll - 10000L); |
||
250 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
||
683 | killagreg | 251 | } |
252 | if(AdValueGyrRoll < 15) MesswertRoll = -1000; |
||
253 | if(AdValueGyrRoll < 7) MesswertRoll = -2000; |
||
685 | killagreg | 254 | if(BoardRelease == 10) |
401 | hbuss | 255 | { |
683 | killagreg | 256 | if(AdValueGyrRoll > 1010) MesswertRoll = +1000; |
257 | if(AdValueGyrRoll > 1017) MesswertRoll = +2000; |
||
401 | hbuss | 258 | } |
683 | killagreg | 259 | else |
401 | hbuss | 260 | { |
683 | killagreg | 261 | if(AdValueGyrRoll > 2020) MesswertRoll = +1000; |
262 | if(AdValueGyrRoll > 2034) MesswertRoll = +2000; |
||
401 | hbuss | 263 | } |
395 | hbuss | 264 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
265 | MesswertNick -= tmpl2; |
||
266 | MesswertNick -= (tmpl*Parameter_AchsGegenKopplung1)/512L; |
||
267 | Mess_IntegralNick2 += MesswertNick; |
||
498 | hbuss | 268 | Mess_IntegralNick += MesswertNick - LageKorrekturNick; |
683 | killagreg | 269 | if(Mess_IntegralNick > Umschlag180Nick) |
395 | hbuss | 270 | { |
271 | Mess_IntegralNick = -(Umschlag180Nick - 10000L); |
||
272 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
683 | killagreg | 273 | } |
274 | if(Mess_IntegralNick <-Umschlag180Nick) |
||
395 | hbuss | 275 | { |
276 | Mess_IntegralNick = (Umschlag180Nick - 10000L); |
||
277 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
683 | killagreg | 278 | } |
279 | if(AdValueGyrNick < 15) MesswertNick = -1000; |
||
280 | if(AdValueGyrNick < 7) MesswertNick = -2000; |
||
685 | killagreg | 281 | if(BoardRelease == 10) |
401 | hbuss | 282 | { |
683 | killagreg | 283 | if(AdValueGyrNick > 1010) MesswertNick = +1000; |
284 | if(AdValueGyrNick > 1017) MesswertNick = +2000; |
||
401 | hbuss | 285 | } |
683 | killagreg | 286 | else |
401 | hbuss | 287 | { |
683 | killagreg | 288 | if(AdValueGyrNick > 2020) MesswertNick = +1000; |
289 | if(AdValueGyrNick > 2034) MesswertNick = +2000; |
||
401 | hbuss | 290 | } |
395 | hbuss | 291 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
292 | // ADC einschalten |
||
683 | killagreg | 293 | ADC_Enable(); |
395 | hbuss | 294 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
295 | |||
1 | ingob | 296 | Integral_Gier = Mess_Integral_Gier; |
297 | IntegralNick = Mess_IntegralNick; |
||
298 | IntegralRoll = Mess_IntegralRoll; |
||
683 | killagreg | 299 | IntegralNick2 = Mess_IntegralNick2; |
1 | ingob | 300 | IntegralRoll2 = Mess_IntegralRoll2; |
301 | |||
690 | killagreg | 302 | if(ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER && !Looping_Nick && !Looping_Roll) |
395 | hbuss | 303 | { |
304 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
||
683 | killagreg | 305 | else if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
395 | hbuss | 306 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
683 | killagreg | 307 | else if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
395 | hbuss | 308 | } |
690 | killagreg | 309 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
310 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
||
311 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
||
312 | if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--; |
||
1 | ingob | 313 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
314 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
315 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
316 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
317 | } |
||
318 | |||
319 | //############################################################################ |
||
320 | // Messwerte beim Ermitteln der Nullage |
||
321 | void CalibrierMittelwert(void) |
||
322 | //############################################################################ |
||
683 | killagreg | 323 | { |
1 | ingob | 324 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
683 | killagreg | 325 | ADC_Disable(); |
326 | MesswertNick = AdValueGyrNick; |
||
327 | MesswertRoll = AdValueGyrRoll; |
||
328 | MesswertGier = AdValueGyrGier; |
||
329 | Mittelwert_AccNick = ACC_AMPLIFY * (long)AdValueAccNick; |
||
330 | Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdValueAccRoll; |
||
331 | Mittelwert_AccHoch = (long)AdValueAccTop; |
||
395 | hbuss | 332 | // ADC einschalten |
683 | killagreg | 333 | ADC_Enable(); |
690 | killagreg | 334 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
335 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
||
336 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
||
337 | if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--; |
||
1 | ingob | 338 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
339 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
340 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
341 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
395 | hbuss | 342 | |
687 | killagreg | 343 | Umschlag180Nick = (long) ParamSet.WinkelUmschlagNick * 2500L; |
344 | Umschlag180Roll = (long) ParamSet.WinkelUmschlagNick * 2500L; |
||
1 | ingob | 345 | } |
346 | |||
347 | //############################################################################ |
||
348 | // Senden der Motorwerte per I2C-Bus |
||
349 | void SendMotorData(void) |
||
350 | //############################################################################ |
||
683 | killagreg | 351 | { |
1 | ingob | 352 | if(MOTOR_OFF || !MotorenEin) |
353 | { |
||
354 | Motor_Hinten = 0; |
||
355 | Motor_Vorne = 0; |
||
356 | Motor_Rechts = 0; |
||
357 | Motor_Links = 0; |
||
358 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
||
359 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
||
360 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
||
361 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
||
362 | } |
||
363 | |||
364 | DebugOut.Analog[12] = Motor_Vorne; |
||
365 | DebugOut.Analog[13] = Motor_Hinten; |
||
366 | DebugOut.Analog[14] = Motor_Links; |
||
683 | killagreg | 367 | DebugOut.Analog[15] = Motor_Rechts; |
1 | ingob | 368 | |
369 | //Start I2C Interrupt Mode |
||
370 | twi_state = 0; |
||
371 | motor = 0; |
||
683 | killagreg | 372 | i2c_start(); |
1 | ingob | 373 | } |
374 | |||
375 | |||
376 | |||
377 | //############################################################################ |
||
378 | // Trägt ggf. das Poti als Parameter ein |
||
683 | killagreg | 379 | void ParameterZuordnung(void) |
1 | ingob | 380 | //############################################################################ |
381 | { |
||
382 | |||
383 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
||
687 | killagreg | 384 | CHK_POTI(Parameter_MaxHoehe,ParamSet.MaxHoehe,0,255); |
385 | CHK_POTI(Parameter_Luftdruck_D,ParamSet.Luftdruck_D,0,100); |
||
386 | CHK_POTI(Parameter_Hoehe_P,ParamSet.Hoehe_P,0,100); |
||
387 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,ParamSet.Hoehe_ACC_Wirkung,0,255); |
||
388 | CHK_POTI(Parameter_KompassWirkung,ParamSet.KompassWirkung,0,255); |
||
389 | CHK_POTI(Parameter_Gyro_P,ParamSet.Gyro_P,10,255); |
||
390 | CHK_POTI(Parameter_Gyro_I,ParamSet.Gyro_I,0,255); |
||
690 | killagreg | 391 | CHK_POTI(Parameter_I_Factor,ParamSet.I_Factor,0,255); |
687 | killagreg | 392 | CHK_POTI(Parameter_UserParam1,ParamSet.UserParam1,0,255); |
393 | CHK_POTI(Parameter_UserParam2,ParamSet.UserParam2,0,255); |
||
394 | CHK_POTI(Parameter_UserParam3,ParamSet.UserParam3,0,255); |
||
395 | CHK_POTI(Parameter_UserParam4,ParamSet.UserParam4,0,255); |
||
396 | CHK_POTI(Parameter_UserParam5,ParamSet.UserParam5,0,255); |
||
397 | CHK_POTI(Parameter_UserParam6,ParamSet.UserParam6,0,255); |
||
398 | CHK_POTI(Parameter_UserParam7,ParamSet.UserParam7,0,255); |
||
399 | CHK_POTI(Parameter_UserParam8,ParamSet.UserParam8,0,255); |
||
400 | CHK_POTI(Parameter_ServoNickControl,ParamSet.ServoNickControl,0,255); |
||
401 | CHK_POTI(Parameter_LoopGasLimit,ParamSet.LoopGasLimit,0,255); |
||
402 | CHK_POTI(Parameter_AchsKopplung1, ParamSet.AchsKopplung1,0,255); |
||
403 | CHK_POTI(Parameter_AchsGegenKopplung1,ParamSet.AchsGegenKopplung1,0,255); |
||
404 | CHK_POTI(Parameter_DynamicStability,ParamSet.DynamicStability,0,255); |
||
1 | ingob | 405 | |
690 | killagreg | 406 | Ki = (float) Parameter_I_Factor * 0.0001; |
687 | killagreg | 407 | MAX_GAS = ParamSet.Gas_Max; |
408 | MIN_GAS = ParamSet.Gas_Min; |
||
1 | ingob | 409 | } |
410 | |||
411 | |||
412 | //############################################################################ |
||
413 | // |
||
414 | void MotorRegler(void) |
||
415 | //############################################################################ |
||
416 | { |
||
417 | int motorwert,pd_ergebnis,h,tmp_int; |
||
418 | int GierMischanteil,GasMischanteil; |
||
419 | static long SummeNick=0,SummeRoll=0; |
||
420 | static long sollGier = 0,tmp_long,tmp_long2; |
||
395 | hbuss | 421 | static long IntegralFehlerNick = 0; |
422 | static long IntegralFehlerRoll = 0; |
||
1 | ingob | 423 | static unsigned int RcLostTimer; |
424 | static unsigned char delay_neutral = 0; |
||
425 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
426 | static unsigned int modell_fliegt = 0; |
||
427 | static int hoehenregler = 0; |
||
428 | static char TimerWerteausgabe = 0; |
||
429 | static char NeueKompassRichtungMerken = 0; |
||
395 | hbuss | 430 | static long ausgleichNick, ausgleichRoll; |
1 | ingob | 431 | |
683 | killagreg | 432 | Mittelwert(); |
433 | |||
1 | ingob | 434 | GRN_ON; |
683 | killagreg | 435 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 436 | // Gaswert ermitteln |
683 | killagreg | 437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
438 | GasMischanteil = StickGas; |
||
1 | ingob | 439 | if(GasMischanteil < 0) GasMischanteil = 0; |
683 | killagreg | 440 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 441 | // Emfang schlecht |
683 | killagreg | 442 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 443 | if(SenderOkay < 100) |
444 | { |
||
683 | killagreg | 445 | if(!PcZugriff) |
173 | holgerb | 446 | { |
683 | killagreg | 447 | if(BeepModulation == 0xFFFF) |
448 | { |
||
449 | BeepTime = 15000; // 1.5 seconds |
||
450 | BeepModulation = 0x0C00; |
||
451 | } |
||
173 | holgerb | 452 | } |
683 | killagreg | 453 | if(RcLostTimer) RcLostTimer--; |
454 | else |
||
1 | ingob | 455 | { |
456 | MotorenEin = 0; |
||
457 | Notlandung = 0; |
||
683 | killagreg | 458 | } |
1 | ingob | 459 | ROT_ON; |
460 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
||
461 | { |
||
690 | killagreg | 462 | GasMischanteil = ParamSet.EmergencyGas; |
1 | ingob | 463 | Notlandung = 1; |
690 | killagreg | 464 | PPM_in[ParamSet.ChannelAssignment[CH_NICK]] = 0; |
465 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
||
466 | PPM_in[ParamSet.ChannelAssignment[CH_GIER]] = 0; |
||
173 | holgerb | 467 | } |
1 | ingob | 468 | else MotorenEin = 0; |
469 | } |
||
683 | killagreg | 470 | else |
471 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 472 | // Emfang gut |
683 | killagreg | 473 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 474 | if(SenderOkay > 140) |
475 | { |
||
476 | Notlandung = 0; |
||
690 | killagreg | 477 | RcLostTimer = ParamSet.EmergencyGasDuration * 50; |
1 | ingob | 478 | if(GasMischanteil > 40) |
479 | { |
||
480 | if(modell_fliegt < 0xffff) modell_fliegt++; |
||
481 | } |
||
482 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
||
483 | { |
||
484 | SummeNick = 0; |
||
485 | SummeRoll = 0; |
||
683 | killagreg | 486 | Mess_Integral_Gier = 0; |
1 | ingob | 487 | Mess_Integral_Gier2 = 0; |
488 | } |
||
690 | killagreg | 489 | if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && MotorenEin == 0) |
1 | ingob | 490 | { |
683 | killagreg | 491 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 492 | // auf Nullwerte kalibrieren |
683 | killagreg | 493 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
690 | killagreg | 494 | if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] > 75) // Neutralwerte |
1 | ingob | 495 | { |
496 | if(++delay_neutral > 200) // nicht sofort |
||
497 | { |
||
498 | GRN_OFF; |
||
499 | MotorenEin = 0; |
||
500 | delay_neutral = 0; |
||
501 | modell_fliegt = 0; |
||
690 | killagreg | 502 | if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70 || abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > 70) |
1 | ingob | 503 | { |
304 | ingob | 504 | unsigned char setting=1; |
690 | killagreg | 505 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 1; |
506 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 2; |
||
507 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < 70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 3; |
||
508 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > 70) setting = 4; |
||
509 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < 70) setting = 5; |
||
687 | killagreg | 510 | SetActiveParamSet(setting); // aktiven Datensatz merken |
1 | ingob | 511 | } |
690 | killagreg | 512 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung aktiviert? |
1 | ingob | 513 | { |
514 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
||
683 | killagreg | 515 | } |
687 | killagreg | 516 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
173 | holgerb | 517 | SetNeutral(); |
687 | killagreg | 518 | Piep(GetActiveParamSet()); |
683 | killagreg | 519 | } |
1 | ingob | 520 | } |
683 | killagreg | 521 | else |
690 | killagreg | 522 | if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] < -75) // ACC Neutralwerte speichern |
513 | hbuss | 523 | { |
524 | if(++delay_neutral > 200) // nicht sofort |
||
525 | { |
||
526 | GRN_OFF; |
||
687 | killagreg | 527 | SetParamByte(PID_ACC_NICK,0xFF); // Werte löschen |
513 | hbuss | 528 | MotorenEin = 0; |
529 | delay_neutral = 0; |
||
530 | modell_fliegt = 0; |
||
531 | SetNeutral(); |
||
687 | killagreg | 532 | SetParamByte(PID_ACC_NICK, NeutralAccX / 256); // ACC-NeutralWerte speichern |
533 | SetParamByte(PID_ACC_NICK+1,NeutralAccX % 256); // ACC-NeutralWerte speichern |
||
534 | SetParamByte(PID_ACC_ROLL,NeutralAccY / 256); |
||
535 | SetParamByte(PID_ACC_ROLL+1,NeutralAccY % 256); |
||
536 | SetParamByte(PID_ACC_Z,(int)NeutralAccZ / 256); |
||
537 | SetParamByte(PID_ACC_Z+1,(int)NeutralAccZ % 256); |
||
538 | Piep(GetActiveParamSet()); |
||
683 | killagreg | 539 | } |
513 | hbuss | 540 | } |
1 | ingob | 541 | else delay_neutral = 0; |
542 | } |
||
683 | killagreg | 543 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 544 | // Gas ist unten |
683 | killagreg | 545 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
690 | killagreg | 546 | if(PPM_in[ParamSet.ChannelAssignment[CH_GAS]] < 35-120) |
1 | ingob | 547 | { |
548 | // Starten |
||
690 | killagreg | 549 | if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] < -75) |
1 | ingob | 550 | { |
683 | killagreg | 551 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 552 | // Einschalten |
683 | killagreg | 553 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 554 | if(++delay_einschalten > 200) |
555 | { |
||
556 | delay_einschalten = 200; |
||
557 | modell_fliegt = 1; |
||
558 | MotorenEin = 1; |
||
559 | sollGier = 0; |
||
683 | killagreg | 560 | Mess_Integral_Gier = 0; |
1 | ingob | 561 | Mess_Integral_Gier2 = 0; |
562 | Mess_IntegralNick = 0; |
||
563 | Mess_IntegralRoll = 0; |
||
564 | Mess_IntegralNick2 = IntegralNick; |
||
565 | Mess_IntegralRoll2 = IntegralRoll; |
||
566 | SummeNick = 0; |
||
567 | SummeRoll = 0; |
||
683 | killagreg | 568 | } |
569 | } |
||
1 | ingob | 570 | else delay_einschalten = 0; |
571 | //Auf Neutralwerte setzen |
||
683 | killagreg | 572 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 573 | // Auschalten |
683 | killagreg | 574 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
690 | killagreg | 575 | if(PPM_in[ParamSet.ChannelAssignment[CH_GIER]] > 75) |
1 | ingob | 576 | { |
577 | if(++delay_ausschalten > 200) // nicht sofort |
||
578 | { |
||
579 | MotorenEin = 0; |
||
580 | delay_ausschalten = 200; |
||
581 | modell_fliegt = 0; |
||
683 | killagreg | 582 | } |
1 | ingob | 583 | } |
584 | else delay_ausschalten = 0; |
||
585 | } |
||
586 | } |
||
587 | |||
683 | killagreg | 588 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 589 | // neue Werte von der Funke |
683 | killagreg | 590 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
591 | if(!NewPpmData-- || Notlandung) |
||
1 | ingob | 592 | { |
492 | hbuss | 593 | int tmp_int; |
604 | hbuss | 594 | static int stick_nick,stick_roll; |
1 | ingob | 595 | ParameterZuordnung(); |
690 | killagreg | 596 | StickNick = (StickNick * 3 + PPM_in[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_P) / 4; |
597 | StickNick += PPM_diff[ParamSet.ChannelAssignment[CH_NICK]] * ParamSet.Stick_D; |
||
598 | StickRoll = (StickRoll * 3 + PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_P) / 4; |
||
599 | StickRoll += PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_D; |
||
604 | hbuss | 600 | |
690 | killagreg | 601 | StickGier = -PPM_in[ParamSet.ChannelAssignment[CH_GIER]]; |
602 | StickGas = PPM_in[ParamSet.ChannelAssignment[CH_GAS]] + 120; |
||
595 | hbuss | 603 | |
690 | killagreg | 604 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]) > MaxStickNick) |
605 | MaxStickNick = abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]); else MaxStickNick--; |
||
606 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll) |
||
607 | MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); else MaxStickRoll--; |
||
614 | hbuss | 608 | if(Notlandung) {MaxStickNick = 0; MaxStickRoll = 0;} |
609 | |||
1 | ingob | 610 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
611 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
||
612 | |||
595 | hbuss | 613 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
614 | //+ Digitale Steuerung per DubWise |
||
615 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
492 | hbuss | 616 | #define KEY_VALUE (Parameter_UserParam1 * 4) //(Poti3 * 8) |
683 | killagreg | 617 | if(DubWiseKeys[1]) BeepTime = 10; |
492 | hbuss | 618 | if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; else |
619 | if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; else tmp_int = 0; |
||
620 | ExternStickNick = (ExternStickNick * 7 + tmp_int) / 8; |
||
621 | if(DubWiseKeys[1] & DUB_KEY_LEFT) tmp_int = KEY_VALUE; else |
||
622 | if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0; |
||
623 | ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8; |
||
624 | |||
625 | if(DubWiseKeys[0] & 8) ExternStickGier = 50;else |
||
626 | if(DubWiseKeys[0] & 4) ExternStickGier =-50;else ExternStickGier = 0; |
||
627 | if(DubWiseKeys[0] & 2) ExternHoehenValue++; |
||
628 | if(DubWiseKeys[0] & 16) ExternHoehenValue--; |
||
629 | |||
630 | StickNick += ExternStickNick / 8; |
||
631 | StickRoll += ExternStickRoll / 8; |
||
632 | StickGier += ExternStickGier; |
||
595 | hbuss | 633 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
634 | //+ Analoge Steuerung per Seriell |
||
635 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
636 | if(ExternControl.Config & 0x01 && Parameter_UserParam1 > 128) |
||
637 | { |
||
687 | killagreg | 638 | StickNick += (int) ExternControl.Nick * (int) ParamSet.Stick_P; |
639 | StickRoll += (int) ExternControl.Roll * (int) ParamSet.Stick_P; |
||
595 | hbuss | 640 | StickGier += ExternControl.Gier; |
687 | killagreg | 641 | ExternHoehenValue = (int) ExternControl.Hight * (int)ParamSet.Hoehe_Verstaerkung; |
595 | hbuss | 642 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
643 | } |
||
492 | hbuss | 644 | |
687 | killagreg | 645 | if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
1 | ingob | 646 | if(GyroFaktor < 0) GyroFaktor = 0; |
647 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
||
683 | killagreg | 648 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 649 | // Looping? |
683 | killagreg | 650 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
690 | killagreg | 651 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT) Looping_Links = 1; |
683 | killagreg | 652 | else |
653 | { |
||
395 | hbuss | 654 | { |
690 | killagreg | 655 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Links = 0; |
683 | killagreg | 656 | } |
657 | } |
||
690 | killagreg | 658 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Rechts = 1; |
683 | killagreg | 659 | else |
395 | hbuss | 660 | { |
661 | if(Looping_Rechts) // Hysterese |
||
662 | { |
||
690 | killagreg | 663 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Rechts = 0; |
395 | hbuss | 664 | } |
683 | killagreg | 665 | } |
173 | holgerb | 666 | |
690 | killagreg | 667 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Oben = 1; |
683 | killagreg | 668 | else |
669 | { |
||
395 | hbuss | 670 | if(Looping_Oben) // Hysterese |
671 | { |
||
690 | killagreg | 672 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Oben = 0; |
683 | killagreg | 673 | } |
674 | } |
||
690 | killagreg | 675 | if((PPM_in[ParamSet.ChannelAssignment[CH_NICK]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Unten = 1; |
683 | killagreg | 676 | else |
395 | hbuss | 677 | { |
678 | if(Looping_Unten) // Hysterese |
||
679 | { |
||
690 | killagreg | 680 | if(PPM_in[ParamSet.ChannelAssignment[CH_NICK]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Unten = 0; |
395 | hbuss | 681 | } |
683 | killagreg | 682 | } |
395 | hbuss | 683 | |
684 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
||
685 | if(Looping_Oben || Looping_Unten) {Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
||
686 | } // Ende neue Funken-Werte |
||
687 | |||
683 | killagreg | 688 | if(Looping_Roll) BeepTime = 100; |
395 | hbuss | 689 | if(Looping_Roll || Looping_Nick) |
690 | { |
||
687 | killagreg | 691 | if(GasMischanteil > ParamSet.LoopGasLimit) GasMischanteil = ParamSet.LoopGasLimit; |
173 | holgerb | 692 | } |
693 | |||
683 | killagreg | 694 | |
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
696 | // Bei Empfangsausfall im Flug |
||
697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 698 | if(Notlandung) |
699 | { |
||
700 | StickGier = 0; |
||
701 | StickNick = 0; |
||
702 | StickRoll = 0; |
||
703 | GyroFaktor = 0.1; |
||
704 | IntegralFaktor = 0.005; |
||
173 | holgerb | 705 | Looping_Roll = 0; |
706 | Looping_Nick = 0; |
||
683 | killagreg | 707 | } |
395 | hbuss | 708 | |
709 | |||
683 | killagreg | 710 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 711 | // Integrale auf ACC-Signal abgleichen |
683 | killagreg | 712 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 713 | #define ABGLEICH_ANZAHL 256L |
714 | |||
715 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
||
716 | MittelIntegralRoll += IntegralRoll; |
||
717 | MittelIntegralNick2 += IntegralNick2; |
||
718 | MittelIntegralRoll2 += IntegralRoll2; |
||
719 | |||
720 | if(Looping_Nick || Looping_Roll) |
||
721 | { |
||
722 | IntegralAccNick = 0; |
||
723 | IntegralAccRoll = 0; |
||
724 | MittelIntegralNick = 0; |
||
725 | MittelIntegralRoll = 0; |
||
726 | MittelIntegralNick2 = 0; |
||
727 | MittelIntegralRoll2 = 0; |
||
728 | Mess_IntegralNick2 = Mess_IntegralNick; |
||
729 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
||
730 | ZaehlMessungen = 0; |
||
498 | hbuss | 731 | LageKorrekturNick = 0; |
732 | LageKorrekturRoll = 0; |
||
395 | hbuss | 733 | } |
734 | |||
683 | killagreg | 735 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
498 | hbuss | 736 | if(!Looping_Nick && !Looping_Roll) |
469 | hbuss | 737 | { |
738 | long tmp_long, tmp_long2; |
||
687 | killagreg | 739 | tmp_long = (long)(IntegralNick / ParamSet.GyroAccFaktor - (long)Mittelwert_AccNick); |
740 | tmp_long2 = (long)(IntegralRoll / ParamSet.GyroAccFaktor - (long)Mittelwert_AccRoll); |
||
469 | hbuss | 741 | tmp_long /= 16; |
742 | tmp_long2 /= 16; |
||
623 | hbuss | 743 | if((MaxStickNick > 15) || (MaxStickRoll > 15)) |
614 | hbuss | 744 | { |
745 | tmp_long /= 3; |
||
746 | tmp_long2 /= 3; |
||
747 | } |
||
690 | killagreg | 748 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_GIER]]) > 25) |
623 | hbuss | 749 | { |
750 | tmp_long /= 3; |
||
751 | tmp_long2 /= 3; |
||
752 | } |
||
614 | hbuss | 753 | |
754 | #define AUSGLEICH 32 |
||
469 | hbuss | 755 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
756 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
||
757 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
||
758 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
||
614 | hbuss | 759 | |
469 | hbuss | 760 | Mess_IntegralNick -= tmp_long; |
761 | Mess_IntegralRoll -= tmp_long2; |
||
762 | } |
||
683 | killagreg | 763 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
469 | hbuss | 764 | |
395 | hbuss | 765 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
766 | { |
||
767 | static int cnt = 0; |
||
768 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
||
769 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
||
297 | holgerb | 770 | if(!Looping_Nick && !Looping_Roll) |
173 | holgerb | 771 | { |
395 | hbuss | 772 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
773 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
||
687 | killagreg | 774 | IntegralAccNick = (ParamSet.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
775 | IntegralAccRoll = (ParamSet.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
||
395 | hbuss | 776 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
492 | hbuss | 777 | #define MAX_I 0//(Poti2/10) |
395 | hbuss | 778 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
779 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
||
687 | killagreg | 780 | ausgleichNick = IntegralFehlerNick / ParamSet.GyroAccAbgleich; |
683 | killagreg | 781 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
782 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
||
687 | killagreg | 783 | ausgleichRoll = IntegralFehlerRoll / ParamSet.GyroAccAbgleich; |
614 | hbuss | 784 | |
785 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
||
498 | hbuss | 786 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 787 | |
690 | killagreg | 788 | if((MaxStickNick > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_GIER]]) > 25)) |
614 | hbuss | 789 | { |
790 | LageKorrekturNick /= 2; |
||
791 | LageKorrekturNick /= 2; |
||
792 | } |
||
498 | hbuss | 793 | |
683 | killagreg | 794 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 795 | // Gyro-Drift ermitteln |
683 | killagreg | 796 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 797 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
798 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
||
683 | killagreg | 799 | tmp_long = IntegralNick2 - IntegralNick; |
800 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
||
395 | hbuss | 801 | //DebugOut.Analog[25] = MittelIntegralRoll2 / 26; |
802 | |||
803 | IntegralFehlerNick = tmp_long; |
||
804 | IntegralFehlerRoll = tmp_long2; |
||
805 | Mess_IntegralNick2 -= IntegralFehlerNick; |
||
806 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
||
807 | |||
808 | // IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2; |
||
809 | // IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2; |
||
810 | |||
811 | |||
812 | DebugOut.Analog[17] = IntegralAccNick / 26; |
||
813 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
||
814 | DebugOut.Analog[19] = IntegralFehlerNick;// / 26; |
||
815 | DebugOut.Analog[20] = IntegralFehlerRoll;// / 26; |
||
816 | DebugOut.Analog[21] = MittelIntegralNick / 26; |
||
817 | DebugOut.Analog[22] = MittelIntegralRoll / 26; |
||
469 | hbuss | 818 | //DebugOut.Analog[28] = ausgleichNick; |
395 | hbuss | 819 | DebugOut.Analog[29] = ausgleichRoll; |
498 | hbuss | 820 | DebugOut.Analog[30] = LageKorrekturRoll * 10; |
395 | hbuss | 821 | |
492 | hbuss | 822 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
823 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
||
824 | #define BEWEGUNGS_LIMIT 20000 |
||
395 | hbuss | 825 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
826 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
||
492 | hbuss | 827 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT) |
828 | { |
||
683 | killagreg | 829 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
395 | hbuss | 830 | { |
683 | killagreg | 831 | if(last_n_p) |
395 | hbuss | 832 | { |
683 | killagreg | 833 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
492 | hbuss | 834 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 835 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
498 | hbuss | 836 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
683 | killagreg | 837 | } |
395 | hbuss | 838 | else last_n_p = 1; |
839 | } else last_n_p = 0; |
||
683 | killagreg | 840 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
395 | hbuss | 841 | { |
842 | if(last_n_n) |
||
683 | killagreg | 843 | { |
844 | cnt += labs(IntegralFehlerNick) / FEHLER_LIMIT2; |
||
492 | hbuss | 845 | ausgleichNick = IntegralFehlerNick / 8; |
401 | hbuss | 846 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
498 | hbuss | 847 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
683 | killagreg | 848 | } |
395 | hbuss | 849 | else last_n_n = 1; |
850 | } else last_n_n = 0; |
||
492 | hbuss | 851 | } else cnt = 0; |
690 | killagreg | 852 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
395 | hbuss | 853 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
854 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
||
401 | hbuss | 855 | |
395 | hbuss | 856 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
492 | hbuss | 857 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
858 | |||
498 | hbuss | 859 | ausgleichRoll = 0; |
492 | hbuss | 860 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT) |
861 | { |
||
683 | killagreg | 862 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
395 | hbuss | 863 | { |
683 | killagreg | 864 | if(last_r_p) |
395 | hbuss | 865 | { |
683 | killagreg | 866 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
492 | hbuss | 867 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 868 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
498 | hbuss | 869 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
683 | killagreg | 870 | } |
395 | hbuss | 871 | else last_r_p = 1; |
872 | } else last_r_p = 0; |
||
683 | killagreg | 873 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
395 | hbuss | 874 | { |
683 | killagreg | 875 | if(last_r_n) |
395 | hbuss | 876 | { |
683 | killagreg | 877 | cnt += labs(IntegralFehlerRoll) / FEHLER_LIMIT2; |
492 | hbuss | 878 | ausgleichRoll = IntegralFehlerRoll / 8; |
401 | hbuss | 879 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
498 | hbuss | 880 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
395 | hbuss | 881 | } |
882 | else last_r_n = 1; |
||
883 | } else last_r_n = 0; |
||
683 | killagreg | 884 | } else |
492 | hbuss | 885 | { |
886 | cnt = 0; |
||
683 | killagreg | 887 | } |
614 | hbuss | 888 | |
690 | killagreg | 889 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
395 | hbuss | 890 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
891 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
||
614 | hbuss | 892 | DebugOut.Analog[27] = ausgleichRoll; |
492 | hbuss | 893 | DebugOut.Analog[23] = AdNeutralNick;//10*(AdNeutralNick - StartNeutralNick); |
401 | hbuss | 894 | DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll); |
173 | holgerb | 895 | } |
683 | killagreg | 896 | else |
498 | hbuss | 897 | { |
898 | LageKorrekturRoll = 0; |
||
899 | LageKorrekturNick = 0; |
||
900 | } |
||
595 | hbuss | 901 | |
498 | hbuss | 902 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
683 | killagreg | 903 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
904 | MittelIntegralNick_Alt = MittelIntegralNick; |
||
905 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
||
906 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
395 | hbuss | 907 | IntegralAccNick = 0; |
908 | IntegralAccRoll = 0; |
||
909 | IntegralAccZ = 0; |
||
910 | MittelIntegralNick = 0; |
||
911 | MittelIntegralRoll = 0; |
||
912 | MittelIntegralNick2 = 0; |
||
913 | MittelIntegralRoll2 = 0; |
||
914 | ZaehlMessungen = 0; |
||
915 | } |
||
469 | hbuss | 916 | //DebugOut.Analog[31] = StickRoll / (26*IntegralFaktor); |
395 | hbuss | 917 | |
683 | killagreg | 918 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 919 | // Gieren |
683 | killagreg | 920 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
921 | if(abs(StickGier) > 20) // war 35 |
||
1 | ingob | 922 | { |
690 | killagreg | 923 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) NeueKompassRichtungMerken = 1; |
1 | ingob | 924 | } |
687 | killagreg | 925 | tmp_int = (long) ParamSet.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
926 | tmp_int += (ParamSet.Gier_P * StickGier) / 4; |
||
173 | holgerb | 927 | sollGier = tmp_int; |
683 | killagreg | 928 | Mess_Integral_Gier -= tmp_int; |
395 | hbuss | 929 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
930 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
||
683 | killagreg | 931 | |
932 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 933 | // Kompass |
683 | killagreg | 934 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
694 | killagreg | 935 | if(ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE) |
936 | { |
||
937 | int w,v; |
||
938 | static uint8_t updKompass = 0; |
||
939 | |||
940 | if (!updKompass--) // Aufruf mit ~10 Hz |
||
941 | { |
||
942 | KompassValue = MM3_heading(); |
||
943 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
||
944 | updKompass = 50; |
||
945 | } |
||
946 | |||
947 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
||
948 | v = abs(IntegralRoll /512); |
||
949 | if(v > w) w = v; // grösste Neigung ermitteln |
||
950 | if(w < 35 && NeueKompassRichtungMerken) |
||
951 | { |
||
952 | KompassStartwert = KompassValue; |
||
953 | NeueKompassRichtungMerken = 0; |
||
954 | } |
||
955 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
||
956 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
||
957 | if(w > 0) |
||
683 | killagreg | 958 | { |
694 | killagreg | 959 | Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
960 | } |
||
683 | killagreg | 961 | } |
962 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 963 | |
683 | killagreg | 964 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 965 | // Debugwerte zuordnen |
683 | killagreg | 966 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 967 | if(!TimerWerteausgabe--) |
968 | { |
||
395 | hbuss | 969 | TimerWerteausgabe = 24; |
687 | killagreg | 970 | DebugOut.Analog[0] = IntegralNick / ParamSet.GyroAccFaktor; |
971 | DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFaktor; |
||
1 | ingob | 972 | DebugOut.Analog[2] = Mittelwert_AccNick; |
973 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
||
974 | DebugOut.Analog[4] = MesswertGier; |
||
975 | DebugOut.Analog[5] = HoehenWert; |
||
395 | hbuss | 976 | DebugOut.Analog[6] =(Mess_Integral_Hoch / 512); |
1 | ingob | 977 | DebugOut.Analog[8] = KompassValue; |
297 | holgerb | 978 | DebugOut.Analog[9] = UBat; |
979 | DebugOut.Analog[10] = SenderOkay; |
||
395 | hbuss | 980 | DebugOut.Analog[16] = Mittelwert_AccHoch; |
173 | holgerb | 981 | |
982 | /* DebugOut.Analog[16] = motor_rx[0]; |
||
983 | DebugOut.Analog[17] = motor_rx[1]; |
||
984 | DebugOut.Analog[18] = motor_rx[2]; |
||
985 | DebugOut.Analog[19] = motor_rx[3]; |
||
986 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
||
987 | DebugOut.Analog[20] /= 14; |
||
988 | DebugOut.Analog[21] = motor_rx[4]; |
||
989 | DebugOut.Analog[22] = motor_rx[5]; |
||
990 | DebugOut.Analog[23] = motor_rx[6]; |
||
991 | DebugOut.Analog[24] = motor_rx[7]; |
||
992 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
||
993 | */ |
||
994 | // DebugOut.Analog[9] = MesswertNick; |
||
1 | ingob | 995 | // DebugOut.Analog[9] = SollHoehe; |
996 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
||
997 | // DebugOut.Analog[11] = KompassStartwert; |
||
683 | killagreg | 998 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
687 | killagreg | 999 | // DebugOut.Analog[10] = ParamSet.Gyro_I; |
683 | killagreg | 1000 | // DebugOut.Analog[9] = KompassRichtung; |
1 | ingob | 1001 | // DebugOut.Analog[10] = GasMischanteil; |
1002 | // DebugOut.Analog[3] = HoeheD * 32; |
||
1003 | // DebugOut.Analog[4] = hoehenregler; |
||
1004 | } |
||
1005 | |||
683 | killagreg | 1006 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1007 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
683 | killagreg | 1008 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
604 | hbuss | 1009 | //DebugOut.Analog[26] = MesswertNick; |
1010 | //DebugOut.Analog[28] = MesswertRoll; |
||
1011 | |||
173 | holgerb | 1012 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
1013 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
||
1014 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
||
1015 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
||
623 | hbuss | 1016 | MesswertGier = MesswertGier * (2 * GyroFaktor) + Integral_Gier * IntegralFaktor / 2; |
1 | ingob | 1017 | |
469 | hbuss | 1018 | DebugOut.Analog[25] = IntegralRoll * IntegralFaktor; |
1019 | DebugOut.Analog[31] = StickRoll;// / (26*IntegralFaktor); |
||
604 | hbuss | 1020 | DebugOut.Analog[28] = MesswertRoll; |
469 | hbuss | 1021 | |
1 | ingob | 1022 | // Maximalwerte abfangen |
1023 | #define MAX_SENSOR 2048 |
||
1024 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
||
1025 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
||
1026 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
||
1027 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
||
1028 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
||
1029 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
||
1030 | |||
683 | killagreg | 1031 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1032 | // Höhenregelung |
1033 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
||
683 | killagreg | 1034 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1035 | //OCR0B = 180 - (Poti1 + 120) / 4; |
1036 | //DruckOffsetSetting = OCR0B; |
||
690 | killagreg | 1037 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung |
1 | ingob | 1038 | { |
1039 | int tmp_int; |
||
690 | killagreg | 1040 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) // Regler wird über Schalter gesteuert |
1 | ingob | 1041 | { |
683 | killagreg | 1042 | if(Parameter_MaxHoehe < 50) |
1 | ingob | 1043 | { |
1044 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
||
1045 | HoehenReglerAktiv = 0; |
||
1046 | } |
||
683 | killagreg | 1047 | else |
1 | ingob | 1048 | HoehenReglerAktiv = 1; |
1049 | } |
||
683 | killagreg | 1050 | else |
1 | ingob | 1051 | { |
687 | killagreg | 1052 | SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)ParamSet.Hoehe_Verstaerkung - 20; |
1 | ingob | 1053 | HoehenReglerAktiv = 1; |
1054 | } |
||
1055 | |||
1056 | if(Notlandung) SollHoehe = 0; |
||
1057 | h = HoehenWert; |
||
1058 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
||
1059 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
||
1060 | h = GasMischanteil - h; // vom Gas abziehen |
||
1061 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
||
1062 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
||
1063 | if(tmp_int > 50) tmp_int = 50; |
||
1064 | else if(tmp_int < -50) tmp_int = -50; |
||
1065 | h -= tmp_int; |
||
683 | killagreg | 1066 | hoehenregler = (hoehenregler*15 + h) / 16; |
687 | killagreg | 1067 | if(hoehenregler < ParamSet.Hoehe_MinGas) // nicht unter MIN |
1 | ingob | 1068 | { |
687 | killagreg | 1069 | if(GasMischanteil >= ParamSet.Hoehe_MinGas) hoehenregler = ParamSet.Hoehe_MinGas; |
1070 | if(GasMischanteil < ParamSet.Hoehe_MinGas) hoehenregler = GasMischanteil; |
||
683 | killagreg | 1071 | } |
1 | ingob | 1072 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
1073 | GasMischanteil = hoehenregler; |
||
683 | killagreg | 1074 | } |
1 | ingob | 1075 | } |
595 | hbuss | 1076 | if(GasMischanteil > MAX_GAS - 20) GasMischanteil = MAX_GAS - 20; |
683 | killagreg | 1077 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1078 | // + Mischer und PI-Regler |
683 | killagreg | 1079 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 1080 | DebugOut.Analog[7] = GasMischanteil; |
683 | killagreg | 1081 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1082 | // Gier-Anteil |
683 | killagreg | 1083 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
188 | holgerb | 1084 | #define MUL_G 1.0 |
173 | holgerb | 1085 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
604 | hbuss | 1086 | // GierMischanteil = 0; |
173 | holgerb | 1087 | |
683 | killagreg | 1088 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1089 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
||
1090 | if(GierMischanteil > ((MAX_GAS - GasMischanteil))) GierMischanteil = ((MAX_GAS - GasMischanteil)); |
||
514 | hbuss | 1091 | if(GierMischanteil < -((MAX_GAS - GasMischanteil))) GierMischanteil = -((MAX_GAS - GasMischanteil)); |
513 | hbuss | 1092 | |
188 | holgerb | 1093 | if(GasMischanteil < 20) GierMischanteil = 0; |
683 | killagreg | 1094 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1095 | // Nick-Achse |
683 | killagreg | 1096 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
513 | hbuss | 1097 | DiffNick = MesswertNick - (StickNick - GPS_Nick); // Differenz bestimmen |
498 | hbuss | 1098 | if(IntegralFaktor) SummeNick += IntegralNick * IntegralFaktor - (StickNick - GPS_Nick); // I-Anteil bei Winkelregelung |
683 | killagreg | 1099 | else SummeNick += DiffNick; // I-Anteil bei HH |
1 | ingob | 1100 | if(SummeNick > 16000) SummeNick = 16000; |
1101 | if(SummeNick < -16000) SummeNick = -16000; |
||
683 | killagreg | 1102 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
1 | ingob | 1103 | // Motor Vorn |
499 | hbuss | 1104 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
683 | killagreg | 1105 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1106 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
||
173 | holgerb | 1107 | |
1 | ingob | 1108 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
173 | holgerb | 1109 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1110 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
683 | killagreg | 1111 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1112 | Motor_Vorne = motorwert; |
||
1 | ingob | 1113 | // Motor Heck |
1114 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
||
173 | holgerb | 1115 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1116 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1117 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
683 | killagreg | 1118 | Motor_Hinten = motorwert; |
1119 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 1120 | // Roll-Achse |
683 | killagreg | 1121 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
513 | hbuss | 1122 | DiffRoll = MesswertRoll - (StickRoll - GPS_Roll); // Differenz bestimmen |
498 | hbuss | 1123 | if(IntegralFaktor) SummeRoll += IntegralRoll * IntegralFaktor - (StickRoll - GPS_Roll);// I-Anteil bei Winkelregelung |
1124 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
||
1 | ingob | 1125 | if(SummeRoll > 16000) SummeRoll = 16000; |
1126 | if(SummeRoll < -16000) SummeRoll = -16000; |
||
297 | holgerb | 1127 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
499 | hbuss | 1128 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
683 | killagreg | 1129 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1130 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
||
1 | ingob | 1131 | // Motor Links |
1132 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
||
604 | hbuss | 1133 | #define GRENZE Poti1 |
1134 | |||
173 | holgerb | 1135 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1136 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
1137 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
683 | killagreg | 1138 | Motor_Links = motorwert; |
1 | ingob | 1139 | // Motor Rechts |
1140 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
||
604 | hbuss | 1141 | |
173 | holgerb | 1142 | if ((motorwert < 0)) motorwert = 0; |
1 | ingob | 1143 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
683 | killagreg | 1144 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
1145 | Motor_Rechts = motorwert; |
||
1 | ingob | 1146 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
1147 | } |
||
1148 |