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