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