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