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