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