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