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