Rev 461 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 461 | Rev 467 | ||
---|---|---|---|
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 char Timeout = 0; |
59 | volatile unsigned char Timeout = 0; |
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; |
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch; |
63 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
63 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
64 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
64 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
65 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
65 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
66 | volatile long Integral_Gier = 0; |
66 | volatile long Integral_Gier = 0; |
67 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
67 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
68 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
68 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
69 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
69 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
70 | volatile long Mess_Integral_Hoch = 0; |
70 | volatile long Mess_Integral_Hoch = 0; |
71 | volatile int KompassValue = 0; |
71 | int KompassValue = 0; |
72 | volatile int KompassStartwert = 0; |
72 | int KompassStartwert = 0; |
73 | volatile int KompassRichtung = 0; |
73 | int KompassRichtung = 0; |
74 | uint8_t updKompass = 0; |
74 | uint8_t updKompass = 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 | float GyroFaktor; |
79 | float GyroFaktor; |
80 | float IntegralFaktor; |
80 | float IntegralFaktor; |
81 | 81 | ||
82 | volatile int DiffNick,DiffRoll; |
82 | volatile int DiffNick,DiffRoll; |
83 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
83 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
84 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
84 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
85 | unsigned char MotorWert[5]; |
85 | unsigned char MotorWert[5]; |
86 | volatile unsigned char SenderOkay = 0; |
86 | volatile unsigned char SenderOkay = 0; |
87 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
87 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
88 | char MotorenEin = 0; |
88 | char MotorenEin = 0; |
89 | int HoehenWert = 0; |
89 | int HoehenWert = 0; |
90 | int SollHoehe = 0; |
90 | int SollHoehe = 0; |
91 | 91 | ||
92 | float Kp = FAKTOR_P; |
92 | float Kp = FAKTOR_P; |
93 | float Ki = FAKTOR_I; |
93 | float Ki = FAKTOR_I; |
94 | 94 | ||
95 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
95 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
96 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
96 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
97 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
97 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
98 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
98 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
99 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
99 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
100 | unsigned char Parameter_Gyro_P = 50; // Wert : 10-250 |
100 | unsigned char Parameter_Gyro_P = 50; // Wert : 10-250 |
101 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
101 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
102 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
102 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
103 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
103 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
104 | unsigned char Parameter_UserParam1 = 0; |
104 | unsigned char Parameter_UserParam1 = 0; |
105 | unsigned char Parameter_UserParam2 = 0; |
105 | unsigned char Parameter_UserParam2 = 0; |
106 | unsigned char Parameter_UserParam3 = 0; |
106 | unsigned char Parameter_UserParam3 = 0; |
107 | unsigned char Parameter_UserParam4 = 0; |
107 | unsigned char Parameter_UserParam4 = 0; |
108 | unsigned char Parameter_ServoNickControl = 100; |
108 | unsigned char Parameter_ServoNickControl = 100; |
109 | struct mk_param_struct EE_Parameter; |
109 | struct mk_param_struct EE_Parameter; |
110 | 110 | ||
111 | struct acc_neutral_struct ee_acc_neutral EEMEM; // Reservierung im EEPROM |
111 | struct acc_neutral_struct ee_acc_neutral EEMEM; // Reservierung im EEPROM |
112 | struct acc_neutral_struct acc_neutral; |
112 | struct acc_neutral_struct acc_neutral; |
113 | 113 | ||
114 | void Piep(unsigned char Anzahl) |
114 | void Piep(unsigned char Anzahl) |
115 | { |
115 | { |
116 | while(Anzahl--) |
116 | while(Anzahl--) |
117 | { |
117 | { |
118 | if(MotorenEin) return; //auf keinen Fall im Flug! |
118 | if(MotorenEin) return; //auf keinen Fall im Flug! |
119 | beeptime = 100; |
119 | beeptime = 100; |
120 | Delay_ms(250); |
120 | Delay_ms(250); |
121 | } |
121 | } |
122 | } |
122 | } |
123 | 123 | ||
124 | 124 | ||
125 | //############################################################################ |
125 | //############################################################################ |
126 | // Neutrallage kalibrieren und fest im EEPROM abspeichern |
126 | // Neutrallage kalibrieren und fest im EEPROM abspeichern |
127 | void calib_acc(void) |
127 | void calib_acc(void) |
128 | //############################################################################ |
128 | //############################################################################ |
129 | { |
129 | { |
130 | unsigned int timer; |
130 | unsigned int timer; |
131 | acc_neutral.X = 0; |
131 | acc_neutral.X = 0; |
132 | acc_neutral.Y = 0; |
132 | acc_neutral.Y = 0; |
133 | acc_neutral.Z = 0; |
133 | acc_neutral.Z = 0; |
134 | CalibrierMittelwert(); |
134 | CalibrierMittelwert(); |
135 | timer = SetDelay(5); |
135 | timer = SetDelay(5); |
136 | while (!CheckDelay(timer)); |
136 | while (!CheckDelay(timer)); |
137 | CalibrierMittelwert(); |
137 | CalibrierMittelwert(); |
138 | 138 | ||
139 | acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
139 | acc_neutral.X = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
140 | acc_neutral.Y = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
140 | acc_neutral.Y = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
141 | acc_neutral.Z = Aktuell_az; |
141 | acc_neutral.Z = Aktuell_az; |
142 | 142 | ||
143 | eeprom_write_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct)); |
143 | eeprom_write_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct)); |
144 | } |
144 | } |
145 | 145 | ||
146 | //############################################################################ |
146 | //############################################################################ |
147 | // Nullwerte ermitteln |
147 | // Nullwerte ermitteln |
148 | void SetNeutral(void) |
148 | void SetNeutral(void) |
149 | //############################################################################ |
149 | //############################################################################ |
150 | { |
150 | { |
151 | unsigned int timer; |
151 | unsigned int timer; |
152 | acc_neutral.X = 0; |
152 | acc_neutral.X = 0; |
153 | acc_neutral.Y = 0; |
153 | acc_neutral.Y = 0; |
154 | acc_neutral.Z = 0; |
154 | acc_neutral.Z = 0; |
155 | AdNeutralNick = 0; |
155 | AdNeutralNick = 0; |
156 | AdNeutralRoll = 0; |
156 | AdNeutralRoll = 0; |
157 | AdNeutralGier = 0; |
157 | AdNeutralGier = 0; |
158 | CalibrierMittelwert(); |
158 | CalibrierMittelwert(); |
159 | timer = SetDelay(5); |
159 | timer = SetDelay(5); |
160 | while (!CheckDelay(timer)); |
160 | while (!CheckDelay(timer)); |
161 | CalibrierMittelwert(); |
161 | CalibrierMittelwert(); |
162 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
162 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
163 | { |
163 | { |
164 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
164 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
165 | } |
165 | } |
166 | AdNeutralNick= abs(MesswertNick); |
166 | AdNeutralNick= abs(MesswertNick); |
167 | AdNeutralRoll= abs(MesswertRoll); |
167 | AdNeutralRoll= abs(MesswertRoll); |
168 | AdNeutralGier= abs(MesswertGier); |
168 | AdNeutralGier= abs(MesswertGier); |
169 | 169 | ||
170 | eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct)); |
170 | eeprom_read_block(&acc_neutral,&ee_acc_neutral,sizeof(struct acc_neutral_struct)); |
171 | 171 | ||
172 | Mess_IntegralNick = 0; |
172 | Mess_IntegralNick = 0; |
173 | Mess_IntegralNick2 = 0; |
173 | Mess_IntegralNick2 = 0; |
174 | Mess_IntegralRoll = 0; |
174 | Mess_IntegralRoll = 0; |
175 | Mess_IntegralRoll2 = 0; |
175 | Mess_IntegralRoll2 = 0; |
176 | Mess_Integral_Gier = 0; |
176 | Mess_Integral_Gier = 0; |
177 | MesswertNick = 0; |
177 | MesswertNick = 0; |
178 | MesswertRoll = 0; |
178 | MesswertRoll = 0; |
179 | MesswertGier = 0; |
179 | MesswertGier = 0; |
180 | StartLuftdruck = Luftdruck; |
180 | StartLuftdruck = Luftdruck; |
181 | HoeheD = 0; |
181 | HoeheD = 0; |
182 | Mess_Integral_Hoch = 0; |
182 | Mess_Integral_Hoch = 0; |
183 | KompassStartwert = KompassValue; |
183 | KompassStartwert = KompassValue; |
184 | GPS_Neutral(); |
184 | GPS_Neutral(); |
185 | beeptime = 50; |
185 | beeptime = 50; |
186 | } |
186 | } |
187 | 187 | ||
188 | //############################################################################ |
188 | //############################################################################ |
189 | // Bildet den Mittelwert aus den Messwerten |
189 | // Bildet den Mittelwert aus den Messwerten |
190 | void Mittelwert(void) |
190 | void Mittelwert(void) |
191 | //############################################################################ |
191 | //############################################################################ |
192 | { |
192 | { |
193 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
193 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
194 | ANALOG_OFF; |
194 | ANALOG_OFF; |
195 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
195 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
196 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
196 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
197 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
197 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
198 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
198 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
199 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
199 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
200 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
200 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
201 | AccumulateNick = 0; MessanzahlNick = 0; |
201 | AccumulateNick = 0; MessanzahlNick = 0; |
202 | AccumulateRoll = 0; MessanzahlRoll = 0; |
202 | AccumulateRoll = 0; MessanzahlRoll = 0; |
203 | AccumulateGier = 0; MessanzahlGier = 0; |
203 | AccumulateGier = 0; MessanzahlGier = 0; |
204 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
204 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
205 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
205 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
206 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
206 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
207 | Integral_Gier = Mess_Integral_Gier; |
207 | Integral_Gier = Mess_Integral_Gier; |
208 | // Integral_Gier2 = Mess_Integral_Gier2; |
208 | // Integral_Gier2 = Mess_Integral_Gier2; |
209 | IntegralNick = Mess_IntegralNick; |
209 | IntegralNick = Mess_IntegralNick; |
210 | IntegralRoll = Mess_IntegralRoll; |
210 | IntegralRoll = Mess_IntegralRoll; |
211 | IntegralNick2 = Mess_IntegralNick2; |
211 | IntegralNick2 = Mess_IntegralNick2; |
212 | IntegralRoll2 = Mess_IntegralRoll2; |
212 | IntegralRoll2 = Mess_IntegralRoll2; |
213 | // ADC einschalten |
213 | // ADC einschalten |
214 | ANALOG_ON; |
214 | ANALOG_ON; |
215 | 215 | ||
216 | /* |
216 | /* |
217 | //------------------------------------------------------------------------------ |
217 | //------------------------------------------------------------------------------ |
218 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
218 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
219 | else |
219 | else |
220 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
220 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
221 | 221 | ||
222 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
222 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
223 | else |
223 | else |
224 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
224 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
225 | //------------------------------------------------------------------------------ |
225 | //------------------------------------------------------------------------------ |
226 | */ |
226 | */ |
227 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
227 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
228 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
228 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
229 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
229 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
230 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
230 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
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 | } |
235 | } |
236 | 236 | ||
237 | //############################################################################ |
237 | //############################################################################ |
238 | // Messwerte beim Ermitteln der Nullage |
238 | // Messwerte beim Ermitteln der Nullage |
239 | void CalibrierMittelwert(void) |
239 | void CalibrierMittelwert(void) |
240 | //############################################################################ |
240 | //############################################################################ |
241 | { |
241 | { |
242 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
242 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
243 | ANALOG_OFF; |
243 | ANALOG_OFF; |
244 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
244 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
245 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
245 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
246 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
246 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
247 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
247 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
248 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
248 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
249 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
249 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
250 | AccumulateNick = 0; MessanzahlNick = 0; |
250 | AccumulateNick = 0; MessanzahlNick = 0; |
251 | AccumulateRoll = 0; MessanzahlRoll = 0; |
251 | AccumulateRoll = 0; MessanzahlRoll = 0; |
252 | AccumulateGier = 0; MessanzahlGier = 0; |
252 | AccumulateGier = 0; MessanzahlGier = 0; |
253 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
253 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
254 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
254 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
255 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
255 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
256 | // ADC einschalten |
256 | // ADC einschalten |
257 | ANALOG_ON; |
257 | ANALOG_ON; |
258 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
258 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
259 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
259 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
260 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
260 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
261 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
261 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
262 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
262 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
263 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
263 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
264 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
264 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
265 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
265 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
266 | } |
266 | } |
267 | 267 | ||
268 | //############################################################################ |
268 | //############################################################################ |
269 | // Senden der Motorwerte per I2C-Bus |
269 | // Senden der Motorwerte per I2C-Bus |
270 | void SendMotorData(void) |
270 | void SendMotorData(void) |
271 | //############################################################################ |
271 | //############################################################################ |
272 | { |
272 | { |
273 | if(MOTOR_OFF || !MotorenEin) |
273 | if(MOTOR_OFF || !MotorenEin) |
274 | { |
274 | { |
275 | Motor_Hinten = 0; |
275 | Motor_Hinten = 0; |
276 | Motor_Vorne = 0; |
276 | Motor_Vorne = 0; |
277 | Motor_Rechts = 0; |
277 | Motor_Rechts = 0; |
278 | Motor_Links = 0; |
278 | Motor_Links = 0; |
279 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
279 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
280 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
280 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
281 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
281 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
282 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
282 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
283 | } |
283 | } |
284 | 284 | ||
285 | DebugOut.Analog[12] = Motor_Vorne; |
285 | DebugOut.Analog[12] = Motor_Vorne; |
286 | DebugOut.Analog[13] = Motor_Hinten; |
286 | DebugOut.Analog[13] = Motor_Hinten; |
287 | DebugOut.Analog[14] = Motor_Links; |
287 | DebugOut.Analog[14] = Motor_Links; |
288 | DebugOut.Analog[15] = Motor_Rechts; |
288 | DebugOut.Analog[15] = Motor_Rechts; |
289 | 289 | ||
290 | //Start I2C Interrupt Mode |
290 | //Start I2C Interrupt Mode |
291 | twi_state = 0; |
291 | twi_state = 0; |
292 | motor = 0; |
292 | motor = 0; |
293 | i2c_start(); |
293 | i2c_start(); |
294 | } |
294 | } |
295 | 295 | ||
296 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
296 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
297 | // + Konstanten |
297 | // + Konstanten |
298 | // + 0-250 -> normale Werte |
298 | // + 0-250 -> normale Werte |
299 | // + 251 -> Poti1 |
299 | // + 251 -> Poti1 |
300 | // + 252 -> Poti2 |
300 | // + 252 -> Poti2 |
301 | // + 253 -> Poti3 |
301 | // + 253 -> Poti3 |
302 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
302 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
303 | void DefaultKonstanten1(void) |
303 | void DefaultKonstanten1(void) |
304 | { |
304 | { |
305 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
305 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
306 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
306 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
307 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
307 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
308 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
308 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
309 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
309 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
310 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
310 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
311 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
311 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
312 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
312 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
313 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
313 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
314 | EE_Parameter.Hoehe_MinGas = 30; |
314 | EE_Parameter.Hoehe_MinGas = 30; |
315 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
315 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
316 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
316 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
317 | EE_Parameter.Luftdruck_D = 70; // Wert : 0-250 |
317 | EE_Parameter.Luftdruck_D = 70; // Wert : 0-250 |
318 | EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250 |
318 | EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250 |
319 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
319 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
320 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
320 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
321 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
321 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
322 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
322 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
323 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
323 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
324 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
324 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
325 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
325 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
326 | EE_Parameter.KompassWirkung = 16; // Wert : 0-250 |
326 | EE_Parameter.KompassWirkung = 16; // Wert : 0-250 |
327 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
327 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
328 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
328 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
329 | EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250 |
329 | EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250 |
330 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
330 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
331 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
331 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
332 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
332 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
333 | EE_Parameter.I_Faktor = 5; |
333 | EE_Parameter.I_Faktor = 5; |
334 | EE_Parameter.UserParam1 = 178; //zur freien Verwendung |
334 | EE_Parameter.UserParam1 = 178; //zur freien Verwendung |
335 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
335 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
336 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
336 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
337 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
337 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
338 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
338 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
339 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
339 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
340 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
340 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
341 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
341 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
342 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
342 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
343 | EE_Parameter.ServoNickRefresh = 5; |
343 | EE_Parameter.ServoNickRefresh = 5; |
344 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
344 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
345 | } |
345 | } |
346 | 346 | ||
347 | void DefaultKonstanten2(void) |
347 | void DefaultKonstanten2(void) |
348 | { |
348 | { |
349 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
349 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
350 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
350 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
351 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
351 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
352 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
352 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
353 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
353 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
354 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
354 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
355 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
355 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
356 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
356 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
357 | EE_Parameter.Hoehe_MinGas = 30; |
357 | EE_Parameter.Hoehe_MinGas = 30; |
358 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
358 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
359 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
359 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
360 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
360 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
361 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
361 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
362 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
362 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
363 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
363 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
364 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
364 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
365 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
365 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
366 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
366 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
367 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
367 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
368 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
368 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
369 | EE_Parameter.KompassWirkung = 16; // Wert : 0-250 |
369 | EE_Parameter.KompassWirkung = 16; // Wert : 0-250 |
370 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
370 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
371 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
371 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
372 | EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250 |
372 | EE_Parameter.UnterspannungsWarnung = 90; // Wert : 0-250 |
373 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
373 | EE_Parameter.NotGas = 35; // Wert : 0-250 // Gaswert bei Empangsverlust |
374 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
374 | EE_Parameter.NotGasZeit = 20; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
375 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
375 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
376 | EE_Parameter.I_Faktor = 5; |
376 | EE_Parameter.I_Faktor = 5; |
377 | EE_Parameter.UserParam1 = 178; //zur freien Verwendung |
377 | EE_Parameter.UserParam1 = 178; //zur freien Verwendung |
378 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
378 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
379 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
379 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
380 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
380 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
381 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
381 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
382 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
382 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
383 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
383 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
384 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
384 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
385 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
385 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
386 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
386 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
387 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
387 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
388 | EE_Parameter.ServoNickRefresh = 5; |
388 | EE_Parameter.ServoNickRefresh = 5; |
389 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
389 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
390 | } |
390 | } |
391 | 391 | ||
392 | 392 | ||
393 | //############################################################################ |
393 | //############################################################################ |
394 | // Trägt ggf. das Poti als Parameter ein |
394 | // Trägt ggf. das Poti als Parameter ein |
395 | void ParameterZuordnung(void) |
395 | void ParameterZuordnung(void) |
396 | //############################################################################ |
396 | //############################################################################ |
397 | { |
397 | { |
398 | 398 | ||
399 | #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;} |
399 | #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;} |
400 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
400 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
401 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
401 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
402 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
402 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
403 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
403 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
404 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
404 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
405 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
405 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
406 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
406 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
407 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
407 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
408 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
408 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
409 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
409 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
410 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
410 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
411 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
411 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
412 | 412 | ||
413 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
413 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
414 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
414 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
415 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
415 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
416 | 416 | ||
417 | Ki = (float) Parameter_I_Faktor * 0.0001; |
417 | Ki = (float) Parameter_I_Faktor * 0.0001; |
418 | MAX_GAS = EE_Parameter.Gas_Max; |
418 | MAX_GAS = EE_Parameter.Gas_Max; |
419 | MIN_GAS = EE_Parameter.Gas_Min; |
419 | MIN_GAS = EE_Parameter.Gas_Min; |
420 | } |
420 | } |
421 | 421 | ||
422 | 422 | ||
423 | //############################################################################ |
423 | //############################################################################ |
424 | // |
424 | // |
425 | void MotorRegler(void) |
425 | void MotorRegler(void) |
426 | //############################################################################ |
426 | //############################################################################ |
427 | { |
427 | { |
428 | int motorwert,pd_ergebnis,h,tmp_int; |
428 | int motorwert,pd_ergebnis,h,tmp_int; |
429 | int GierMischanteil,GasMischanteil; |
429 | int GierMischanteil,GasMischanteil; |
430 | static long SummeNick=0,SummeRoll=0; |
430 | static long SummeNick=0,SummeRoll=0; |
431 | static long sollGier = 0,tmp_long,tmp_long2; |
431 | static long sollGier = 0,tmp_long,tmp_long2; |
432 | static int IntegralFehlerNick = 0; |
432 | static int IntegralFehlerNick = 0; |
433 | static int IntegralFehlerRoll = 0; |
433 | static int IntegralFehlerRoll = 0; |
434 | static unsigned int RcLostTimer; |
434 | static unsigned int RcLostTimer; |
435 | static unsigned char delay_neutral = 0; |
435 | static unsigned char delay_neutral = 0; |
436 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
436 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
437 | static unsigned int modell_fliegt = 0; |
437 | static unsigned int modell_fliegt = 0; |
438 | static int hoehenregler = 0; |
438 | static int hoehenregler = 0; |
439 | static char TimerWerteausgabe = 0; |
439 | static char TimerWerteausgabe = 0; |
440 | static char NeueKompassRichtungMerken = 1; |
440 | static char NeueKompassRichtungMerken = 1; |
441 | Mittelwert(); |
441 | Mittelwert(); |
442 | 442 | ||
443 | GRN_ON; |
443 | GRN_ON; |
444 | 444 | ||
445 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
445 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
446 | // Gaswert ermitteln |
446 | // Gaswert ermitteln |
447 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
447 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
448 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
448 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
449 | if(GasMischanteil < 0) GasMischanteil = 0; |
449 | if(GasMischanteil < 0) GasMischanteil = 0; |
450 | 450 | ||
451 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
451 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
452 | // Emfang schlecht |
452 | // Emfang schlecht |
453 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
453 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
454 | if(SenderOkay < 100) |
454 | if(SenderOkay < 100) |
455 | { |
455 | { |
456 | if(!PcZugriff) beeptime = 500; |
456 | if(!PcZugriff) beeptime = 500; |
457 | if(RcLostTimer) RcLostTimer--; |
457 | if(RcLostTimer) RcLostTimer--; |
458 | else |
458 | else |
459 | { |
459 | { |
460 | MotorenEin = 0; |
460 | MotorenEin = 0; |
461 | Notlandung = 0; |
461 | Notlandung = 0; |
462 | } |
462 | } |
463 | ROT_ON; |
463 | ROT_ON; |
464 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
464 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
465 | { |
465 | { |
466 | GasMischanteil = EE_Parameter.NotGas; |
466 | GasMischanteil = EE_Parameter.NotGas; |
467 | Notlandung = 1; |
467 | Notlandung = 1; |
468 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
468 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
469 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
469 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
470 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
470 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
471 | /* Poti1 = 65; |
471 | /* Poti1 = 65; |
472 | Poti2 = 48; |
472 | Poti2 = 48; |
473 | Poti3 = 0; |
473 | Poti3 = 0; |
474 | */ } |
474 | */ } |
475 | else MotorenEin = 0; |
475 | else MotorenEin = 0; |
476 | } |
476 | } |
477 | else |
477 | else |
478 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
478 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
479 | // Emfang gut |
479 | // Emfang gut |
480 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
480 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
481 | if(SenderOkay > 140) |
481 | if(SenderOkay > 140) |
482 | { |
482 | { |
483 | Notlandung = 0; |
483 | Notlandung = 0; |
484 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
484 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
485 | if(GasMischanteil > 40) |
485 | if(GasMischanteil > 40) |
486 | { |
486 | { |
487 | if(modell_fliegt < 0xffff) modell_fliegt++; |
487 | if(modell_fliegt < 0xffff) modell_fliegt++; |
488 | } |
488 | } |
489 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
489 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
490 | { |
490 | { |
491 | SummeNick = 0; |
491 | SummeNick = 0; |
492 | SummeRoll = 0; |
492 | SummeRoll = 0; |
493 | Mess_Integral_Gier = 0; |
493 | Mess_Integral_Gier = 0; |
494 | Mess_Integral_Gier2 = 0; |
494 | Mess_Integral_Gier2 = 0; |
495 | } |
495 | } |
496 | if((GasMischanteil > 200) && MotorenEin == 0) |
496 | if((GasMischanteil > 200) && MotorenEin == 0) |
497 | { |
497 | { |
498 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
498 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
499 | // auf Nullwerte kalibrieren |
499 | // auf Nullwerte kalibrieren |
500 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
500 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
501 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
501 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
502 | { |
502 | { |
503 | unsigned char setting; |
503 | unsigned char setting; |
504 | if(++delay_neutral > 200) // nicht sofort |
504 | if(++delay_neutral > 200) // nicht sofort |
505 | { |
505 | { |
506 | GRN_OFF; |
506 | GRN_OFF; |
507 | SetNeutral(); |
507 | SetNeutral(); |
508 | MotorenEin = 0; |
508 | MotorenEin = 0; |
509 | delay_neutral = 0; |
509 | delay_neutral = 0; |
510 | modell_fliegt = 0; |
510 | modell_fliegt = 0; |
511 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
511 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
512 | { |
512 | { |
513 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
513 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
514 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
514 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
515 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
515 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
516 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
516 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
517 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
517 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
518 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
518 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
519 | } |
519 | } |
520 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], sizeof(struct mk_param_struct)); |
520 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], sizeof(struct mk_param_struct)); |
521 | Piep(GetActiveParamSetNumber()); |
521 | Piep(GetActiveParamSetNumber()); |
522 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
522 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
523 | { |
523 | { |
524 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
524 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
525 | } |
525 | } |
526 | } |
526 | } |
527 | } |
527 | } |
528 | else delay_neutral = 0; |
528 | else delay_neutral = 0; |
529 | } |
529 | } |
530 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
530 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
531 | // Gas ist unten |
531 | // Gas ist unten |
532 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
532 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
533 | if(GasMischanteil < 35) |
533 | if(GasMischanteil < 35) |
534 | { |
534 | { |
535 | // Starten |
535 | // Starten |
536 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
536 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
537 | { |
537 | { |
538 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
538 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
539 | // Einschalten |
539 | // Einschalten |
540 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
540 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
541 | if(++delay_einschalten > 200) |
541 | if(++delay_einschalten > 200) |
542 | { |
542 | { |
543 | delay_einschalten = 200; |
543 | delay_einschalten = 200; |
544 | modell_fliegt = 1; |
544 | modell_fliegt = 1; |
545 | MotorenEin = 1; |
545 | MotorenEin = 1; |
546 | sollGier = 0; |
546 | sollGier = 0; |
547 | Mess_Integral_Gier = 0; |
547 | Mess_Integral_Gier = 0; |
548 | Mess_Integral_Gier2 = 0; |
548 | Mess_Integral_Gier2 = 0; |
549 | Mess_IntegralNick = 0; |
549 | Mess_IntegralNick = 0; |
550 | Mess_IntegralRoll = 0; |
550 | Mess_IntegralRoll = 0; |
551 | Mess_IntegralNick2 = IntegralNick; |
551 | Mess_IntegralNick2 = IntegralNick; |
552 | Mess_IntegralRoll2 = IntegralRoll; |
552 | Mess_IntegralRoll2 = IntegralRoll; |
553 | SummeNick = 0; |
553 | SummeNick = 0; |
554 | SummeRoll = 0; |
554 | SummeRoll = 0; |
555 | } |
555 | } |
556 | } |
556 | } |
557 | else delay_einschalten = 0; |
557 | else delay_einschalten = 0; |
558 | //Auf Neutralwerte setzen |
558 | //Auf Neutralwerte setzen |
559 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
559 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
560 | // Auschalten |
560 | // Auschalten |
561 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
561 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
562 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
562 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
563 | { |
563 | { |
564 | if(++delay_ausschalten > 200) // nicht sofort |
564 | if(++delay_ausschalten > 200) // nicht sofort |
565 | { |
565 | { |
566 | MotorenEin = 0; |
566 | MotorenEin = 0; |
567 | delay_ausschalten = 200; |
567 | delay_ausschalten = 200; |
568 | modell_fliegt = 0; |
568 | modell_fliegt = 0; |
569 | } |
569 | } |
570 | } |
570 | } |
571 | else delay_ausschalten = 0; |
571 | else delay_ausschalten = 0; |
572 | } |
572 | } |
573 | } |
573 | } |
574 | 574 | ||
575 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
575 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
576 | // neue Werte von der Funke |
576 | // neue Werte von der Funke |
577 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
577 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
578 | if(!NewPpmData-- || Notlandung) |
578 | if(!NewPpmData-- || Notlandung) |
579 | { |
579 | { |
580 | ParameterZuordnung(); |
580 | ParameterZuordnung(); |
581 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
581 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
582 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
582 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
583 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
583 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
584 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
584 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
585 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
585 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
586 | 586 | ||
587 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
587 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
588 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
588 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
589 | 589 | ||
590 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
590 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
591 | if(GyroFaktor < 0) GyroFaktor = 0; |
591 | if(GyroFaktor < 0) GyroFaktor = 0; |
592 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
592 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
593 | } |
593 | } |
594 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
594 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
595 | // Bei Empfangsausfall im Flug |
595 | // Bei Empfangsausfall im Flug |
596 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
596 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
597 | if(Notlandung) |
597 | if(Notlandung) |
598 | { |
598 | { |
599 | StickGier = 0; |
599 | StickGier = 0; |
600 | StickNick = 0; |
600 | StickNick = 0; |
601 | StickRoll = 0; |
601 | StickRoll = 0; |
602 | GyroFaktor = 0.1; |
602 | GyroFaktor = 0.1; |
603 | IntegralFaktor = 0.005; |
603 | IntegralFaktor = 0.005; |
604 | } |
604 | } |
605 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
605 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
606 | // Gyro-Drift kompensieren |
606 | // Gyro-Drift kompensieren |
607 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
607 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
608 | #define DRIFT_FAKTOR 3 |
608 | #define DRIFT_FAKTOR 3 |
609 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
609 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
610 | { |
610 | { |
611 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
611 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
612 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
612 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
613 | ZaehlMessungen = 0; |
613 | ZaehlMessungen = 0; |
614 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
614 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
615 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
615 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
616 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
616 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
617 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
617 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
618 | //if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; |
618 | //if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; |
619 | //if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; |
619 | //if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; |
620 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
620 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
621 | Mess_IntegralNick2 = IntegralNick; |
621 | Mess_IntegralNick2 = IntegralNick; |
622 | Mess_IntegralRoll2 = IntegralRoll; |
622 | Mess_IntegralRoll2 = IntegralRoll; |
623 | Mess_Integral_Gier2 = Integral_Gier; |
623 | Mess_Integral_Gier2 = Integral_Gier; |
624 | ANALOG_ON; // ADC einschalten |
624 | ANALOG_ON; // ADC einschalten |
625 | } |
625 | } |
626 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
626 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
627 | // Integrale auf ACC-Signal abgleichen |
627 | // Integrale auf ACC-Signal abgleichen |
628 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
628 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
629 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
629 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
630 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
630 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
631 | #define AUSGLEICH 500 |
631 | #define AUSGLEICH 500 |
632 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
632 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
633 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
633 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
634 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
634 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
635 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
635 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
636 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
636 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
637 | Mess_IntegralNick -= tmp_long; |
637 | Mess_IntegralNick -= tmp_long; |
638 | Mess_IntegralRoll -= tmp_long2; |
638 | Mess_IntegralRoll -= tmp_long2; |
639 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
639 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
640 | // Gieren |
640 | // Gieren |
641 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
641 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
642 | sollGier = StickGier; |
642 | sollGier = StickGier; |
643 | if(abs(StickGier) > 35) |
643 | if(abs(StickGier) > 35) |
644 | { |
644 | { |
645 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
645 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
646 | } |
646 | } |
647 | tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo |
647 | tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo |
648 | Mess_Integral_Gier -= tmp_int; |
648 | Mess_Integral_Gier -= tmp_int; |
649 | if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000; // begrenzen |
649 | if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000; // begrenzen |
650 | if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000; |
650 | if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000; |
651 | 651 | ||
652 | ANALOG_ON; // ADC einschalten |
652 | ANALOG_ON; // ADC einschalten |
653 | 653 | ||
654 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
654 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
655 | // Kompass |
655 | // Kompass |
656 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
656 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
657 | if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
657 | if(EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) |
658 | { |
658 | { |
659 | int w,v; |
659 | int w,v; |
660 | static uint8_t SignalSchlecht = 0; |
660 | static uint8_t SignalSchlecht = 0; |
661 | 661 | ||
662 | if (!updKompass--) // Aufruf mit ~10 Hz |
662 | if (!updKompass--) // Aufruf mit ~10 Hz |
663 | { |
663 | { |
664 | KompassValue = heading_MM3(); |
664 | KompassValue = heading_MM3(); |
665 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
665 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
666 | updKompass = 50; |
666 | updKompass = 50; |
667 | } |
667 | } |
668 | 668 | ||
669 | w = abs(IntegralNick /1024); // mit zunehmender Neigung den Einfluss drosseln |
669 | w = abs(IntegralNick /1024); // mit zunehmender Neigung den Einfluss drosseln |
670 | v = abs(IntegralRoll /1024); |
670 | v = abs(IntegralRoll /1024); |
671 | if(v > w) w = v; // grösste Neigung ermitteln |
671 | if(v > w) w = v; // grösste Neigung ermitteln |
672 | if(w < 35 && NeueKompassRichtungMerken && !SignalSchlecht) |
672 | if(w < 35 && NeueKompassRichtungMerken && !SignalSchlecht) |
673 | { |
673 | { |
674 | KompassStartwert = KompassValue; |
674 | KompassStartwert = KompassValue; |
675 | NeueKompassRichtungMerken = 0; |
675 | NeueKompassRichtungMerken = 0; |
676 | } |
676 | } |
677 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
677 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
678 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
678 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
679 | if(w > 0) |
679 | if(w > 0) |
680 | { |
680 | { |
681 | if(!SignalSchlecht) |
681 | if(!SignalSchlecht) |
682 | { |
682 | { |
683 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
683 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
684 | Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
684 | Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
685 | ANALOG_ON; // ADC einschalten |
685 | ANALOG_ON; // ADC einschalten |
686 | } |
686 | } |
687 | else SignalSchlecht--; |
687 | else SignalSchlecht--; |
688 | 688 | ||
689 | } |
689 | } |
690 | else SignalSchlecht = 250; // so lange das Signal taub stellen --> ca. 1/2 sek |
690 | else SignalSchlecht = 250; // so lange das Signal taub stellen --> ca. 1/2 sek |
691 | } |
691 | } |
692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
693 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
694 | 694 | ||
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
696 | // Debugwerte zuordnen |
696 | // Debugwerte zuordnen |
697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
698 | DebugOut.Sekunden++; |
698 | DebugOut.Sekunden++; |
699 | if(!TimerWerteausgabe--) |
699 | if(!TimerWerteausgabe--) |
700 | { |
700 | { |
701 | TimerWerteausgabe = 49; |
701 | TimerWerteausgabe = 49; |
702 | // DebugOut.Analog[0] = MesswertNick; |
702 | // DebugOut.Analog[0] = MesswertNick; |
703 | // DebugOut.Analog[1] = MesswertRoll; |
703 | // DebugOut.Analog[1] = MesswertRoll; |
704 | // DebugOut.Analog[2] = MesswertGier; |
704 | // DebugOut.Analog[2] = MesswertGier; |
705 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
705 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
706 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
706 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
707 | 707 | ||
708 | // DebugOut.Analog[0] = MM3.NickGrad; |
708 | // DebugOut.Analog[0] = MM3.NickGrad; |
709 | // DebugOut.Analog[1] = MM3.RollGrad; |
709 | // DebugOut.Analog[1] = MM3.RollGrad; |
710 | DebugOut.Analog[2] = Mittelwert_AccNick; |
710 | DebugOut.Analog[2] = Mittelwert_AccNick; |
711 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
711 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
712 | DebugOut.Analog[4] = MesswertGier; |
712 | DebugOut.Analog[4] = MesswertGier; |
713 | DebugOut.Analog[5] = HoehenWert; |
713 | DebugOut.Analog[5] = HoehenWert; |
714 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
714 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
715 | DebugOut.Analog[7] = GasMischanteil; |
715 | DebugOut.Analog[7] = GasMischanteil; |
716 | DebugOut.Analog[8] = KompassValue; |
716 | DebugOut.Analog[8] = KompassValue; |
717 | 717 | ||
718 | // Kanäle 9 bis 11 in compass.c |
718 | // Kanäle 9 bis 11 in compass.c |
719 | 719 | ||
720 | // DebugOut.Analog[9] = SollHoehe; |
720 | // DebugOut.Analog[9] = SollHoehe; |
721 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
721 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
722 | // DebugOut.Analog[11] = KompassStartwert; |
722 | // DebugOut.Analog[11] = KompassStartwert; |
723 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
723 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
724 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
724 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
725 | // DebugOut.Analog[9] = KompassRichtung; |
725 | // DebugOut.Analog[9] = KompassRichtung; |
726 | // DebugOut.Analog[10] = GasMischanteil; |
726 | // DebugOut.Analog[10] = GasMischanteil; |
727 | // DebugOut.Analog[3] = HoeheD * 32; |
727 | // DebugOut.Analog[3] = HoeheD * 32; |
728 | // DebugOut.Analog[4] = hoehenregler; |
728 | // DebugOut.Analog[4] = hoehenregler; |
729 | } |
729 | } |
730 | 730 | ||
731 | 731 | ||
732 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
732 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
733 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
733 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
734 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
734 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
735 | MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
735 | MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
736 | MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
736 | MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
737 | MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
737 | MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
738 | // Maximalwerte abfangen |
738 | // Maximalwerte abfangen |
739 | #define MAX_SENSOR 2048 |
739 | #define MAX_SENSOR 2048 |
740 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
740 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
741 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
741 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
742 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
742 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
743 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
743 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
744 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
744 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
745 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
745 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
746 | 746 | ||
747 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
747 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
748 | // Höhenregelung |
748 | // Höhenregelung |
749 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
749 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
750 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
750 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
751 | //OCR0B = 180 - (Poti1 + 120) / 4; |
751 | //OCR0B = 180 - (Poti1 + 120) / 4; |
752 | //DruckOffsetSetting = OCR0B; |
752 | //DruckOffsetSetting = OCR0B; |
753 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
753 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
754 | { |
754 | { |
755 | int tmp_int; |
755 | int tmp_int; |
756 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
756 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
757 | { |
757 | { |
758 | if(Parameter_MaxHoehe < 50) |
758 | if(Parameter_MaxHoehe < 50) |
759 | { |
759 | { |
760 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
760 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
761 | HoehenReglerAktiv = 0; |
761 | HoehenReglerAktiv = 0; |
762 | } |
762 | } |
763 | else |
763 | else |
764 | HoehenReglerAktiv = 1; |
764 | HoehenReglerAktiv = 1; |
765 | } |
765 | } |
766 | else |
766 | else |
767 | { |
767 | { |
768 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
768 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
769 | HoehenReglerAktiv = 1; |
769 | HoehenReglerAktiv = 1; |
770 | } |
770 | } |
771 | 771 | ||
772 | if(Notlandung) SollHoehe = 0; |
772 | if(Notlandung) SollHoehe = 0; |
773 | h = HoehenWert; |
773 | h = HoehenWert; |
774 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
774 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
775 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
775 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
776 | h = GasMischanteil - h; // vom Gas abziehen |
776 | h = GasMischanteil - h; // vom Gas abziehen |
777 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
777 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
778 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
778 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
779 | if(tmp_int > 50) tmp_int = 50; |
779 | if(tmp_int > 50) tmp_int = 50; |
780 | else if(tmp_int < -50) tmp_int = -50; |
780 | else if(tmp_int < -50) tmp_int = -50; |
781 | h -= tmp_int; |
781 | h -= tmp_int; |
782 | hoehenregler = (hoehenregler*15 + h) / 16; |
782 | hoehenregler = (hoehenregler*15 + h) / 16; |
783 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
783 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
784 | { |
784 | { |
785 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
785 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
786 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
786 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
787 | } |
787 | } |
788 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
788 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
789 | GasMischanteil = hoehenregler; |
789 | GasMischanteil = hoehenregler; |
790 | } |
790 | } |
791 | } |
791 | } |
792 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
792 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
793 | // + Mischer und PI-Regler |
793 | // + Mischer und PI-Regler |
794 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
794 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
795 | 795 | ||
796 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
796 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
797 | // Gier-Anteil |
797 | // Gier-Anteil |
798 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
798 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
799 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
799 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
800 | if(GierMischanteil > 100) GierMischanteil = 100; |
800 | if(GierMischanteil > 100) GierMischanteil = 100; |
801 | if(GierMischanteil < -100) GierMischanteil = -100; |
801 | if(GierMischanteil < -100) GierMischanteil = -100; |
802 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
802 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
803 | // Nick-Achse |
803 | // Nick-Achse |
804 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
804 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
805 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
805 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
806 | SummeNick += DiffNick; // I-Anteil |
806 | SummeNick += DiffNick; // I-Anteil |
807 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
807 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
808 | if(SummeNick > 16000) SummeNick = 16000; |
808 | if(SummeNick > 16000) SummeNick = 16000; |
809 | if(SummeNick < -16000) SummeNick = -16000; |
809 | if(SummeNick < -16000) SummeNick = -16000; |
810 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
810 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
811 | // Motor Vorn |
811 | // Motor Vorn |
812 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
812 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
813 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
813 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
814 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
814 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
815 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
815 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
816 | Motor_Vorne = motorwert; |
816 | Motor_Vorne = motorwert; |
817 | // Motor Heck |
817 | // Motor Heck |
818 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
818 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
819 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
819 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
820 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
820 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
821 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
821 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
822 | Motor_Hinten = motorwert; |
822 | Motor_Hinten = motorwert; |
823 | 823 | ||
824 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
824 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
825 | // Roll-Achse |
825 | // Roll-Achse |
826 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
826 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
827 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
827 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
828 | SummeRoll += DiffRoll; // I-Anteil |
828 | SummeRoll += DiffRoll; // I-Anteil |
829 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
829 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
830 | if(SummeRoll > 16000) SummeRoll = 16000; |
830 | if(SummeRoll > 16000) SummeRoll = 16000; |
831 | if(SummeRoll < -16000) SummeRoll = -16000; |
831 | if(SummeRoll < -16000) SummeRoll = -16000; |
832 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
832 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
833 | // Motor Links |
833 | // Motor Links |
834 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
834 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
835 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
835 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
836 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
836 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
837 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
837 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
838 | Motor_Links = motorwert; |
838 | Motor_Links = motorwert; |
839 | // Motor Rechts |
839 | // Motor Rechts |
840 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
840 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
841 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
841 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
842 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
842 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
843 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
843 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
844 | Motor_Rechts = motorwert; |
844 | Motor_Rechts = motorwert; |
845 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
845 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
846 | 846 | ||
847 | } |
847 | } |
848 | 848 | ||
849 | 849 |