Rev 459 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
202 | joko | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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. |
||
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
27 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
28 | // + mit unserer Zustimmung zulässig |
||
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
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. |
||
36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
||
37 | // + for non-commercial use (directly or indirectly) |
||
38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
39 | // + with our written permission |
||
40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
41 | // + clearly linked as origin |
||
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 |
||
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
53 | // + POSSIBILITY OF SUCH DAMAGE. |
||
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
55 | |||
56 | #include "main.h" |
||
57 | |||
58 | unsigned char h,m,s; |
||
59 | volatile unsigned int I2CTimeout = 100; |
||
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
||
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
||
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
||
63 | volatile float NeutralAccZ = 0; |
||
64 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
||
65 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
||
66 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
||
67 | volatile long Integral_Gier = 0; |
||
68 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
||
69 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
||
70 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
||
71 | volatile long Mess_Integral_Hoch = 0; |
||
72 | volatile int KompassValue = 0; |
||
73 | volatile int KompassStartwert = 0; |
||
74 | volatile int KompassRichtung = 0; |
||
75 | unsigned char MAX_GAS,MIN_GAS; |
||
76 | unsigned char Notlandung = 0; |
||
77 | unsigned char HoehenReglerAktiv = 0; |
||
78 | |||
79 | unsigned char blinkcount_LED1 = 0;//Hilfszähler für die blinkende LED (310807Kr) |
||
80 | unsigned int modell_fliegt_gps = 0;//(030907Kr) |
||
81 | unsigned char Limit_D_Anteil = 0;//(210907Kr) |
||
501 | joko | 82 | unsigned char Limit_P_Anteil = 0;//(131107Kr) |
202 | joko | 83 | |
84 | float GyroFaktor; |
||
85 | float IntegralFaktor; |
||
86 | |||
87 | volatile int DiffNick,DiffRoll; |
||
273 | joko | 88 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; //PPM24-Erweiterung (121007Kr) |
202 | joko | 89 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
90 | unsigned char MotorWert[5]; |
||
91 | volatile unsigned char SenderOkay = 0; |
||
92 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
||
93 | char MotorenEin = 0; |
||
94 | int HoehenWert = 0; |
||
95 | int SollHoehe = 0; |
||
96 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
||
97 | |||
98 | float Kp = FAKTOR_P; |
||
99 | float Ki = FAKTOR_I; |
||
100 | |||
101 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
||
102 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
||
103 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
||
104 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
||
105 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
||
106 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
||
107 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
||
108 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
||
109 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
||
110 | unsigned char Parameter_UserParam1 = 0; |
||
111 | unsigned char Parameter_UserParam2 = 0; |
||
112 | unsigned char Parameter_UserParam3 = 0; |
||
113 | unsigned char Parameter_UserParam4 = 0; |
||
114 | unsigned char Parameter_ServoNickControl = 100; |
||
115 | unsigned char Parameter_LoopGasLimit = 70; |
||
116 | struct mk_param_struct EE_Parameter; |
||
117 | |||
118 | void Piep(unsigned char Anzahl) |
||
119 | { |
||
120 | while(Anzahl--) |
||
121 | { |
||
122 | if(MotorenEin) return; //auf keinen Fall im Flug! |
||
123 | beeptime = 100; |
||
124 | Delay_ms(250); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | //############################################################################ |
||
129 | // Nullwerte ermitteln |
||
130 | void SetNeutral(void) |
||
131 | //############################################################################ |
||
132 | { |
||
133 | unsigned int timer; |
||
134 | NeutralAccX = 0; |
||
135 | NeutralAccY = 0; |
||
136 | NeutralAccZ = 0; |
||
137 | AdNeutralNick = 0; |
||
138 | AdNeutralRoll = 0; |
||
139 | AdNeutralGier = 0; |
||
140 | CalibrierMittelwert(); |
||
141 | timer = SetDelay(5); |
||
142 | while (!CheckDelay(timer)); |
||
143 | CalibrierMittelwert(); |
||
144 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
||
145 | { |
||
146 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
||
147 | } |
||
148 | |||
149 | if(PlatinenVersion == 10) |
||
150 | { |
||
151 | AdNeutralNick= abs(MesswertNick); |
||
152 | AdNeutralRoll= abs(MesswertRoll); |
||
153 | AdNeutralGier= abs(MesswertGier); |
||
154 | } |
||
155 | else |
||
156 | { |
||
157 | AdNeutralNick= abs(MesswertNick) / 2; |
||
158 | AdNeutralRoll= abs(MesswertRoll) / 2; |
||
159 | AdNeutralGier= abs(MesswertGier) / 2; |
||
160 | } |
||
161 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
||
162 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
||
163 | NeutralAccZ = Aktuell_az; |
||
164 | |||
165 | Mess_IntegralNick = 0; |
||
166 | Mess_IntegralNick2 = 0; |
||
167 | Mess_IntegralRoll = 0; |
||
168 | Mess_IntegralRoll2 = 0; |
||
169 | Mess_Integral_Gier = 0; |
||
170 | MesswertNick = 0; |
||
171 | MesswertRoll = 0; |
||
172 | MesswertGier = 0; |
||
173 | StartLuftdruck = Luftdruck; |
||
174 | HoeheD = 0; |
||
175 | Mess_Integral_Hoch = 0; |
||
176 | KompassStartwert = KompassValue; |
||
177 | beeptime = 50; |
||
178 | } |
||
179 | |||
180 | //############################################################################ |
||
181 | // Bildet den Mittelwert aus den Messwerten |
||
182 | void Mittelwert(void) |
||
183 | //############################################################################ |
||
184 | { |
||
185 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
||
186 | ANALOG_OFF; |
||
187 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
||
188 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
||
189 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
||
190 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
||
191 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
||
192 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
||
193 | AccumulateNick = 0; MessanzahlNick = 0; |
||
194 | AccumulateRoll = 0; MessanzahlRoll = 0; |
||
195 | AccumulateGier = 0; MessanzahlGier = 0; |
||
196 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
||
197 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
||
198 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
||
199 | Integral_Gier = Mess_Integral_Gier; |
||
200 | // Integral_Gier2 = Mess_Integral_Gier2; |
||
201 | IntegralNick = Mess_IntegralNick; |
||
202 | IntegralRoll = Mess_IntegralRoll; |
||
203 | IntegralNick2 = Mess_IntegralNick2; |
||
204 | IntegralRoll2 = Mess_IntegralRoll2; |
||
205 | // ADC einschalten |
||
206 | ANALOG_ON; |
||
207 | |||
208 | //------------------------------------------------------------------------------ |
||
459 | joko | 209 | if(!Looping_Nick && !Looping_Roll && !(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD)) //übernommen aus der V0.66b und um Heading_Hold erweitert //(071107Kr) |
414 | joko | 210 | { |
211 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
||
212 | else |
||
213 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
||
214 | |||
215 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
||
216 | else |
||
217 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
||
218 | } |
||
202 | joko | 219 | //------------------------------------------------------------------------------ |
414 | joko | 220 | |
202 | joko | 221 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
222 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
||
223 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
||
224 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
||
273 | joko | 225 | //PPM24-Erweiterung (121007Kr) |
226 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
||
202 | joko | 227 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
228 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
||
229 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
||
230 | |||
231 | |||
232 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
||
233 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
234 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
235 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
273 | joko | 236 | //PPM24-Erweiterung (121007Kr) |
202 | joko | 237 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
238 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
||
239 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
||
240 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
||
241 | } |
||
242 | |||
243 | //############################################################################ |
||
244 | // Messwerte beim Ermitteln der Nullage |
||
245 | void CalibrierMittelwert(void) |
||
246 | //############################################################################ |
||
247 | { |
||
248 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
||
249 | ANALOG_OFF; |
||
250 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
||
251 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
||
252 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
||
253 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
||
254 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
||
255 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
||
256 | AccumulateNick = 0; MessanzahlNick = 0; |
||
257 | AccumulateRoll = 0; MessanzahlRoll = 0; |
||
258 | AccumulateGier = 0; MessanzahlGier = 0; |
||
259 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
||
260 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
||
261 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
||
262 | // ADC einschalten |
||
263 | ANALOG_ON; |
||
264 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
||
265 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
||
266 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
||
267 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
||
273 | joko | 268 | //PPM24-Erweiterung (121007Kr) |
269 | if(Poti5 < PPM_in[9] + 110) Poti5++; else if(Poti5 > PPM_in[9] + 110 && Poti5) Poti5--; |
||
202 | joko | 270 | if(Poti6 < PPM_in[10] + 110) Poti6++; else if(Poti6 > PPM_in[10] + 110 && Poti6) Poti6--; |
271 | if(Poti7 < PPM_in[11] + 110) Poti7++; else if(Poti7 > PPM_in[11] + 110 && Poti7) Poti7--; |
||
272 | if(Poti8 < PPM_in[12] + 110) Poti8++; else if(Poti8 > PPM_in[12] + 110 && Poti8) Poti8--; |
||
273 | |||
274 | |||
275 | |||
276 | |||
277 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
||
278 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
||
279 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
||
280 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
||
273 | joko | 281 | //PPM24-Erweiterung (121007Kr) |
282 | if(Poti5 < 0) Poti5 = 0; else if(Poti5 > 255) Poti5 = 255; |
||
202 | joko | 283 | if(Poti6 < 0) Poti6 = 0; else if(Poti6 > 255) Poti6 = 255; |
284 | if(Poti7 < 0) Poti7 = 0; else if(Poti7 > 255) Poti7 = 255; |
||
285 | if(Poti8 < 0) Poti8 = 0; else if(Poti8 > 255) Poti8 = 255; |
||
286 | } |
||
287 | |||
288 | //############################################################################ |
||
289 | // Senden der Motorwerte per I2C-Bus |
||
290 | void SendMotorData(void) |
||
291 | //############################################################################ |
||
292 | { |
||
293 | if(MOTOR_OFF || !MotorenEin) |
||
294 | { |
||
295 | Motor_Hinten = 0; |
||
296 | Motor_Vorne = 0; |
||
297 | Motor_Rechts = 0; |
||
298 | Motor_Links = 0; |
||
299 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
||
300 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
||
301 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
||
302 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
||
303 | } |
||
304 | |||
305 | // DebugOut.Analog[12] = Motor_Vorne; |
||
306 | // DebugOut.Analog[13] = Motor_Hinten; |
||
307 | // DebugOut.Analog[14] = Motor_Links; |
||
308 | // DebugOut.Analog[15] = Motor_Rechts; |
||
309 | |||
310 | // DebugOut.Analog[12] = motor_rx[0]; //Motorstrom vorne |
||
311 | // DebugOut.Analog[13] = motor_rx[1]; //Motorstrom hinten |
||
312 | // DebugOut.Analog[14] = motor_rx[2]; //Motorstrom links |
||
313 | // DebugOut.Analog[15] = motor_rx[3]; //Motorstrom rechts |
||
314 | |||
315 | |||
316 | //Start I2C Interrupt Mode |
||
317 | twi_state = 0; |
||
318 | motor = 0; |
||
319 | i2c_start(); |
||
320 | } |
||
321 | |||
322 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
323 | // + Konstanten |
||
324 | // + 0-250 -> normale Werte |
||
325 | // + 251 -> Poti1 |
||
326 | // + 252 -> Poti2 |
||
327 | // + 253 -> Poti3 |
||
328 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
329 | void DefaultKonstanten1(void) |
||
330 | { |
||
501 | joko | 331 | EE_Parameter.Kanalbelegung[K_NICK] = 3; // (300807Kr) |
204 | joko | 332 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
501 | joko | 333 | EE_Parameter.Kanalbelegung[K_GAS] = 1; // (300807Kr) |
204 | joko | 334 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
335 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
||
336 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
||
337 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
||
338 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
||
202 | joko | 339 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
340 | EE_Parameter.Hoehe_MinGas = 30; |
||
341 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
||
342 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
||
343 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
||
344 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
||
459 | joko | 345 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
202 | joko | 346 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
459 | joko | 347 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
202 | joko | 348 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
349 | EE_Parameter.Gas_Min = 5; // Wert : 0-32 // (160607Kr) |
||
350 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
||
351 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
||
352 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
||
353 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
||
354 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
||
501 | joko | 355 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
202 | joko | 356 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
357 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
||
358 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
||
459 | joko | 359 | EE_Parameter.I_Faktor = 5; |
202 | joko | 360 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
361 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
||
362 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
||
363 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
||
364 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
||
365 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
366 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
367 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
||
368 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
||
369 | EE_Parameter.ServoNickRefresh = 5; |
||
370 | EE_Parameter.LoopGasLimit = 50; |
||
371 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
||
372 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts / wird getrennt behandelt |
||
373 | memcpy(EE_Parameter.Name, "Sport\0", 12); |
||
374 | } |
||
375 | |||
376 | void DefaultKonstanten2(void) |
||
377 | { |
||
501 | joko | 378 | EE_Parameter.Kanalbelegung[K_NICK] = 3; // (300807Kr) |
204 | joko | 379 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
501 | joko | 380 | EE_Parameter.Kanalbelegung[K_GAS] = 1; // (300807Kr) |
204 | joko | 381 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
382 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
||
383 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
||
384 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
||
385 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
||
202 | joko | 386 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
387 | EE_Parameter.Hoehe_MinGas = 30; |
||
388 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
||
389 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
||
390 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
||
391 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
||
392 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
||
393 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
||
394 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
||
395 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
||
396 | EE_Parameter.Gas_Min = 5; // Wert : 0-32 // (160607Kr) |
||
397 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
||
398 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
||
399 | EE_Parameter.KompassWirkung = 128; // Wert : 0-250 |
||
400 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
||
401 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
||
501 | joko | 402 | EE_Parameter.UnterspannungsWarnung = 94; // Wert : 0-250 |
202 | joko | 403 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
404 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
||
405 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
||
459 | joko | 406 | EE_Parameter.I_Faktor = 5; |
202 | joko | 407 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
408 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
||
409 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
||
410 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
||
411 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
||
412 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
||
413 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
||
414 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
||
415 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
||
416 | EE_Parameter.ServoNickRefresh = 5; |
||
417 | EE_Parameter.LoopGasLimit = 50; |
||
418 | EE_Parameter.LoopThreshold = 90; // Wert: 0-250 Schwelle für Stickausschlag |
||
419 | EE_Parameter.LoopConfig = 0; // Bitcodiert: 0x01=oben, 0x02=unten, 0x04=links, 0x08=rechts |
||
420 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
||
421 | } |
||
422 | |||
423 | |||
424 | //############################################################################ |
||
425 | // Trägt ggf. das Poti als Parameter ein |
||
426 | void ParameterZuordnung(void) |
||
427 | //############################################################################ |
||
428 | { |
||
429 | |||
430 | #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;} |
||
431 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
||
432 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
||
433 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
||
434 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
||
435 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
||
436 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
||
437 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
||
438 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
||
439 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
||
440 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
||
441 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
||
442 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
||
443 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
||
444 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
||
445 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
||
446 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
||
447 | |||
448 | Ki = (float) Parameter_I_Faktor * 0.0001; |
||
449 | MAX_GAS = EE_Parameter.Gas_Max; |
||
450 | MIN_GAS = EE_Parameter.Gas_Min; |
||
451 | } |
||
452 | |||
453 | |||
454 | //############################################################################ |
||
455 | // |
||
456 | void MotorRegler(void) |
||
457 | //############################################################################ |
||
458 | { |
||
459 | int motorwert,pd_ergebnis,h,tmp_int; |
||
460 | int GierMischanteil,GasMischanteil; |
||
461 | static long SummeNick=0,SummeRoll=0; |
||
462 | static long sollGier = 0,tmp_long,tmp_long2; |
||
414 | joko | 463 | static long IntegralFehlerNick = 0; |
464 | static long IntegralFehlerRoll = 0; |
||
202 | joko | 465 | static unsigned int RcLostTimer; |
466 | static unsigned char delay_neutral = 0; |
||
467 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
468 | static unsigned int modell_fliegt = 0; |
||
469 | static int hoehenregler = 0; |
||
470 | static char TimerWerteausgabe = 0; |
||
471 | static char NeueKompassRichtungMerken = 0; |
||
472 | Mittelwert(); |
||
473 | |||
474 | GRN_ON; |
||
475 | |||
476 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
477 | // Gaswert ermitteln |
||
478 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
479 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
||
480 | if(GasMischanteil < 0) GasMischanteil = 0; |
||
481 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
482 | // Emfang schlecht |
||
483 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
484 | if(SenderOkay < 100) |
||
485 | { |
||
486 | if(!PcZugriff) |
||
487 | { |
||
488 | if(BeepMuster == 0xffff) |
||
489 | { |
||
490 | beeptime = 15000; |
||
491 | BeepMuster = 0x0c00; |
||
492 | } |
||
493 | } |
||
494 | if(RcLostTimer) RcLostTimer--; |
||
495 | else |
||
496 | { |
||
497 | MotorenEin = 0; |
||
498 | Notlandung = 0; |
||
499 | } |
||
500 | ROT_ON; |
||
501 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
||
502 | { |
||
503 | GasMischanteil = EE_Parameter.NotGas; |
||
504 | Notlandung = 1; |
||
505 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
||
506 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
||
507 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
||
508 | } |
||
509 | else MotorenEin = 0; |
||
510 | } |
||
511 | else |
||
512 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
513 | // Emfang gut |
||
514 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
515 | if(SenderOkay > 140) |
||
516 | { |
||
517 | Notlandung = 0; |
||
518 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
||
519 | if(GasMischanteil > 40) |
||
520 | { |
||
521 | if(modell_fliegt < 0xffff) modell_fliegt++; |
||
522 | modell_fliegt_gps = modell_fliegt;// (030907Kr) |
||
523 | } |
||
524 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
||
525 | { |
||
526 | SummeNick = 0; |
||
527 | SummeRoll = 0; |
||
528 | Mess_Integral_Gier = 0; |
||
529 | Mess_Integral_Gier2 = 0; |
||
530 | } |
||
531 | if((GasMischanteil > 200) && MotorenEin == 0) |
||
532 | { |
||
533 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
534 | // auf Nullwerte kalibrieren |
||
535 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
536 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
||
537 | { |
||
538 | unsigned char setting; |
||
539 | if(++delay_neutral > 200) // nicht sofort |
||
540 | { |
||
541 | GRN_OFF; |
||
542 | MotorenEin = 0; |
||
543 | delay_neutral = 0; |
||
544 | modell_fliegt = 0; |
||
545 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
||
546 | { |
||
547 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
||
548 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
||
549 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
||
550 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
||
551 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
||
552 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
||
553 | } |
||
554 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
||
555 | { |
||
556 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
||
557 | } |
||
558 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
559 | SetNeutral(); |
||
560 | Piep(GetActiveParamSetNumber()); |
||
561 | } |
||
562 | } |
||
563 | else delay_neutral = 0; |
||
564 | } |
||
565 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
566 | // Gas ist unten |
||
567 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
568 | if(GasMischanteil < 35) |
||
569 | { |
||
570 | // Starten |
||
571 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
||
572 | { |
||
573 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
574 | // Einschalten |
||
575 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
576 | if(++delay_einschalten > 200) |
||
577 | { |
||
578 | delay_einschalten = 200; |
||
579 | modell_fliegt = 1; |
||
580 | MotorenEin = 1; |
||
581 | sollGier = 0; |
||
582 | Mess_Integral_Gier = 0; |
||
583 | Mess_Integral_Gier2 = 0; |
||
584 | Mess_IntegralNick = 0; |
||
585 | Mess_IntegralRoll = 0; |
||
586 | Mess_IntegralNick2 = IntegralNick; |
||
587 | Mess_IntegralRoll2 = IntegralRoll; |
||
588 | SummeNick = 0; |
||
589 | SummeRoll = 0; |
||
590 | } |
||
591 | } |
||
592 | else delay_einschalten = 0; |
||
593 | //Auf Neutralwerte setzen |
||
594 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
595 | // Auschalten |
||
596 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
597 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
||
598 | { |
||
599 | if(++delay_ausschalten > 200) // nicht sofort |
||
600 | { |
||
601 | MotorenEin = 0; |
||
602 | delay_ausschalten = 200; |
||
603 | modell_fliegt = 0; |
||
604 | } |
||
605 | } |
||
606 | else delay_ausschalten = 0; |
||
607 | } |
||
608 | } |
||
609 | |||
610 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
611 | // neue Werte von der Funke |
||
612 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
613 | if(!NewPpmData-- || Notlandung) |
||
614 | { |
||
615 | ParameterZuordnung(); |
||
616 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
||
617 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
||
618 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
||
619 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
||
620 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
||
621 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
||
622 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
||
623 | |||
624 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
||
625 | if(GyroFaktor < 0) GyroFaktor = 0; |
||
626 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
||
627 | // greift in den Stick ein, um ungewolltes überschlagen zu verhindern |
||
414 | joko | 628 | //bei aktiviertem GPS dürfen die Stickwerte nicht beeinflusst werden, da ansonsten ein Neulernen der Sollposition stattfinden könnte //(051107Kr) |
629 | if(!(EE_Parameter.LoopConfig & CFG_LOOP_LINKS) && !(EE_Parameter.LoopConfig & CFG_LOOP_RECHTS) && !(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) && !(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD)) //(051107Kr) |
||
202 | joko | 630 | { |
631 | if(IntegralNick > 60000) |
||
632 | { |
||
633 | StickNick -= 8 * EE_Parameter.Stick_P; |
||
634 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
||
635 | } |
||
636 | else |
||
637 | if(IntegralNick < -60000) |
||
638 | { |
||
639 | StickNick += 8 * EE_Parameter.Stick_P; |
||
640 | if(IntegralNick > 80000) StickNick -= 16 * EE_Parameter.Stick_P; |
||
641 | } |
||
642 | if(IntegralRoll > 60000) |
||
643 | { |
||
644 | StickRoll -= 8 * EE_Parameter.Stick_P; |
||
645 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
||
646 | } |
||
647 | else |
||
648 | if(IntegralRoll < -60000) |
||
649 | { |
||
650 | StickRoll += 8 * EE_Parameter.Stick_P; |
||
651 | if(IntegralRoll > 80000) StickRoll -= 16 * EE_Parameter.Stick_P; |
||
652 | } |
||
653 | } |
||
654 | |||
655 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
656 | // LED Stuff |
||
657 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
658 | |||
414 | joko | 659 | #define LED1_ONTIME 20 |
501 | joko | 660 | #define LED1_TOTALTIME 60 //um das Blinkverhalten per Fernsteuerung zu beeinflussen, kann in der LED Routine anstelle von "LED1_TOTALTIME" auch "Parameter_UserParam4" stehen |
414 | joko | 661 | |
393 | joko | 662 | LED1_OFF; |
414 | joko | 663 | |
501 | joko | 664 | if(LED1_TOTALTIME >= 200) |
393 | joko | 665 | { |
414 | joko | 666 | LED1_ON; |
393 | joko | 667 | blinkcount_LED1 = 0; |
668 | } |
||
414 | joko | 669 | |
501 | joko | 670 | else if(blinkcount_LED1 >= LED1_TOTALTIME && LED1_TOTALTIME > 0 && MotorenEin == 1) |
414 | joko | 671 | { |
672 | LED1_ON; |
||
673 | |||
501 | joko | 674 | if(blinkcount_LED1 >= LED1_ONTIME + LED1_TOTALTIME) |
414 | joko | 675 | { |
676 | LED1_OFF; |
||
677 | blinkcount_LED1 = 0; |
||
678 | } |
||
679 | } |
||
202 | joko | 680 | |
393 | joko | 681 | blinkcount_LED1++; |
202 | joko | 682 | |
683 | //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] > 75) LED1_ON; else LED1_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr) |
||
684 | //if(PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] > 75) LED2_ON; else LED2_OFF; //Erweiterung von Smartie aus dem MK-Forum vom 14.06.07. Dadurch können die Transistorausgänge J16 und J17 geschaltet werden. // (160607Kr) |
||
685 | } |
||
686 | |||
687 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
688 | // Looping? |
||
689 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
690 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_LINKS) || |
||
691 | ((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_RECHTS)) |
||
692 | { |
||
693 | Looping_Roll = 1; |
||
694 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
||
695 | } |
||
696 | else Looping_Roll = 0; |
||
697 | |||
698 | if(((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_OBEN) || |
||
699 | ((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.LoopConfig & CFG_LOOP_UNTEN)) |
||
700 | { |
||
701 | Looping_Nick = 1; |
||
702 | Looping_Roll = 0; |
||
703 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
||
704 | } |
||
705 | else Looping_Nick = 0; |
||
706 | |||
707 | |||
708 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
709 | // Bei Empfangsausfall im Flug |
||
710 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
711 | if(Notlandung) |
||
712 | { |
||
713 | StickGier = 0; |
||
714 | StickNick = 0; |
||
715 | StickRoll = 0; |
||
716 | GyroFaktor = 0.1; |
||
717 | IntegralFaktor = 0.005; |
||
718 | Looping_Roll = 0; |
||
719 | Looping_Nick = 0; |
||
720 | } |
||
721 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
722 | // Gyro-Drift kompensieren |
||
723 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
724 | #define DRIFT_FAKTOR 3 |
||
725 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
||
726 | { |
||
727 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
||
728 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
||
729 | ZaehlMessungen = 0; |
||
730 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
||
731 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
||
732 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
||
733 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
||
734 | // if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; // macht nur mit Referenz (Kompass Sinn) |
||
735 | // if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; // macht nur mit Referenz (Kompass Sinn) |
||
736 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
||
737 | Mess_IntegralNick2 = IntegralNick; |
||
738 | Mess_IntegralRoll2 = IntegralRoll; |
||
739 | Mess_Integral_Gier2 = Integral_Gier; |
||
740 | ANALOG_ON; // ADC einschalten |
||
741 | } |
||
742 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
743 | // Integrale auf ACC-Signal abgleichen |
||
744 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
267 | joko | 745 | |
746 | |||
747 | if(IntegralFaktor && !Looping_Nick && !Looping_Roll) |
||
748 | { |
||
459 | joko | 749 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
750 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
||
267 | joko | 751 | #define AUSGLEICH 500 |
752 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
||
753 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
||
754 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
||
755 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
||
756 | } |
||
757 | |||
758 | else |
||
759 | { |
||
760 | tmp_long = 0; |
||
761 | tmp_long2 = 0; |
||
762 | } |
||
763 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
||
764 | Mess_IntegralNick -= tmp_long; |
||
765 | Mess_IntegralRoll -= tmp_long2; |
||
202 | joko | 766 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
767 | // Gieren |
||
768 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
769 | if(abs(StickGier) > 20) // war 35 |
||
770 | { |
||
771 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
||
772 | } |
||
459 | joko | 773 | tmp_int = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
202 | joko | 774 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
775 | sollGier = tmp_int; |
||
776 | Mess_Integral_Gier -= tmp_int; |
||
777 | if(Mess_Integral_Gier > 25000) Mess_Integral_Gier = 25000; // begrenzen |
||
778 | if(Mess_Integral_Gier <-25000) Mess_Integral_Gier =-25000; |
||
779 | |||
780 | ANALOG_ON; // ADC einschalten |
||
781 | |||
782 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
783 | // Kompass |
||
784 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
785 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
||
786 | { |
||
787 | int w,v; |
||
788 | static int SignalSchlecht = 0; |
||
789 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
||
790 | v = abs(IntegralRoll /512); |
||
791 | if(v > w) w = v; // grösste Neigung ermitteln |
||
792 | if(w < 25 && NeueKompassRichtungMerken && !SignalSchlecht) |
||
793 | { |
||
794 | KompassStartwert = KompassValue; |
||
795 | NeueKompassRichtungMerken = 0; |
||
796 | } |
||
797 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
||
798 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
||
799 | if(w > 0) |
||
800 | { |
||
801 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
||
802 | if(!SignalSchlecht) Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
||
803 | ANALOG_ON; // ADC einschalten |
||
804 | if(SignalSchlecht) SignalSchlecht--; |
||
805 | } |
||
806 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
||
807 | } |
||
808 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
809 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
810 | |||
811 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
812 | // GPS |
||
813 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
393 | joko | 814 | if(EE_Parameter.GlobalConfig & CFG_GPS_AKTIV) |
815 | { |
||
816 | P_GPS_Verstaerkung = Parameter_UserParam1; |
||
817 | D_GPS_Verstaerkung = Parameter_UserParam2; |
||
501 | joko | 818 | Limit_P_Anteil = Parameter_UserParam3; |
819 | Limit_D_Anteil = Parameter_UserParam4; |
||
393 | joko | 820 | gps_main(); |
821 | } |
||
822 | else |
||
823 | { |
||
824 | GPS_Nick = 0; |
||
825 | GPS_Roll = 0; |
||
826 | } |
||
202 | joko | 827 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
828 | // Debugwerte zuordnen |
||
829 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
830 | if(!TimerWerteausgabe--) |
||
831 | { |
||
832 | TimerWerteausgabe = 49; |
||
833 | |||
501 | joko | 834 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
835 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
||
836 | DebugOut.Analog[2] = Mittelwert_AccNick; |
||
837 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
||
838 | DebugOut.Analog[4] = Parameter_UserParam1; |
||
839 | DebugOut.Analog[5] = Parameter_UserParam2; |
||
840 | DebugOut.Analog[6] = Parameter_UserParam3; |
||
841 | DebugOut.Analog[7] = Parameter_UserParam4; |
||
842 | DebugOut.Analog[8] = KompassValue; |
||
843 | DebugOut.Analog[9] = UBat; |
||
844 | DebugOut.Analog[10] = SenderOkay; |
||
845 | DebugOut.Analog[11] = actualPos.GPSFix; |
||
846 | DebugOut.Analog[12] = motor_rx[0]; //Motorstrom vorne |
||
847 | DebugOut.Analog[13] = motor_rx[1]; //Motorstrom hinten |
||
848 | DebugOut.Analog[14] = motor_rx[2]; //Motorstrom links |
||
849 | DebugOut.Analog[15] = motor_rx[3]; //Motorstrom rechts |
||
850 | DebugOut.Analog[16] = Poti3; |
||
393 | joko | 851 | DebugOut.Analog[17] = actualPos.altitude; |
501 | joko | 852 | DebugOut.Analog[18] = actualPos.velNorth; |
853 | DebugOut.Analog[19] = actualPos.velEast; |
||
854 | DebugOut.Analog[20] = GPS_Positionsabweichung_North; |
||
855 | DebugOut.Analog[21] = GPS_Positionsabweichung_East; |
||
856 | DebugOut.Analog[22] = P_Einfluss_North; |
||
857 | DebugOut.Analog[23] = P_Einfluss_East; |
||
858 | DebugOut.Analog[24] = D_Einfluss_North; |
||
859 | DebugOut.Analog[25] = D_Einfluss_East; |
||
860 | DebugOut.Analog[26] = GPS_North; |
||
861 | DebugOut.Analog[27] = GPS_East; |
||
862 | DebugOut.Analog[28] = GPS_Roll; |
||
863 | DebugOut.Analog[29] = GPS_Nick; |
||
864 | DebugOut.Analog[30] = StickNick; |
||
865 | DebugOut.Analog[31] = StickRoll; |
||
866 | |||
867 | //DebugOut.Analog[32] = (motor_rx[0]+motor_rx[1]+motor_rx[2]+motor_rx[3]); //Gesamtstrom |
||
868 | //DebugOut.Analog[33] = StickGier; |
||
869 | //DebugOut.Analog[34] = actualPos.GSpeed; |
||
870 | //DebugOut.Analog[35] = GPS_Home_North; |
||
871 | //DebugOut.Analog[36] = GPS_Home_East; |
||
872 | //DebugOut.Analog[37] = Soll_Position_North; |
||
873 | //DebugOut.Analog[38] = Soll_Position_East; |
||
874 | //DebugOut.Analog[39] = actualPos.northing; |
||
875 | //DebugOut.Analog[40] = actualPos.easting; |
||
876 | //DebugOut.Analog[41] = NORTH_MITTEL; |
||
877 | //DebugOut.Analog[42] = EAST_MITTEL; |
||
393 | joko | 878 | |
202 | joko | 879 | } |
880 | |||
881 | |||
882 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
883 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
||
884 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
885 | if(Looping_Nick) MesswertNick = MesswertNick * GyroFaktor; |
||
886 | else MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
||
887 | if(Looping_Roll) MesswertRoll = MesswertRoll * GyroFaktor; |
||
888 | else MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
||
889 | // MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
||
890 | MesswertGier = MesswertGier * (GyroFaktor) + Integral_Gier * IntegralFaktor/2; |
||
891 | |||
892 | // Maximalwerte abfangen |
||
893 | #define MAX_SENSOR 2048 |
||
894 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
||
895 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
||
896 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
||
897 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
||
898 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
||
899 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
||
900 | |||
901 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
902 | // Höhenregelung |
||
903 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
||
904 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
905 | //OCR0B = 180 - (Poti1 + 120) / 4; |
||
906 | //DruckOffsetSetting = OCR0B; |
||
907 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
||
908 | { |
||
909 | int tmp_int; |
||
910 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
||
911 | { |
||
912 | if(Parameter_MaxHoehe < 50) |
||
913 | { |
||
501 | joko | 914 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
202 | joko | 915 | HoehenReglerAktiv = 0; |
916 | } |
||
917 | else |
||
918 | HoehenReglerAktiv = 1; |
||
919 | } |
||
920 | else |
||
921 | { |
||
501 | joko | 922 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
202 | joko | 923 | HoehenReglerAktiv = 1; |
924 | } |
||
925 | |||
926 | if(Notlandung) SollHoehe = 0; |
||
927 | h = HoehenWert; |
||
928 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
||
929 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
||
930 | h = GasMischanteil - h; // vom Gas abziehen |
||
931 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
||
932 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
||
933 | if(tmp_int > 50) tmp_int = 50; |
||
934 | else if(tmp_int < -50) tmp_int = -50; |
||
935 | h -= tmp_int; |
||
936 | hoehenregler = (hoehenregler*15 + h) / 16; |
||
937 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
||
938 | { |
||
939 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
||
940 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
||
941 | } |
||
942 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
||
943 | GasMischanteil = hoehenregler; |
||
944 | } |
||
945 | } |
||
946 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
947 | // + Mischer und PI-Regler |
||
948 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
949 | // DebugOut.Analog[7] = GasMischanteil; |
||
950 | |||
951 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
952 | // Gier-Anteil |
||
953 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
954 | #define MUL_G 1.0 |
||
955 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
||
956 | //GierMischanteil = 0; |
||
957 | if(GierMischanteil > (MUL_G * GasMischanteil)) GierMischanteil = MUL_G * GasMischanteil; |
||
958 | if(GierMischanteil < -(MUL_G * GasMischanteil)) GierMischanteil = -(MUL_G * GasMischanteil); |
||
959 | if(GierMischanteil > 100) GierMischanteil = 100; |
||
960 | if(GierMischanteil < -100) GierMischanteil = -100; |
||
961 | |||
962 | if(GasMischanteil < 20) GierMischanteil = 0; |
||
963 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
964 | // Nick-Achse |
||
965 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
966 | |||
967 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
||
968 | SummeNick += DiffNick; // I-Anteil |
||
969 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
||
970 | if(SummeNick > 16000) SummeNick = 16000; |
||
971 | if(SummeNick < -16000) SummeNick = -16000; |
||
414 | joko | 972 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
202 | joko | 973 | // Motor Vorn |
974 | #define MUL 2 |
||
975 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
||
976 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
||
977 | |||
978 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
||
979 | if ((motorwert < 0)) motorwert = 0; |
||
980 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
||
981 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
982 | Motor_Vorne = motorwert; |
||
983 | // Motor Heck |
||
984 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
||
985 | if ((motorwert < 0)) motorwert = 0; |
||
986 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
||
987 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
988 | Motor_Hinten = motorwert; |
||
989 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
990 | // Roll-Achse |
||
991 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
992 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
||
993 | SummeRoll += DiffRoll; // I-Anteil |
||
994 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
||
995 | if(SummeRoll > 16000) SummeRoll = 16000; |
||
996 | if(SummeRoll < -16000) SummeRoll = -16000; |
||
414 | joko | 997 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
202 | joko | 998 | if(pd_ergebnis > MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = MUL * (GasMischanteil + abs(GierMischanteil)); |
999 | if(pd_ergebnis < -MUL * (GasMischanteil + abs(GierMischanteil))) pd_ergebnis = -MUL * (GasMischanteil + abs(GierMischanteil)); |
||
1000 | // Motor Links |
||
1001 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
||
1002 | if ((motorwert < 0)) motorwert = 0; |
||
1003 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
||
1004 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
1005 | Motor_Links = motorwert; |
||
1006 | // Motor Rechts |
||
1007 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
||
1008 | if ((motorwert < 0)) motorwert = 0; |
||
1009 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
||
1010 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
||
1011 | Motor_Rechts = motorwert; |
||
1012 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
||
1013 | } |
||
1014 |