Rev 1210 | Rev 1212 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1210 | Rev 1211 | ||
---|---|---|---|
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 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
60 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
61 | int TrimNick, TrimRoll; |
61 | int TrimNick, TrimRoll; |
62 | int AdNeutralGierBias; |
62 | int AdNeutralGierBias; |
63 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
63 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
64 | int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
64 | int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
65 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
65 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
66 | volatile float NeutralAccZ = 0; |
66 | volatile float NeutralAccZ = 0; |
67 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
67 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
68 | long IntegralNick = 0,IntegralNick2 = 0; |
68 | long IntegralNick = 0,IntegralNick2 = 0; |
69 | long IntegralRoll = 0,IntegralRoll2 = 0; |
69 | long IntegralRoll = 0,IntegralRoll2 = 0; |
70 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
70 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
71 | long Integral_Gier = 0; |
71 | long Integral_Gier = 0; |
72 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
72 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
73 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
73 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
74 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
74 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
75 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
75 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
76 | volatile long Mess_Integral_Hoch = 0; |
76 | volatile long Mess_Integral_Hoch = 0; |
77 | int KompassValue = 0; |
77 | int KompassValue = 0; |
78 | int KompassStartwert = 0; |
78 | int KompassStartwert = 0; |
79 | int KompassRichtung = 0; |
79 | int KompassRichtung = 0; |
80 | unsigned int KompassSignalSchlecht = 500; |
80 | unsigned int KompassSignalSchlecht = 500; |
81 | unsigned char MAX_GAS,MIN_GAS; |
81 | unsigned char MAX_GAS,MIN_GAS; |
82 | unsigned char Notlandung = 0; |
82 | unsigned char Notlandung = 0; |
83 | unsigned char HoehenReglerAktiv = 0; |
83 | unsigned char HoehenReglerAktiv = 0; |
84 | unsigned char TrichterFlug = 0; |
84 | unsigned char TrichterFlug = 0; |
85 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
85 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
86 | long ErsatzKompass; |
86 | long ErsatzKompass; |
87 | int ErsatzKompassInGrad; // Kompasswert in Grad |
87 | int ErsatzKompassInGrad; // Kompasswert in Grad |
88 | int GierGyroFehler = 0; |
88 | int GierGyroFehler = 0; |
89 | char GyroFaktor; |
89 | char GyroFaktor,GyroFaktorGier; |
90 | char IntegralFaktor; |
90 | char IntegralFaktor,IntegralFaktorGier; |
91 | int DiffNick,DiffRoll; |
91 | 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; |
93 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links; |
94 | volatile unsigned char Motor1, Motor2,Motor3,Motor4,Motor5,Motor6,Motor7,Motor8; |
94 | volatile unsigned char Motor1, Motor2,Motor3,Motor4,Motor5,Motor6,Motor7,Motor8; |
95 | volatile unsigned char SenderOkay = 0; |
95 | volatile unsigned char SenderOkay = 0; |
96 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
96 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
97 | char MotorenEin = 0; |
97 | char MotorenEin = 0; |
98 | int HoehenWert = 0; |
98 | int HoehenWert = 0; |
99 | int SollHoehe = 0; |
99 | int SollHoehe = 0; |
100 | int LageKorrekturRoll = 0,LageKorrekturNick = 0; |
100 | int LageKorrekturRoll = 0,LageKorrekturNick = 0; |
101 | //float Ki = FAKTOR_I; |
101 | //float Ki = FAKTOR_I; |
102 | int Ki = 10300 / 33; |
102 | int Ki = 10300 / 33; |
103 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
103 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
104 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
104 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
105 | 105 | ||
106 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
106 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
107 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
107 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
108 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
108 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
109 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
109 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
110 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
110 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
111 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
111 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
112 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
112 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
113 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
113 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
114 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
114 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
115 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
115 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
116 | unsigned char Parameter_UserParam1 = 0; |
116 | unsigned char Parameter_UserParam1 = 0; |
117 | unsigned char Parameter_UserParam2 = 0; |
117 | unsigned char Parameter_UserParam2 = 0; |
118 | unsigned char Parameter_UserParam3 = 0; |
118 | unsigned char Parameter_UserParam3 = 0; |
119 | unsigned char Parameter_UserParam4 = 0; |
119 | unsigned char Parameter_UserParam4 = 0; |
120 | unsigned char Parameter_UserParam5 = 0; |
120 | unsigned char Parameter_UserParam5 = 0; |
121 | unsigned char Parameter_UserParam6 = 0; |
121 | unsigned char Parameter_UserParam6 = 0; |
122 | unsigned char Parameter_UserParam7 = 0; |
122 | unsigned char Parameter_UserParam7 = 0; |
123 | unsigned char Parameter_UserParam8 = 0; |
123 | unsigned char Parameter_UserParam8 = 0; |
124 | unsigned char Parameter_ServoNickControl = 100; |
124 | unsigned char Parameter_ServoNickControl = 100; |
125 | unsigned char Parameter_LoopGasLimit = 70; |
125 | unsigned char Parameter_LoopGasLimit = 70; |
126 | unsigned char Parameter_AchsKopplung1 = 90; |
126 | unsigned char Parameter_AchsKopplung1 = 90; |
127 | unsigned char Parameter_AchsKopplung2 = 65; |
127 | unsigned char Parameter_AchsKopplung2 = 65; |
128 | unsigned char Parameter_CouplingYawCorrection = 64; |
128 | unsigned char Parameter_CouplingYawCorrection = 64; |
129 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
129 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
130 | unsigned char Parameter_DynamicStability = 100; |
130 | unsigned char Parameter_DynamicStability = 100; |
131 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
131 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
132 | unsigned char Parameter_J16Timing; // for the J16 Output |
132 | unsigned char Parameter_J16Timing; // for the J16 Output |
133 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
133 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
134 | unsigned char Parameter_J17Timing; // for the J17 Output |
134 | unsigned char Parameter_J17Timing; // for the J17 Output |
135 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
135 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
136 | unsigned char Parameter_NaviGpsGain; |
136 | unsigned char Parameter_NaviGpsGain; |
137 | unsigned char Parameter_NaviGpsP; |
137 | unsigned char Parameter_NaviGpsP; |
138 | unsigned char Parameter_NaviGpsI; |
138 | unsigned char Parameter_NaviGpsI; |
139 | unsigned char Parameter_NaviGpsD; |
139 | unsigned char Parameter_NaviGpsD; |
140 | unsigned char Parameter_NaviGpsACC; |
140 | unsigned char Parameter_NaviGpsACC; |
141 | unsigned char Parameter_NaviOperatingRadius; |
141 | unsigned char Parameter_NaviOperatingRadius; |
142 | unsigned char Parameter_NaviWindCorrection; |
142 | unsigned char Parameter_NaviWindCorrection; |
143 | unsigned char Parameter_NaviSpeedCompensation; |
143 | unsigned char Parameter_NaviSpeedCompensation; |
144 | unsigned char Parameter_ExternalControl; |
144 | unsigned char Parameter_ExternalControl; |
145 | struct mk_param_struct EE_Parameter; |
145 | struct mk_param_struct EE_Parameter; |
146 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
146 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
147 | int MaxStickNick = 0,MaxStickRoll = 0; |
147 | int MaxStickNick = 0,MaxStickRoll = 0; |
148 | unsigned int modell_fliegt = 0; |
148 | unsigned int modell_fliegt = 0; |
149 | volatile unsigned char MikroKopterFlags = 0; |
149 | volatile unsigned char MikroKopterFlags = 0; |
150 | long GIER_GRAD_FAKTOR = 1291; |
150 | long GIER_GRAD_FAKTOR = 1291; |
151 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
151 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
152 | unsigned char RequiredMotors = 4; |
152 | unsigned char RequiredMotors = 4; |
153 | - | ||
154 | /* |
- | |
155 | signed char Mixer.Motor[MAX_MOTORS][4] = { |
- | |
156 | {64, +64, 0, +64},//1 |
- | |
157 | {64, +64, -64, -64},//2 |
- | |
158 | {64, 0, -64, +64},//3 |
- | |
159 | {64, -64, -64, -64},//4 |
- | |
160 | {64, -64, 0, +64},//5 |
- | |
161 | {64, -64, +64, -64},//6 |
- | |
162 | {64, 0, +64, +64},//7 |
- | |
163 | {64, +64, +64, -64},//8 |
- | |
164 | { 0, 0, 0, 0},//9 |
- | |
165 | { 0, 0, 0, 0},//10 |
- | |
166 | { 0, 0, 0, 0},//11 |
- | |
167 | { 0, 0, 0, 0}};//12 |
- | |
168 | */ |
- | |
169 | /* |
- | |
170 | signed char Mixer.Motor[MAX_MOTORS][4] = { |
- | |
171 | { 64, +64, 0, +64},//1 |
- | |
172 | { 64, -64, 0, +64},//2 |
- | |
173 | { 64, 0, -64, -64},//3 |
- | |
174 | { 64, 0, +64, -64},//4 |
- | |
175 | { 0, 0, 0, 0},//5 |
- | |
176 | { 0, 0, 0, 0},//6 |
- | |
177 | { 0, 0, 0, 0},//7 |
- | |
178 | { 0, 0, 0, 0},//8 |
- | |
179 | { 0, 0, 0, 0},//9 |
- | |
180 | { 0, 0, 0, 0},//10 |
- | |
181 | { 0, 0, 0, 0},//11 |
- | |
182 | { 0, 0, 0, 0}};//12 |
- | |
183 | */ |
- | |
184 | unsigned char Motor[MAX_MOTORS]; |
153 | unsigned char Motor[MAX_MOTORS]; |
185 | signed int tmp_motorwert[MAX_MOTORS]; |
154 | signed int tmp_motorwert[MAX_MOTORS]; |
186 | 155 | ||
187 | int MotorSmoothing(int neu, int alt) |
156 | int MotorSmoothing(int neu, int alt) |
188 | { |
157 | { |
189 | int motor; |
158 | int motor; |
190 | if(neu > alt) motor = (1*(int)alt + neu) / 2; |
159 | if(neu > alt) motor = (1*(int)alt + neu) / 2; |
191 | else motor = neu - (alt - neu)*1; |
160 | else motor = neu - (alt - neu)*1; |
192 | //if(Poti2 < 20) return(neu); |
161 | //if(Poti2 < 20) return(neu); |
193 | return(motor); |
162 | return(motor); |
194 | } |
163 | } |
195 | 164 | ||
196 | 165 | ||
197 | void Piep(unsigned char Anzahl) |
166 | void Piep(unsigned char Anzahl) |
198 | { |
167 | { |
199 | while(Anzahl--) |
168 | while(Anzahl--) |
200 | { |
169 | { |
201 | if(MotorenEin) return; //auf keinen Fall im Flug! |
170 | if(MotorenEin) return; //auf keinen Fall im Flug! |
202 | beeptime = 100; |
171 | beeptime = 100; |
203 | Delay_ms(250); |
172 | Delay_ms(250); |
204 | } |
173 | } |
205 | } |
174 | } |
206 | 175 | ||
207 | //############################################################################ |
176 | //############################################################################ |
208 | // Nullwerte ermitteln |
177 | // Nullwerte ermitteln |
209 | void SetNeutral(void) |
178 | void SetNeutral(void) |
210 | //############################################################################ |
179 | //############################################################################ |
211 | { |
180 | { |
212 | unsigned char i; |
181 | unsigned char i; |
213 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
182 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
214 | ServoActive = 0; HEF4017R_ON; |
183 | ServoActive = 0; HEF4017R_ON; |
215 | NeutralAccX = 0; |
184 | NeutralAccX = 0; |
216 | NeutralAccY = 0; |
185 | NeutralAccY = 0; |
217 | NeutralAccZ = 0; |
186 | NeutralAccZ = 0; |
218 | AdNeutralNick = 0; |
187 | AdNeutralNick = 0; |
219 | AdNeutralRoll = 0; |
188 | AdNeutralRoll = 0; |
220 | AdNeutralGier = 0; |
189 | AdNeutralGier = 0; |
221 | AdNeutralGierBias = 0; |
190 | AdNeutralGierBias = 0; |
222 | Parameter_AchsKopplung1 = 0; |
191 | Parameter_AchsKopplung1 = 0; |
223 | Parameter_AchsKopplung2 = 0; |
192 | Parameter_AchsKopplung2 = 0; |
224 | ExpandBaro = 0; |
193 | ExpandBaro = 0; |
225 | CalibrierMittelwert(); |
194 | CalibrierMittelwert(); |
226 | Delay_ms_Mess(100); |
195 | Delay_ms_Mess(100); |
227 | CalibrierMittelwert(); |
196 | CalibrierMittelwert(); |
228 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
197 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
229 | { |
198 | { |
230 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
199 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
231 | } |
200 | } |
232 | #define NEUTRAL_FILTER 32 |
201 | #define NEUTRAL_FILTER 32 |
233 | for(i=0; i<NEUTRAL_FILTER; i++) |
202 | for(i=0; i<NEUTRAL_FILTER; i++) |
234 | { |
203 | { |
235 | Delay_ms_Mess(10); |
204 | Delay_ms_Mess(10); |
236 | gier_neutral += AdWertGier; |
205 | gier_neutral += AdWertGier; |
237 | nick_neutral += AdWertNick; |
206 | nick_neutral += AdWertNick; |
238 | roll_neutral += AdWertRoll; |
207 | roll_neutral += AdWertRoll; |
239 | } |
208 | } |
240 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
209 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
241 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
210 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
242 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
211 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
243 | AdNeutralGierBias = AdNeutralGier; |
212 | AdNeutralGierBias = AdNeutralGier; |
244 | StartNeutralRoll = AdNeutralRoll; |
213 | StartNeutralRoll = AdNeutralRoll; |
245 | StartNeutralNick = AdNeutralNick; |
214 | StartNeutralNick = AdNeutralNick; |
246 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
215 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
247 | { |
216 | { |
248 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
217 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
249 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
218 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
250 | NeutralAccZ = Aktuell_az; |
219 | NeutralAccZ = Aktuell_az; |
251 | } |
220 | } |
252 | else |
221 | else |
253 | { |
222 | { |
254 | NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]); |
223 | NeutralAccX = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1]); |
255 | NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]); |
224 | NeutralAccY = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1]); |
256 | NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]); |
225 | NeutralAccZ = (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z]) * 256 + (int)eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1]); |
257 | } |
226 | } |
258 | 227 | ||
259 | MesswertNick = 0; |
228 | MesswertNick = 0; |
260 | MesswertRoll = 0; |
229 | MesswertRoll = 0; |
261 | MesswertGier = 0; |
230 | MesswertGier = 0; |
262 | Delay_ms_Mess(100); |
231 | Delay_ms_Mess(100); |
263 | Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick; |
232 | Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick; |
264 | Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll; |
233 | Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll; |
265 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
234 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
266 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
235 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
267 | Mess_IntegralNick2 = IntegralNick; |
236 | Mess_IntegralNick2 = IntegralNick; |
268 | Mess_IntegralRoll2 = IntegralRoll; |
237 | Mess_IntegralRoll2 = IntegralRoll; |
269 | Mess_Integral_Gier = 0; |
238 | Mess_Integral_Gier = 0; |
270 | StartLuftdruck = Luftdruck; |
239 | StartLuftdruck = Luftdruck; |
271 | HoeheD = 0; |
240 | HoeheD = 0; |
272 | Mess_Integral_Hoch = 0; |
241 | Mess_Integral_Hoch = 0; |
273 | KompassStartwert = KompassValue; |
242 | KompassStartwert = KompassValue; |
274 | GPS_Neutral(); |
243 | GPS_Neutral(); |
275 | beeptime = 50; |
244 | beeptime = 50; |
276 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
245 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
277 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
246 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
278 | ExternHoehenValue = 0; |
247 | ExternHoehenValue = 0; |
279 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
248 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
280 | GierGyroFehler = 0; |
249 | GierGyroFehler = 0; |
281 | SendVersionToNavi = 1; |
250 | SendVersionToNavi = 1; |
282 | LED_Init(); |
251 | LED_Init(); |
283 | MikroKopterFlags |= FLAG_CALIBRATE; |
252 | MikroKopterFlags |= FLAG_CALIBRATE; |
284 | FromNaviCtrl_Value.Kalman_K = -1; |
253 | FromNaviCtrl_Value.Kalman_K = -1; |
285 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
254 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
286 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
255 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
287 | Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110; |
256 | Poti1 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110; |
288 | Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110; |
257 | Poti2 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110; |
289 | Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110; |
258 | Poti3 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110; |
290 | Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110; |
259 | Poti4 = PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110; |
291 | ServoActive = 1; |
260 | ServoActive = 1; |
292 | SenderOkay = 100; |
261 | SenderOkay = 100; |
293 | } |
262 | } |
294 | 263 | ||
295 | //############################################################################ |
264 | //############################################################################ |
296 | // Bearbeitet die Messwerte |
265 | // Bearbeitet die Messwerte |
297 | void Mittelwert(void) |
266 | void Mittelwert(void) |
298 | //############################################################################ |
267 | //############################################################################ |
299 | { |
268 | { |
300 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
269 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
301 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
270 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
302 | signed long winkel_nick, winkel_roll; |
271 | signed long winkel_nick, winkel_roll; |
303 | 272 | ||
304 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
273 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
305 | // MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier; |
274 | // MesswertGierBias = (signed int) AdNeutralGierBias - AdWertGier; |
306 | MesswertNick = (signed int) AdWertNickFilter / 8; |
275 | MesswertNick = (signed int) AdWertNickFilter / 8; |
307 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
276 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
308 | RohMesswertNick = MesswertNick; |
277 | RohMesswertNick = MesswertNick; |
309 | RohMesswertRoll = MesswertRoll; |
278 | RohMesswertRoll = MesswertRoll; |
310 | //DebugOut.Analog[21] = MesswertNick; |
279 | //DebugOut.Analog[21] = MesswertNick; |
311 | //DebugOut.Analog[22] = MesswertRoll; |
280 | //DebugOut.Analog[22] = MesswertRoll; |
312 | //DebugOut.Analog[22] = Mess_Integral_Gier; |
281 | //DebugOut.Analog[22] = Mess_Integral_Gier; |
313 | //DebugOut.Analog[21] = MesswertNick; |
282 | //DebugOut.Analog[21] = MesswertNick; |
314 | //DebugOut.Analog[22] = MesswertRoll; |
283 | //DebugOut.Analog[22] = MesswertRoll; |
315 | 284 | ||
316 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
285 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
317 | Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L; |
286 | Mittelwert_AccNick = ((long)Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * (long)AdWertAccNick))) / 4L; |
318 | Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L; |
287 | Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * (long)AdWertAccRoll))) / 4L; |
319 | Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L; |
288 | Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 3 + ((long)AdWertAccHoch)) / 4L; |
320 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
289 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
321 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
290 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
322 | NaviAccNick += AdWertAccNick; |
291 | NaviAccNick += AdWertAccNick; |
323 | NaviAccRoll += AdWertAccRoll; |
292 | NaviAccRoll += AdWertAccRoll; |
324 | NaviCntAcc++; |
293 | NaviCntAcc++; |
325 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
294 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
326 | 295 | ||
327 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
296 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
328 | // ADC einschalten |
297 | // ADC einschalten |
329 | ANALOG_ON; |
298 | ANALOG_ON; |
330 | AdReady = 0; |
299 | AdReady = 0; |
331 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
300 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
332 | 301 | ||
333 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
302 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
334 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
303 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
335 | else winkel_roll = Mess_IntegralRoll; |
304 | else winkel_roll = Mess_IntegralRoll; |
336 | 305 | ||
337 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
306 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
338 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
307 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
339 | else winkel_nick = Mess_IntegralNick; |
308 | else winkel_nick = Mess_IntegralNick; |
340 | 309 | ||
341 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
310 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
342 | Mess_Integral_Gier += MesswertGier; |
311 | Mess_Integral_Gier += MesswertGier; |
343 | ErsatzKompass += MesswertGier; |
312 | ErsatzKompass += MesswertGier; |
344 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
313 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
345 | if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
314 | if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
346 | { |
315 | { |
347 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
316 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
348 | tmpl3 *= Parameter_AchsKopplung2; //65 |
317 | tmpl3 *= Parameter_AchsKopplung2; //65 |
349 | tmpl3 /= 4096L; |
318 | tmpl3 /= 4096L; |
350 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
319 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
351 | tmpl4 *= Parameter_AchsKopplung2; //65 |
320 | tmpl4 *= Parameter_AchsKopplung2; //65 |
352 | tmpl4 /= 4096L; |
321 | tmpl4 /= 4096L; |
353 | KopplungsteilNickRoll = tmpl3; |
322 | KopplungsteilNickRoll = tmpl3; |
354 | KopplungsteilRollNick = tmpl4; |
323 | KopplungsteilRollNick = tmpl4; |
355 | tmpl4 -= tmpl3; |
324 | tmpl4 -= tmpl3; |
356 | ErsatzKompass += tmpl4; |
325 | ErsatzKompass += tmpl4; |
357 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
326 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
358 | 327 | ||
359 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
328 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
360 | tmpl *= Parameter_AchsKopplung1; // 90 |
329 | tmpl *= Parameter_AchsKopplung1; // 90 |
361 | tmpl /= 4096L; |
330 | tmpl /= 4096L; |
362 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
331 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
363 | tmpl2 *= Parameter_AchsKopplung1; |
332 | tmpl2 *= Parameter_AchsKopplung1; |
364 | tmpl2 /= 4096L; |
333 | tmpl2 /= 4096L; |
365 | if(labs(tmpl) > 128 || labs(tmpl2) > 128 /* || abs(KopplungsteilNickRoll) > 128 || abs(KopplungsteilRollNick) > 128)*/) TrichterFlug = 1; |
334 | if(labs(tmpl) > 128 || labs(tmpl2) > 128 /* || abs(KopplungsteilNickRoll) > 128 || abs(KopplungsteilRollNick) > 128)*/) TrichterFlug = 1; |
366 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
335 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
367 | } |
336 | } |
368 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
337 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
369 | 338 | ||
370 | TrimRoll = tmpl - tmpl2 / 100L; |
339 | TrimRoll = tmpl - tmpl2 / 100L; |
371 | TrimNick = -tmpl2 + tmpl / 100L; |
340 | TrimNick = -tmpl2 + tmpl / 100L; |
372 | 341 | ||
373 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
342 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
374 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
343 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
375 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
344 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
376 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
345 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
377 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
346 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
378 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
347 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
379 | if(Mess_IntegralRoll > Umschlag180Roll) |
348 | if(Mess_IntegralRoll > Umschlag180Roll) |
380 | { |
349 | { |
381 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
350 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
382 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
351 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
383 | } |
352 | } |
384 | if(Mess_IntegralRoll <-Umschlag180Roll) |
353 | if(Mess_IntegralRoll <-Umschlag180Roll) |
385 | { |
354 | { |
386 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
355 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
387 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
356 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
388 | } |
357 | } |
389 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
358 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
390 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
359 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
391 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
360 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
392 | if(Mess_IntegralNick > Umschlag180Nick) |
361 | if(Mess_IntegralNick > Umschlag180Nick) |
393 | { |
362 | { |
394 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
363 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
395 | Mess_IntegralNick2 = Mess_IntegralNick; |
364 | Mess_IntegralNick2 = Mess_IntegralNick; |
396 | } |
365 | } |
397 | if(Mess_IntegralNick <-Umschlag180Nick) |
366 | if(Mess_IntegralNick <-Umschlag180Nick) |
398 | { |
367 | { |
399 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
368 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
400 | Mess_IntegralNick2 = Mess_IntegralNick; |
369 | Mess_IntegralNick2 = Mess_IntegralNick; |
401 | } |
370 | } |
402 | 371 | ||
403 | Integral_Gier = Mess_Integral_Gier; |
372 | Integral_Gier = Mess_Integral_Gier; |
404 | IntegralNick = Mess_IntegralNick; |
373 | IntegralNick = Mess_IntegralNick; |
405 | IntegralRoll = Mess_IntegralRoll; |
374 | IntegralRoll = Mess_IntegralRoll; |
406 | IntegralNick2 = Mess_IntegralNick2; |
375 | IntegralNick2 = Mess_IntegralNick2; |
407 | IntegralRoll2 = Mess_IntegralRoll2; |
376 | IntegralRoll2 = Mess_IntegralRoll2; |
408 | 377 | ||
409 | #define D_LIMIT 128 |
378 | #define D_LIMIT 128 |
410 | 379 | ||
411 | MesswertNick = HiResNick / 8; |
380 | MesswertNick = HiResNick / 8; |
412 | MesswertRoll = HiResRoll / 8; |
381 | MesswertRoll = HiResRoll / 8; |
413 | 382 | ||
414 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
383 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
415 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
384 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
416 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
385 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
417 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
386 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
418 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
387 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
419 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
388 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
420 | 389 | ||
421 | if(Parameter_Gyro_D) |
390 | if(Parameter_Gyro_D) |
422 | { |
391 | { |
423 | d2Nick = HiResNick - oldNick; |
392 | d2Nick = HiResNick - oldNick; |
424 | oldNick = (oldNick + HiResNick)/2; |
393 | oldNick = (oldNick + HiResNick)/2; |
425 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
394 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
426 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
395 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
427 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
396 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
428 | d2Roll = HiResRoll - oldRoll; |
397 | d2Roll = HiResRoll - oldRoll; |
429 | oldRoll = (oldRoll + HiResRoll)/2; |
398 | oldRoll = (oldRoll + HiResRoll)/2; |
430 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
399 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
431 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
400 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
432 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
401 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
433 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
402 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
434 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
403 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
435 | } |
404 | } |
436 | 405 | ||
437 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
406 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
438 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
407 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
439 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
408 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
440 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
409 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
441 | 410 | ||
442 | if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
411 | if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
443 | { |
412 | { |
444 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
413 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
445 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
414 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
446 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
415 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
447 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
416 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
448 | } |
417 | } |
449 | 418 | ||
450 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
419 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
451 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
420 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
452 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
421 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
453 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
422 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
454 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
423 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
455 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
424 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
456 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
425 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
457 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
426 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
458 | } |
427 | } |
459 | 428 | ||
460 | //############################################################################ |
429 | //############################################################################ |
461 | // Messwerte beim Ermitteln der Nullage |
430 | // Messwerte beim Ermitteln der Nullage |
462 | void CalibrierMittelwert(void) |
431 | void CalibrierMittelwert(void) |
463 | //############################################################################ |
432 | //############################################################################ |
464 | { |
433 | { |
465 | if(PlatinenVersion == 13) SucheGyroOffset(); |
434 | if(PlatinenVersion == 13) SucheGyroOffset(); |
466 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
435 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
467 | ANALOG_OFF; |
436 | ANALOG_OFF; |
468 | MesswertNick = AdWertNick; |
437 | MesswertNick = AdWertNick; |
469 | MesswertRoll = AdWertRoll; |
438 | MesswertRoll = AdWertRoll; |
470 | MesswertGier = AdWertGier; |
439 | MesswertGier = AdWertGier; |
471 | Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick; |
440 | Mittelwert_AccNick = ACC_AMPLIFY * (long)AdWertAccNick; |
472 | Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll; |
441 | Mittelwert_AccRoll = ACC_AMPLIFY * (long)AdWertAccRoll; |
473 | Mittelwert_AccHoch = (long)AdWertAccHoch; |
442 | Mittelwert_AccHoch = (long)AdWertAccHoch; |
474 | // ADC einschalten |
443 | // ADC einschalten |
475 | ANALOG_ON; |
444 | ANALOG_ON; |
476 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
445 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
477 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
446 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
478 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
447 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
479 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
448 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
480 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
449 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
481 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
450 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
482 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
451 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
483 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
452 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
484 | 453 | ||
485 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
454 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
486 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
455 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
487 | } |
456 | } |
488 | 457 | ||
489 | //############################################################################ |
458 | //############################################################################ |
490 | // Senden der Motorwerte per I2C-Bus |
459 | // Senden der Motorwerte per I2C-Bus |
491 | void SendMotorData(void) |
460 | void SendMotorData(void) |
492 | //############################################################################ |
461 | //############################################################################ |
493 | { |
462 | { |
494 | unsigned char i; |
463 | unsigned char i; |
495 | if(!MotorenEin) |
464 | if(!MotorenEin) |
496 | { |
465 | { |
497 | for(i=0;i<MAX_MOTORS;i++) Motor[i] = 0; |
466 | for(i=0;i<MAX_MOTORS;i++) Motor[i] = 0; |
498 | #ifndef QUADRO |
467 | #ifndef QUADRO |
499 | Motor1 = 0;Motor2 = 0;Motor3 = 0;Motor4 = 0;Motor5 = 0;Motor6 = 0;Motor7 = 0;Motor8 = 0; |
468 | Motor1 = 0;Motor2 = 0;Motor3 = 0;Motor4 = 0;Motor5 = 0;Motor6 = 0;Motor7 = 0;Motor8 = 0; |
500 | if(MotorTest[0]) {Motor1 = MotorTest[0]; Motor2 = MotorTest[0];} |
469 | if(MotorTest[0]) {Motor1 = MotorTest[0]; Motor2 = MotorTest[0];} |
501 | if(MotorTest[3]) {Motor3 = MotorTest[3]; Motor4 = MotorTest[3];} |
470 | if(MotorTest[3]) {Motor3 = MotorTest[3]; Motor4 = MotorTest[3];} |
502 | if(MotorTest[1]) {Motor5 = MotorTest[1]; Motor6 = MotorTest[1];} |
471 | if(MotorTest[1]) {Motor5 = MotorTest[1]; Motor6 = MotorTest[1];} |
503 | if(MotorTest[2]) {Motor7 = MotorTest[2]; Motor8 = MotorTest[2];} |
472 | if(MotorTest[2]) {Motor7 = MotorTest[2]; Motor8 = MotorTest[2];} |
504 | #else |
473 | #else |
505 | Motor_Hinten = 0; Motor_Vorne = 0; Motor_Rechts = 0; Motor_Links = 0; |
474 | Motor_Hinten = 0; Motor_Vorne = 0; Motor_Rechts = 0; Motor_Links = 0; |
506 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
475 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
507 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
476 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
508 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
477 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
509 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
478 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
510 | #endif |
479 | #endif |
511 | if(MotorTest[0]) Motor[0] = MotorTest[0]; |
480 | if(MotorTest[0]) Motor[0] = MotorTest[0]; |
512 | if(MotorTest[1]) Motor[1] = MotorTest[1]; |
481 | if(MotorTest[1]) Motor[1] = MotorTest[1]; |
513 | if(MotorTest[2]) Motor[2] = MotorTest[2]; |
482 | if(MotorTest[2]) Motor[2] = MotorTest[2]; |
514 | if(MotorTest[3]) Motor[3] = MotorTest[3]; |
483 | if(MotorTest[3]) Motor[3] = MotorTest[3]; |
515 | 484 | ||
516 | MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY); |
485 | MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY); |
517 | } else MikroKopterFlags |= FLAG_MOTOR_RUN; |
486 | } else MikroKopterFlags |= FLAG_MOTOR_RUN; |
518 | 487 | ||
519 | DebugOut.Analog[12] = Motor_Vorne; |
488 | DebugOut.Analog[12] = Motor_Vorne; |
520 | DebugOut.Analog[13] = Motor_Hinten; |
489 | DebugOut.Analog[13] = Motor_Hinten; |
521 | DebugOut.Analog[14] = Motor_Links; |
490 | DebugOut.Analog[14] = Motor_Links; |
522 | DebugOut.Analog[15] = Motor_Rechts; |
491 | DebugOut.Analog[15] = Motor_Rechts; |
523 | 492 | ||
524 | //Start I2C Interrupt Mode |
493 | //Start I2C Interrupt Mode |
525 | twi_state = 0; |
494 | twi_state = 0; |
526 | motor = 0; |
495 | motor = 0; |
527 | i2c_start(); |
496 | i2c_start(); |
528 | } |
497 | } |
529 | 498 | ||
530 | 499 | ||
531 | 500 | ||
532 | //############################################################################ |
501 | //############################################################################ |
533 | // Trägt ggf. das Poti als Parameter ein |
502 | // Trägt ggf. das Poti als Parameter ein |
534 | void ParameterZuordnung(void) |
503 | void ParameterZuordnung(void) |
535 | //############################################################################ |
504 | //############################################################################ |
536 | { |
505 | { |
537 | #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;} |
506 | #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;} |
538 | #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; } |
507 | #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; } |
539 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
508 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
540 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
509 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
541 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
510 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
542 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
511 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
543 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
512 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
544 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
513 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
545 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
514 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
546 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255); |
515 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D,0,255); |
547 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
516 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
548 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
517 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
549 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
518 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
550 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
519 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
551 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
520 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
552 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255); |
521 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5,0,255); |
553 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255); |
522 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6,0,255); |
554 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255); |
523 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7,0,255); |
555 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255); |
524 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8,0,255); |
556 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
525 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
557 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
526 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit,0,255); |
558 | CHK_POTI(Parameter_AchsKopplung1, EE_Parameter.AchsKopplung1,0,255); |
527 | CHK_POTI(Parameter_AchsKopplung1, EE_Parameter.AchsKopplung1,0,255); |
559 | CHK_POTI(Parameter_AchsKopplung2, EE_Parameter.AchsKopplung2,0,255); |
528 | CHK_POTI(Parameter_AchsKopplung2, EE_Parameter.AchsKopplung2,0,255); |
560 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255); |
529 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection,0,255); |
561 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
530 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
562 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255); |
531 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability,0,255); |
563 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255); |
532 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255); |
564 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255); |
533 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255); |
565 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255); |
534 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl,0,255); |
566 | Ki = 10300 / (Parameter_I_Faktor + 1); |
535 | Ki = 10300 / (Parameter_I_Faktor + 1); |
567 | MAX_GAS = EE_Parameter.Gas_Max; |
536 | MAX_GAS = EE_Parameter.Gas_Max; |
568 | MIN_GAS = EE_Parameter.Gas_Min; |
537 | MIN_GAS = EE_Parameter.Gas_Min; |
569 | } |
538 | } |
570 | 539 | ||
571 | 540 | ||
572 | 541 | ||
573 | //############################################################################ |
542 | //############################################################################ |
574 | // |
543 | // |
575 | void MotorRegler(void) |
544 | void MotorRegler(void) |
576 | //############################################################################ |
545 | //############################################################################ |
577 | { |
546 | { |
578 | int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int; |
547 | int pd_ergebnis_nick,pd_ergebnis_roll,h,tmp_int; |
579 | int GierMischanteil,GasMischanteil; |
548 | int GierMischanteil,GasMischanteil; |
580 | static long SummeNick=0,SummeRoll=0; |
549 | static long SummeNick=0,SummeRoll=0; |
581 | static long sollGier = 0,tmp_long,tmp_long2; |
550 | static long sollGier = 0,tmp_long,tmp_long2; |
582 | static long IntegralFehlerNick = 0; |
551 | static long IntegralFehlerNick = 0; |
583 | static long IntegralFehlerRoll = 0; |
552 | static long IntegralFehlerRoll = 0; |
584 | static unsigned int RcLostTimer; |
553 | static unsigned int RcLostTimer; |
585 | static unsigned char delay_neutral = 0; |
554 | static unsigned char delay_neutral = 0; |
586 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
555 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
587 | static int hoehenregler = 0; |
556 | static int hoehenregler = 0; |
588 | // static int motorwert1,motorwert2,motorwert3,motorwert4,motorwert5,motorwert6,motorwert7,motorwert8; |
- | |
589 | static char TimerWerteausgabe = 0; |
557 | static char TimerWerteausgabe = 0; |
590 | static char NeueKompassRichtungMerken = 0; |
558 | static char NeueKompassRichtungMerken = 0; |
591 | static long ausgleichNick, ausgleichRoll; |
559 | static long ausgleichNick, ausgleichRoll; |
592 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
560 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
593 | unsigned char i; |
561 | unsigned char i; |
594 | Mittelwert(); |
562 | Mittelwert(); |
595 | 563 | ||
596 | GRN_ON; |
564 | GRN_ON; |
597 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
565 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
598 | // Gaswert ermitteln |
566 | // Gaswert ermitteln |
599 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
567 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
600 | GasMischanteil = StickGas; |
568 | GasMischanteil = StickGas; |
601 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
569 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
602 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
570 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
603 | // Empfang schlecht |
571 | // Empfang schlecht |
604 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
572 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
605 | if(SenderOkay < 100) |
573 | if(SenderOkay < 100) |
606 | { |
574 | { |
607 | if(!PcZugriff) |
575 | if(!PcZugriff) |
608 | { |
576 | { |
609 | if(BeepMuster == 0xffff) |
577 | if(BeepMuster == 0xffff) |
610 | { |
578 | { |
611 | beeptime = 15000; |
579 | beeptime = 15000; |
612 | BeepMuster = 0x0c00; |
580 | BeepMuster = 0x0c00; |
613 | } |
581 | } |
614 | } |
582 | } |
615 | if(RcLostTimer) RcLostTimer--; |
583 | if(RcLostTimer) RcLostTimer--; |
616 | else |
584 | else |
617 | { |
585 | { |
618 | MotorenEin = 0; |
586 | MotorenEin = 0; |
619 | Notlandung = 0; |
587 | Notlandung = 0; |
620 | } |
588 | } |
621 | ROT_ON; |
589 | ROT_ON; |
622 | if(modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
590 | if(modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
623 | { |
591 | { |
624 | GasMischanteil = EE_Parameter.NotGas; |
592 | GasMischanteil = EE_Parameter.NotGas; |
625 | Notlandung = 1; |
593 | Notlandung = 1; |
626 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
594 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
627 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
595 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
628 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
596 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
629 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
597 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
630 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
598 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
631 | } |
599 | } |
632 | else MotorenEin = 0; |
600 | else MotorenEin = 0; |
633 | } |
601 | } |
634 | else |
602 | else |
635 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
603 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
636 | // Emfang gut |
604 | // Emfang gut |
637 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
605 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
638 | if(SenderOkay > 140) |
606 | if(SenderOkay > 140) |
639 | { |
607 | { |
640 | Notlandung = 0; |
608 | Notlandung = 0; |
641 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
609 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
642 | if(GasMischanteil > 40 && MotorenEin) |
610 | if(GasMischanteil > 40 && MotorenEin) |
643 | { |
611 | { |
644 | if(modell_fliegt < 0xffff) modell_fliegt++; |
612 | if(modell_fliegt < 0xffff) modell_fliegt++; |
645 | } |
613 | } |
646 | if((modell_fliegt < 256)) |
614 | if((modell_fliegt < 256)) |
647 | { |
615 | { |
648 | SummeNick = 0; |
616 | SummeNick = 0; |
649 | SummeRoll = 0; |
617 | SummeRoll = 0; |
650 | if(modell_fliegt == 250) |
618 | if(modell_fliegt == 250) |
651 | { |
619 | { |
652 | NeueKompassRichtungMerken = 1; |
620 | NeueKompassRichtungMerken = 1; |
653 | sollGier = 0; |
621 | sollGier = 0; |
654 | Mess_Integral_Gier = 0; |
622 | Mess_Integral_Gier = 0; |
655 | // Mess_Integral_Gier2 = 0; |
623 | // Mess_Integral_Gier2 = 0; |
656 | } |
624 | } |
657 | } else MikroKopterFlags |= FLAG_FLY; |
625 | } else MikroKopterFlags |= FLAG_FLY; |
658 | 626 | ||
659 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
627 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
660 | { |
628 | { |
661 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
629 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
662 | // auf Nullwerte kalibrieren |
630 | // auf Nullwerte kalibrieren |
663 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
631 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
664 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
632 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
665 | { |
633 | { |
666 | if(++delay_neutral > 200) // nicht sofort |
634 | if(++delay_neutral > 200) // nicht sofort |
667 | { |
635 | { |
668 | GRN_OFF; |
636 | GRN_OFF; |
669 | MotorenEin = 0; |
637 | MotorenEin = 0; |
670 | delay_neutral = 0; |
638 | delay_neutral = 0; |
671 | modell_fliegt = 0; |
639 | modell_fliegt = 0; |
672 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
640 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
673 | { |
641 | { |
674 | unsigned char setting=1; |
642 | unsigned char setting=1; |
675 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
643 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
676 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
644 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
677 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
645 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
678 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
646 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
679 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
647 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
680 | SetActiveParamSetNumber(setting); // aktiven Datensatz merken |
648 | SetActiveParamSetNumber(setting); // aktiven Datensatz merken |
681 | } |
649 | } |
682 | // else |
650 | // else |
683 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
651 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
684 | { |
652 | { |
685 | WinkelOut.CalcState = 1; |
653 | WinkelOut.CalcState = 1; |
686 | beeptime = 1000; |
654 | beeptime = 1000; |
687 | } |
655 | } |
688 | else |
656 | else |
689 | { |
657 | { |
690 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
658 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
691 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
659 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
692 | { |
660 | { |
693 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
661 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
694 | } |
662 | } |
695 | SetNeutral(); |
663 | SetNeutral(); |
696 | Piep(GetActiveParamSetNumber()); |
664 | Piep(GetActiveParamSetNumber()); |
697 | } |
665 | } |
698 | } |
666 | } |
699 | } |
667 | } |
700 | else |
668 | else |
701 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
669 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
702 | { |
670 | { |
703 | if(++delay_neutral > 200) // nicht sofort |
671 | if(++delay_neutral > 200) // nicht sofort |
704 | { |
672 | { |
705 | GRN_OFF; |
673 | GRN_OFF; |
706 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen |
674 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],0xff); // Werte löschen |
707 | MotorenEin = 0; |
675 | MotorenEin = 0; |
708 | delay_neutral = 0; |
676 | delay_neutral = 0; |
709 | modell_fliegt = 0; |
677 | modell_fliegt = 0; |
710 | SetNeutral(); |
678 | SetNeutral(); |
711 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern |
679 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK],NeutralAccX / 256); // ACC-NeutralWerte speichern |
712 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern |
680 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_NICK+1],NeutralAccX % 256); // ACC-NeutralWerte speichern |
713 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256); |
681 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL],NeutralAccY / 256); |
714 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256); |
682 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_ROLL+1],NeutralAccY % 256); |
715 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256); |
683 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z],(int)NeutralAccZ / 256); |
716 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256); |
684 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACC_Z+1],(int)NeutralAccZ % 256); |
717 | Piep(GetActiveParamSetNumber()); |
685 | Piep(GetActiveParamSetNumber()); |
718 | } |
686 | } |
719 | } |
687 | } |
720 | else delay_neutral = 0; |
688 | else delay_neutral = 0; |
721 | } |
689 | } |
722 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
690 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
723 | // Gas ist unten |
691 | // Gas ist unten |
724 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
725 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
693 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
726 | { |
694 | { |
727 | // Starten |
695 | // Starten |
728 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
696 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
729 | { |
697 | { |
730 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
698 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
731 | // Einschalten |
699 | // Einschalten |
732 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
700 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
733 | if(++delay_einschalten > 200) |
701 | if(++delay_einschalten > 200) |
734 | { |
702 | { |
735 | delay_einschalten = 200; |
703 | delay_einschalten = 200; |
736 | modell_fliegt = 1; |
704 | modell_fliegt = 1; |
737 | MotorenEin = 1; |
705 | MotorenEin = 1; |
738 | sollGier = 0; |
706 | sollGier = 0; |
739 | Mess_Integral_Gier = 0; |
707 | Mess_Integral_Gier = 0; |
740 | Mess_Integral_Gier2 = 0; |
708 | Mess_Integral_Gier2 = 0; |
741 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
709 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
742 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
710 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
743 | Mess_IntegralNick2 = IntegralNick; |
711 | Mess_IntegralNick2 = IntegralNick; |
744 | Mess_IntegralRoll2 = IntegralRoll; |
712 | Mess_IntegralRoll2 = IntegralRoll; |
745 | SummeNick = 0; |
713 | SummeNick = 0; |
746 | SummeRoll = 0; |
714 | SummeRoll = 0; |
747 | MikroKopterFlags |= FLAG_START; |
715 | MikroKopterFlags |= FLAG_START; |
748 | } |
716 | } |
749 | } |
717 | } |
750 | else delay_einschalten = 0; |
718 | else delay_einschalten = 0; |
751 | //Auf Neutralwerte setzen |
719 | //Auf Neutralwerte setzen |
752 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
720 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
753 | // Auschalten |
721 | // Auschalten |
754 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
722 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
755 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
723 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
756 | { |
724 | { |
757 | if(++delay_ausschalten > 200) // nicht sofort |
725 | if(++delay_ausschalten > 200) // nicht sofort |
758 | { |
726 | { |
759 | MotorenEin = 0; |
727 | MotorenEin = 0; |
760 | delay_ausschalten = 200; |
728 | delay_ausschalten = 200; |
761 | modell_fliegt = 0; |
729 | modell_fliegt = 0; |
762 | } |
730 | } |
763 | } |
731 | } |
764 | else delay_ausschalten = 0; |
732 | else delay_ausschalten = 0; |
765 | } |
733 | } |
766 | } |
734 | } |
767 | 735 | ||
768 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
736 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
769 | // neue Werte von der Funke |
737 | // neue Werte von der Funke |
770 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
738 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
771 | 739 | ||
772 | if(!NewPpmData-- || Notlandung) |
740 | if(!NewPpmData-- || Notlandung) |
773 | { |
741 | { |
774 | int tmp_int; |
- | |
775 | static int stick_nick,stick_roll; |
742 | static int stick_nick,stick_roll; |
776 | ParameterZuordnung(); |
743 | ParameterZuordnung(); |
777 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
744 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
778 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
745 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
779 | StickNick = stick_nick - (GPS_Nick + GPS_Nick2); |
746 | StickNick = stick_nick - (GPS_Nick + GPS_Nick2); |
780 | 747 | ||
781 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
748 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
782 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
749 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
783 | StickRoll = stick_roll - (GPS_Roll + GPS_Roll2); |
750 | StickRoll = stick_roll - (GPS_Roll + GPS_Roll2); |
784 | 751 | ||
785 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
752 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
786 | if(StickGier > 2) StickGier -= 2; else |
753 | if(StickGier > 2) StickGier -= 2; else |
787 | if(StickGier < -2) StickGier += 2; else StickGier = 0; |
754 | if(StickGier < -2) StickGier += 2; else StickGier = 0; |
788 | 755 | ||
789 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
756 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
790 | - | ||
791 | /* if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]) > MaxStickNick) |
- | |
792 | MaxStickNick = abs(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]); else MaxStickNick--; |
- | |
793 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > MaxStickRoll) |
- | |
794 | MaxStickRoll = abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]); else MaxStickRoll--; |
- | |
795 | */ |
- | |
796 | // GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / (256.0/STICK_GAIN); |
- | |
797 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
757 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
798 | // IntegralFaktor = ((float) Parameter_Gyro_I) / (44000 / STICK_GAIN); |
- | |
799 | IntegralFaktor = Parameter_Gyro_I; |
758 | IntegralFaktor = Parameter_Gyro_I; |
- | 759 | GyroFaktorGier = (Parameter_Gyro_P + 10.0); |
|
- | 760 | IntegralFaktorGier = Parameter_Gyro_I; |
|
800 | 761 | ||
801 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
762 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
802 | //+ Analoge Steuerung per Seriell |
763 | //+ Analoge Steuerung per Seriell |
803 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
764 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
804 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
765 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
805 | { |
766 | { |
806 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
767 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
807 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
768 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
808 | StickGier += ExternControl.Gier; |
769 | StickGier += ExternControl.Gier; |
809 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
770 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
810 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
771 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
811 | } |
772 | } |
812 | if(StickGas < 0) StickGas = 0; |
773 | if(StickGas < 0) StickGas = 0; |
813 | 774 | ||
814 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
775 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
815 | if(GyroFaktor < 0) GyroFaktor = 0; |
776 | if(GyroFaktor < 0) GyroFaktor = 0; |
816 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
777 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
817 | 778 | ||
818 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
779 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
819 | { |
780 | { |
820 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
781 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
821 | if(MaxStickNick > 100) MaxStickNick = 100; |
782 | if(MaxStickNick > 100) MaxStickNick = 100; |
822 | } |
783 | } |
823 | else MaxStickNick--; |
784 | else MaxStickNick--; |
824 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
785 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
825 | { |
786 | { |
826 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
787 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
827 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
788 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
828 | } |
789 | } |
829 | else MaxStickRoll--; |
790 | else MaxStickRoll--; |
830 | if(Notlandung) {MaxStickNick = 0; MaxStickRoll = 0;} |
791 | if(Notlandung) {MaxStickNick = 0; MaxStickRoll = 0;} |
831 | 792 | ||
832 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
793 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
833 | // Looping? |
794 | // Looping? |
834 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
795 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
835 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
796 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
836 | else |
797 | else |
837 | { |
798 | { |
838 | { |
799 | { |
839 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
800 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
840 | } |
801 | } |
841 | } |
802 | } |
842 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
803 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
843 | else |
804 | else |
844 | { |
805 | { |
845 | if(Looping_Rechts) // Hysterese |
806 | if(Looping_Rechts) // Hysterese |
846 | { |
807 | { |
847 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
808 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
848 | } |
809 | } |
849 | } |
810 | } |
850 | 811 | ||
851 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
812 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
852 | else |
813 | else |
853 | { |
814 | { |
854 | if(Looping_Oben) // Hysterese |
815 | if(Looping_Oben) // Hysterese |
855 | { |
816 | { |
856 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
817 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
857 | } |
818 | } |
858 | } |
819 | } |
859 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
820 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
860 | else |
821 | else |
861 | { |
822 | { |
862 | if(Looping_Unten) // Hysterese |
823 | if(Looping_Unten) // Hysterese |
863 | { |
824 | { |
864 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
825 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
865 | } |
826 | } |
866 | } |
827 | } |
867 | 828 | ||
868 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
829 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
869 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
830 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
870 | } // Ende neue Funken-Werte |
831 | } // Ende neue Funken-Werte |
871 | 832 | ||
872 | if(Looping_Roll || Looping_Nick) |
833 | if(Looping_Roll || Looping_Nick) |
873 | { |
834 | { |
874 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
835 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
875 | TrichterFlug = 1; |
836 | TrichterFlug = 1; |
876 | } |
837 | } |
877 | 838 | ||
878 | 839 | ||
879 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
840 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
880 | // Bei Empfangsausfall im Flug |
841 | // Bei Empfangsausfall im Flug |
881 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
842 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
882 | if(Notlandung) |
843 | if(Notlandung) |
883 | { |
844 | { |
884 | StickGier = 0; |
845 | StickGier = 0; |
885 | StickNick = 0; |
846 | StickNick = 0; |
886 | StickRoll = 0; |
847 | StickRoll = 0; |
887 | GyroFaktor = 90;//(float) 100 / (256.0 / STICK_GAIN); |
848 | GyroFaktor = 90; |
888 | IntegralFaktor = 120;//(float) 120 / (44000 / STICK_GAIN); |
849 | IntegralFaktor = 120; |
- | 850 | GyroFaktorGier = 90; |
|
- | 851 | IntegralFaktorGier = 120; |
|
889 | Looping_Roll = 0; |
852 | Looping_Roll = 0; |
890 | Looping_Nick = 0; |
853 | Looping_Nick = 0; |
891 | } |
854 | } |
892 | 855 | ||
893 | 856 | ||
894 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
857 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
895 | // Integrale auf ACC-Signal abgleichen |
858 | // Integrale auf ACC-Signal abgleichen |
896 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
859 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
897 | #define ABGLEICH_ANZAHL 256L |
860 | #define ABGLEICH_ANZAHL 256L |
898 | 861 | ||
899 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
862 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
900 | MittelIntegralRoll += IntegralRoll; |
863 | MittelIntegralRoll += IntegralRoll; |
901 | MittelIntegralNick2 += IntegralNick2; |
864 | MittelIntegralNick2 += IntegralNick2; |
902 | MittelIntegralRoll2 += IntegralRoll2; |
865 | MittelIntegralRoll2 += IntegralRoll2; |
903 | 866 | ||
904 | if(Looping_Nick || Looping_Roll) |
867 | if(Looping_Nick || Looping_Roll) |
905 | { |
868 | { |
906 | IntegralAccNick = 0; |
869 | IntegralAccNick = 0; |
907 | IntegralAccRoll = 0; |
870 | IntegralAccRoll = 0; |
908 | MittelIntegralNick = 0; |
871 | MittelIntegralNick = 0; |
909 | MittelIntegralRoll = 0; |
872 | MittelIntegralRoll = 0; |
910 | MittelIntegralNick2 = 0; |
873 | MittelIntegralNick2 = 0; |
911 | MittelIntegralRoll2 = 0; |
874 | MittelIntegralRoll2 = 0; |
912 | Mess_IntegralNick2 = Mess_IntegralNick; |
875 | Mess_IntegralNick2 = Mess_IntegralNick; |
913 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
876 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
914 | ZaehlMessungen = 0; |
877 | ZaehlMessungen = 0; |
915 | LageKorrekturNick = 0; |
878 | LageKorrekturNick = 0; |
916 | LageKorrekturRoll = 0; |
879 | LageKorrekturRoll = 0; |
917 | } |
880 | } |
918 | 881 | ||
919 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
882 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
920 | if(!Looping_Nick && !Looping_Roll && Aktuell_az > 512) |
883 | if(!Looping_Nick && !Looping_Roll && Aktuell_az > 512) |
921 | { |
884 | { |
922 | long tmp_long, tmp_long2; |
885 | long tmp_long, tmp_long2; |
923 | if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/) |
886 | if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/) |
924 | { |
887 | { |
925 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
888 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
926 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
889 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
927 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
890 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
928 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
891 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
929 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
892 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
930 | { |
893 | { |
931 | tmp_long /= 2; |
894 | tmp_long /= 2; |
932 | tmp_long2 /= 2; |
895 | tmp_long2 /= 2; |
933 | } |
896 | } |
934 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
897 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
935 | { |
898 | { |
936 | tmp_long /= 3; |
899 | tmp_long /= 3; |
937 | tmp_long2 /= 3; |
900 | tmp_long2 /= 3; |
938 | } |
901 | } |
939 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
902 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
940 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
903 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
941 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
904 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
942 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
905 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
943 | } |
906 | } |
944 | else |
907 | else |
945 | { |
908 | { |
946 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
909 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
947 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
910 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
948 | tmp_long /= 16; |
911 | tmp_long /= 16; |
949 | tmp_long2 /= 16; |
912 | tmp_long2 /= 16; |
950 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
913 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
951 | { |
914 | { |
952 | tmp_long /= 3; |
915 | tmp_long /= 3; |
953 | tmp_long2 /= 3; |
916 | tmp_long2 /= 3; |
954 | } |
917 | } |
955 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
918 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
956 | { |
919 | { |
957 | tmp_long /= 3; |
920 | tmp_long /= 3; |
958 | tmp_long2 /= 3; |
921 | tmp_long2 /= 3; |
959 | } |
922 | } |
960 | 923 | ||
961 | #define AUSGLEICH 32 |
924 | #define AUSGLEICH 32 |
962 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
925 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
963 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
926 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
964 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
927 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
965 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
928 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
966 | } |
929 | } |
967 | 930 | ||
968 | //if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;} |
931 | //if(Poti2 > 20) { tmp_long = 0; tmp_long2 = 0;} |
969 | Mess_IntegralNick -= tmp_long; |
932 | Mess_IntegralNick -= tmp_long; |
970 | Mess_IntegralRoll -= tmp_long2; |
933 | Mess_IntegralRoll -= tmp_long2; |
971 | } |
934 | } |
972 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
935 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
973 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
936 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
974 | { |
937 | { |
975 | static int cnt = 0; |
938 | static int cnt = 0; |
976 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
939 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
977 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
940 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
978 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
941 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
979 | { |
942 | { |
980 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
943 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
981 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
944 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
982 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
945 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
983 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
946 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
984 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
947 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
985 | #define MAX_I 0//(Poti2/10) |
948 | #define MAX_I 0//(Poti2/10) |
986 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
949 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
987 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
950 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
988 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
951 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
989 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
952 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
990 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
953 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
991 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
954 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
992 | 955 | ||
993 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
956 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
994 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
957 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
995 | 958 | ||
996 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
959 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
997 | { |
960 | { |
998 | LageKorrekturNick /= 2; |
961 | LageKorrekturNick /= 2; |
999 | LageKorrekturRoll /= 2; |
962 | LageKorrekturRoll /= 2; |
1000 | } |
963 | } |
1001 | 964 | ||
1002 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
965 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1003 | // Gyro-Drift ermitteln |
966 | // Gyro-Drift ermitteln |
1004 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
967 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1005 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
968 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1006 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
969 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
1007 | tmp_long = IntegralNick2 - IntegralNick; |
970 | tmp_long = IntegralNick2 - IntegralNick; |
1008 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
971 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
1009 | //DebugOut.Analog[25] = MittelIntegralRoll2 / 26; |
972 | //DebugOut.Analog[25] = MittelIntegralRoll2 / 26; |
1010 | 973 | ||
1011 | IntegralFehlerNick = tmp_long; |
974 | IntegralFehlerNick = tmp_long; |
1012 | IntegralFehlerRoll = tmp_long2; |
975 | IntegralFehlerRoll = tmp_long2; |
1013 | Mess_IntegralNick2 -= IntegralFehlerNick; |
976 | Mess_IntegralNick2 -= IntegralFehlerNick; |
1014 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
977 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
1015 | 978 | ||
1016 | // IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2; |
979 | // IntegralFehlerNick = (IntegralFehlerNick * 1 + tmp_long) / 2; |
1017 | // IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2; |
980 | // IntegralFehlerRoll = (IntegralFehlerRoll * 1 + tmp_long2) / 2; |
1018 | if(EE_Parameter.Driftkomp) |
981 | if(EE_Parameter.Driftkomp) |
1019 | { |
982 | { |
1020 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; } |
983 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; AdNeutralGierBias++; } |
1021 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; } |
984 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; AdNeutralGierBias--; } |
1022 | } |
985 | } |
1023 | //DebugOut.Analog[22] = MittelIntegralRoll / 26; |
986 | //DebugOut.Analog[22] = MittelIntegralRoll / 26; |
1024 | //DebugOut.Analog[24] = GierGyroFehler; |
987 | //DebugOut.Analog[24] = GierGyroFehler; |
1025 | GierGyroFehler = 0; |
988 | GierGyroFehler = 0; |
1026 | 989 | ||
1027 | 990 | ||
1028 | /*DebugOut.Analog[17] = IntegralAccNick / 26; |
991 | /*DebugOut.Analog[17] = IntegralAccNick / 26; |
1029 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
992 | DebugOut.Analog[18] = IntegralAccRoll / 26; |
1030 | DebugOut.Analog[19] = IntegralFehlerNick;// / 26; |
993 | DebugOut.Analog[19] = IntegralFehlerNick;// / 26; |
1031 | DebugOut.Analog[20] = IntegralFehlerRoll;// / 26; |
994 | DebugOut.Analog[20] = IntegralFehlerRoll;// / 26; |
1032 | */ |
995 | */ |
1033 | //DebugOut.Analog[21] = MittelIntegralNick / 26; |
996 | //DebugOut.Analog[21] = MittelIntegralNick / 26; |
1034 | //MittelIntegralRoll = MittelIntegralRoll; |
997 | //MittelIntegralRoll = MittelIntegralRoll; |
1035 | //DebugOut.Analog[28] = ausgleichNick; |
998 | //DebugOut.Analog[28] = ausgleichNick; |
1036 | /* |
999 | /* |
1037 | DebugOut.Analog[29] = ausgleichRoll; |
1000 | DebugOut.Analog[29] = ausgleichRoll; |
1038 | DebugOut.Analog[30] = LageKorrekturRoll * 10; |
1001 | DebugOut.Analog[30] = LageKorrekturRoll * 10; |
1039 | */ |
1002 | */ |
1040 | 1003 | ||
1041 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
1004 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL * 4) |
1042 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
1005 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) |
1043 | #define BEWEGUNGS_LIMIT 20000 |
1006 | #define BEWEGUNGS_LIMIT 20000 |
1044 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1007 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1045 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1008 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1046 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1009 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1047 | { |
1010 | { |
1048 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
1011 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
1049 | { |
1012 | { |
1050 | if(last_n_p) |
1013 | if(last_n_p) |
1051 | { |
1014 | { |
1052 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1015 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1053 | ausgleichNick = IntegralFehlerNick / 8; |
1016 | ausgleichNick = IntegralFehlerNick / 8; |
1054 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
1017 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
1055 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1018 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1056 | } |
1019 | } |
1057 | else last_n_p = 1; |
1020 | else last_n_p = 1; |
1058 | } else last_n_p = 0; |
1021 | } else last_n_p = 0; |
1059 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
1022 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
1060 | { |
1023 | { |
1061 | if(last_n_n) |
1024 | if(last_n_n) |
1062 | { |
1025 | { |
1063 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1026 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1064 | ausgleichNick = IntegralFehlerNick / 8; |
1027 | ausgleichNick = IntegralFehlerNick / 8; |
1065 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
1028 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
1066 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1029 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1067 | } |
1030 | } |
1068 | else last_n_n = 1; |
1031 | else last_n_n = 1; |
1069 | } else last_n_n = 0; |
1032 | } else last_n_n = 0; |
1070 | } |
1033 | } |
1071 | else |
1034 | else |
1072 | { |
1035 | { |
1073 | cnt = 0; |
1036 | cnt = 0; |
1074 | KompassSignalSchlecht = 1000; |
1037 | KompassSignalSchlecht = 1000; |
1075 | } |
1038 | } |
1076 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1039 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1077 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1040 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1078 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1041 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1079 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
1042 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
1080 | 1043 | ||
1081 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1044 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1082 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1045 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1083 | 1046 | ||
1084 | ausgleichRoll = 0; |
1047 | ausgleichRoll = 0; |
1085 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1048 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1086 | { |
1049 | { |
1087 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
1050 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
1088 | { |
1051 | { |
1089 | if(last_r_p) |
1052 | if(last_r_p) |
1090 | { |
1053 | { |
1091 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1054 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1092 | ausgleichRoll = IntegralFehlerRoll / 8; |
1055 | ausgleichRoll = IntegralFehlerRoll / 8; |
1093 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
1056 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
1094 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1057 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1095 | } |
1058 | } |
1096 | else last_r_p = 1; |
1059 | else last_r_p = 1; |
1097 | } else last_r_p = 0; |
1060 | } else last_r_p = 0; |
1098 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
1061 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
1099 | { |
1062 | { |
1100 | if(last_r_n) |
1063 | if(last_r_n) |
1101 | { |
1064 | { |
1102 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1065 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1103 | ausgleichRoll = IntegralFehlerRoll / 8; |
1066 | ausgleichRoll = IntegralFehlerRoll / 8; |
1104 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
1067 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
1105 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1068 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1106 | } |
1069 | } |
1107 | else last_r_n = 1; |
1070 | else last_r_n = 1; |
1108 | } else last_r_n = 0; |
1071 | } else last_r_n = 0; |
1109 | } else |
1072 | } else |
1110 | { |
1073 | { |
1111 | cnt = 0; |
1074 | cnt = 0; |
1112 | KompassSignalSchlecht = 1000; |
1075 | KompassSignalSchlecht = 1000; |
1113 | } |
1076 | } |
1114 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1077 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1115 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1078 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1116 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1079 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1117 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1080 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1118 | } |
1081 | } |
1119 | else |
1082 | else |
1120 | { |
1083 | { |
1121 | LageKorrekturRoll = 0; |
1084 | LageKorrekturRoll = 0; |
1122 | LageKorrekturNick = 0; |
1085 | LageKorrekturNick = 0; |
1123 | TrichterFlug = 0; |
1086 | TrichterFlug = 0; |
1124 | } |
1087 | } |
1125 | 1088 | ||
1126 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1089 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1127 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1090 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1128 | MittelIntegralNick_Alt = MittelIntegralNick; |
1091 | MittelIntegralNick_Alt = MittelIntegralNick; |
1129 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1092 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1130 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1093 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1131 | IntegralAccNick = 0; |
1094 | IntegralAccNick = 0; |
1132 | IntegralAccRoll = 0; |
1095 | IntegralAccRoll = 0; |
1133 | IntegralAccZ = 0; |
1096 | IntegralAccZ = 0; |
1134 | MittelIntegralNick = 0; |
1097 | MittelIntegralNick = 0; |
1135 | MittelIntegralRoll = 0; |
1098 | MittelIntegralRoll = 0; |
1136 | MittelIntegralNick2 = 0; |
1099 | MittelIntegralNick2 = 0; |
1137 | MittelIntegralRoll2 = 0; |
1100 | MittelIntegralRoll2 = 0; |
1138 | ZaehlMessungen = 0; |
1101 | ZaehlMessungen = 0; |
1139 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1102 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1140 | 1103 | ||
1141 | 1104 | ||
1142 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1105 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1143 | // Gieren |
1106 | // Gieren |
1144 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1107 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1145 | // if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;}; |
1108 | // if(GasMischanteil < 35) { if(StickGier > 10) StickGier = 10; else if(StickGier < -10) StickGier = -10;}; |
1146 | if(abs(StickGier) > 15) // war 35 |
1109 | if(abs(StickGier) > 15) // war 35 |
1147 | { |
1110 | { |
1148 | KompassSignalSchlecht = 1000; |
1111 | KompassSignalSchlecht = 1000; |
1149 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) |
1112 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) |
1150 | { |
1113 | { |
1151 | NeueKompassRichtungMerken = 1; |
1114 | NeueKompassRichtungMerken = 1; |
1152 | }; |
1115 | }; |
1153 | } |
1116 | } |
1154 | tmp_int = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1117 | tmp_int = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1155 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
1118 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
1156 | sollGier = tmp_int; |
1119 | sollGier = tmp_int; |
1157 | Mess_Integral_Gier -= tmp_int; |
1120 | Mess_Integral_Gier -= tmp_int; |
1158 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1121 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1159 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1122 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1160 | 1123 | ||
1161 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1124 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1162 | // Kompass |
1125 | // Kompass |
1163 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1126 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1164 | //DebugOut.Analog[16] = KompassSignalSchlecht; |
1127 | //DebugOut.Analog[16] = KompassSignalSchlecht; |
1165 | 1128 | ||
1166 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
1129 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
1167 | { |
1130 | { |
1168 | int w,v,r,fehler,korrektur; |
1131 | int w,v,r,fehler,korrektur; |
1169 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1132 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1170 | v = abs(IntegralRoll /512); |
1133 | v = abs(IntegralRoll /512); |
1171 | if(v > w) w = v; // grösste Neigung ermitteln |
1134 | if(v > w) w = v; // grösste Neigung ermitteln |
1172 | korrektur = w / 8 + 1; |
1135 | korrektur = w / 8 + 1; |
1173 | fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180; |
1136 | fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180; |
1174 | if(abs(MesswertGier) > 128) |
1137 | if(abs(MesswertGier) > 128) |
1175 | { |
1138 | { |
1176 | fehler = 0; |
1139 | fehler = 0; |
1177 | } |
1140 | } |
1178 | - | ||
1179 | if(NeueKompassRichtungMerken) |
- | |
1180 | { |
- | |
1181 | // ErsatzKompass += (fehler * 32) / korrektur; |
- | |
1182 | // fehler = 0; |
- | |
1183 | // fehler /= 4; |
- | |
1184 | // ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
- | |
1185 | } |
- | |
1186 | if(!KompassSignalSchlecht && w < 25) |
1141 | if(!KompassSignalSchlecht && w < 25) |
1187 | { |
1142 | { |
1188 | GierGyroFehler += fehler; |
1143 | GierGyroFehler += fehler; |
1189 | if(NeueKompassRichtungMerken) |
1144 | if(NeueKompassRichtungMerken) |
1190 | { |
1145 | { |
1191 | beeptime = 200; |
1146 | beeptime = 200; |
1192 | // KompassStartwert = KompassValue; |
1147 | // KompassStartwert = KompassValue; |
1193 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
1148 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
1194 | KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR); |
1149 | KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR); |
1195 | NeueKompassRichtungMerken = 0; |
1150 | NeueKompassRichtungMerken = 0; |
1196 | } |
1151 | } |
1197 | } |
1152 | } |
1198 | ErsatzKompass += (fehler * 8) / korrektur; |
1153 | ErsatzKompass += (fehler * 8) / korrektur; |
1199 | w = (w * Parameter_KompassWirkung) / 32; // auf die Wirkung normieren |
1154 | w = (w * Parameter_KompassWirkung) / 32; // auf die Wirkung normieren |
1200 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
1155 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
1201 | if(w >= 0) |
1156 | if(w >= 0) |
1202 | { |
1157 | { |
1203 | if(!KompassSignalSchlecht) |
1158 | if(!KompassSignalSchlecht) |
1204 | { |
1159 | { |
1205 | v = 64 + ((MaxStickNick + MaxStickRoll)) / 8; |
1160 | v = 64 + ((MaxStickNick + MaxStickRoll)) / 8; |
1206 | r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180; |
1161 | r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180; |
1207 | // r = KompassRichtung; |
1162 | // r = KompassRichtung; |
1208 | v = (r * w) / v; // nach Kompass ausrichten |
1163 | v = (r * w) / v; // nach Kompass ausrichten |
1209 | w = 3 * Parameter_KompassWirkung; |
1164 | w = 3 * Parameter_KompassWirkung; |
1210 | if(v > w) v = w; // Begrenzen |
1165 | if(v > w) v = w; // Begrenzen |
1211 | else |
1166 | else |
1212 | if(v < -w) v = -w; |
1167 | if(v < -w) v = -w; |
1213 | Mess_Integral_Gier += v; |
1168 | Mess_Integral_Gier += v; |
1214 | } |
1169 | } |
1215 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1170 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1216 | } |
1171 | } |
1217 | else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
1172 | else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
1218 | } |
1173 | } |
1219 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1174 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1220 | 1175 | ||
1221 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1176 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1222 | // Debugwerte zuordnen |
1177 | // Debugwerte zuordnen |
1223 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1178 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1224 | if(!TimerWerteausgabe--) |
1179 | if(!TimerWerteausgabe--) |
1225 | { |
1180 | { |
1226 | TimerWerteausgabe = 24; |
1181 | TimerWerteausgabe = 24; |
1227 | 1182 | ||
1228 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
1183 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
1229 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
1184 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
1230 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
1185 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
1231 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
1186 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
1232 | DebugOut.Analog[4] = MesswertGier; |
1187 | DebugOut.Analog[4] = MesswertGier; |
1233 | DebugOut.Analog[5] = HoehenWert; |
1188 | DebugOut.Analog[5] = HoehenWert; |
1234 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);//Aktuell_az; |
1189 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512);//Aktuell_az; |
1235 | DebugOut.Analog[8] = KompassValue; |
1190 | DebugOut.Analog[8] = KompassValue; |
1236 | DebugOut.Analog[9] = UBat; |
1191 | DebugOut.Analog[9] = UBat; |
1237 | DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR; |
1192 | DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR; |
1238 | DebugOut.Analog[10] = SenderOkay; |
1193 | DebugOut.Analog[10] = SenderOkay; |
1239 | //DebugOut.Analog[16] = Mittelwert_AccHoch; |
1194 | //DebugOut.Analog[16] = Mittelwert_AccHoch; |
1240 | //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance; |
1195 | //DebugOut.Analog[17] = FromNaviCtrl_Value.Distance; |
1241 | //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar; |
1196 | //DebugOut.Analog[18] = (int)FromNaviCtrl_Value.OsdBar; |
1242 | DebugOut.Analog[19] = WinkelOut.CalcState; |
1197 | DebugOut.Analog[19] = WinkelOut.CalcState; |
1243 | DebugOut.Analog[20] = ServoValue; |
1198 | DebugOut.Analog[20] = ServoValue; |
1244 | // DebugOut.Analog[24] = MesswertNick/2; |
1199 | // DebugOut.Analog[24] = MesswertNick/2; |
1245 | // DebugOut.Analog[25] = MesswertRoll/2; |
1200 | // DebugOut.Analog[25] = MesswertRoll/2; |
1246 | DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift; |
1201 | DebugOut.Analog[27] = (int)FromNaviCtrl_Value.Kalman_MaxDrift; |
1247 | // DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion; |
1202 | // DebugOut.Analog[28] = (int)FromNaviCtrl_Value.Kalman_MaxFusion; |
1248 | // DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K; |
1203 | // DebugOut.Analog[29] = (int)FromNaviCtrl_Value.Kalman_K; |
1249 | DebugOut.Analog[30] = GPS_Nick; |
1204 | DebugOut.Analog[30] = GPS_Nick; |
1250 | DebugOut.Analog[31] = GPS_Roll; |
1205 | DebugOut.Analog[31] = GPS_Roll; |
1251 | 1206 | ||
1252 | 1207 | ||
1253 | // DebugOut.Analog[19] -= DebugOut.Analog[19]/128; |
1208 | // DebugOut.Analog[19] -= DebugOut.Analog[19]/128; |
1254 | // if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++; |
1209 | // if(DebugOut.Analog[19] > 0) DebugOut.Analog[19]--; else DebugOut.Analog[19]++; |
1255 | 1210 | ||
1256 | /* DebugOut.Analog[16] = motor_rx[0]; |
1211 | /* DebugOut.Analog[16] = motor_rx[0]; |
1257 | DebugOut.Analog[17] = motor_rx[1]; |
1212 | DebugOut.Analog[17] = motor_rx[1]; |
1258 | DebugOut.Analog[18] = motor_rx[2]; |
1213 | DebugOut.Analog[18] = motor_rx[2]; |
1259 | DebugOut.Analog[19] = motor_rx[3]; |
1214 | DebugOut.Analog[19] = motor_rx[3]; |
1260 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
1215 | DebugOut.Analog[20] = motor_rx[0] + motor_rx[1] + motor_rx[2] + motor_rx[3]; |
1261 | DebugOut.Analog[20] /= 14; |
1216 | DebugOut.Analog[20] /= 14; |
1262 | DebugOut.Analog[21] = motor_rx[4]; |
1217 | DebugOut.Analog[21] = motor_rx[4]; |
1263 | DebugOut.Analog[22] = motor_rx[5]; |
1218 | DebugOut.Analog[22] = motor_rx[5]; |
1264 | DebugOut.Analog[23] = motor_rx[6]; |
1219 | DebugOut.Analog[23] = motor_rx[6]; |
1265 | DebugOut.Analog[24] = motor_rx[7]; |
1220 | DebugOut.Analog[24] = motor_rx[7]; |
1266 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
1221 | DebugOut.Analog[25] = motor_rx[4] + motor_rx[5] + motor_rx[6] + motor_rx[7]; |
1267 | */ |
1222 | */ |
1268 | // DebugOut.Analog[9] = MesswertNick; |
1223 | // DebugOut.Analog[9] = MesswertNick; |
1269 | // DebugOut.Analog[9] = SollHoehe; |
1224 | // DebugOut.Analog[9] = SollHoehe; |
1270 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
1225 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
1271 | // DebugOut.Analog[11] = KompassStartwert; |
1226 | // DebugOut.Analog[11] = KompassStartwert; |
1272 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
1227 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
1273 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
1228 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
1274 | // DebugOut.Analog[9] = KompassRichtung; |
1229 | // DebugOut.Analog[9] = KompassRichtung; |
1275 | // DebugOut.Analog[10] = GasMischanteil; |
1230 | // DebugOut.Analog[10] = GasMischanteil; |
1276 | // DebugOut.Analog[3] = HoeheD * 32; |
1231 | // DebugOut.Analog[3] = HoeheD * 32; |
1277 | // DebugOut.Analog[4] = hoehenregler; |
1232 | // DebugOut.Analog[4] = hoehenregler; |
1278 | } |
1233 | } |
1279 | 1234 | ||
1280 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1235 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1281 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1236 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1282 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1237 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1283 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1238 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1284 | 1239 | ||
1285 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1240 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1286 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1241 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1287 | 1242 | ||
1288 | #define TRIM_MAX 200 |
1243 | #define TRIM_MAX 200 |
1289 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1244 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1290 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1245 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1291 | - | ||
1292 | { |
1246 | |
1293 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1247 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1294 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
- | |
1295 | } |
- | |
1296 | - | ||
1297 | #ifndef QUADRO |
- | |
1298 | MesswertGier = (long)(MesswertGier * 4 * (long)GyroFaktor) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktor) / (4 * (44000 / STICK_GAIN)); |
- | |
1299 | #else |
1248 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
1300 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktor) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktor) / (2 * (44000 / STICK_GAIN)); |
- | |
1301 | #endif |
1249 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1302 | 1250 | ||
1303 | // Maximalwerte abfangen |
1251 | // Maximalwerte abfangen |
1304 | // #define MAX_SENSOR (4096*STICK_GAIN) |
1252 | // #define MAX_SENSOR (4096*STICK_GAIN) |
1305 | #define MAX_SENSOR (4096*4) |
1253 | #define MAX_SENSOR (4096*4) |
1306 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1254 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1307 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1255 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1308 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1256 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1309 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1257 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1310 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1258 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1311 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1259 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1312 | 1260 | ||
1313 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1261 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1314 | // all BL-Ctrl connected? |
1262 | // all BL-Ctrl connected? |
1315 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1263 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1316 | if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) |
1264 | if(MissingMotor) if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) |
1317 | { |
1265 | { |
1318 | modell_fliegt = 1; |
1266 | modell_fliegt = 1; |
1319 | GasMischanteil = MIN_GAS; |
1267 | GasMischanteil = MIN_GAS; |
1320 | } |
1268 | } |
1321 | 1269 | ||
1322 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1270 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1323 | // Höhenregelung |
1271 | // Höhenregelung |
1324 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
1272 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
1325 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1273 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1326 | GasMischanteil *= STICK_GAIN; |
1274 | GasMischanteil *= STICK_GAIN; |
1327 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
1275 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
1328 | { |
1276 | { |
1329 | int tmp_int; |
1277 | int tmp_int; |
1330 | static char delay = 100; |
1278 | static char delay = 100; |
1331 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1279 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1332 | { |
1280 | { |
1333 | if(((EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && ((Parameter_MaxHoehe > 80) && (Parameter_MaxHoehe < 140))) || |
1281 | if(((EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && ((Parameter_MaxHoehe > 80) && (Parameter_MaxHoehe < 140))) || |
1334 | (!(EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && (Parameter_MaxHoehe < 50))) |
1282 | (!(EE_Parameter.BitConfig & CFG_HIGHT_3SWITCH) && (Parameter_MaxHoehe < 50))) |
1335 | { |
1283 | { |
1336 | if(!delay--) |
1284 | if(!delay--) |
1337 | { |
1285 | { |
1338 | if(MessLuftdruck > 1000) |
1286 | if(MessLuftdruck > 1000) |
1339 | { |
1287 | { |
1340 | ExpandBaro -= 10; |
1288 | ExpandBaro -= 10; |
1341 | OCR0A = DruckOffsetSetting - ExpandBaro; |
1289 | OCR0A = DruckOffsetSetting - ExpandBaro; |
1342 | beeptime = 300; |
1290 | beeptime = 300; |
1343 | delay = 250; |
1291 | delay = 250; |
1344 | } |
1292 | } |
1345 | else |
1293 | else |
1346 | if(MessLuftdruck < 100) |
1294 | if(MessLuftdruck < 100) |
1347 | { |
1295 | { |
1348 | ExpandBaro += 10; |
1296 | ExpandBaro += 10; |
1349 | OCR0A = DruckOffsetSetting - ExpandBaro; |
1297 | OCR0A = DruckOffsetSetting - ExpandBaro; |
1350 | beeptime = 300; |
1298 | beeptime = 300; |
1351 | delay = 250; |
1299 | delay = 250; |
1352 | } |
1300 | } |
1353 | else |
1301 | else |
1354 | { |
1302 | { |
1355 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
1303 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
1356 | HoehenReglerAktiv = 0; |
1304 | HoehenReglerAktiv = 0; |
1357 | delay = 1; |
1305 | delay = 1; |
1358 | } |
1306 | } |
1359 | } |
1307 | } |
1360 | } |
1308 | } |
1361 | else |
1309 | else |
1362 | { |
1310 | { |
1363 | HoehenReglerAktiv = 1; |
1311 | HoehenReglerAktiv = 1; |
1364 | delay = 200; |
1312 | delay = 200; |
1365 | } |
1313 | } |
1366 | } |
1314 | } |
1367 | else |
1315 | else |
1368 | { |
1316 | { |
1369 | SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20; |
1317 | SollHoehe = ((int) ExternHoehenValue + (int) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung - 20; |
1370 | HoehenReglerAktiv = 1; |
1318 | HoehenReglerAktiv = 1; |
1371 | } |
1319 | } |
1372 | 1320 | ||
1373 | if(Notlandung) SollHoehe = 0; |
1321 | if(Notlandung) SollHoehe = 0; |
1374 | h = HoehenWert; |
1322 | h = HoehenWert; |
1375 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
1323 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
1376 | { |
1324 | { |
1377 | h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil |
1325 | h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / (16 / STICK_GAIN); // Differenz bestimmen --> P-Anteil |
1378 | h = GasMischanteil - h; // vom Gas abziehen |
1326 | h = GasMischanteil - h; // vom Gas abziehen |
1379 | // h -= (HoeheD * Parameter_Luftdruck_D)/(8/STICK_GAIN); // D-Anteil |
- | |
1380 | h -= (HoeheD)/(8/STICK_GAIN); // D-Anteil |
1327 | h -= (HoeheD)/(8/STICK_GAIN); // D-Anteil |
1381 | tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN); |
1328 | tmp_int = ((Mess_Integral_Hoch / 128) * (signed long) Parameter_Hoehe_ACC_Wirkung) / (128 / STICK_GAIN); |
1382 | if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN; |
1329 | if(tmp_int > 70*STICK_GAIN) tmp_int = 70*STICK_GAIN; |
1383 | else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN); |
1330 | else if(tmp_int < -(70*STICK_GAIN)) tmp_int = -(70*STICK_GAIN); |
1384 | h -= tmp_int; |
1331 | h -= tmp_int; |
1385 | hoehenregler = (hoehenregler*15 + h) / 16; |
1332 | hoehenregler = (hoehenregler*15 + h) / 16; |
1386 | if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN |
1333 | if(hoehenregler < EE_Parameter.Hoehe_MinGas * STICK_GAIN) // nicht unter MIN |
1387 | { |
1334 | { |
1388 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN; |
1335 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = EE_Parameter.Hoehe_MinGas * STICK_GAIN; |
1389 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil; |
1336 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas * STICK_GAIN) hoehenregler = GasMischanteil; |
1390 | } |
1337 | } |
1391 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
1338 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
1392 | GasMischanteil = hoehenregler; |
1339 | GasMischanteil = hoehenregler; |
1393 | } |
1340 | } |
1394 | } |
1341 | } |
1395 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1342 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1396 | 1343 | ||
1397 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1344 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1398 | // + Mischer und PI-Regler |
1345 | // + Mischer und PI-Regler |
1399 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1346 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1400 | DebugOut.Analog[7] = GasMischanteil; |
1347 | DebugOut.Analog[7] = GasMischanteil; |
1401 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1348 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1402 | // Gier-Anteil |
1349 | // Gier-Anteil |
1403 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1350 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1404 | #define MUL_G 1.0 |
1351 | #define MUL_G 1.0 |
1405 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1352 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1406 | // GierMischanteil = 0; |
1353 | // GierMischanteil = 0; |
1407 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
1354 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
1408 | if(GasMischanteil > MIN_GIERGAS) |
1355 | if(GasMischanteil > MIN_GIERGAS) |
1409 | { |
1356 | { |
1410 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1357 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1411 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
1358 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
1412 | } |
1359 | } |
1413 | else |
1360 | else |
1414 | { |
1361 | { |
1415 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1362 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1416 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
1363 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
1417 | } |
1364 | } |
1418 | tmp_int = MAX_GAS*STICK_GAIN; |
1365 | tmp_int = MAX_GAS*STICK_GAIN; |
1419 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
1366 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
1420 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
1367 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
1421 | 1368 | ||
1422 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1369 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1423 | // Nick-Achse |
1370 | // Nick-Achse |
1424 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1371 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1425 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1372 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1426 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1373 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1427 | else SummeNick += DiffNick; // I-Anteil bei HH |
1374 | else SummeNick += DiffNick; // I-Anteil bei HH |
1428 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1375 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1429 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1376 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1430 | pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick |
1377 | pd_ergebnis_nick = DiffNick + SummeNick / Ki; // PI-Regler für Nick |
1431 | // Motor Vorn |
1378 | // Motor Vorn |
1432 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1379 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1433 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1380 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1434 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
1381 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
1435 | 1382 | ||
1436 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1383 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1437 | // Roll-Achse |
1384 | // Roll-Achse |
1438 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1385 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1439 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1386 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1440 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
1387 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
1441 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1388 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1442 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1389 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1443 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1390 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1444 | pd_ergebnis_roll = DiffRoll + SummeRoll / Ki; // PI-Regler für Roll |
1391 | pd_ergebnis_roll = DiffRoll + SummeRoll / Ki; // PI-Regler für Roll |
1445 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1392 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1446 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1393 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1447 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
1394 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
1448 | 1395 | ||
1449 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1396 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1450 | // Universal Mixer |
1397 | // Universal Mixer |
1451 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1398 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1452 | for(i=0; i<MAX_MOTORS; i++) |
1399 | for(i=0; i<MAX_MOTORS; i++) |
1453 | { |
1400 | { |
1454 | signed int tmp_int; |
1401 | signed int tmp_int; |
1455 | if(Mixer.Motor[i][0] > 0) |
1402 | if(Mixer.Motor[i][0] > 0) |
1456 | { |
1403 | { |
1457 | tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1404 | tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1458 | tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
1405 | tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
1459 | tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
1406 | tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
1460 | tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
1407 | tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
1461 | tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]); // Filter |
1408 | tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]); // Filter |
1462 | tmp_int = tmp_motorwert[i] / STICK_GAIN; |
1409 | tmp_int = tmp_motorwert[i] / STICK_GAIN; |
1463 | CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS); |
1410 | CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS); |
1464 | Motor[i] = tmp_int; |
1411 | Motor[i] = tmp_int; |
1465 | } |
1412 | } |
1466 | else Motor[i] = 0; |
1413 | else Motor[i] = 0; |
1467 | } |
1414 | } |
1468 | /* |
1415 | /* |
1469 | if(Poti1 > 20) Motor1 = 0; |
1416 | if(Poti1 > 20) Motor1 = 0; |
1470 | if(Poti1 > 90) Motor6 = 0; |
1417 | if(Poti1 > 90) Motor6 = 0; |
1471 | if(Poti1 > 140) Motor2 = 0; |
1418 | if(Poti1 > 140) Motor2 = 0; |
1472 | //if(Poti1 > 200) Motor7 = 0; |
1419 | //if(Poti1 > 200) Motor7 = 0; |
1473 | */ |
1420 | */ |
1474 | } |
1421 | } |
1475 | 1422 |