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