Rev 701 | Rev 706 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
2 | Flight Control |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + 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 | |
703 | killagreg | 69 | |
173 | holgerb | 70 | volatile unsigned int I2CTimeout = 100; |
703 | killagreg | 71 | // gyro readings |
72 | volatile int16_t ReadingPitch, ReadingRoll, ReadingYaw; |
||
73 | // gyro neutral readings |
||
74 | volatile int16_t AdNeutralPitch = 0, AdNeutralRoll = 0, AdNeutralYaw = 0; |
||
75 | volatile int16_t StartNeutralRoll = 0, StartNeutralPitch = 0; |
||
76 | // mean accelerations |
||
77 | volatile int16_t Mean_AccPitch, Mean_AccRoll, Mean_AccTop; |
||
78 | |||
79 | // neutral acceleration readings |
||
80 | volatile int16_t NeutralAccX=0, NeutralAccY=0; |
||
1 | ingob | 81 | volatile float NeutralAccZ = 0; |
82 | |||
703 | killagreg | 83 | // attitude gyro integrals |
84 | volatile int32_t IntegralPitch = 0,IntegralPitch2 = 0; |
||
85 | volatile int32_t IntegralRoll = 0,IntegralRoll2 = 0; |
||
86 | volatile int32_t IntegralYaw = 0; |
||
87 | volatile int32_t Reading_IntegralPitch = 0, Reading_IntegralPitch2 = 0; |
||
88 | volatile int32_t Reading_IntegralRoll = 0, Reading_IntegralRoll2 = 0; |
||
89 | volatile int32_t Reading_IntegralYaw = 0, Reading_IntegralYaw2 = 0; |
||
90 | volatile int32_t MeanIntegralPitch, MeanIntegralPitch2; |
||
91 | volatile int32_t MeanIntegralRoll, MeanIntegralRoll2; |
||
92 | |||
93 | // attitude acceleration integrals |
||
94 | volatile int32_t IntegralAccPitch = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
||
95 | volatile int32_t Reading_Integral_Top = 0; |
||
96 | |||
97 | // compass course |
||
98 | volatile int16_t CompassHeading = 0; |
||
99 | volatile int16_t CompassCourse = 0; |
||
100 | volatile int16_t CompassOffCourse = 0; |
||
101 | |||
102 | // flags |
||
103 | uint8_t EmergencyLanding = 0; |
||
104 | uint8_t HightControlActive = 0; |
||
105 | uint8_t MotorsOn = 0; |
||
106 | |||
107 | int32_t TurnOver180Pitch = 250000L, TurnOver180Roll = 250000L; |
||
108 | |||
701 | killagreg | 109 | float GyroFactor; |
110 | float IntegralFactor; |
||
703 | killagreg | 111 | |
112 | volatile int16_t DiffPitch, DiffRoll; |
||
113 | |||
114 | int16_t Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
||
115 | |||
116 | // setpoints for motors |
||
117 | volatile uint8_t Motor_Front, Motor_Rear, Motor_Right, Motor_Left; |
||
118 | |||
119 | // stick values derived by rc channels readings |
||
701 | killagreg | 120 | int16_t StickPitch = 0, StickRoll = 0, StickYaw = 0, StickGas = 0; |
703 | killagreg | 121 | // stick values derived by uart inputs |
122 | int16_t ExternStickPitch = 0, ExternStickRoll = 0, ExternStickYaw = 0, ExternHightValue = -20; |
||
1 | ingob | 123 | |
701 | killagreg | 124 | int MaxStickPitch = 0, MaxStickRoll = 0; |
1 | ingob | 125 | |
703 | killagreg | 126 | |
127 | int16_t ReadingHight = 0; |
||
128 | int16_t SetPointHight = 0; |
||
129 | |||
130 | int16_t AttitudeCorrectionRoll = 0, AttitudeCorrectionPitch = 0; |
||
131 | |||
132 | float Ki = FACTOR_I; |
||
133 | |||
134 | uint8_t Looping_Pitch = 0, Looping_Roll = 0; |
||
135 | uint8_t Looping_Left = 0, Looping_Right = 0, Looping_Down = 0, Looping_Top = 0; |
||
136 | |||
137 | |||
138 | fc_param_t FCParam = {48,251,16,58,64,150,150,2,10,0,0,0,0,0,0,0,0,100,70,0,0,100}; |
||
139 | |||
140 | |||
141 | /************************************************************************/ |
||
142 | /* Creates numbeeps beeps at the speaker */ |
||
143 | /************************************************************************/ |
||
144 | void Beep(uint8_t numbeeps) |
||
1 | ingob | 145 | { |
703 | killagreg | 146 | while(numbeeps--) |
147 | { |
||
148 | if(MotorsOn) return; //auf keinen Fall im Flug! |
||
149 | BeepTime = 100; // 0.1 second |
||
150 | Delay_ms(250); // blocks 250 ms as pause to next beep, |
||
151 | // this will block the flight control loop, |
||
152 | // therefore do not use this funktion if motors are running |
||
153 | } |
||
1 | ingob | 154 | } |
155 | |||
703 | killagreg | 156 | /************************************************************************/ |
157 | /* Neutral Readings */ |
||
158 | /************************************************************************/ |
||
1 | ingob | 159 | void SetNeutral(void) |
160 | { |
||
683 | killagreg | 161 | NeutralAccX = 0; |
1 | ingob | 162 | NeutralAccY = 0; |
163 | NeutralAccZ = 0; |
||
701 | killagreg | 164 | AdNeutralPitch = 0; |
683 | killagreg | 165 | AdNeutralRoll = 0; |
701 | killagreg | 166 | AdNeutralYaw = 0; |
703 | killagreg | 167 | FCParam.AchsKopplung1 = 0; |
168 | FCParam.AchsGegenKopplung1 = 0; |
||
701 | killagreg | 169 | CalibMean(); |
395 | hbuss | 170 | Delay_ms_Mess(100); |
701 | killagreg | 171 | CalibMean(); |
703 | killagreg | 172 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Hight Control activated? |
173 | { |
||
174 | if((ReadingAirPressure > 950) || (ReadingAirPressure < 750)) SearchAirPressureOffset(); |
||
175 | } |
||
176 | AdNeutralPitch = AdValueGyrPitch; |
||
177 | AdNeutralRoll = AdValueGyrRoll; |
||
178 | AdNeutralYaw = AdValueGyrYaw; |
||
179 | StartNeutralRoll = AdNeutralRoll; |
||
180 | StartNeutralPitch = AdNeutralPitch; |
||
701 | killagreg | 181 | if(GetParamByte(PID_ACC_PITCH) > 4) |
513 | hbuss | 182 | { |
703 | killagreg | 183 | NeutralAccY = abs(Mean_AccRoll) / ACC_AMPLIFY; |
184 | NeutralAccX = abs(Mean_AccPitch) / ACC_AMPLIFY; |
||
185 | NeutralAccZ = Current_AccZ; |
||
513 | hbuss | 186 | } |
683 | killagreg | 187 | else |
703 | killagreg | 188 | { |
189 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_PITCH); |
||
190 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
||
191 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_Z); |
||
513 | hbuss | 192 | } |
701 | killagreg | 193 | Reading_IntegralPitch = 0; |
194 | Reading_IntegralPitch2 = 0; |
||
195 | Reading_IntegralRoll = 0; |
||
196 | Reading_IntegralRoll2 = 0; |
||
703 | killagreg | 197 | Reading_IntegralYaw = 0; |
701 | killagreg | 198 | ReadingPitch = 0; |
199 | ReadingRoll = 0; |
||
200 | ReadingYaw = 0; |
||
201 | StartAirPressure = AirPressure; |
||
703 | killagreg | 202 | HightD = 0; |
701 | killagreg | 203 | Reading_Integral_Top = 0; |
204 | CompassCourse = CompassHeading; |
||
1 | ingob | 205 | GPS_Neutral(); |
683 | killagreg | 206 | BeepTime = 50; |
703 | killagreg | 207 | TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L; |
208 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
||
701 | killagreg | 209 | ExternHightValue = 0; |
1 | ingob | 210 | } |
211 | |||
703 | killagreg | 212 | /************************************************************************/ |
213 | /* Averaging Measurement Readings */ |
||
214 | /************************************************************************/ |
||
701 | killagreg | 215 | void Mean(void) |
683 | killagreg | 216 | { |
701 | killagreg | 217 | static int32_t tmpl,tmpl2; |
401 | hbuss | 218 | |
703 | killagreg | 219 | // Get offset corrected gyro readings |
220 | ReadingYaw = AdNeutralYaw - AdValueGyrYaw; |
||
221 | ReadingRoll = AdValueGyrRoll - AdNeutralRoll; |
||
222 | ReadingPitch = AdValueGyrPitch - AdNeutralPitch; |
||
604 | hbuss | 223 | |
703 | killagreg | 224 | DebugOut.Analog[26] = ReadingPitch; |
225 | DebugOut.Analog[28] = ReadingRoll; |
||
226 | |||
227 | // Acceleration Sensor |
||
228 | Mean_AccPitch = ((int32_t)Mean_AccPitch * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccPitch))) / 2L; |
||
229 | Mean_AccRoll = ((int32_t)Mean_AccRoll * 1 + ((ACC_AMPLIFY * (int32_t)AdValueAccRoll))) / 2L; |
||
230 | Mean_AccTop = ((int32_t)Mean_AccTop * 1 + ((int32_t)AdValueAccTop)) / 2L; |
||
231 | |||
701 | killagreg | 232 | IntegralAccPitch += ACC_AMPLIFY * AdValueAccPitch; |
703 | killagreg | 233 | IntegralAccRoll += ACC_AMPLIFY * AdValueAccRoll; |
234 | IntegralAccZ += Current_AccZ - NeutralAccZ; |
||
235 | |||
236 | // Yaw |
||
237 | Reading_IntegralYaw += ReadingYaw; |
||
238 | Reading_IntegralYaw2 += ReadingYaw; |
||
239 | |||
240 | // Coupling fraction |
||
241 | if(!Looping_Pitch && !Looping_Roll && (ParamSet.GlobalConfig & CFG_AXIS_COUPLING_ACTIVE)) |
||
242 | { |
||
243 | tmpl = Reading_IntegralPitch / 4096L; |
||
244 | tmpl *= ReadingYaw; |
||
245 | tmpl *= FCParam.AchsKopplung1; //125 |
||
246 | tmpl /= 2048L; |
||
247 | tmpl2 = Reading_IntegralRoll / 4096L; |
||
248 | tmpl2 *= ReadingYaw; |
||
249 | tmpl2 *= FCParam.AchsKopplung1; |
||
250 | tmpl2 /= 2048L; |
||
251 | } |
||
252 | else tmpl = tmpl2 = 0; |
||
253 | // Roll |
||
254 | ReadingRoll += tmpl; |
||
255 | ReadingRoll += (tmpl2 * FCParam.AchsGegenKopplung1) / 512L; //109 |
||
256 | Reading_IntegralRoll2 += ReadingRoll; |
||
257 | Reading_IntegralRoll += ReadingRoll - AttitudeCorrectionRoll; |
||
258 | if(Reading_IntegralRoll > TurnOver180Roll) |
||
259 | { |
||
260 | Reading_IntegralRoll = -(TurnOver180Roll - 10000L); |
||
261 | Reading_IntegralRoll2 = Reading_IntegralRoll; |
||
262 | } |
||
263 | if(Reading_IntegralRoll < -TurnOver180Roll) |
||
264 | { |
||
265 | Reading_IntegralRoll = (TurnOver180Roll - 10000L); |
||
266 | Reading_IntegralRoll2 = Reading_IntegralRoll; |
||
267 | } |
||
268 | if(AdValueGyrRoll < 15) ReadingRoll = -1000; |
||
269 | if(AdValueGyrRoll < 7) ReadingRoll = -2000; |
||
270 | if(BoardRelease == 10) |
||
271 | { |
||
272 | if(AdValueGyrRoll > 1010) ReadingRoll = +1000; |
||
273 | if(AdValueGyrRoll > 1017) ReadingRoll = +2000; |
||
274 | } |
||
275 | else |
||
276 | { |
||
277 | if(AdValueGyrRoll > 2020) ReadingRoll = +1000; |
||
278 | if(AdValueGyrRoll > 2034) ReadingRoll = +2000; |
||
279 | } |
||
280 | // Pitch |
||
281 | ReadingPitch -= tmpl2; |
||
282 | ReadingPitch -= (tmpl*FCParam.AchsGegenKopplung1) / 512L; |
||
283 | Reading_IntegralPitch2 += ReadingPitch; |
||
284 | Reading_IntegralPitch += ReadingPitch - AttitudeCorrectionPitch; |
||
285 | if(Reading_IntegralPitch > TurnOver180Pitch) |
||
286 | { |
||
287 | Reading_IntegralPitch = -(TurnOver180Pitch - 10000L); |
||
288 | Reading_IntegralPitch2 = Reading_IntegralPitch; |
||
289 | } |
||
290 | if(Reading_IntegralPitch < -TurnOver180Pitch) |
||
291 | { |
||
292 | Reading_IntegralPitch = (TurnOver180Pitch - 10000L); |
||
293 | Reading_IntegralPitch2 = Reading_IntegralPitch; |
||
294 | } |
||
295 | if(AdValueGyrPitch < 15) ReadingPitch = -1000; |
||
296 | if(AdValueGyrPitch < 7) ReadingPitch = -2000; |
||
297 | if(BoardRelease == 10) |
||
298 | { |
||
299 | if(AdValueGyrPitch > 1010) ReadingPitch = +1000; |
||
300 | if(AdValueGyrPitch > 1017) ReadingPitch = +2000; |
||
301 | } |
||
302 | else |
||
303 | { |
||
304 | if(AdValueGyrPitch > 2020) ReadingPitch = +1000; |
||
305 | if(AdValueGyrPitch > 2034) ReadingPitch = +2000; |
||
306 | } |
||
307 | |||
308 | // start ADC |
||
683 | killagreg | 309 | ADC_Enable(); |
395 | hbuss | 310 | |
703 | killagreg | 311 | IntegralYaw = Reading_IntegralYaw; |
701 | killagreg | 312 | IntegralPitch = Reading_IntegralPitch; |
313 | IntegralRoll = Reading_IntegralRoll; |
||
314 | IntegralPitch2 = Reading_IntegralPitch2; |
||
315 | IntegralRoll2 = Reading_IntegralRoll2; |
||
1 | ingob | 316 | |
703 | killagreg | 317 | if(ParamSet.GlobalConfig & CFG_ROTARY_RATE_LIMITER && !Looping_Pitch && !Looping_Roll) |
318 | { |
||
319 | if(ReadingPitch > 200) ReadingPitch += 4 * (ReadingPitch - 200); |
||
320 | else if(ReadingPitch < -200) ReadingPitch += 4 * (ReadingPitch + 200); |
||
321 | if(ReadingRoll > 200) ReadingRoll += 4 * (ReadingRoll - 200); |
||
322 | else if(ReadingRoll < -200) ReadingRoll += 4 * (ReadingRoll + 200); |
||
323 | } |
||
324 | //update poti values by rc-signals (why not +127?) |
||
690 | killagreg | 325 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
326 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
||
327 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
||
328 | if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--; |
||
703 | killagreg | 329 | //limit poti values |
1 | ingob | 330 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
331 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
332 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
333 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
334 | } |
||
335 | |||
703 | killagreg | 336 | /************************************************************************/ |
337 | /* Averaging Measurement Readings for Calibration */ |
||
338 | /************************************************************************/ |
||
701 | killagreg | 339 | void CalibMean(void) |
683 | killagreg | 340 | { |
703 | killagreg | 341 | // stop ADC to avoid changing values during calculation |
683 | killagreg | 342 | ADC_Disable(); |
703 | killagreg | 343 | |
701 | killagreg | 344 | ReadingPitch = AdValueGyrPitch; |
345 | ReadingRoll = AdValueGyrRoll; |
||
346 | ReadingYaw = AdValueGyrYaw; |
||
703 | killagreg | 347 | |
348 | Mean_AccPitch = ACC_AMPLIFY * (int32_t)AdValueAccPitch; |
||
349 | Mean_AccRoll = ACC_AMPLIFY * (int32_t)AdValueAccRoll; |
||
350 | Mean_AccTop = (int32_t)AdValueAccTop; |
||
351 | // start ADC |
||
683 | killagreg | 352 | ADC_Enable(); |
703 | killagreg | 353 | //update poti values by rc-signals (why not +127?) |
690 | killagreg | 354 | if(Poti1 < PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[ParamSet.ChannelAssignment[CH_POTI1]] + 110 && Poti1) Poti1--; |
355 | if(Poti2 < PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[ParamSet.ChannelAssignment[CH_POTI2]] + 110 && Poti2) Poti2--; |
||
356 | if(Poti3 < PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[ParamSet.ChannelAssignment[CH_POTI3]] + 110 && Poti3) Poti3--; |
||
357 | if(Poti4 < PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[ParamSet.ChannelAssignment[CH_POTI4]] + 110 && Poti4) Poti4--; |
||
703 | killagreg | 358 | //limit poti values |
1 | ingob | 359 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
360 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
361 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
362 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
395 | hbuss | 363 | |
703 | killagreg | 364 | TurnOver180Pitch = (int32_t) ParamSet.AngleTurnOverPitch * 2500L; |
365 | TurnOver180Roll = (int32_t) ParamSet.AngleTurnOverRoll * 2500L; |
||
1 | ingob | 366 | } |
367 | |||
703 | killagreg | 368 | /************************************************************************/ |
369 | /* Transmit Motor Data via I2C */ |
||
370 | /************************************************************************/ |
||
1 | ingob | 371 | void SendMotorData(void) |
683 | killagreg | 372 | { |
701 | killagreg | 373 | if(MOTOR_OFF || !MotorsOn) |
703 | killagreg | 374 | { |
701 | killagreg | 375 | Motor_Rear = 0; |
376 | Motor_Front = 0; |
||
377 | Motor_Right = 0; |
||
378 | Motor_Left = 0; |
||
379 | if(MotorTest[0]) Motor_Front = MotorTest[0]; |
||
380 | if(MotorTest[1]) Motor_Rear = MotorTest[1]; |
||
381 | if(MotorTest[2]) Motor_Left = MotorTest[2]; |
||
382 | if(MotorTest[3]) Motor_Right = MotorTest[3]; |
||
703 | killagreg | 383 | } |
1 | ingob | 384 | |
701 | killagreg | 385 | DebugOut.Analog[12] = Motor_Front; |
386 | DebugOut.Analog[13] = Motor_Rear; |
||
387 | DebugOut.Analog[14] = Motor_Left; |
||
388 | DebugOut.Analog[15] = Motor_Right; |
||
1 | ingob | 389 | |
390 | //Start I2C Interrupt Mode |
||
391 | twi_state = 0; |
||
392 | motor = 0; |
||
683 | killagreg | 393 | i2c_start(); |
1 | ingob | 394 | } |
395 | |||
396 | |||
397 | |||
703 | killagreg | 398 | /************************************************************************/ |
399 | /* Maps the parameter to poti values */ |
||
400 | /************************************************************************/ |
||
401 | void ParameterMapping(void) |
||
1 | ingob | 402 | { |
403 | |||
404 | #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;} |
||
703 | killagreg | 405 | CHK_POTI(FCParam.MaxHight,ParamSet.MaxHight,0,255); |
406 | CHK_POTI(FCParam.AirPressure_D,ParamSet.AirPressure_D,0,100); |
||
407 | CHK_POTI(FCParam.Hight_P,ParamSet.Hight_P,0,100); |
||
408 | CHK_POTI(FCParam.Hight_ACC_Effect,ParamSet.Hight_ACC_Effect,0,255); |
||
409 | CHK_POTI(FCParam.CompassYawEffect,ParamSet.CompassYawEffect,0,255); |
||
410 | CHK_POTI(FCParam.Gyro_P,ParamSet.Gyro_P,10,255); |
||
411 | CHK_POTI(FCParam.Gyro_I,ParamSet.Gyro_I,0,255); |
||
412 | CHK_POTI(FCParam.I_Factor,ParamSet.I_Factor,0,255); |
||
413 | CHK_POTI(FCParam.UserParam1,ParamSet.UserParam1,0,255); |
||
414 | CHK_POTI(FCParam.UserParam2,ParamSet.UserParam2,0,255); |
||
415 | CHK_POTI(FCParam.UserParam3,ParamSet.UserParam3,0,255); |
||
416 | CHK_POTI(FCParam.UserParam4,ParamSet.UserParam4,0,255); |
||
417 | CHK_POTI(FCParam.UserParam5,ParamSet.UserParam5,0,255); |
||
418 | CHK_POTI(FCParam.UserParam6,ParamSet.UserParam6,0,255); |
||
419 | CHK_POTI(FCParam.UserParam7,ParamSet.UserParam7,0,255); |
||
420 | CHK_POTI(FCParam.UserParam8,ParamSet.UserParam8,0,255); |
||
421 | CHK_POTI(FCParam.ServoPitchControl,ParamSet.ServoPitchControl,0,255); |
||
422 | CHK_POTI(FCParam.LoopGasLimit,ParamSet.LoopGasLimit,0,255); |
||
423 | CHK_POTI(FCParam.AchsKopplung1, ParamSet.AchsKopplung1,0,255); |
||
424 | CHK_POTI(FCParam.AchsGegenKopplung1,ParamSet.AchsGegenKopplung1,0,255); |
||
425 | CHK_POTI(FCParam.DynamicStability,ParamSet.DynamicStability,0,255); |
||
1 | ingob | 426 | |
703 | killagreg | 427 | Ki = (float) FCParam.I_Factor * FACTOR_I; |
1 | ingob | 428 | } |
429 | |||
430 | |||
431 | //############################################################################ |
||
432 | // |
||
433 | void MotorRegler(void) |
||
434 | //############################################################################ |
||
435 | { |
||
701 | killagreg | 436 | int MotorValue, pd_ergebnis, h, tmp_int; |
437 | int YawMixingFraction, GasMixingFraction; |
||
438 | static long SumPitch = 0, SumRoll = 0; |
||
439 | static long SetPointYaw = 0, tmp_long, tmp_long2; |
||
440 | static long IntegralErrorPitch = 0; |
||
441 | static long IntegralErrorRoll = 0; |
||
1 | ingob | 442 | static unsigned int RcLostTimer; |
443 | static unsigned char delay_neutral = 0; |
||
444 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
445 | static unsigned int modell_fliegt = 0; |
||
446 | static int hoehenregler = 0; |
||
701 | killagreg | 447 | static char TimerDebugOut = 0; |
448 | static char StoreNewCompassCourse = 0; |
||
449 | static long CorrectionPitch, CorrectionRoll; |
||
1 | ingob | 450 | |
701 | killagreg | 451 | Mean(); |
683 | killagreg | 452 | |
1 | ingob | 453 | GRN_ON; |
683 | killagreg | 454 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 455 | // Gaswert ermitteln |
683 | killagreg | 456 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 457 | GasMixingFraction = StickGas; |
458 | if(GasMixingFraction < 0) GasMixingFraction = 0; |
||
683 | killagreg | 459 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 460 | // Emfang schlecht |
683 | killagreg | 461 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 462 | if(SenderOkay < 100) |
463 | { |
||
683 | killagreg | 464 | if(!PcZugriff) |
173 | holgerb | 465 | { |
683 | killagreg | 466 | if(BeepModulation == 0xFFFF) |
467 | { |
||
468 | BeepTime = 15000; // 1.5 seconds |
||
469 | BeepModulation = 0x0C00; |
||
470 | } |
||
173 | holgerb | 471 | } |
683 | killagreg | 472 | if(RcLostTimer) RcLostTimer--; |
473 | else |
||
1 | ingob | 474 | { |
701 | killagreg | 475 | MotorsOn = 0; |
476 | EmergencyLanding = 0; |
||
683 | killagreg | 477 | } |
1 | ingob | 478 | ROT_ON; |
479 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
||
480 | { |
||
701 | killagreg | 481 | GasMixingFraction = ParamSet.EmergencyGas; |
482 | EmergencyLanding = 1; |
||
483 | PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] = 0; |
||
690 | killagreg | 484 | PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] = 0; |
701 | killagreg | 485 | PPM_in[ParamSet.ChannelAssignment[CH_YAW]] = 0; |
173 | holgerb | 486 | } |
701 | killagreg | 487 | else MotorsOn = 0; |
1 | ingob | 488 | } |
683 | killagreg | 489 | else |
490 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 491 | // Emfang gut |
683 | killagreg | 492 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 493 | if(SenderOkay > 140) |
494 | { |
||
701 | killagreg | 495 | EmergencyLanding = 0; |
690 | killagreg | 496 | RcLostTimer = ParamSet.EmergencyGasDuration * 50; |
701 | killagreg | 497 | if(GasMixingFraction > 40) |
1 | ingob | 498 | { |
499 | if(modell_fliegt < 0xffff) modell_fliegt++; |
||
500 | } |
||
701 | killagreg | 501 | if((modell_fliegt < 200) || (GasMixingFraction < 40)) |
1 | ingob | 502 | { |
701 | killagreg | 503 | SumPitch = 0; |
504 | SumRoll = 0; |
||
703 | killagreg | 505 | Reading_IntegralYaw = 0; |
506 | Reading_IntegralYaw2 = 0; |
||
1 | ingob | 507 | } |
701 | killagreg | 508 | if((PPM_in[ParamSet.ChannelAssignment[CH_GAS]] > 80) && MotorsOn == 0) |
1 | ingob | 509 | { |
683 | killagreg | 510 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 511 | // auf Nullwerte kalibrieren |
683 | killagreg | 512 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 513 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) // Neutralwerte |
1 | ingob | 514 | { |
515 | if(++delay_neutral > 200) // nicht sofort |
||
516 | { |
||
517 | GRN_OFF; |
||
701 | killagreg | 518 | MotorsOn = 0; |
1 | ingob | 519 | delay_neutral = 0; |
520 | modell_fliegt = 0; |
||
701 | killagreg | 521 | if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70 || abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > 70) |
1 | ingob | 522 | { |
304 | ingob | 523 | unsigned char setting=1; |
701 | killagreg | 524 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < 70) setting = 1; |
525 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 2; |
||
526 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < 70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 3; |
||
527 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > 70) setting = 4; |
||
528 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] <-70 && PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < 70) setting = 5; |
||
687 | killagreg | 529 | SetActiveParamSet(setting); // aktiven Datensatz merken |
1 | ingob | 530 | } |
690 | killagreg | 531 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung aktiviert? |
1 | ingob | 532 | { |
701 | killagreg | 533 | if((ReadingAirPressure > 950) || (ReadingAirPressure < 750)) SearchAirPressureOffset(); |
683 | killagreg | 534 | } |
687 | killagreg | 535 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
173 | holgerb | 536 | SetNeutral(); |
703 | killagreg | 537 | Beep(GetActiveParamSet()); |
683 | killagreg | 538 | } |
1 | ingob | 539 | } |
683 | killagreg | 540 | else |
701 | killagreg | 541 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) // ACC Neutralwerte speichern |
513 | hbuss | 542 | { |
543 | if(++delay_neutral > 200) // nicht sofort |
||
544 | { |
||
545 | GRN_OFF; |
||
703 | killagreg | 546 | SetParamWord(PID_ACC_PITCH,0xFFFF); // Werte löschen |
701 | killagreg | 547 | MotorsOn = 0; |
513 | hbuss | 548 | delay_neutral = 0; |
549 | modell_fliegt = 0; |
||
550 | SetNeutral(); |
||
703 | killagreg | 551 | // ACC-NeutralWerte speichern |
552 | SetParamWord(PID_ACC_PITCH, (uint16_t)NeutralAccX); |
||
553 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
||
554 | SetParamWord(PID_ACC_Z, (uint16_t)NeutralAccZ); |
||
555 | Beep(GetActiveParamSet()); |
||
683 | killagreg | 556 | } |
513 | hbuss | 557 | } |
1 | ingob | 558 | else delay_neutral = 0; |
559 | } |
||
683 | killagreg | 560 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 561 | // Gas ist unten |
683 | killagreg | 562 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
690 | killagreg | 563 | if(PPM_in[ParamSet.ChannelAssignment[CH_GAS]] < 35-120) |
1 | ingob | 564 | { |
565 | // Starten |
||
701 | killagreg | 566 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] < -75) |
1 | ingob | 567 | { |
683 | killagreg | 568 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 569 | // Einschalten |
683 | killagreg | 570 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 571 | if(++delay_einschalten > 200) |
572 | { |
||
573 | delay_einschalten = 200; |
||
574 | modell_fliegt = 1; |
||
701 | killagreg | 575 | MotorsOn = 1; |
576 | SetPointYaw = 0; |
||
703 | killagreg | 577 | Reading_IntegralYaw = 0; |
578 | Reading_IntegralYaw2 = 0; |
||
701 | killagreg | 579 | Reading_IntegralPitch = 0; |
580 | Reading_IntegralRoll = 0; |
||
581 | Reading_IntegralPitch2 = IntegralPitch; |
||
582 | Reading_IntegralRoll2 = IntegralRoll; |
||
583 | SumPitch = 0; |
||
584 | SumRoll = 0; |
||
683 | killagreg | 585 | } |
586 | } |
||
1 | ingob | 587 | else delay_einschalten = 0; |
588 | //Auf Neutralwerte setzen |
||
683 | killagreg | 589 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 590 | // Auschalten |
683 | killagreg | 591 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 592 | if(PPM_in[ParamSet.ChannelAssignment[CH_YAW]] > 75) |
1 | ingob | 593 | { |
594 | if(++delay_ausschalten > 200) // nicht sofort |
||
595 | { |
||
701 | killagreg | 596 | MotorsOn = 0; |
1 | ingob | 597 | delay_ausschalten = 200; |
598 | modell_fliegt = 0; |
||
683 | killagreg | 599 | } |
1 | ingob | 600 | } |
601 | else delay_ausschalten = 0; |
||
602 | } |
||
603 | } |
||
604 | |||
683 | killagreg | 605 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 606 | // neue Werte von der Funke |
683 | killagreg | 607 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 608 | if(!NewPpmData-- || EmergencyLanding) |
1 | ingob | 609 | { |
492 | hbuss | 610 | int tmp_int; |
703 | killagreg | 611 | ParameterMapping(); |
701 | killagreg | 612 | StickPitch = (StickPitch * 3 + PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_P) / 4; |
613 | StickPitch += PPM_diff[ParamSet.ChannelAssignment[CH_PITCH]] * ParamSet.Stick_D; |
||
690 | killagreg | 614 | StickRoll = (StickRoll * 3 + PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_P) / 4; |
615 | StickRoll += PPM_diff[ParamSet.ChannelAssignment[CH_ROLL]] * ParamSet.Stick_D; |
||
604 | hbuss | 616 | |
701 | killagreg | 617 | StickYaw = -PPM_in[ParamSet.ChannelAssignment[CH_YAW]]; |
690 | killagreg | 618 | StickGas = PPM_in[ParamSet.ChannelAssignment[CH_GAS]] + 120; |
595 | hbuss | 619 | |
701 | killagreg | 620 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]) > MaxStickPitch) |
621 | MaxStickPitch = abs(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]]); else MaxStickPitch--; |
||
690 | killagreg | 622 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) > MaxStickRoll) |
623 | MaxStickRoll = abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]); else MaxStickRoll--; |
||
701 | killagreg | 624 | if(EmergencyLanding) {MaxStickPitch = 0; MaxStickRoll = 0;} |
614 | hbuss | 625 | |
703 | killagreg | 626 | GyroFactor = ((float)FCParam.Gyro_P + 10.0) / 256.0; |
627 | IntegralFactor = ((float) FCParam.Gyro_I) / 44000; |
||
1 | ingob | 628 | |
595 | hbuss | 629 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
630 | //+ Digitale Steuerung per DubWise |
||
631 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
703 | killagreg | 632 | #define KEY_VALUE (FCParam.UserParam1 * 4) //(Poti3 * 8) |
683 | killagreg | 633 | if(DubWiseKeys[1]) BeepTime = 10; |
492 | hbuss | 634 | if(DubWiseKeys[1] & DUB_KEY_UP) tmp_int = KEY_VALUE; else |
635 | if(DubWiseKeys[1] & DUB_KEY_DOWN) tmp_int = -KEY_VALUE; else tmp_int = 0; |
||
701 | killagreg | 636 | ExternStickPitch= (ExternStickPitch* 7 + tmp_int) / 8; |
492 | hbuss | 637 | if(DubWiseKeys[1] & DUB_KEY_LEFT) tmp_int = KEY_VALUE; else |
638 | if(DubWiseKeys[1] & DUB_KEY_RIGHT) tmp_int = -KEY_VALUE; else tmp_int = 0; |
||
639 | ExternStickRoll = (ExternStickRoll * 7 + tmp_int) / 8; |
||
640 | |||
701 | killagreg | 641 | if(DubWiseKeys[0] & 8) ExternStickYaw = 50;else |
642 | if(DubWiseKeys[0] & 4) ExternStickYaw =-50;else ExternStickYaw = 0; |
||
643 | if(DubWiseKeys[0] & 2) ExternHightValue++; |
||
644 | if(DubWiseKeys[0] & 16) ExternHightValue--; |
||
492 | hbuss | 645 | |
701 | killagreg | 646 | StickPitch += ExternStickPitch/ 8; |
492 | hbuss | 647 | StickRoll += ExternStickRoll / 8; |
701 | killagreg | 648 | StickYaw += ExternStickYaw; |
595 | hbuss | 649 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
650 | //+ Analoge Steuerung per Seriell |
||
651 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
703 | killagreg | 652 | if(ExternControl.Config & 0x01 && FCParam.UserParam1 > 128) |
595 | hbuss | 653 | { |
701 | killagreg | 654 | StickPitch += (int) ExternControl.Pitch * (int) ParamSet.Stick_P; |
687 | killagreg | 655 | StickRoll += (int) ExternControl.Roll * (int) ParamSet.Stick_P; |
701 | killagreg | 656 | StickYaw += ExternControl.Yaw; |
657 | ExternHightValue = (int) ExternControl.Hight * (int)ParamSet.Hight_Gain; |
||
595 | hbuss | 658 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
659 | } |
||
492 | hbuss | 660 | |
701 | killagreg | 661 | if(ParamSet.GlobalConfig & CFG_HEADING_HOLD) IntegralFactor = 0; |
662 | if(GyroFactor < 0) GyroFactor = 0; |
||
663 | if(IntegralFactor < 0) IntegralFactor = 0; |
||
683 | killagreg | 664 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
173 | holgerb | 665 | // Looping? |
683 | killagreg | 666 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 667 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_LEFT) Looping_Left = 1; |
683 | killagreg | 668 | else |
669 | { |
||
395 | hbuss | 670 | { |
701 | killagreg | 671 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Left = 0; |
683 | killagreg | 672 | } |
673 | } |
||
701 | killagreg | 674 | if((PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_RIGHT) Looping_Right = 1; |
683 | killagreg | 675 | else |
395 | hbuss | 676 | { |
701 | killagreg | 677 | if(Looping_Right) // Hysterese |
395 | hbuss | 678 | { |
701 | killagreg | 679 | if(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Right = 0; |
395 | hbuss | 680 | } |
683 | killagreg | 681 | } |
173 | holgerb | 682 | |
701 | killagreg | 683 | if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_UP) Looping_Top = 1; |
683 | killagreg | 684 | else |
685 | { |
||
701 | killagreg | 686 | if(Looping_Top) // Hysterese |
395 | hbuss | 687 | { |
701 | killagreg | 688 | if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < (ParamSet.LoopThreshold - ParamSet.LoopHysteresis))) Looping_Top = 0; |
683 | killagreg | 689 | } |
690 | } |
||
701 | killagreg | 691 | if((PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] < -ParamSet.LoopThreshold) && ParamSet.LoopConfig & CFG_LOOP_DOWN) Looping_Down = 1; |
683 | killagreg | 692 | else |
395 | hbuss | 693 | { |
701 | killagreg | 694 | if(Looping_Down) // Hysterese |
395 | hbuss | 695 | { |
701 | killagreg | 696 | if(PPM_in[ParamSet.ChannelAssignment[CH_PITCH]] > -(ParamSet.LoopThreshold - ParamSet.LoopHysteresis)) Looping_Down = 0; |
395 | hbuss | 697 | } |
683 | killagreg | 698 | } |
395 | hbuss | 699 | |
701 | killagreg | 700 | if(Looping_Left || Looping_Right) Looping_Roll = 1; else Looping_Roll = 0; |
701 | if(Looping_Top || Looping_Down) {Looping_Pitch = 1; Looping_Roll = 0; Looping_Left = 0; Looping_Right = 0;} else Looping_Pitch = 0; |
||
395 | hbuss | 702 | } // Ende neue Funken-Werte |
703 | |||
683 | killagreg | 704 | if(Looping_Roll) BeepTime = 100; |
701 | killagreg | 705 | if(Looping_Roll || Looping_Pitch) |
395 | hbuss | 706 | { |
701 | killagreg | 707 | if(GasMixingFraction > ParamSet.LoopGasLimit) GasMixingFraction = ParamSet.LoopGasLimit; |
173 | holgerb | 708 | } |
709 | |||
683 | killagreg | 710 | |
711 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
712 | // Bei Empfangsausfall im Flug |
||
713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
701 | killagreg | 714 | if(EmergencyLanding) |
1 | ingob | 715 | { |
701 | killagreg | 716 | StickYaw = 0; |
717 | StickPitch = 0; |
||
1 | ingob | 718 | StickRoll = 0; |
701 | killagreg | 719 | GyroFactor = 0.5;//Originalwert von Holger 0.1; |
720 | IntegralFactor = 0.003; //Originalwert von Holger 0.005; |
||
173 | holgerb | 721 | Looping_Roll = 0; |
701 | killagreg | 722 | Looping_Pitch = 0; |
683 | killagreg | 723 | } |
395 | hbuss | 724 | |
725 | |||
683 | killagreg | 726 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 727 | // Integrale auf ACC-Signal abgleichen |
683 | killagreg | 728 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 729 | #define ABGLEICH_ANZAHL 256L |
730 | |||
701 | killagreg | 731 | MeanIntegralPitch += IntegralPitch; // Für die Mittelwertbildung aufsummieren |
732 | MeanIntegralRoll += IntegralRoll; |
||
733 | MeanIntegralPitch2 += IntegralPitch2; |
||
734 | MeanIntegralRoll2 += IntegralRoll2; |
||
395 | hbuss | 735 | |
701 | killagreg | 736 | if(Looping_Pitch || Looping_Roll) |
395 | hbuss | 737 | { |
701 | killagreg | 738 | IntegralAccPitch = 0; |
395 | hbuss | 739 | IntegralAccRoll = 0; |
701 | killagreg | 740 | MeanIntegralPitch = 0; |
741 | MeanIntegralRoll = 0; |
||
742 | MeanIntegralPitch2 = 0; |
||
743 | MeanIntegralRoll2 = 0; |
||
744 | Reading_IntegralPitch2 = Reading_IntegralPitch; |
||
745 | Reading_IntegralRoll2 = Reading_IntegralRoll; |
||
395 | hbuss | 746 | ZaehlMessungen = 0; |
701 | killagreg | 747 | AttitudeCorrectionPitch = 0; |
748 | AttitudeCorrectionRoll = 0; |
||
395 | hbuss | 749 | } |
750 | |||
683 | killagreg | 751 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 752 | if(!Looping_Pitch && !Looping_Roll) |
469 | hbuss | 753 | { |
754 | long tmp_long, tmp_long2; |
||
701 | killagreg | 755 | tmp_long = (long)(IntegralPitch / ParamSet.GyroAccFaktor - (long)Mean_AccPitch); |
756 | tmp_long2 = (long)(IntegralRoll / ParamSet.GyroAccFaktor - (long)Mean_AccRoll); |
||
469 | hbuss | 757 | tmp_long /= 16; |
758 | tmp_long2 /= 16; |
||
701 | killagreg | 759 | if((MaxStickPitch > 15) || (MaxStickRoll > 15)) |
614 | hbuss | 760 | { |
761 | tmp_long /= 3; |
||
762 | tmp_long2 /= 3; |
||
763 | } |
||
701 | killagreg | 764 | if(abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25) |
623 | hbuss | 765 | { |
766 | tmp_long /= 3; |
||
767 | tmp_long2 /= 3; |
||
768 | } |
||
614 | hbuss | 769 | |
770 | #define AUSGLEICH 32 |
||
469 | hbuss | 771 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
772 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
||
773 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
||
774 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
||
614 | hbuss | 775 | |
701 | killagreg | 776 | Reading_IntegralPitch -= tmp_long; |
777 | Reading_IntegralRoll -= tmp_long2; |
||
469 | hbuss | 778 | } |
683 | killagreg | 779 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
469 | hbuss | 780 | |
395 | hbuss | 781 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
782 | { |
||
783 | static int cnt = 0; |
||
784 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
||
701 | killagreg | 785 | static long MeanIntegralPitch_old,MeanIntegralRoll_old; |
786 | if(!Looping_Pitch && !Looping_Roll) |
||
173 | holgerb | 787 | { |
701 | killagreg | 788 | MeanIntegralPitch /= ABGLEICH_ANZAHL; |
789 | MeanIntegralRoll /= ABGLEICH_ANZAHL; |
||
790 | IntegralAccPitch = (ParamSet.GyroAccFaktor * IntegralAccPitch) / ABGLEICH_ANZAHL; |
||
687 | killagreg | 791 | IntegralAccRoll = (ParamSet.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
395 | hbuss | 792 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
492 | hbuss | 793 | #define MAX_I 0//(Poti2/10) |
701 | killagreg | 794 | // Pitch ++++++++++++++++++++++++++++++++++++++++++++++++ |
795 | IntegralErrorPitch = (long)(MeanIntegralPitch - (long)IntegralAccPitch); |
||
796 | CorrectionPitch = IntegralErrorPitch / ParamSet.GyroAccTrim; |
||
683 | killagreg | 797 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 798 | IntegralErrorRoll = (long)(MeanIntegralRoll - (long)IntegralAccRoll); |
799 | CorrectionRoll = IntegralErrorRoll / ParamSet.GyroAccTrim; |
||
614 | hbuss | 800 | |
701 | killagreg | 801 | AttitudeCorrectionPitch = CorrectionPitch / ABGLEICH_ANZAHL; |
802 | AttitudeCorrectionRoll = CorrectionRoll / ABGLEICH_ANZAHL; |
||
395 | hbuss | 803 | |
701 | killagreg | 804 | if((MaxStickPitch > 15) || (MaxStickRoll > 15) || (abs(PPM_in[ParamSet.ChannelAssignment[CH_YAW]]) > 25)) |
614 | hbuss | 805 | { |
701 | killagreg | 806 | AttitudeCorrectionPitch /= 2; |
807 | AttitudeCorrectionPitch /= 2; |
||
614 | hbuss | 808 | } |
498 | hbuss | 809 | |
683 | killagreg | 810 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | hbuss | 811 | // Gyro-Drift ermitteln |
683 | killagreg | 812 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 813 | MeanIntegralPitch2 /= ABGLEICH_ANZAHL; |
814 | MeanIntegralRoll2 /= ABGLEICH_ANZAHL; |
||
815 | tmp_long = IntegralPitch2 - IntegralPitch; |
||
683 | killagreg | 816 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
701 | killagreg | 817 | //DebugOut.Analog[25] = MeanIntegralRoll2 / 26; |
395 | hbuss | 818 | |
701 | killagreg | 819 | IntegralErrorPitch = tmp_long; |
820 | IntegralErrorRoll = tmp_long2; |
||
821 | Reading_IntegralPitch2 -= IntegralErrorPitch; |
||
822 | Reading_IntegralRoll2 -= IntegralErrorRoll; |
||
395 | hbuss | 823 | |
701 | killagreg | 824 | // IntegralErrorPitch = (IntegralErrorPitch * 1 + tmp_long) / 2; |
825 | // IntegralErrorRoll = (IntegralErrorRoll * 1 + tmp_long2) / 2; |
||
395 | hbuss | 826 | |
827 | |||
701 | killagreg | 828 | DebugOut.Analog[17] = IntegralAccPitch / 26; |
395 | hbuss | 829 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
701 | killagreg | 830 | DebugOut.Analog[19] = IntegralErrorPitch;// / 26; |
831 | DebugOut.Analog[20] = IntegralErrorRoll;// / 26; |
||
832 | DebugOut.Analog[21] = MeanIntegralPitch / 26; |
||
833 | DebugOut.Analog[22] = MeanIntegralRoll / 26; |
||
834 | //DebugOut.Analog[28] = CorrectionPitch; |
||
835 | DebugOut.Analog[29] = CorrectionRoll; |
||
836 | DebugOut.Analog[30] = AttitudeCorrectionRoll * 10; |
||
395 | hbuss | 837 | |
492 | hbuss | 838 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
839 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
||
840 | #define BEWEGUNGS_LIMIT 20000 |
||
701 | killagreg | 841 | // Pitch +++++++++++++++++++++++++++++++++++++++++++++++++ |
842 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
||
843 | if(labs(MeanIntegralPitch_old - MeanIntegralPitch) < BEWEGUNGS_LIMIT) |
||
492 | hbuss | 844 | { |
701 | killagreg | 845 | if(IntegralErrorPitch > FEHLER_LIMIT2) |
395 | hbuss | 846 | { |
683 | killagreg | 847 | if(last_n_p) |
395 | hbuss | 848 | { |
701 | killagreg | 849 | cnt += labs(IntegralErrorPitch) / FEHLER_LIMIT2; |
850 | CorrectionPitch = IntegralErrorPitch / 8; |
||
851 | if(CorrectionPitch > 5000) CorrectionPitch = 5000; |
||
852 | AttitudeCorrectionPitch += CorrectionPitch / ABGLEICH_ANZAHL; |
||
683 | killagreg | 853 | } |
395 | hbuss | 854 | else last_n_p = 1; |
855 | } else last_n_p = 0; |
||
701 | killagreg | 856 | if(IntegralErrorPitch < -FEHLER_LIMIT2) |
395 | hbuss | 857 | { |
858 | if(last_n_n) |
||
683 | killagreg | 859 | { |
701 | killagreg | 860 | cnt += labs(IntegralErrorPitch) / FEHLER_LIMIT2; |
861 | CorrectionPitch = IntegralErrorPitch / 8; |
||
862 | if(CorrectionPitch < -5000) CorrectionPitch = -5000; |
||
863 | AttitudeCorrectionPitch += CorrectionPitch / ABGLEICH_ANZAHL; |
||
683 | killagreg | 864 | } |
395 | hbuss | 865 | else last_n_n = 1; |
866 | } else last_n_n = 0; |
||
492 | hbuss | 867 | } else cnt = 0; |
690 | killagreg | 868 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
701 | killagreg | 869 | if(IntegralErrorPitch > FEHLER_LIMIT) AdNeutralPitch += cnt; |
870 | if(IntegralErrorPitch < -FEHLER_LIMIT) AdNeutralPitch -= cnt; |
||
401 | hbuss | 871 | |
395 | hbuss | 872 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 873 | cnt = 1;// + labs(IntegralErrorPitch) / 4096; |
492 | hbuss | 874 | |
701 | killagreg | 875 | CorrectionRoll = 0; |
876 | if(labs(MeanIntegralRoll_old - MeanIntegralRoll) < BEWEGUNGS_LIMIT) |
||
492 | hbuss | 877 | { |
701 | killagreg | 878 | if(IntegralErrorRoll > FEHLER_LIMIT2) |
395 | hbuss | 879 | { |
683 | killagreg | 880 | if(last_r_p) |
395 | hbuss | 881 | { |
701 | killagreg | 882 | cnt += labs(IntegralErrorRoll) / FEHLER_LIMIT2; |
883 | CorrectionRoll = IntegralErrorRoll / 8; |
||
884 | if(CorrectionRoll > 5000) CorrectionRoll = 5000; |
||
885 | AttitudeCorrectionRoll += CorrectionRoll / ABGLEICH_ANZAHL; |
||
683 | killagreg | 886 | } |
395 | hbuss | 887 | else last_r_p = 1; |
888 | } else last_r_p = 0; |
||
701 | killagreg | 889 | if(IntegralErrorRoll < -FEHLER_LIMIT2) |
395 | hbuss | 890 | { |
683 | killagreg | 891 | if(last_r_n) |
395 | hbuss | 892 | { |
701 | killagreg | 893 | cnt += labs(IntegralErrorRoll) / FEHLER_LIMIT2; |
894 | CorrectionRoll = IntegralErrorRoll / 8; |
||
895 | if(CorrectionRoll < -5000) CorrectionRoll = -5000; |
||
896 | AttitudeCorrectionRoll += CorrectionRoll / ABGLEICH_ANZAHL; |
||
395 | hbuss | 897 | } |
898 | else last_r_n = 1; |
||
899 | } else last_r_n = 0; |
||
683 | killagreg | 900 | } else |
492 | hbuss | 901 | { |
902 | cnt = 0; |
||
683 | killagreg | 903 | } |
614 | hbuss | 904 | |
690 | killagreg | 905 | if(cnt > ParamSet.DriftComp) cnt = ParamSet.DriftComp; |
701 | killagreg | 906 | if(IntegralErrorRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
907 | if(IntegralErrorRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
||
908 | DebugOut.Analog[27] = CorrectionRoll; |
||
909 | DebugOut.Analog[23] = AdNeutralPitch;//10*(AdNeutralPitch - StartNeutralPitch); |
||
401 | hbuss | 910 | DebugOut.Analog[24] = 10*(AdNeutralRoll - StartNeutralRoll); |
173 | holgerb | 911 | } |
683 | killagreg | 912 | else |
498 | hbuss | 913 | { |
701 | killagreg | 914 | AttitudeCorrectionRoll = 0; |
915 | AttitudeCorrectionPitch = 0; |
||
498 | hbuss | 916 | } |
595 | hbuss | 917 | |
701 | killagreg | 918 | if(!IntegralFactor) { AttitudeCorrectionRoll = 0; AttitudeCorrectionPitch = 0;} // z.B. bei HH |
683 | killagreg | 919 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 920 | MeanIntegralPitch_old = MeanIntegralPitch; |
921 | MeanIntegralRoll_old = MeanIntegralRoll; |
||
683 | killagreg | 922 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 923 | IntegralAccPitch = 0; |
395 | hbuss | 924 | IntegralAccRoll = 0; |
925 | IntegralAccZ = 0; |
||
701 | killagreg | 926 | MeanIntegralPitch = 0; |
927 | MeanIntegralRoll = 0; |
||
928 | MeanIntegralPitch2 = 0; |
||
929 | MeanIntegralRoll2 = 0; |
||
395 | hbuss | 930 | ZaehlMessungen = 0; |
931 | } |
||
701 | killagreg | 932 | //DebugOut.Analog[31] = StickRoll / (26*IntegralFactor); |
395 | hbuss | 933 | |
683 | killagreg | 934 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 935 | // Gieren |
683 | killagreg | 936 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 937 | if(abs(StickYaw) > 20) // war 35 |
1 | ingob | 938 | { |
701 | killagreg | 939 | if(!(ParamSet.GlobalConfig & CFG_COMPASS_FIX)) StoreNewCompassCourse = 1; |
1 | ingob | 940 | } |
701 | killagreg | 941 | tmp_int = (long) ParamSet.Yaw_P * ((long)StickYaw * abs(StickYaw)) / 512L; // expo y = ax + bx² |
942 | tmp_int += (ParamSet.Yaw_P * StickYaw) / 4; |
||
943 | SetPointYaw = tmp_int; |
||
703 | killagreg | 944 | Reading_IntegralYaw -= tmp_int; |
945 | if(Reading_IntegralYaw > 50000) Reading_IntegralYaw = 50000; // begrenzen |
||
946 | if(Reading_IntegralYaw <-50000) Reading_IntegralYaw =-50000; |
||
683 | killagreg | 947 | |
948 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 949 | // Kompass |
683 | killagreg | 950 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
694 | killagreg | 951 | if(ParamSet.GlobalConfig & CFG_COMPASS_ACTIVE) |
952 | { |
||
953 | int w,v; |
||
701 | killagreg | 954 | static uint8_t updCompass = 0; |
694 | killagreg | 955 | |
701 | killagreg | 956 | if (!updCompass--) // Aufruf mit ~10 Hz |
694 | killagreg | 957 | { |
701 | killagreg | 958 | CompassHeading = MM3_heading(); // get current compass reading |
959 | CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180; |
||
960 | updCompass = 50; |
||
694 | killagreg | 961 | } |
962 | |||
701 | killagreg | 963 | w = abs(IntegralPitch /512); // mit zunehmender Neigung den Einfluss drosseln |
694 | killagreg | 964 | v = abs(IntegralRoll /512); |
965 | if(v > w) w = v; // grösste Neigung ermitteln |
||
701 | killagreg | 966 | if(w < 35 && StoreNewCompassCourse) |
694 | killagreg | 967 | { |
701 | killagreg | 968 | CompassCourse = CompassHeading; |
969 | StoreNewCompassCourse = 0; |
||
694 | killagreg | 970 | } |
703 | killagreg | 971 | w = (w * FCParam.CompassYawEffect) / 64; // auf die Wirkung normieren |
972 | w = FCParam.CompassYawEffect - w; // Wirkung ggf drosseln |
||
694 | killagreg | 973 | if(w > 0) |
683 | killagreg | 974 | { |
703 | killagreg | 975 | Reading_IntegralYaw -= (CompassOffCourse * w) / 32; // nach Kompass ausrichten |
694 | killagreg | 976 | } |
683 | killagreg | 977 | } |
978 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
1 | ingob | 979 | |
683 | killagreg | 980 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 981 | // Debugwerte zuordnen |
683 | killagreg | 982 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 983 | if(!TimerDebugOut--) |
1 | ingob | 984 | { |
701 | killagreg | 985 | TimerDebugOut = 24; |
986 | DebugOut.Analog[0] = IntegralPitch / ParamSet.GyroAccFaktor; |
||
687 | killagreg | 987 | DebugOut.Analog[1] = IntegralRoll / ParamSet.GyroAccFaktor; |
701 | killagreg | 988 | DebugOut.Analog[2] = Mean_AccPitch; |
989 | DebugOut.Analog[3] = Mean_AccRoll; |
||
990 | DebugOut.Analog[4] = ReadingYaw; |
||
991 | DebugOut.Analog[5] = ReadingHight; |
||
992 | DebugOut.Analog[6] = (Reading_Integral_Top / 512); |
||
993 | DebugOut.Analog[8] = CompassHeading; |
||
297 | holgerb | 994 | DebugOut.Analog[9] = UBat; |
995 | DebugOut.Analog[10] = SenderOkay; |
||
701 | killagreg | 996 | DebugOut.Analog[16] = Mean_AccTop; |
173 | holgerb | 997 | |
998 | /* DebugOut.Analog[16] = motor_rx[0]; |
||
999 | DebugOut.Analog[17] = motor_rx[1]; |
||
1000 | DebugOut.Analog[18] = motor_rx[2]; |
||
1001 | DebugOut.Analog[19] = motor_rx[3]; |
||
1002 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
||
1003 | DebugOut.Analog[20] /= 14; |
||
1004 | DebugOut.Analog[21] = motor_rx[4]; |
||
1005 | DebugOut.Analog[22] = motor_rx[5]; |
||
1006 | DebugOut.Analog[23] = motor_rx[6]; |
||
1007 | DebugOut.Analog[24] = motor_rx[7]; |
||
1008 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
||
1009 | */ |
||
701 | killagreg | 1010 | // DebugOut.Analog[9] = ReadingPitch; |
1011 | // DebugOut.Analog[9] = SetPointHight; |
||
703 | killagreg | 1012 | // DebugOut.Analog[10] = Reading_IntegralYaw / 128; |
701 | killagreg | 1013 | // DebugOut.Analog[11] = CompassCourse; |
703 | killagreg | 1014 | // DebugOut.Analog[10] = FCParam.Gyro_I; |
687 | killagreg | 1015 | // DebugOut.Analog[10] = ParamSet.Gyro_I; |
701 | killagreg | 1016 | // DebugOut.Analog[9] = CompassOffCourse; |
1017 | // DebugOut.Analog[10] = GasMixingFraction; |
||
703 | killagreg | 1018 | // DebugOut.Analog[3] = HightD * 32; |
1 | ingob | 1019 | // DebugOut.Analog[4] = hoehenregler; |
1020 | } |
||
1021 | |||
683 | killagreg | 1022 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1023 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
683 | killagreg | 1024 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 1025 | //DebugOut.Analog[26] = ReadingPitch; |
1026 | //DebugOut.Analog[28] = ReadingRoll; |
||
604 | hbuss | 1027 | |
701 | killagreg | 1028 | if(Looping_Pitch) ReadingPitch = ReadingPitch * GyroFactor; |
1029 | else ReadingPitch = IntegralPitch * IntegralFactor + ReadingPitch * GyroFactor; |
||
1030 | if(Looping_Roll) ReadingRoll = ReadingRoll * GyroFactor; |
||
1031 | else ReadingRoll = IntegralRoll * IntegralFactor + ReadingRoll * GyroFactor; |
||
703 | killagreg | 1032 | ReadingYaw = ReadingYaw * (2 * GyroFactor) + IntegralYaw * IntegralFactor / 2; |
1 | ingob | 1033 | |
701 | killagreg | 1034 | DebugOut.Analog[25] = IntegralRoll * IntegralFactor; |
1035 | DebugOut.Analog[31] = StickRoll;// / (26*IntegralFactor); |
||
1036 | DebugOut.Analog[28] = ReadingRoll; |
||
469 | hbuss | 1037 | |
1 | ingob | 1038 | // Maximalwerte abfangen |
1039 | #define MAX_SENSOR 2048 |
||
701 | killagreg | 1040 | if(ReadingPitch > MAX_SENSOR) ReadingPitch = MAX_SENSOR; |
1041 | if(ReadingPitch < -MAX_SENSOR) ReadingPitch = -MAX_SENSOR; |
||
1042 | if(ReadingRoll > MAX_SENSOR) ReadingRoll = MAX_SENSOR; |
||
1043 | if(ReadingRoll < -MAX_SENSOR) ReadingRoll = -MAX_SENSOR; |
||
1044 | if(ReadingYaw > MAX_SENSOR) ReadingYaw = MAX_SENSOR; |
||
1045 | if(ReadingYaw < -MAX_SENSOR) ReadingYaw = -MAX_SENSOR; |
||
1 | ingob | 1046 | |
683 | killagreg | 1047 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1048 | // Höhenregelung |
1049 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
||
683 | killagreg | 1050 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1051 | //OCR0B = 180 - (Poti1 + 120) / 4; |
1052 | //DruckOffsetSetting = OCR0B; |
||
690 | killagreg | 1053 | if((ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)) // Höhenregelung |
1 | ingob | 1054 | { |
1055 | int tmp_int; |
||
690 | killagreg | 1056 | if(ParamSet.GlobalConfig & CFG_HEIGHT_SWITCH) // Regler wird über Schalter gesteuert |
1 | ingob | 1057 | { |
703 | killagreg | 1058 | if(FCParam.MaxHight < 50) |
1 | ingob | 1059 | { |
703 | killagreg | 1060 | SetPointHight = ReadingHight - 20; // FCParam.MaxHight ist der PPM-Wert des Schalters |
701 | killagreg | 1061 | HightControlActive = 0; |
1 | ingob | 1062 | } |
683 | killagreg | 1063 | else |
701 | killagreg | 1064 | HightControlActive = 1; |
1 | ingob | 1065 | } |
683 | killagreg | 1066 | else |
1 | ingob | 1067 | { |
703 | killagreg | 1068 | SetPointHight = ((int) ExternHightValue + (int) FCParam.MaxHight) * (int)ParamSet.Hight_Gain - 20; |
701 | killagreg | 1069 | HightControlActive = 1; |
1 | ingob | 1070 | } |
1071 | |||
701 | killagreg | 1072 | if(EmergencyLanding) SetPointHight = 0; |
1073 | h = ReadingHight; |
||
1074 | if((h > SetPointHight) && HightControlActive) // zu hoch --> drosseln |
||
703 | killagreg | 1075 | { h = ((h - SetPointHight) * (int) FCParam.Hight_P) / 16; // Differenz bestimmen --> P-Anteil |
701 | killagreg | 1076 | h = GasMixingFraction - h; // vom Gas abziehen |
703 | killagreg | 1077 | h -= (HightD * FCParam.AirPressure_D)/8; // D-Anteil |
1078 | tmp_int = ((Reading_Integral_Top / 512) * (signed long) FCParam.Hight_ACC_Effect) / 32; |
||
1 | ingob | 1079 | if(tmp_int > 50) tmp_int = 50; |
1080 | else if(tmp_int < -50) tmp_int = -50; |
||
1081 | h -= tmp_int; |
||
683 | killagreg | 1082 | hoehenregler = (hoehenregler*15 + h) / 16; |
701 | killagreg | 1083 | if(hoehenregler < ParamSet.Hight_MinGas) // nicht unter MIN |
1 | ingob | 1084 | { |
701 | killagreg | 1085 | if(GasMixingFraction >= ParamSet.Hight_MinGas) hoehenregler = ParamSet.Hight_MinGas; |
1086 | if(GasMixingFraction < ParamSet.Hight_MinGas) hoehenregler = GasMixingFraction; |
||
683 | killagreg | 1087 | } |
701 | killagreg | 1088 | if(hoehenregler > GasMixingFraction) hoehenregler = GasMixingFraction; // nicht mehr als Gas |
1089 | GasMixingFraction = hoehenregler; |
||
683 | killagreg | 1090 | } |
1 | ingob | 1091 | } |
703 | killagreg | 1092 | if(GasMixingFraction > ParamSet.Gas_Max - 20) GasMixingFraction = ParamSet.Gas_Max - 20; |
683 | killagreg | 1093 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1094 | // + Mischer und PI-Regler |
683 | killagreg | 1095 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 1096 | DebugOut.Analog[7] = GasMixingFraction; |
683 | killagreg | 1097 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1098 | // Gier-Anteil |
683 | killagreg | 1099 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
188 | holgerb | 1100 | #define MUL_G 1.0 |
701 | killagreg | 1101 | YawMixingFraction = ReadingYaw - SetPointYaw; // Regler für Gier |
1102 | // YawMixingFraction = 0; |
||
173 | holgerb | 1103 | |
701 | killagreg | 1104 | if(YawMixingFraction > (GasMixingFraction / 2)) YawMixingFraction = GasMixingFraction / 2; |
1105 | if(YawMixingFraction < -(GasMixingFraction / 2)) YawMixingFraction = -(GasMixingFraction / 2); |
||
703 | killagreg | 1106 | if(YawMixingFraction > ((ParamSet.Gas_Max - GasMixingFraction))) YawMixingFraction = ((ParamSet.Gas_Max - GasMixingFraction)); |
1107 | if(YawMixingFraction < -((ParamSet.Gas_Max - GasMixingFraction))) YawMixingFraction = -((ParamSet.Gas_Max - GasMixingFraction)); |
||
513 | hbuss | 1108 | |
701 | killagreg | 1109 | if(GasMixingFraction < 20) YawMixingFraction = 0; |
683 | killagreg | 1110 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 1111 | // Pitch-Achse |
683 | killagreg | 1112 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 1113 | DiffPitch = ReadingPitch - (StickPitch - GPS_Pitch); // Differenz bestimmen |
1114 | if(IntegralFactor) SumPitch += IntegralPitch * IntegralFactor - (StickPitch - GPS_Pitch); // I-Anteil bei Winkelregelung |
||
1115 | else SumPitch += DiffPitch; // I-Anteil bei HH |
||
1116 | if(SumPitch > 16000) SumPitch = 16000; |
||
1117 | if(SumPitch < -16000) SumPitch = -16000; |
||
1118 | pd_ergebnis = DiffPitch + Ki * SumPitch; // PI-Regler für Pitch |
||
1 | ingob | 1119 | // Motor Vorn |
703 | killagreg | 1120 | tmp_int = (long)((long)FCParam.DynamicStability * (long)(GasMixingFraction + abs(YawMixingFraction)/2)) / 64; |
683 | killagreg | 1121 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1122 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
||
173 | holgerb | 1123 | |
701 | killagreg | 1124 | MotorValue = GasMixingFraction + pd_ergebnis + YawMixingFraction; // Mischer |
1125 | if ((MotorValue < 0)) MotorValue = 0; |
||
703 | killagreg | 1126 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1127 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
||
701 | killagreg | 1128 | Motor_Front = MotorValue; |
1 | ingob | 1129 | // Motor Heck |
701 | killagreg | 1130 | MotorValue = GasMixingFraction - pd_ergebnis + YawMixingFraction; |
1131 | if ((MotorValue < 0)) MotorValue = 0; |
||
703 | killagreg | 1132 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1133 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
||
701 | killagreg | 1134 | Motor_Rear = MotorValue; |
683 | killagreg | 1135 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | ingob | 1136 | // Roll-Achse |
683 | killagreg | 1137 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | killagreg | 1138 | DiffRoll = ReadingRoll - (StickRoll - GPS_Roll); // Differenz bestimmen |
1139 | if(IntegralFactor) SumRoll += IntegralRoll * IntegralFactor - (StickRoll - GPS_Roll);// I-Anteil bei Winkelregelung |
||
1140 | else SumRoll += DiffRoll; // I-Anteil bei HH |
||
1141 | if(SumRoll > 16000) SumRoll = 16000; |
||
1142 | if(SumRoll < -16000) SumRoll = -16000; |
||
1143 | pd_ergebnis = DiffRoll + Ki * SumRoll; // PI-Regler für Roll |
||
703 | killagreg | 1144 | tmp_int = (long)((long)FCParam.DynamicStability * (long)(GasMixingFraction + abs(YawMixingFraction)/2)) / 64; |
683 | killagreg | 1145 | if(pd_ergebnis > tmp_int) pd_ergebnis = tmp_int; |
1146 | if(pd_ergebnis < -tmp_int) pd_ergebnis = -tmp_int; |
||
1 | ingob | 1147 | // Motor Links |
701 | killagreg | 1148 | MotorValue = GasMixingFraction + pd_ergebnis - YawMixingFraction; |
604 | hbuss | 1149 | #define GRENZE Poti1 |
1150 | |||
701 | killagreg | 1151 | if ((MotorValue < 0)) MotorValue = 0; |
703 | killagreg | 1152 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1153 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
||
701 | killagreg | 1154 | Motor_Left = MotorValue; |
1 | ingob | 1155 | // Motor Rechts |
701 | killagreg | 1156 | MotorValue = GasMixingFraction - pd_ergebnis - YawMixingFraction; |
604 | hbuss | 1157 | |
701 | killagreg | 1158 | if ((MotorValue < 0)) MotorValue = 0; |
703 | killagreg | 1159 | else if(MotorValue > ParamSet.Gas_Max) MotorValue = ParamSet.Gas_Max; |
1160 | if (MotorValue < ParamSet.Gas_Min) MotorValue = ParamSet.Gas_Min; |
||
701 | killagreg | 1161 | Motor_Right = MotorValue; |
1 | ingob | 1162 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
1163 | } |
||
1164 |