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