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