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