Rev 1749 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1749 | Rev 1756 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Flight Control |
2 | Flight Control |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) Holger Buss, Ingo Busker |
5 | // + Copyright (c) Holger Buss, Ingo Busker |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
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 oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
27 | // + Die Portierung oder Nutzung 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 the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
42 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
43 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
43 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
44 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
44 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 55 | ||
- | 56 | //Interessanten Maximumwerte |
|
- | 57 | //Capacity.ActualCurrent/10, Capacity.ActualCurrent%10 |
|
- | 58 | //GPSInfo.Speed,GPSInfo.NumOfSats |
|
- | 59 | //VarioMeter |
|
- | 60 | //HoverGas/4 |
|
- | 61 | ||
- | 62 | ||
55 | 63 | ||
56 | #include "main.h" |
64 | #include "main.h" |
57 | #include "mymath.h" |
65 | #include "mymath.h" |
58 | #include "isqrt.h" |
66 | #include "isqrt.h" |
59 | 67 | ||
60 | #ifdef NODISPLAY // main.h |
68 | #ifdef NODISPLAY // main.h |
61 | 69 | ||
62 | 70 | ||
63 | 71 | ||
64 | #endif |
72 | #endif |
65 | unsigned char loop1, loop2, loop3, loop4; |
73 | unsigned char loop1, loop2, loop3; |
- | 74 | unsigned char settingdest = 5; |
|
66 | int keynumber=-7; |
75 | int keynumber=-7; |
- | 76 | ||
67 | 77 | unsigned short CurrentOffset = 0;/// |
|
68 | 78 | ||
69 | unsigned char pos1, pos2, pos3, pos4=0; |
79 | unsigned char pos1, pos2, pos3, pos4=0; |
70 | unsigned char Motors0,Motors1,Motors2,Motors3,Motors4,Motors5,Motors6,Motors7; |
80 | unsigned char Motors0,Motors1,Motors2,Motors3,Motors4,Motors5,Motors6,Motors7; |
- | 81 | unsigned char Motors0max,Motors1max,Motors2max,Motors3max,Motors4max,Motors5max,Motors6max,Motors7max; |
|
- | 82 | unsigned short MotorsTmax; |
|
71 | unsigned char updatemotors=5; |
83 | unsigned char updatemotors=5; |
72 | unsigned char h,m,s; |
84 | unsigned char h,m,s; |
73 | unsigned int BaroExpandActive = 0; |
85 | unsigned int BaroExpandActive = 0; |
74 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
86 | int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
75 | int TrimNick, TrimRoll; |
87 | int TrimNick, TrimRoll; |
76 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
88 | int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
77 | int Mittelwert_AccNick, Mittelwert_AccRoll; |
89 | int Mittelwert_AccNick, Mittelwert_AccRoll; |
78 | unsigned int NeutralAccX=0, NeutralAccY=0; |
90 | unsigned int NeutralAccX=0, NeutralAccY=0; |
79 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
91 | int NaviAccNick, NaviAccRoll,NaviCntAcc = 0; |
80 | int NeutralAccZ = 0; |
92 | int NeutralAccZ = 0; |
81 | unsigned char ControlHeading = 0;// in 2° |
93 | unsigned char ControlHeading = 0;// in 2° |
82 | long IntegralNick = 0,IntegralNick2 = 0; |
94 | long IntegralNick = 0,IntegralNick2 = 0; |
83 | long IntegralRoll = 0,IntegralRoll2 = 0; |
95 | long IntegralRoll = 0,IntegralRoll2 = 0; |
84 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
96 | long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0; |
85 | long Integral_Gier = 0; |
97 | long Integral_Gier = 0; |
86 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
98 | long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
87 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
99 | long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
88 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
100 | long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
89 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
101 | long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2; |
90 | long SummeNick=0,SummeRoll=0; |
102 | long SummeNick=0,SummeRoll=0; |
91 | volatile long Mess_Integral_Hoch = 0; |
103 | volatile long Mess_Integral_Hoch = 0; |
92 | int KompassValue = 0; |
104 | int KompassValue = 0; |
93 | int KompassStartwert = 0; |
105 | int KompassStartwert = 0; |
94 | int KompassRichtung = 0; |
106 | int KompassRichtung = 0; |
95 | unsigned int KompassSignalSchlecht = 500; |
107 | unsigned int KompassSignalSchlecht = 500; |
96 | unsigned char MAX_GAS,MIN_GAS; |
108 | unsigned char MAX_GAS,MIN_GAS; |
97 | unsigned char HoehenReglerAktiv = 0; |
109 | unsigned char HoehenReglerAktiv = 0; |
98 | unsigned char TrichterFlug = 0; |
110 | unsigned char TrichterFlug = 0; |
99 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
111 | long Umschlag180Nick = 250000L, Umschlag180Roll = 250000L; |
100 | long ErsatzKompass; |
112 | long ErsatzKompass; |
101 | int ErsatzKompassInGrad; // Kompasswert in Grad |
113 | int ErsatzKompassInGrad; // Kompasswert in Grad |
102 | int GierGyroFehler = 0; |
114 | int GierGyroFehler = 0; |
103 | char GyroFaktor,GyroFaktorGier; |
115 | char GyroFaktor,GyroFaktorGier; |
104 | char IntegralFaktor,IntegralFaktorGier; |
116 | char IntegralFaktor,IntegralFaktorGier; |
105 | int DiffNick,DiffRoll; |
117 | int DiffNick,DiffRoll; |
106 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
118 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
107 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
119 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
108 | volatile unsigned char SenderOkay = 0; |
120 | volatile unsigned char SenderOkay = 0; |
109 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
121 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
110 | char MotorenEin = 0,StartTrigger = 0; |
122 | char MotorenEin = 0,StartTrigger = 0; |
111 | long HoehenWert = 0; |
123 | long HoehenWert = 0; |
112 | long SollHoehe = 0; |
124 | long SollHoehe = 0; |
113 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
125 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
114 | //float Ki = FAKTOR_I; |
126 | //float Ki = FAKTOR_I; |
115 | int Ki = 10300 / 33; |
127 | int Ki = 10300 / 33; |
116 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
128 | unsigned char Looping_Nick = 0,Looping_Roll = 0; |
117 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
129 | unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
118 | 130 | ||
119 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
131 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
120 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
132 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
121 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
133 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
122 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
134 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
123 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
135 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
124 | unsigned char Parameter_Hoehe_GPS_Z = 64; // Wert : 0-250 |
136 | unsigned char Parameter_Hoehe_GPS_Z = 64; // Wert : 0-250 |
125 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
137 | unsigned char Parameter_Gyro_D = 8; // Wert : 0-250 |
126 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
138 | unsigned char Parameter_Gyro_P = 150; // Wert : 10-250 |
127 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
139 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
128 | unsigned char Parameter_Gyro_Gier_P = 150; // Wert : 10-250 |
140 | unsigned char Parameter_Gyro_Gier_P = 150; // Wert : 10-250 |
129 | unsigned char Parameter_Gyro_Gier_I = 150; // Wert : 10-250 |
141 | unsigned char Parameter_Gyro_Gier_I = 150; // Wert : 10-250 |
130 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
142 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
131 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
143 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
132 | unsigned char Parameter_UserParam1 = 0; |
144 | unsigned char Parameter_UserParam1 = 0; |
133 | unsigned char Parameter_UserParam2 = 0; |
145 | unsigned char Parameter_UserParam2 = 0; |
134 | unsigned char Parameter_UserParam3 = 0; |
146 | unsigned char Parameter_UserParam3 = 0; |
135 | unsigned char Parameter_UserParam4 = 0; |
147 | unsigned char Parameter_UserParam4 = 0; |
136 | unsigned char Parameter_UserParam5 = 0; |
148 | unsigned char Parameter_UserParam5 = 0; |
137 | unsigned char Parameter_UserParam6 = 0; |
149 | unsigned char Parameter_UserParam6 = 0; |
138 | unsigned char Parameter_UserParam7 = 0; |
150 | unsigned char Parameter_UserParam7 = 0; |
139 | unsigned char Parameter_UserParam8 = 0; |
151 | unsigned char Parameter_UserParam8 = 0; |
140 | unsigned char Parameter_ServoNickControl = 100; |
152 | unsigned char Parameter_ServoNickControl = 100; |
141 | unsigned char Parameter_ServoRollControl = 100; |
153 | unsigned char Parameter_ServoRollControl = 100; |
142 | unsigned char Parameter_LoopGasLimit = 70; |
154 | unsigned char Parameter_LoopGasLimit = 70; |
143 | unsigned char Parameter_AchsKopplung1 = 90; |
155 | unsigned char Parameter_AchsKopplung1 = 90; |
144 | unsigned char Parameter_AchsKopplung2 = 65; |
156 | unsigned char Parameter_AchsKopplung2 = 65; |
145 | unsigned char Parameter_CouplingYawCorrection = 64; |
157 | unsigned char Parameter_CouplingYawCorrection = 64; |
146 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
158 | //unsigned char Parameter_AchsGegenKopplung1 = 0; |
147 | unsigned char Parameter_DynamicStability = 100; |
159 | unsigned char Parameter_DynamicStability = 100; |
148 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
160 | unsigned char Parameter_J16Bitmask; // for the J16 Output |
149 | unsigned char Parameter_J16Timing; // for the J16 Output |
161 | unsigned char Parameter_J16Timing; // for the J16 Output |
150 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
162 | unsigned char Parameter_J17Bitmask; // for the J17 Output |
151 | unsigned char Parameter_J17Timing; // for the J17 Output |
163 | unsigned char Parameter_J17Timing; // for the J17 Output |
152 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
164 | unsigned char Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
153 | unsigned char Parameter_NaviGpsGain; |
165 | unsigned char Parameter_NaviGpsGain; |
154 | unsigned char Parameter_NaviGpsP; |
166 | unsigned char Parameter_NaviGpsP; |
155 | unsigned char Parameter_NaviGpsI; |
167 | unsigned char Parameter_NaviGpsI; |
156 | unsigned char Parameter_NaviGpsD; |
168 | unsigned char Parameter_NaviGpsD; |
157 | unsigned char Parameter_NaviGpsACC; |
169 | unsigned char Parameter_NaviGpsACC; |
158 | unsigned char Parameter_NaviOperatingRadius; |
170 | unsigned char Parameter_NaviOperatingRadius; |
159 | unsigned char Parameter_NaviWindCorrection; |
171 | unsigned char Parameter_NaviWindCorrection; |
160 | unsigned char Parameter_NaviSpeedCompensation; |
172 | unsigned char Parameter_NaviSpeedCompensation; |
161 | unsigned char Parameter_ExternalControl; |
173 | unsigned char Parameter_ExternalControl; |
162 | unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
174 | unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
163 | unsigned char CareFree = 0; |
175 | unsigned char CareFree = 0; |
164 | 176 | ||
165 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
177 | signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
166 | int MaxStickNick = 0,MaxStickRoll = 0; |
178 | int MaxStickNick = 0,MaxStickRoll = 0; |
167 | unsigned int modell_fliegt = 0; |
179 | unsigned int modell_fliegt = 0; |
168 | volatile unsigned char FCFlags = 0; |
180 | volatile unsigned char FCFlags = 0; |
169 | long GIER_GRAD_FAKTOR = 1291; |
181 | long GIER_GRAD_FAKTOR = 1291; |
170 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
182 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
171 | signed int tmp_motorwert[MAX_MOTORS]; |
183 | signed int tmp_motorwert[MAX_MOTORS]; |
172 | char VarioCharacter = ' '; |
184 | char VarioCharacter = ' '; |
173 | 185 | ||
174 | #define LIMIT_MIN(value, min) {if(value <= min) value = min;} |
186 | #define LIMIT_MIN(value, min) {if(value <= min) value = min;} |
175 | #define LIMIT_MAX(value, max) {if(value >= max) value = max;} |
187 | #define LIMIT_MAX(value, max) {if(value >= max) value = max;} |
176 | #define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;} |
188 | #define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;} |
177 | 189 | ||
178 | 190 | ||
179 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
191 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
180 | // Debugwerte zuordnen |
192 | // Debugwerte zuordnen |
181 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
193 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
182 | void CopyDebugValues(void) |
194 | void CopyDebugValues(void) |
183 | { |
195 | { |
184 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
196 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
185 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
197 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
186 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
198 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
187 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
199 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
188 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
200 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
189 | DebugOut.Analog[5] = HoehenWert/5; |
201 | DebugOut.Analog[5] = HoehenWert/5; |
190 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
202 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
191 | DebugOut.Analog[8] = KompassValue; |
203 | DebugOut.Analog[8] = KompassValue; |
192 | DebugOut.Analog[9] = UBat; |
204 | DebugOut.Analog[9] = UBat; |
193 | DebugOut.Analog[10] = SenderOkay; |
205 | DebugOut.Analog[10] = SenderOkay; |
194 | DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR; |
206 | DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR; |
195 | DebugOut.Analog[12] = Motor[0].SetPoint; |
207 | DebugOut.Analog[12] = Motor[0].SetPoint; |
196 | DebugOut.Analog[13] = Motor[1].SetPoint; |
208 | DebugOut.Analog[13] = Motor[1].SetPoint; |
197 | DebugOut.Analog[14] = Motor[2].SetPoint; |
209 | DebugOut.Analog[14] = Motor[2].SetPoint; |
198 | DebugOut.Analog[15] = Motor[3].SetPoint; |
210 | DebugOut.Analog[15] = Motor[3].SetPoint; |
199 | 211 | ||
200 | DebugOut.Analog[16] = Motor[4].SetPoint; |
212 | DebugOut.Analog[16] = Motor[4].SetPoint; |
201 | DebugOut.Analog[17] = Motor[5].SetPoint; |
213 | DebugOut.Analog[17] = Motor[5].SetPoint; |
202 | 214 | ||
203 | DebugOut.Analog[24] = Motor[6].SetPoint; |
215 | DebugOut.Analog[24] = Motor[6].SetPoint; |
204 | DebugOut.Analog[25] = Motor[7].SetPoint; |
216 | DebugOut.Analog[25] = Motor[7].SetPoint; |
205 | DebugOut.Analog[26] = Motor[8].SetPoint; |
217 | DebugOut.Analog[26] = Motor[8].SetPoint; |
206 | DebugOut.Analog[27] = Motor[9].SetPoint; |
218 | DebugOut.Analog[27] = Motor[9].SetPoint; |
207 | 219 | ||
208 | DebugOut.Analog[20] = ServoNickValue; |
220 | DebugOut.Analog[20] = ServoNickValue; |
209 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
221 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
210 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
222 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
211 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
223 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
212 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
224 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
213 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
225 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
214 | DebugOut.Analog[30] = GPS_Nick; |
226 | DebugOut.Analog[30] = GPS_Nick; |
215 | DebugOut.Analog[31] = GPS_Roll; |
227 | DebugOut.Analog[31] = GPS_Roll; |
216 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
228 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
217 | } |
229 | } |
218 | 230 | ||
219 | void Piep(unsigned char Anzahl, unsigned int dauer) |
231 | void Piep(unsigned char Anzahl, unsigned int dauer) |
220 | { |
232 | { |
221 | if(MotorenEin) return; //auf keinen Fall im Flug! |
233 | if(MotorenEin) return; //auf keinen Fall im Flug! |
222 | while(Anzahl--) |
234 | while(Anzahl--) |
223 | { |
235 | { |
224 | beeptime = dauer; |
236 | beeptime = dauer; |
225 | while(beeptime); |
237 | while(beeptime); |
226 | Delay_ms(dauer * 2); |
238 | Delay_ms(dauer * 2); |
227 | } |
239 | } |
228 | } |
240 | } |
229 | 241 | ||
230 | //############################################################################ |
242 | //############################################################################ |
231 | // Messwerte beim Ermitteln der Nullage |
243 | // Messwerte beim Ermitteln der Nullage |
232 | void CalibrierMittelwert(void) |
244 | void CalibrierMittelwert(void) |
233 | //############################################################################ |
245 | //############################################################################ |
234 | { |
246 | { |
235 | unsigned char i; |
247 | unsigned char i; |
236 | if(PlatinenVersion == 13) SucheGyroOffset(); |
248 | if(PlatinenVersion == 13) SucheGyroOffset(); |
237 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
249 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
238 | ANALOG_OFF; |
250 | ANALOG_OFF; |
239 | MesswertNick = AdWertNick; |
251 | MesswertNick = AdWertNick; |
240 | MesswertRoll = AdWertRoll; |
252 | MesswertRoll = AdWertRoll; |
241 | MesswertGier = AdWertGier; |
253 | MesswertGier = AdWertGier; |
242 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
254 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
243 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
255 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
244 | // ADC einschalten |
256 | // ADC einschalten |
245 | ANALOG_ON; |
257 | ANALOG_ON; |
246 | for(i=0;i<8;i++) |
258 | for(i=0;i<8;i++) |
247 | { |
259 | { |
248 | int tmp; |
260 | int tmp; |
249 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
261 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
250 | LIMIT_MIN_MAX(tmp, 0, 255); |
262 | LIMIT_MIN_MAX(tmp, 0, 255); |
251 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
263 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
252 | } |
264 | } |
253 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
265 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
254 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
266 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
255 | } |
267 | } |
256 | 268 | ||
257 | //############################################################################ |
269 | //############################################################################ |
258 | // Nullwerte ermitteln |
270 | // Nullwerte ermitteln |
259 | void SetNeutral(unsigned char AccAdjustment) |
271 | void SetNeutral(unsigned char AccAdjustment) |
260 | //############################################################################ |
272 | //############################################################################ |
261 | { |
273 | { |
262 | unsigned char i; |
274 | unsigned char i; |
263 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
275 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
264 | VersionInfo.HardwareError[0] = 0; |
276 | VersionInfo.HardwareError[0] = 0; |
265 | HEF4017R_ON; |
277 | HEF4017R_ON; |
266 | NeutralAccX = 0; |
278 | NeutralAccX = 0; |
267 | NeutralAccY = 0; |
279 | NeutralAccY = 0; |
268 | NeutralAccZ = 0; |
280 | NeutralAccZ = 0; |
269 | 281 | ||
270 | AdNeutralNick = 0; |
282 | AdNeutralNick = 0; |
271 | AdNeutralRoll = 0; |
283 | AdNeutralRoll = 0; |
272 | AdNeutralGier = 0; |
284 | AdNeutralGier = 0; |
273 | 285 | ||
274 | Parameter_AchsKopplung1 = 0; |
286 | Parameter_AchsKopplung1 = 0; |
275 | Parameter_AchsKopplung2 = 0; |
287 | Parameter_AchsKopplung2 = 0; |
276 | 288 | ||
277 | ExpandBaro = 0; |
289 | ExpandBaro = 0; |
278 | 290 | ||
279 | CalibrierMittelwert(); |
291 | CalibrierMittelwert(); |
280 | Delay_ms_Mess(100); |
292 | Delay_ms_Mess(100); |
281 | 293 | ||
282 | CalibrierMittelwert(); |
294 | CalibrierMittelwert(); |
283 | 295 | ||
284 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
296 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
285 | { |
297 | { |
286 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
298 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
287 | } |
299 | } |
288 | #define NEUTRAL_FILTER 32 |
300 | #define NEUTRAL_FILTER 32 |
289 | for(i=0; i<NEUTRAL_FILTER; i++) |
301 | for(i=0; i<NEUTRAL_FILTER; i++) |
290 | { |
302 | { |
291 | Delay_ms_Mess(10); |
303 | Delay_ms_Mess(10); |
292 | gier_neutral += AdWertGier; |
304 | gier_neutral += AdWertGier; |
293 | nick_neutral += AdWertNick; |
305 | nick_neutral += AdWertNick; |
294 | roll_neutral += AdWertRoll; |
306 | roll_neutral += AdWertRoll; |
295 | } |
307 | } |
296 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
308 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
297 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
309 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
298 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
310 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
299 | 311 | ||
300 | StartNeutralRoll = AdNeutralRoll; |
312 | StartNeutralRoll = AdNeutralRoll; |
301 | StartNeutralNick = AdNeutralNick; |
313 | StartNeutralNick = AdNeutralNick; |
302 | 314 | ||
303 | if(AccAdjustment) |
315 | if(AccAdjustment) |
304 | { |
316 | { |
305 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
317 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
306 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
318 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
307 | NeutralAccZ = Aktuell_az; |
319 | NeutralAccZ = Aktuell_az; |
308 | 320 | ||
309 | // Save ACC neutral settings to eeprom |
321 | // Save ACC neutral settings to eeprom |
310 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
322 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
311 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
323 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
312 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
324 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
313 | } |
325 | } |
314 | else |
326 | else |
315 | { |
327 | { |
316 | // restore from eeprom |
328 | // restore from eeprom |
317 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
329 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
318 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
330 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
319 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
331 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
320 | // strange settings? |
332 | // strange settings? |
321 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
333 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
322 | { |
334 | { |
323 | printf("\n\rACC not calibrated!\r\n"); |
335 | printf("\n\rACC not calibrated!\r\n"); |
324 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
336 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
325 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
337 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
326 | NeutralAccZ = Aktuell_az; |
338 | NeutralAccZ = Aktuell_az; |
327 | } |
339 | } |
328 | } |
340 | } |
329 | 341 | ||
330 | MesswertNick = 0; |
342 | MesswertNick = 0; |
331 | MesswertRoll = 0; |
343 | MesswertRoll = 0; |
332 | MesswertGier = 0; |
344 | MesswertGier = 0; |
333 | Delay_ms_Mess(100); |
345 | Delay_ms_Mess(100); |
334 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
346 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
335 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
347 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
336 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
348 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
337 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
349 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
338 | Mess_IntegralNick2 = IntegralNick; |
350 | Mess_IntegralNick2 = IntegralNick; |
339 | Mess_IntegralRoll2 = IntegralRoll; |
351 | Mess_IntegralRoll2 = IntegralRoll; |
340 | Mess_Integral_Gier = 0; |
352 | Mess_Integral_Gier = 0; |
341 | StartLuftdruck = Luftdruck; |
353 | StartLuftdruck = Luftdruck; |
342 | VarioMeter = 0; |
354 | VarioMeter = 0; |
343 | Mess_Integral_Hoch = 0; |
355 | Mess_Integral_Hoch = 0; |
344 | KompassStartwert = KompassValue; |
356 | KompassStartwert = KompassValue; |
345 | GPS_Neutral(); |
357 | GPS_Neutral(); |
346 | beeptime = 50; |
358 | beeptime = 50; |
347 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
359 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
348 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
360 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
349 | ExternHoehenValue = 0; |
361 | ExternHoehenValue = 0; |
350 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
362 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
351 | GierGyroFehler = 0; |
363 | GierGyroFehler = 0; |
352 | SendVersionToNavi = 1; |
364 | SendVersionToNavi = 1; |
353 | LED_Init(); |
365 | LED_Init(); |
354 | FCFlags |= FCFLAG_CALIBRATE; |
366 | FCFlags |= FCFLAG_CALIBRATE; |
355 | FromNaviCtrl_Value.Kalman_K = -1; |
367 | FromNaviCtrl_Value.Kalman_K = -1; |
356 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
368 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
357 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
369 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
358 | 370 | ||
359 | for(i=0;i<8;i++) |
371 | for(i=0;i<8;i++) |
360 | { |
372 | { |
361 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
373 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
362 | } |
374 | } |
363 | SenderOkay = 100; |
375 | SenderOkay = 100; |
364 | if(ServoActive) |
376 | if(ServoActive) |
365 | { |
377 | { |
366 | HEF4017R_ON; |
378 | HEF4017R_ON; |
367 | DDRD |=0x80; // enable J7 -> Servo signal |
379 | DDRD |=0x80; // enable J7 -> Servo signal |
368 | } |
380 | } |
369 | 381 | ||
370 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= DEFEKT_G_NICK; }; |
382 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= DEFEKT_G_NICK; }; |
371 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= DEFEKT_G_ROLL; }; |
383 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= DEFEKT_G_ROLL; }; |
372 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= DEFEKT_G_GIER; }; |
384 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= DEFEKT_G_GIER; }; |
373 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= DEFEKT_A_NICK; }; |
385 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= DEFEKT_A_NICK; }; |
374 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= DEFEKT_A_ROLL; }; |
386 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= DEFEKT_A_ROLL; }; |
375 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= DEFEKT_A_Z; }; |
387 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= DEFEKT_A_Z; }; |
376 | } |
388 | } |
377 | 389 | ||
378 | 390 | ||
379 | //############################################################################ |
391 | //############################################################################ |
380 | // Bearbeitet die Messwerte |
392 | // Bearbeitet die Messwerte |
381 | void Mittelwert(void) |
393 | void Mittelwert(void) |
382 | //############################################################################ |
394 | //############################################################################ |
383 | { |
395 | { |
384 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
396 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
385 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
397 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
386 | signed long winkel_nick, winkel_roll; |
398 | signed long winkel_nick, winkel_roll; |
387 | unsigned char i; |
399 | unsigned char i; |
388 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
400 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
389 | MesswertNick = (signed int) AdWertNickFilter / 8; |
401 | MesswertNick = (signed int) AdWertNickFilter / 8; |
390 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
402 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
391 | RohMesswertNick = MesswertNick; |
403 | RohMesswertNick = MesswertNick; |
392 | RohMesswertRoll = MesswertRoll; |
404 | RohMesswertRoll = MesswertRoll; |
393 | 405 | ||
394 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
406 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
395 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
407 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
396 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
408 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
397 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
409 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
398 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
410 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
399 | NaviAccNick += AdWertAccNick; |
411 | NaviAccNick += AdWertAccNick; |
400 | NaviAccRoll += AdWertAccRoll; |
412 | NaviAccRoll += AdWertAccRoll; |
401 | NaviCntAcc++; |
413 | NaviCntAcc++; |
402 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
414 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
403 | 415 | ||
404 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
416 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
405 | // ADC einschalten |
417 | // ADC einschalten |
406 | ANALOG_ON; |
418 | ANALOG_ON; |
407 | AdReady = 0; |
419 | AdReady = 0; |
408 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
420 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
409 | 421 | ||
410 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
422 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
411 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
423 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
412 | else winkel_roll = Mess_IntegralRoll; |
424 | else winkel_roll = Mess_IntegralRoll; |
413 | 425 | ||
414 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
426 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
415 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
427 | else if(Mess_IntegralNick <-93000L) winkel_nick = -93000L; |
416 | else winkel_nick = Mess_IntegralNick; |
428 | else winkel_nick = Mess_IntegralNick; |
417 | 429 | ||
418 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
430 | // Gier ++++++++++++++++++++++++++++++++++++++++++++++++ |
419 | Mess_Integral_Gier += MesswertGier; |
431 | Mess_Integral_Gier += MesswertGier; |
420 | ErsatzKompass += MesswertGier; |
432 | ErsatzKompass += MesswertGier; |
421 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
433 | // Kopplungsanteil +++++++++++++++++++++++++++++++++++++ |
422 | if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
434 | if(!Looping_Nick && !Looping_Roll && (EE_Parameter.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV)) |
423 | { |
435 | { |
424 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
436 | tmpl3 = (MesswertRoll * winkel_nick) / 2048L; |
425 | tmpl3 *= Parameter_AchsKopplung2; //65 |
437 | tmpl3 *= Parameter_AchsKopplung2; //65 |
426 | tmpl3 /= 4096L; |
438 | tmpl3 /= 4096L; |
427 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
439 | tmpl4 = (MesswertNick * winkel_roll) / 2048L; |
428 | tmpl4 *= Parameter_AchsKopplung2; //65 |
440 | tmpl4 *= Parameter_AchsKopplung2; //65 |
429 | tmpl4 /= 4096L; |
441 | tmpl4 /= 4096L; |
430 | KopplungsteilNickRoll = tmpl3; |
442 | KopplungsteilNickRoll = tmpl3; |
431 | KopplungsteilRollNick = tmpl4; |
443 | KopplungsteilRollNick = tmpl4; |
432 | tmpl4 -= tmpl3; |
444 | tmpl4 -= tmpl3; |
433 | ErsatzKompass += tmpl4; |
445 | ErsatzKompass += tmpl4; |
434 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
446 | if(!Parameter_CouplingYawCorrection) Mess_Integral_Gier -= tmpl4/2; // Gier nachhelfen |
435 | 447 | ||
436 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
448 | tmpl = ((MesswertGier + tmpl4) * winkel_nick) / 2048L; |
437 | tmpl *= Parameter_AchsKopplung1; // 90 |
449 | tmpl *= Parameter_AchsKopplung1; // 90 |
438 | tmpl /= 4096L; |
450 | tmpl /= 4096L; |
439 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
451 | tmpl2 = ((MesswertGier + tmpl4) * winkel_roll) / 2048L; |
440 | tmpl2 *= Parameter_AchsKopplung1; |
452 | tmpl2 *= Parameter_AchsKopplung1; |
441 | tmpl2 /= 4096L; |
453 | tmpl2 /= 4096L; |
442 | if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
454 | if(abs(MesswertGier) > 64) if(labs(tmpl) > 128 || labs(tmpl2) > 128) TrichterFlug = 1; |
443 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
455 | //MesswertGier += (Parameter_CouplingYawCorrection * tmpl4) / 256; |
444 | } |
456 | } |
445 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
457 | else tmpl = tmpl2 = KopplungsteilNickRoll = KopplungsteilRollNick = 0; |
446 | TrimRoll = tmpl - tmpl2 / 100L; |
458 | TrimRoll = tmpl - tmpl2 / 100L; |
447 | TrimNick = -tmpl2 + tmpl / 100L; |
459 | TrimNick = -tmpl2 + tmpl / 100L; |
448 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
460 | // Kompasswert begrenzen ++++++++++++++++++++++++++++++++++++++++++++++++ |
449 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
461 | if(ErsatzKompass >= (360L * GIER_GRAD_FAKTOR)) ErsatzKompass -= 360L * GIER_GRAD_FAKTOR; // 360° Umschlag |
450 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
462 | if(ErsatzKompass < 0) ErsatzKompass += 360L * GIER_GRAD_FAKTOR; |
451 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
463 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
452 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
464 | Mess_IntegralRoll2 += MesswertRoll + TrimRoll; |
453 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
465 | Mess_IntegralRoll += MesswertRoll + TrimRoll - LageKorrekturRoll; |
454 | if(Mess_IntegralRoll > Umschlag180Roll) |
466 | if(Mess_IntegralRoll > Umschlag180Roll) |
455 | { |
467 | { |
456 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
468 | Mess_IntegralRoll = -(Umschlag180Roll - 25000L); |
457 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
469 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
458 | } |
470 | } |
459 | if(Mess_IntegralRoll <-Umschlag180Roll) |
471 | if(Mess_IntegralRoll <-Umschlag180Roll) |
460 | { |
472 | { |
461 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
473 | Mess_IntegralRoll = (Umschlag180Roll - 25000L); |
462 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
474 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
463 | } |
475 | } |
464 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
476 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
465 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
477 | Mess_IntegralNick2 += MesswertNick + TrimNick; |
466 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
478 | Mess_IntegralNick += MesswertNick + TrimNick - LageKorrekturNick; |
467 | if(Mess_IntegralNick > Umschlag180Nick) |
479 | if(Mess_IntegralNick > Umschlag180Nick) |
468 | { |
480 | { |
469 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
481 | Mess_IntegralNick = -(Umschlag180Nick - 25000L); |
470 | Mess_IntegralNick2 = Mess_IntegralNick; |
482 | Mess_IntegralNick2 = Mess_IntegralNick; |
471 | } |
483 | } |
472 | if(Mess_IntegralNick <-Umschlag180Nick) |
484 | if(Mess_IntegralNick <-Umschlag180Nick) |
473 | { |
485 | { |
474 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
486 | Mess_IntegralNick = (Umschlag180Nick - 25000L); |
475 | Mess_IntegralNick2 = Mess_IntegralNick; |
487 | Mess_IntegralNick2 = Mess_IntegralNick; |
476 | } |
488 | } |
477 | 489 | ||
478 | Integral_Gier = Mess_Integral_Gier; |
490 | Integral_Gier = Mess_Integral_Gier; |
479 | IntegralNick = Mess_IntegralNick; |
491 | IntegralNick = Mess_IntegralNick; |
480 | IntegralRoll = Mess_IntegralRoll; |
492 | IntegralRoll = Mess_IntegralRoll; |
481 | IntegralNick2 = Mess_IntegralNick2; |
493 | IntegralNick2 = Mess_IntegralNick2; |
482 | IntegralRoll2 = Mess_IntegralRoll2; |
494 | IntegralRoll2 = Mess_IntegralRoll2; |
483 | 495 | ||
484 | #define D_LIMIT 128 |
496 | #define D_LIMIT 128 |
485 | 497 | ||
486 | MesswertNick = HiResNick / 8; |
498 | MesswertNick = HiResNick / 8; |
487 | MesswertRoll = HiResRoll / 8; |
499 | MesswertRoll = HiResRoll / 8; |
488 | 500 | ||
489 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
501 | if(AdWertNick < 15) MesswertNick = -1000; if(AdWertNick < 7) MesswertNick = -2000; |
490 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
502 | if(PlatinenVersion == 10) { if(AdWertNick > 1010) MesswertNick = +1000; if(AdWertNick > 1017) MesswertNick = +2000; } |
491 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
503 | else { if(AdWertNick > 2000) MesswertNick = +1000; if(AdWertNick > 2015) MesswertNick = +2000; } |
492 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
504 | if(AdWertRoll < 15) MesswertRoll = -1000; if(AdWertRoll < 7) MesswertRoll = -2000; |
493 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
505 | if(PlatinenVersion == 10) { if(AdWertRoll > 1010) MesswertRoll = +1000; if(AdWertRoll > 1017) MesswertRoll = +2000; } |
494 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
506 | else { if(AdWertRoll > 2000) MesswertRoll = +1000; if(AdWertRoll > 2015) MesswertRoll = +2000; } |
495 | 507 | ||
496 | if(Parameter_Gyro_D) |
508 | if(Parameter_Gyro_D) |
497 | { |
509 | { |
498 | d2Nick = HiResNick - oldNick; |
510 | d2Nick = HiResNick - oldNick; |
499 | oldNick = (oldNick + HiResNick)/2; |
511 | oldNick = (oldNick + HiResNick)/2; |
500 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
512 | if(d2Nick > D_LIMIT) d2Nick = D_LIMIT; |
501 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
513 | else if(d2Nick < -D_LIMIT) d2Nick = -D_LIMIT; |
502 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
514 | MesswertNick += (d2Nick * (signed int) Parameter_Gyro_D) / 16; |
503 | d2Roll = HiResRoll - oldRoll; |
515 | d2Roll = HiResRoll - oldRoll; |
504 | oldRoll = (oldRoll + HiResRoll)/2; |
516 | oldRoll = (oldRoll + HiResRoll)/2; |
505 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
517 | if(d2Roll > D_LIMIT) d2Roll = D_LIMIT; |
506 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
518 | else if(d2Roll < -D_LIMIT) d2Roll = -D_LIMIT; |
507 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
519 | MesswertRoll += (d2Roll * (signed int) Parameter_Gyro_D) / 16; |
508 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
520 | HiResNick += (d2Nick * (signed int) Parameter_Gyro_D); |
509 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
521 | HiResRoll += (d2Roll * (signed int) Parameter_Gyro_D); |
510 | } |
522 | } |
511 | 523 | ||
512 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
524 | if(RohMesswertRoll > 0) TrimRoll += ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
513 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
525 | else TrimRoll -= ((long) abs(KopplungsteilNickRoll) * Parameter_CouplingYawCorrection) / 64L; |
514 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
526 | if(RohMesswertNick > 0) TrimNick += ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
515 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
527 | else TrimNick -= ((long) abs(KopplungsteilRollNick) * Parameter_CouplingYawCorrection) / 64L; |
516 | 528 | ||
517 | if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
529 | if(EE_Parameter.GlobalConfig & CFG_DREHRATEN_BEGRENZER && !Looping_Nick && !Looping_Roll) |
518 | { |
530 | { |
519 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
531 | if(RohMesswertNick > 256) MesswertNick += 1 * (RohMesswertNick - 256); |
520 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
532 | else if(RohMesswertNick < -256) MesswertNick += 1 * (RohMesswertNick + 256); |
521 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
533 | if(RohMesswertRoll > 256) MesswertRoll += 1 * (RohMesswertRoll - 256); |
522 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
534 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
523 | } |
535 | } |
524 | for(i=0;i<8;i++) |
536 | for(i=0;i<8;i++) |
525 | { |
537 | { |
526 | int tmp; |
538 | int tmp; |
527 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
539 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 110; |
528 | if(tmp > 255) tmp = 255; else if(tmp < 0) tmp = 0; |
540 | if(tmp > 255) tmp = 255; else if(tmp < 0) tmp = 0; |
529 | if(tmp != Poti[i]) |
541 | if(tmp != Poti[i]) |
530 | { |
542 | { |
531 | Poti[i] += (tmp - Poti[i]) / 8; |
543 | Poti[i] += (tmp - Poti[i]) / 8; |
532 | if(Poti[i] > tmp) Poti[i]--; |
544 | if(Poti[i] > tmp) Poti[i]--; |
533 | else Poti[i]++; |
545 | else Poti[i]++; |
534 | } |
546 | } |
535 | } |
547 | } |
536 | } |
548 | } |
537 | 549 | ||
538 | //############################################################################ |
550 | //############################################################################ |
539 | // Senden der Motorwerte per I2C-Bus |
551 | // Senden der Motorwerte per I2C-Bus |
540 | void SendMotorData(void) |
552 | void SendMotorData(void) |
541 | //############################################################################ |
553 | //############################################################################ |
542 | { |
554 | { |
543 | unsigned char i; |
555 | unsigned char i; |
544 | if(!MotorenEin) |
556 | if(!MotorenEin) |
545 | { |
557 | { |
546 | FCFlags &= ~(FCFLAG_MOTOR_RUN | FCFLAG_FLY); |
558 | FCFlags &= ~(FCFLAG_MOTOR_RUN | FCFLAG_FLY); |
547 | for(i=0;i<MAX_MOTORS;i++) |
559 | for(i=0;i<MAX_MOTORS;i++) |
548 | { |
560 | { |
549 | if(!PC_MotortestActive) MotorTest[i] = 0; |
561 | if(!PC_MotortestActive) MotorTest[i] = 0; |
550 | Motor[i].SetPoint = MotorTest[i]; |
562 | Motor[i].SetPoint = MotorTest[i]; |
551 | Motor[i].SetPointLowerBits = 0; |
563 | Motor[i].SetPointLowerBits = 0; |
552 | /* |
564 | /* |
553 | Motor[i].SetPoint = MotorTest[i] / 4; |
565 | Motor[i].SetPoint = MotorTest[i] / 4; |
554 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
566 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
555 | */ |
567 | */ |
556 | } |
568 | } |
557 | if(PC_MotortestActive) PC_MotortestActive--; |
569 | if(PC_MotortestActive) PC_MotortestActive--; |
558 | } |
570 | } |
559 | else FCFlags |= FCFLAG_MOTOR_RUN; |
571 | else FCFlags |= FCFLAG_MOTOR_RUN; |
560 | //Start I2C Interrupt Mode |
572 | //Start I2C Interrupt Mode |
561 | motor_write = 0; |
573 | motor_write = 0; |
562 | I2C_Start(TWI_STATE_MOTOR_TX); |
574 | I2C_Start(TWI_STATE_MOTOR_TX); |
563 | } |
575 | } |
564 | 576 | ||
565 | 577 | ||
566 | 578 | ||
567 | //############################################################################ |
579 | //############################################################################ |
568 | // Trägt ggf. das Poti als Parameter ein |
580 | // Trägt ggf. das Poti als Parameter ein |
569 | void ParameterZuordnung(void) |
581 | void ParameterZuordnung(void) |
570 | //############################################################################ |
582 | //############################################################################ |
571 | { |
583 | { |
572 | unsigned char tmp; |
584 | unsigned char tmp; |
573 | #define CHK_POTI(b,a) {if(a < 248) b = a; else b = Poti[255 - a];} |
585 | #define CHK_POTI(b,a) {if(a < 248) b = a; else b = Poti[255 - a];} |
574 | #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max);} |
586 | #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max);} |
575 | 587 | ||
576 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
588 | CHK_POTI_MM(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
577 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
589 | CHK_POTI_MM(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
578 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
590 | CHK_POTI_MM(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
579 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255); |
591 | CHK_POTI_MM(Parameter_J16Timing,EE_Parameter.J16Timing,1,255); |
580 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255); |
592 | CHK_POTI_MM(Parameter_J17Timing,EE_Parameter.J17Timing,1,255); |
581 | CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3); |
593 | CHK_POTI(Parameter_Servo3,EE_Parameter.Servo3); |
582 | CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4); |
594 | CHK_POTI(Parameter_Servo4,EE_Parameter.Servo4); |
583 | CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5); |
595 | CHK_POTI(Parameter_Servo5,EE_Parameter.Servo5); |
584 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe); |
596 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe); |
585 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe); |
597 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe); |
586 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung); |
598 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung); |
587 | CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z); |
599 | CHK_POTI(Parameter_Hoehe_GPS_Z,EE_Parameter.Hoehe_GPS_Z); |
588 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung); |
600 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung); |
589 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I); |
601 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I); |
590 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D); |
602 | CHK_POTI(Parameter_Gyro_D,EE_Parameter.Gyro_D); |
591 | CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P); |
603 | CHK_POTI(Parameter_Gyro_Gier_P,EE_Parameter.Gyro_Gier_P); |
592 | CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I); |
604 | CHK_POTI(Parameter_Gyro_Gier_I,EE_Parameter.Gyro_Gier_I); |
593 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor); |
605 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor); |
594 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1); |
606 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1); |
595 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2); |
607 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2); |
596 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3); |
608 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3); |
597 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4); |
609 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4); |
598 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5); |
610 | CHK_POTI(Parameter_UserParam5,EE_Parameter.UserParam5); |
599 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6); |
611 | CHK_POTI(Parameter_UserParam6,EE_Parameter.UserParam6); |
600 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7); |
612 | CHK_POTI(Parameter_UserParam7,EE_Parameter.UserParam7); |
601 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
613 | CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
602 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
614 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
603 | CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
615 | CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
604 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
616 | CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
605 | CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
617 | CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
606 | CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
618 | CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
607 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection); |
619 | CHK_POTI(Parameter_CouplingYawCorrection,EE_Parameter.CouplingYawCorrection); |
608 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
620 | // CHK_POTI(Parameter_AchsGegenKopplung1,EE_Parameter.AchsGegenKopplung1,0,255); |
609 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability); |
621 | CHK_POTI(Parameter_DynamicStability,EE_Parameter.DynamicStability); |
610 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl); |
622 | CHK_POTI(Parameter_ExternalControl,EE_Parameter.ExternalControl); |
611 | Ki = 10300 / (Parameter_I_Faktor + 1); |
623 | Ki = 10300 / (Parameter_I_Faktor + 1); |
612 | MAX_GAS = EE_Parameter.Gas_Max; |
624 | MAX_GAS = EE_Parameter.Gas_Max; |
613 | MIN_GAS = EE_Parameter.Gas_Min; |
625 | MIN_GAS = EE_Parameter.Gas_Min; |
614 | 626 | ||
615 | tmp = EE_Parameter.OrientationModeControl; |
627 | tmp = EE_Parameter.OrientationModeControl; |
616 | if(tmp > 50) |
628 | if(tmp > 50) |
617 | { |
629 | { |
618 | #ifdef SWITCH_LEARNS_CAREFREE |
630 | #ifdef SWITCH_LEARNS_CAREFREE |
619 | if(!CareFree) ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
631 | if(!CareFree) ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
620 | #endif |
632 | #endif |
621 | CareFree = 1; |
633 | CareFree = 1; |
622 | if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; |
634 | if(tmp >= 248 && Poti[255 - tmp] < 50) CareFree = 0; |
623 | if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= DEFEKT_CAREFREE_ERR; else VersionInfo.HardwareError[0] &= ~DEFEKT_CAREFREE_ERR; |
635 | if(FromNaviCtrl.CompassValue < 0 && CareFree) VersionInfo.HardwareError[0] |= DEFEKT_CAREFREE_ERR; else VersionInfo.HardwareError[0] &= ~DEFEKT_CAREFREE_ERR; |
624 | } |
636 | } |
625 | else CareFree = 0; |
637 | else CareFree = 0; |
626 | 638 | ||
627 | if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert |
639 | if(FromNaviCtrl.CompassValue < 0 && MotorenEin && CareFree && BeepMuster == 0xffff) // ungültiger Kompasswert |
628 | { |
640 | { |
629 | beeptime = 15000; |
641 | beeptime = 15000; |
630 | BeepMuster = 0xA400; |
642 | BeepMuster = 0xA400; |
631 | CareFree = 0; |
643 | CareFree = 0; |
632 | } |
644 | } |
633 | 645 | ||
634 | if(CareFree) {if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} |
646 | if(CareFree) {if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} |
635 | } |
647 | } |
636 | 648 | ||
637 | //############################################################################ |
649 | //############################################################################ |
638 | // |
650 | // |
639 | void MotorRegler(void) |
651 | void MotorRegler(void) |
640 | //############################################################################ |
652 | //############################################################################ |
641 | { |
653 | { |
642 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
654 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
643 | int GierMischanteil,GasMischanteil; |
655 | int GierMischanteil,GasMischanteil; |
644 | static long sollGier = 0,tmp_long,tmp_long2; |
656 | static long sollGier = 0,tmp_long,tmp_long2; |
645 | static long IntegralFehlerNick = 0; |
657 | static long IntegralFehlerNick = 0; |
646 | static long IntegralFehlerRoll = 0; |
658 | static long IntegralFehlerRoll = 0; |
647 | static unsigned int RcLostTimer; |
659 | static unsigned int RcLostTimer; |
648 | static unsigned char delay_neutral = 0; |
660 | static unsigned char delay_neutral = 0; |
649 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
661 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
650 | static unsigned char calibration_done = 0; |
662 | static unsigned char calibration_done = 0; |
651 | static char NeueKompassRichtungMerken = 0; |
663 | static char NeueKompassRichtungMerken = 0; |
652 | static long ausgleichNick, ausgleichRoll; |
664 | static long ausgleichNick, ausgleichRoll; |
653 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
665 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
654 | unsigned char i; |
666 | unsigned char i; |
655 | Mittelwert(); |
667 | Mittelwert(); |
656 | GRN_ON; |
668 | GRN_ON; |
657 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
669 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
658 | // Gaswert ermitteln |
670 | // Gaswert ermitteln |
659 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
671 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
660 | GasMischanteil = StickGas; |
672 | GasMischanteil = StickGas; |
661 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
673 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
662 | 674 | ||
663 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
675 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
664 | // Empfang schlecht |
676 | // Empfang schlecht |
665 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
677 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
666 | if(SenderOkay < 100) |
678 | if(SenderOkay < 100) |
667 | { |
679 | { |
668 | if(RcLostTimer) RcLostTimer--; |
680 | if(RcLostTimer) RcLostTimer--; |
669 | else |
681 | else |
670 | { |
682 | { |
671 | MotorenEin = 0; |
683 | MotorenEin = 0; |
672 | FCFlags &= ~FCFLAG_NOTLANDUNG; |
684 | FCFlags &= ~FCFLAG_NOTLANDUNG; |
673 | } |
685 | } |
674 | ROT_ON; |
686 | ROT_ON; |
675 | if(modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
687 | if(modell_fliegt > 1000) // wahrscheinlich in der Luft --> langsam absenken |
676 | { |
688 | { |
677 | GasMischanteil = EE_Parameter.NotGas; |
689 | GasMischanteil = EE_Parameter.NotGas; |
678 | FCFlags |= FCFLAG_NOTLANDUNG; |
690 | FCFlags |= FCFLAG_NOTLANDUNG; |
679 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
691 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
680 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
692 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
681 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
693 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
682 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
694 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
683 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
695 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
684 | } |
696 | } |
685 | else MotorenEin = 0; |
697 | else MotorenEin = 0; |
686 | } |
698 | } |
687 | else |
699 | else |
688 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
700 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
689 | // Emfang gut |
701 | // Emfang gut |
690 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
702 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
691 | if(SenderOkay > 140) |
703 | if(SenderOkay > 140) |
692 | { |
704 | { |
693 | FCFlags &= ~FCFLAG_NOTLANDUNG; |
705 | FCFlags &= ~FCFLAG_NOTLANDUNG; |
694 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
706 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
695 | if(GasMischanteil > 40 && MotorenEin) |
707 | if(GasMischanteil > 40 && MotorenEin) |
696 | { |
708 | { |
697 | if(modell_fliegt < 0xffff) modell_fliegt++; |
709 | if(modell_fliegt < 0xffff) modell_fliegt++; |
698 | } |
710 | } |
699 | if((modell_fliegt < 256)) |
711 | if((modell_fliegt < 256)) |
700 | { |
712 | { |
701 | SummeNick = 0; |
713 | SummeNick = 0; |
702 | SummeRoll = 0; |
714 | SummeRoll = 0; |
703 | sollGier = 0; |
715 | sollGier = 0; |
704 | Mess_Integral_Gier = 0; |
716 | Mess_Integral_Gier = 0; |
705 | if(modell_fliegt == 250) |
717 | if(modell_fliegt == 250) |
706 | { |
718 | { |
707 | NeueKompassRichtungMerken = 1; |
719 | NeueKompassRichtungMerken = 1; |
708 | } |
720 | } |
709 | } else FCFlags |= FCFLAG_FLY; |
721 | } else FCFlags |= FCFLAG_FLY; |
710 | 722 | ||
711 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
723 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
712 | { |
724 | { |
713 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
725 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
714 | // auf Nullwerte kalibrieren |
726 | // auf Nullwerte kalibrieren |
715 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
727 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
716 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
728 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
717 | { |
729 | { |
718 | if(++delay_neutral > 200) // nicht sofort |
730 | if(++delay_neutral > 200) // nicht sofort |
719 | { |
731 | { |
720 | GRN_OFF; |
732 | GRN_OFF; |
721 | MotorenEin = 0; |
733 | MotorenEin = 0; |
722 | delay_neutral = 0; |
734 | delay_neutral = 0; |
723 | modell_fliegt = 0; |
735 | modell_fliegt = 0; |
724 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
736 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
725 | { |
737 | { |
726 | unsigned char setting=1; |
738 | unsigned char setting=1; |
727 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
739 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
728 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
740 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
729 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
741 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
730 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
742 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
731 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
743 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
732 | SetActiveParamSet(setting); // aktiven Datensatz merken |
744 | SetActiveParamSet(setting); // aktiven Datensatz merken |
733 | } |
745 | } |
734 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
746 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
735 | { |
747 | { |
736 | WinkelOut.CalcState = 1; |
748 | WinkelOut.CalcState = 1; |
737 | beeptime = 1000; |
749 | beeptime = 1000; |
738 | } |
750 | } |
739 | else |
751 | else |
740 | { |
752 | { |
741 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
753 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
742 | LipoDetection(0); |
754 | LipoDetection(0); |
743 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
755 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
744 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
756 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
745 | { |
757 | { |
746 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
758 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
747 | } |
759 | } |
748 | ServoActive = 0; |
760 | ServoActive = 0; |
749 | SetNeutral(0); |
761 | SetNeutral(0); |
750 | calibration_done = 1; |
762 | calibration_done = 1; |
751 | ServoActive = 1; |
763 | ServoActive = 1; |
752 | DDRD |=0x80; // enable J7 -> Servo signal |
764 | DDRD |=0x80; // enable J7 -> Servo signal |
753 | Piep(GetActiveParamSet(),120); |
765 | Piep(GetActiveParamSet(),120); |
754 | } |
766 | } |
755 | } |
767 | } |
756 | } |
768 | } |
757 | else |
769 | else |
758 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
770 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
759 | { |
771 | { |
760 | if(++delay_neutral > 200) // nicht sofort |
772 | if(++delay_neutral > 200) // nicht sofort |
761 | { |
773 | { |
762 | GRN_OFF; |
774 | GRN_OFF; |
763 | MotorenEin = 0; |
775 | MotorenEin = 0; |
764 | delay_neutral = 0; |
776 | delay_neutral = 0; |
765 | modell_fliegt = 0; |
777 | modell_fliegt = 0; |
766 | SetNeutral(1); |
778 | SetNeutral(1); |
767 | calibration_done = 1; |
779 | calibration_done = 1; |
768 | Piep(GetActiveParamSet(),120); |
780 | Piep(GetActiveParamSet(),120); |
769 | } |
781 | } |
770 | } |
782 | } |
771 | else delay_neutral = 0; |
783 | else delay_neutral = 0; |
772 | } |
784 | } |
773 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
785 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
774 | // Gas ist unten |
786 | // Gas ist unten |
775 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
787 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
776 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
788 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
777 | { |
789 | { |
778 | // Motoren Starten |
790 | // Motoren Starten |
779 | if(!MotorenEin) |
791 | if(!MotorenEin) |
780 | { |
792 | { |
781 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
793 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
782 | { |
794 | { |
783 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
795 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
784 | // Einschalten |
796 | // Einschalten |
785 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
797 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
786 | if(++delay_einschalten > 200) |
798 | if(++delay_einschalten > 200) |
787 | { |
799 | { |
788 | delay_einschalten = 0; |
800 | delay_einschalten = 0; |
789 | if(!VersionInfo.HardwareError[0] && calibration_done) |
801 | if(!VersionInfo.HardwareError[0] && calibration_done) |
790 | { |
802 | { |
791 | modell_fliegt = 1; |
803 | modell_fliegt = 1; |
792 | MotorenEin = 1; |
804 | MotorenEin = 1; |
793 | sollGier = 0; |
805 | sollGier = 0; |
794 | Mess_Integral_Gier = 0; |
806 | Mess_Integral_Gier = 0; |
795 | Mess_Integral_Gier2 = 0; |
807 | Mess_Integral_Gier2 = 0; |
796 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
808 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
797 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
809 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
798 | Mess_IntegralNick2 = IntegralNick; |
810 | Mess_IntegralNick2 = IntegralNick; |
799 | Mess_IntegralRoll2 = IntegralRoll; |
811 | Mess_IntegralRoll2 = IntegralRoll; |
800 | SummeNick = 0; |
812 | SummeNick = 0; |
801 | SummeRoll = 0; |
813 | SummeRoll = 0; |
802 | FCFlags |= FCFLAG_START; |
814 | FCFlags |= FCFLAG_START; |
803 | ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
815 | ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
804 | } |
816 | } |
805 | else |
817 | else |
806 | { |
818 | { |
807 | beeptime = 1500; // indicate missing calibration |
819 | beeptime = 1500; // indicate missing calibration |
808 | } |
820 | } |
809 | } |
821 | } |
810 | } |
822 | } |
811 | else delay_einschalten = 0; |
823 | else delay_einschalten = 0; |
812 | } |
824 | } |
813 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
825 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
814 | // Auschalten |
826 | // Auschalten |
815 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
827 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
816 | else // only if motors are running |
828 | else // only if motors are running |
817 | { |
829 | { |
818 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
830 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
819 | { |
831 | { |
820 | if(++delay_ausschalten > 200) // nicht sofort |
832 | if(++delay_ausschalten > 200) // nicht sofort |
821 | { |
833 | { |
822 | MotorenEin = 0; |
834 | MotorenEin = 0; |
823 | delay_ausschalten = 0; |
835 | delay_ausschalten = 0; |
824 | modell_fliegt = 0; |
836 | modell_fliegt = 0; |
825 | } |
837 | } |
826 | } |
838 | } |
827 | else delay_ausschalten = 0; |
839 | else delay_ausschalten = 0; |
828 | } |
840 | } |
829 | } |
841 | } |
830 | } |
842 | } |
831 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
843 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
832 | // neue Werte von der Funke |
844 | // neue Werte von der Funke |
833 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
845 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
834 | 846 | ||
835 | if(!NewPpmData-- || (FCFlags & FCFLAG_NOTLANDUNG)) |
847 | if(!NewPpmData-- || (FCFlags & FCFLAG_NOTLANDUNG)) |
836 | { |
848 | { |
837 | static int stick_nick,stick_roll; |
849 | static int stick_nick,stick_roll; |
838 | ParameterZuordnung(); |
850 | ParameterZuordnung(); |
839 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
851 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
840 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
852 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
841 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
853 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
842 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
854 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
843 | 855 | ||
844 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
856 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
845 | // CareFree und freie Wahl der vorderen Richtung |
857 | // CareFree und freie Wahl der vorderen Richtung |
846 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
858 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
847 | signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8}; |
859 | signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8}; |
848 | 860 | ||
849 | if(CareFree) |
861 | if(CareFree) |
850 | { |
862 | { |
851 | signed int nick, roll; |
863 | signed int nick, roll; |
852 | nick = stick_nick / 4; |
864 | nick = stick_nick / 4; |
853 | roll = stick_roll / 4; |
865 | roll = stick_roll / 4; |
854 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
866 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
855 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
867 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
856 | } |
868 | } |
857 | else |
869 | else |
858 | { |
870 | { |
859 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
871 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
860 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
872 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
861 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
873 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
862 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
874 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
863 | } |
875 | } |
864 | 876 | ||
865 | 877 | ||
866 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
878 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
867 | if(StickGier > 2) StickGier -= 2; else |
879 | if(StickGier > 2) StickGier -= 2; else |
868 | if(StickGier < -2) StickGier += 2; else StickGier = 0; |
880 | if(StickGier < -2) StickGier += 2; else StickGier = 0; |
869 | 881 | ||
870 | StickNick -= (GPS_Nick + GPS_Nick2); |
882 | StickNick -= (GPS_Nick + GPS_Nick2); |
871 | StickRoll -= (GPS_Roll + GPS_Roll2); |
883 | StickRoll -= (GPS_Roll + GPS_Roll2); |
872 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
884 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
873 | 885 | ||
874 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
886 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
875 | IntegralFaktor = Parameter_Gyro_I; |
887 | IntegralFaktor = Parameter_Gyro_I; |
876 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
888 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
877 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
889 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
878 | 890 | ||
879 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
891 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
880 | //+ Analoge Steuerung per Seriell |
892 | //+ Analoge Steuerung per Seriell |
881 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
893 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
882 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
894 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
883 | { |
895 | { |
884 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
896 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
885 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
897 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
886 | StickGier += ExternControl.Gier; |
898 | StickGier += ExternControl.Gier; |
887 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
899 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
888 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
900 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
889 | } |
901 | } |
890 | if(StickGas < 0) StickGas = 0; |
902 | if(StickGas < 0) StickGas = 0; |
891 | 903 | ||
892 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
904 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
893 | 905 | ||
894 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
906 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
895 | { |
907 | { |
896 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
908 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
897 | if(MaxStickNick > 100) MaxStickNick = 100; |
909 | if(MaxStickNick > 100) MaxStickNick = 100; |
898 | } |
910 | } |
899 | else MaxStickNick--; |
911 | else MaxStickNick--; |
900 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
912 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
901 | { |
913 | { |
902 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
914 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
903 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
915 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
904 | } |
916 | } |
905 | else MaxStickRoll--; |
917 | else MaxStickRoll--; |
906 | if(FCFlags & FCFLAG_NOTLANDUNG) {MaxStickNick = 0; MaxStickRoll = 0;} |
918 | if(FCFlags & FCFLAG_NOTLANDUNG) {MaxStickNick = 0; MaxStickRoll = 0;} |
907 | 919 | ||
908 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
920 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
909 | // Looping? |
921 | // Looping? |
910 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
922 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
911 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
923 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
912 | else |
924 | else |
913 | { |
925 | { |
914 | { |
926 | { |
915 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
927 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
916 | } |
928 | } |
917 | } |
929 | } |
918 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
930 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
919 | else |
931 | else |
920 | { |
932 | { |
921 | if(Looping_Rechts) // Hysterese |
933 | if(Looping_Rechts) // Hysterese |
922 | { |
934 | { |
923 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
935 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
924 | } |
936 | } |
925 | } |
937 | } |
926 | 938 | ||
927 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
939 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
928 | else |
940 | else |
929 | { |
941 | { |
930 | if(Looping_Oben) // Hysterese |
942 | if(Looping_Oben) // Hysterese |
931 | { |
943 | { |
932 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
944 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
933 | } |
945 | } |
934 | } |
946 | } |
935 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
947 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
936 | else |
948 | else |
937 | { |
949 | { |
938 | if(Looping_Unten) // Hysterese |
950 | if(Looping_Unten) // Hysterese |
939 | { |
951 | { |
940 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
952 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
941 | } |
953 | } |
942 | } |
954 | } |
943 | 955 | ||
944 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
956 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
945 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
957 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
946 | } // Ende neue Funken-Werte |
958 | } // Ende neue Funken-Werte |
947 | 959 | ||
948 | if(Looping_Roll || Looping_Nick) |
960 | if(Looping_Roll || Looping_Nick) |
949 | { |
961 | { |
950 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
962 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
951 | TrichterFlug = 1; |
963 | TrichterFlug = 1; |
952 | } |
964 | } |
953 | 965 | ||
954 | 966 | ||
955 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
967 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
956 | // Bei Empfangsausfall im Flug |
968 | // Bei Empfangsausfall im Flug |
957 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
969 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
958 | if(FCFlags & FCFLAG_NOTLANDUNG) |
970 | if(FCFlags & FCFLAG_NOTLANDUNG) |
959 | { |
971 | { |
960 | StickGier = 0; |
972 | StickGier = 0; |
961 | StickNick = 0; |
973 | StickNick = 0; |
962 | StickRoll = 0; |
974 | StickRoll = 0; |
963 | GyroFaktor = 90; |
975 | GyroFaktor = 90; |
964 | IntegralFaktor = 120; |
976 | IntegralFaktor = 120; |
965 | GyroFaktorGier = 90; |
977 | GyroFaktorGier = 90; |
966 | IntegralFaktorGier = 120; |
978 | IntegralFaktorGier = 120; |
967 | Looping_Roll = 0; |
979 | Looping_Roll = 0; |
968 | Looping_Nick = 0; |
980 | Looping_Nick = 0; |
969 | } |
981 | } |
970 | 982 | ||
971 | 983 | ||
972 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
984 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
973 | // Integrale auf ACC-Signal abgleichen |
985 | // Integrale auf ACC-Signal abgleichen |
974 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
986 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
975 | #define ABGLEICH_ANZAHL 256L |
987 | #define ABGLEICH_ANZAHL 256L |
976 | 988 | ||
977 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
989 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
978 | MittelIntegralRoll += IntegralRoll; |
990 | MittelIntegralRoll += IntegralRoll; |
979 | MittelIntegralNick2 += IntegralNick2; |
991 | MittelIntegralNick2 += IntegralNick2; |
980 | MittelIntegralRoll2 += IntegralRoll2; |
992 | MittelIntegralRoll2 += IntegralRoll2; |
981 | 993 | ||
982 | if(Looping_Nick || Looping_Roll) |
994 | if(Looping_Nick || Looping_Roll) |
983 | { |
995 | { |
984 | IntegralAccNick = 0; |
996 | IntegralAccNick = 0; |
985 | IntegralAccRoll = 0; |
997 | IntegralAccRoll = 0; |
986 | MittelIntegralNick = 0; |
998 | MittelIntegralNick = 0; |
987 | MittelIntegralRoll = 0; |
999 | MittelIntegralRoll = 0; |
988 | MittelIntegralNick2 = 0; |
1000 | MittelIntegralNick2 = 0; |
989 | MittelIntegralRoll2 = 0; |
1001 | MittelIntegralRoll2 = 0; |
990 | Mess_IntegralNick2 = Mess_IntegralNick; |
1002 | Mess_IntegralNick2 = Mess_IntegralNick; |
991 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
1003 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
992 | ZaehlMessungen = 0; |
1004 | ZaehlMessungen = 0; |
993 | LageKorrekturNick = 0; |
1005 | LageKorrekturNick = 0; |
994 | LageKorrekturRoll = 0; |
1006 | LageKorrekturRoll = 0; |
995 | } |
1007 | } |
996 | 1008 | ||
997 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1009 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
998 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
1010 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
999 | { |
1011 | { |
1000 | long tmp_long, tmp_long2; |
1012 | long tmp_long, tmp_long2; |
1001 | if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/) |
1013 | if(FromNaviCtrl_Value.Kalman_K != -1 /*&& !TrichterFlug*/) |
1002 | { |
1014 | { |
1003 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1015 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1004 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1016 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1005 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1017 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1006 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1018 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
1007 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1019 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1008 | { |
1020 | { |
1009 | tmp_long /= 2; |
1021 | tmp_long /= 2; |
1010 | tmp_long2 /= 2; |
1022 | tmp_long2 /= 2; |
1011 | } |
1023 | } |
1012 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1024 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1013 | { |
1025 | { |
1014 | tmp_long /= 3; |
1026 | tmp_long /= 3; |
1015 | tmp_long2 /= 3; |
1027 | tmp_long2 /= 3; |
1016 | } |
1028 | } |
1017 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1029 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1018 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1030 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1019 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1031 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1020 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1032 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1021 | } |
1033 | } |
1022 | else |
1034 | else |
1023 | { |
1035 | { |
1024 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1036 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1025 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1037 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1026 | tmp_long /= 16; |
1038 | tmp_long /= 16; |
1027 | tmp_long2 /= 16; |
1039 | tmp_long2 /= 16; |
1028 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1040 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
1029 | { |
1041 | { |
1030 | tmp_long /= 3; |
1042 | tmp_long /= 3; |
1031 | tmp_long2 /= 3; |
1043 | tmp_long2 /= 3; |
1032 | } |
1044 | } |
1033 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1045 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1034 | { |
1046 | { |
1035 | tmp_long /= 3; |
1047 | tmp_long /= 3; |
1036 | tmp_long2 /= 3; |
1048 | tmp_long2 /= 3; |
1037 | } |
1049 | } |
1038 | 1050 | ||
1039 | #define AUSGLEICH 32 |
1051 | #define AUSGLEICH 32 |
1040 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
1052 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
1041 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
1053 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
1042 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
1054 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
1043 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
1055 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
1044 | } |
1056 | } |
1045 | 1057 | ||
1046 | Mess_IntegralNick -= tmp_long; |
1058 | Mess_IntegralNick -= tmp_long; |
1047 | Mess_IntegralRoll -= tmp_long2; |
1059 | Mess_IntegralRoll -= tmp_long2; |
1048 | } |
1060 | } |
1049 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1061 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1050 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
1062 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
1051 | { |
1063 | { |
1052 | static int cnt = 0; |
1064 | static int cnt = 0; |
1053 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
1065 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
1054 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
1066 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
1055 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
1067 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
1056 | { |
1068 | { |
1057 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
1069 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
1058 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
1070 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
1059 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
1071 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
1060 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
1072 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
1061 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
1073 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
1062 | #define MAX_I 0 |
1074 | #define MAX_I 0 |
1063 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1075 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
1064 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
1076 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
1065 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
1077 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
1066 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1078 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
1067 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
1079 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
1068 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
1080 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
1069 | 1081 | ||
1070 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
1082 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
1071 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
1083 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
1072 | 1084 | ||
1073 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
1085 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
1074 | { |
1086 | { |
1075 | LageKorrekturNick /= 2; |
1087 | LageKorrekturNick /= 2; |
1076 | LageKorrekturRoll /= 2; |
1088 | LageKorrekturRoll /= 2; |
1077 | } |
1089 | } |
1078 | 1090 | ||
1079 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1091 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1080 | // Gyro-Drift ermitteln |
1092 | // Gyro-Drift ermitteln |
1081 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1093 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1082 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1094 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1083 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
1095 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
1084 | tmp_long = IntegralNick2 - IntegralNick; |
1096 | tmp_long = IntegralNick2 - IntegralNick; |
1085 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
1097 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
1086 | 1098 | ||
1087 | IntegralFehlerNick = tmp_long; |
1099 | IntegralFehlerNick = tmp_long; |
1088 | IntegralFehlerRoll = tmp_long2; |
1100 | IntegralFehlerRoll = tmp_long2; |
1089 | Mess_IntegralNick2 -= IntegralFehlerNick; |
1101 | Mess_IntegralNick2 -= IntegralFehlerNick; |
1090 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
1102 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
1091 | 1103 | ||
1092 | if(EE_Parameter.Driftkomp) |
1104 | if(EE_Parameter.Driftkomp) |
1093 | { |
1105 | { |
1094 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
1106 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
1095 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
1107 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
1096 | } |
1108 | } |
1097 | GierGyroFehler = 0; |
1109 | GierGyroFehler = 0; |
1098 | 1110 | ||
1099 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
1111 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
1100 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
1112 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
1101 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
1113 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
1102 | #define BEWEGUNGS_LIMIT 20000 |
1114 | #define BEWEGUNGS_LIMIT 20000 |
1103 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1115 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
1104 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1116 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
1105 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
1117 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
1106 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1118 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1107 | { |
1119 | { |
1108 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
1120 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
1109 | { |
1121 | { |
1110 | if(last_n_p) |
1122 | if(last_n_p) |
1111 | { |
1123 | { |
1112 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1124 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1113 | ausgleichNick = IntegralFehlerNick / 8; |
1125 | ausgleichNick = IntegralFehlerNick / 8; |
1114 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
1126 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
1115 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1127 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1116 | } |
1128 | } |
1117 | else last_n_p = 1; |
1129 | else last_n_p = 1; |
1118 | } else last_n_p = 0; |
1130 | } else last_n_p = 0; |
1119 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
1131 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
1120 | { |
1132 | { |
1121 | if(last_n_n) |
1133 | if(last_n_n) |
1122 | { |
1134 | { |
1123 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1135 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
1124 | ausgleichNick = IntegralFehlerNick / 8; |
1136 | ausgleichNick = IntegralFehlerNick / 8; |
1125 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
1137 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
1126 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1138 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
1127 | } |
1139 | } |
1128 | else last_n_n = 1; |
1140 | else last_n_n = 1; |
1129 | } else last_n_n = 0; |
1141 | } else last_n_n = 0; |
1130 | } |
1142 | } |
1131 | else |
1143 | else |
1132 | { |
1144 | { |
1133 | cnt = 0; |
1145 | cnt = 0; |
1134 | KompassSignalSchlecht = 1000; |
1146 | KompassSignalSchlecht = 1000; |
1135 | } |
1147 | } |
1136 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1148 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1137 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1149 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1138 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1150 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
1139 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
1151 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
1140 | 1152 | ||
1141 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1153 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
1142 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
1154 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
1143 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
1155 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
1144 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1156 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
1145 | { |
1157 | { |
1146 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
1158 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
1147 | { |
1159 | { |
1148 | if(last_r_p) |
1160 | if(last_r_p) |
1149 | { |
1161 | { |
1150 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1162 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1151 | ausgleichRoll = IntegralFehlerRoll / 8; |
1163 | ausgleichRoll = IntegralFehlerRoll / 8; |
1152 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
1164 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
1153 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1165 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1154 | } |
1166 | } |
1155 | else last_r_p = 1; |
1167 | else last_r_p = 1; |
1156 | } else last_r_p = 0; |
1168 | } else last_r_p = 0; |
1157 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
1169 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
1158 | { |
1170 | { |
1159 | if(last_r_n) |
1171 | if(last_r_n) |
1160 | { |
1172 | { |
1161 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1173 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
1162 | ausgleichRoll = IntegralFehlerRoll / 8; |
1174 | ausgleichRoll = IntegralFehlerRoll / 8; |
1163 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
1175 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
1164 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1176 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
1165 | } |
1177 | } |
1166 | else last_r_n = 1; |
1178 | else last_r_n = 1; |
1167 | } else last_r_n = 0; |
1179 | } else last_r_n = 0; |
1168 | } else |
1180 | } else |
1169 | { |
1181 | { |
1170 | cnt = 0; |
1182 | cnt = 0; |
1171 | KompassSignalSchlecht = 1000; |
1183 | KompassSignalSchlecht = 1000; |
1172 | } |
1184 | } |
1173 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1185 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
1174 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1186 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
1175 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1187 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
1176 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1188 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
1177 | } |
1189 | } |
1178 | else |
1190 | else |
1179 | { |
1191 | { |
1180 | LageKorrekturRoll = 0; |
1192 | LageKorrekturRoll = 0; |
1181 | LageKorrekturNick = 0; |
1193 | LageKorrekturNick = 0; |
1182 | TrichterFlug = 0; |
1194 | TrichterFlug = 0; |
1183 | } |
1195 | } |
1184 | 1196 | ||
1185 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1197 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
1186 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1198 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1187 | MittelIntegralNick_Alt = MittelIntegralNick; |
1199 | MittelIntegralNick_Alt = MittelIntegralNick; |
1188 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1200 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
1189 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1201 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1190 | IntegralAccNick = 0; |
1202 | IntegralAccNick = 0; |
1191 | IntegralAccRoll = 0; |
1203 | IntegralAccRoll = 0; |
1192 | IntegralAccZ = 0; |
1204 | IntegralAccZ = 0; |
1193 | MittelIntegralNick = 0; |
1205 | MittelIntegralNick = 0; |
1194 | MittelIntegralRoll = 0; |
1206 | MittelIntegralRoll = 0; |
1195 | MittelIntegralNick2 = 0; |
1207 | MittelIntegralNick2 = 0; |
1196 | MittelIntegralRoll2 = 0; |
1208 | MittelIntegralRoll2 = 0; |
1197 | ZaehlMessungen = 0; |
1209 | ZaehlMessungen = 0; |
1198 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1210 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1199 | 1211 | ||
1200 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1212 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1201 | // Gieren |
1213 | // Gieren |
1202 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1214 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1203 | if(abs(StickGier) > 15) // war 35 |
1215 | if(abs(StickGier) > 15) // war 35 |
1204 | { |
1216 | { |
1205 | KompassSignalSchlecht = 1000; |
1217 | KompassSignalSchlecht = 1000; |
1206 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) |
1218 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) |
1207 | { |
1219 | { |
1208 | NeueKompassRichtungMerken = 1; |
1220 | NeueKompassRichtungMerken = 1; |
1209 | }; |
1221 | }; |
1210 | } |
1222 | } |
1211 | tmp_int = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1223 | tmp_int = (long) EE_Parameter.Gier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1212 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
1224 | tmp_int += (EE_Parameter.Gier_P * StickGier) / 4; |
1213 | sollGier = tmp_int; |
1225 | sollGier = tmp_int; |
1214 | Mess_Integral_Gier -= tmp_int; |
1226 | Mess_Integral_Gier -= tmp_int; |
1215 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1227 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1216 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1228 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1217 | 1229 | ||
1218 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1230 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1219 | // Kompass |
1231 | // Kompass |
1220 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1232 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1221 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
1233 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
1222 | { |
1234 | { |
1223 | int w,v,r,fehler,korrektur; |
1235 | int w,v,r,fehler,korrektur; |
1224 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1236 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1225 | v = abs(IntegralRoll /512); |
1237 | v = abs(IntegralRoll /512); |
1226 | if(v > w) w = v; // grösste Neigung ermitteln |
1238 | if(v > w) w = v; // grösste Neigung ermitteln |
1227 | korrektur = w / 8 + 2; |
1239 | korrektur = w / 8 + 2; |
1228 | fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180; |
1240 | fehler = ((540 + KompassValue - (ErsatzKompass/GIER_GRAD_FAKTOR)) % 360) - 180; |
1229 | //fehler += MesswertGier / 12; |
1241 | //fehler += MesswertGier / 12; |
1230 | 1242 | ||
1231 | if(!KompassSignalSchlecht && w < 25) |
1243 | if(!KompassSignalSchlecht && w < 25) |
1232 | { |
1244 | { |
1233 | GierGyroFehler += fehler; |
1245 | GierGyroFehler += fehler; |
1234 | if(NeueKompassRichtungMerken) |
1246 | if(NeueKompassRichtungMerken) |
1235 | { |
1247 | { |
1236 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
1248 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
1237 | KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR); |
1249 | KompassStartwert = (ErsatzKompass/GIER_GRAD_FAKTOR); |
1238 | NeueKompassRichtungMerken = 0; |
1250 | NeueKompassRichtungMerken = 0; |
1239 | } |
1251 | } |
1240 | } |
1252 | } |
1241 | ErsatzKompass += (fehler * 16) / korrektur; |
1253 | ErsatzKompass += (fehler * 16) / korrektur; |
1242 | w = (w * Parameter_KompassWirkung) / 32; // auf die Wirkung normieren |
1254 | w = (w * Parameter_KompassWirkung) / 32; // auf die Wirkung normieren |
1243 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
1255 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
1244 | if(w >= 0) |
1256 | if(w >= 0) |
1245 | { |
1257 | { |
1246 | if(!KompassSignalSchlecht) |
1258 | if(!KompassSignalSchlecht) |
1247 | { |
1259 | { |
1248 | v = 64 + ((MaxStickNick + MaxStickRoll)) / 8; |
1260 | v = 64 + ((MaxStickNick + MaxStickRoll)) / 8; |
1249 | r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180; |
1261 | r = ((540 + (ErsatzKompass/GIER_GRAD_FAKTOR) - KompassStartwert) % 360) - 180; |
1250 | v = (r * w) / v; // nach Kompass ausrichten |
1262 | v = (r * w) / v; // nach Kompass ausrichten |
1251 | w = 3 * Parameter_KompassWirkung; |
1263 | w = 3 * Parameter_KompassWirkung; |
1252 | if(v > w) v = w; // Begrenzen |
1264 | if(v > w) v = w; // Begrenzen |
1253 | else |
1265 | else |
1254 | if(v < -w) v = -w; |
1266 | if(v < -w) v = -w; |
1255 | Mess_Integral_Gier += v; |
1267 | Mess_Integral_Gier += v; |
1256 | } |
1268 | } |
1257 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1269 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1258 | } |
1270 | } |
1259 | else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
1271 | else KompassSignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
1260 | } |
1272 | } |
1261 | 1273 | ||
1262 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1274 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1263 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1275 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1264 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1276 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1265 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1277 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1266 | 1278 | ||
1267 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1279 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1268 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1280 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1269 | 1281 | ||
1270 | #define TRIM_MAX 200 |
1282 | #define TRIM_MAX 200 |
1271 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1283 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1272 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1284 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1273 | 1285 | ||
1274 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1286 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1275 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
1287 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
1276 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1288 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1277 | 1289 | ||
1278 | // Maximalwerte abfangen |
1290 | // Maximalwerte abfangen |
1279 | // #define MAX_SENSOR (4096*STICK_GAIN) |
1291 | // #define MAX_SENSOR (4096*STICK_GAIN) |
1280 | #define MAX_SENSOR (4096) |
1292 | #define MAX_SENSOR (4096) |
1281 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1293 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1282 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1294 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1283 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1295 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1284 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1296 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1285 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1297 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1286 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1298 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1287 | 1299 | ||
1288 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1300 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1289 | // Höhenregelung |
1301 | // Höhenregelung |
1290 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
1302 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
1291 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1303 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1292 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1304 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1293 | GasMischanteil *= STICK_GAIN; |
1305 | GasMischanteil *= STICK_GAIN; |
1294 | // if height control is activated |
1306 | // if height control is activated |
1295 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1307 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1296 | { |
1308 | { |
1297 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1309 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1298 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1310 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1299 | 1311 | ||
1300 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1312 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1301 | #define OPA_OFFSET_STEP 15 |
1313 | #define OPA_OFFSET_STEP 15 |
1302 | #else |
1314 | #else |
1303 | #define OPA_OFFSET_STEP 10 |
1315 | #define OPA_OFFSET_STEP 10 |
1304 | #endif |
1316 | #endif |
1305 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
1317 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
1306 | static int HeightTrimming = 0; // rate for change of height setpoint |
1318 | static int HeightTrimming = 0; // rate for change of height setpoint |
1307 | static int FilterHCGas = 0; |
1319 | static int FilterHCGas = 0; |
1308 | static int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023; |
1320 | static int StickGasHover = 120, HoverGasMin = 0, HoverGasMax = 1023; |
1309 | static unsigned long HoverGasFilter = 0; |
1321 | static unsigned long HoverGasFilter = 0; |
1310 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1322 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1311 | int CosAttitude; // for projection of hoover gas |
1323 | int CosAttitude; // for projection of hoover gas |
1312 | 1324 | ||
1313 | // get the current hooverpoint |
1325 | // get the current hooverpoint |
- | 1326 | if((FCFlags & FCFLAG_FLY)) /// |
|
- | 1327 | { |
|
1314 | DebugOut.Analog[21] = HoverGas; |
1328 | DebugOut.Analog[21] = HoverGas; |
1315 | 1329 | } |
|
1316 | // Expand the measurement |
1330 | // Expand the measurement |
1317 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
1331 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
1318 | if(!BaroExpandActive) |
1332 | if(!BaroExpandActive) |
1319 | { |
1333 | { |
1320 | if(MessLuftdruck > 920) |
1334 | if(MessLuftdruck > 920) |
1321 | { // increase offset |
1335 | { // increase offset |
1322 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
1336 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
1323 | { |
1337 | { |
1324 | ExpandBaro -= 1; |
1338 | ExpandBaro -= 1; |
1325 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
1339 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
1326 | beeptime = 300; |
1340 | beeptime = 300; |
1327 | BaroExpandActive = 350; |
1341 | BaroExpandActive = 350; |
1328 | } |
1342 | } |
1329 | else |
1343 | else |
1330 | { |
1344 | { |
1331 | BaroAtLowerLimit = 1; |
1345 | BaroAtLowerLimit = 1; |
1332 | } |
1346 | } |
1333 | } |
1347 | } |
1334 | // measurement of air pressure close to lower limit and |
1348 | // measurement of air pressure close to lower limit and |
1335 | else |
1349 | else |
1336 | if(MessLuftdruck < 100) |
1350 | if(MessLuftdruck < 100) |
1337 | { // decrease offset |
1351 | { // decrease offset |
1338 | if(OCR0A > OPA_OFFSET_STEP) |
1352 | if(OCR0A > OPA_OFFSET_STEP) |
1339 | { |
1353 | { |
1340 | ExpandBaro += 1; |
1354 | ExpandBaro += 1; |
1341 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
1355 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
1342 | beeptime = 300; |
1356 | beeptime = 300; |
1343 | BaroExpandActive = 350; |
1357 | BaroExpandActive = 350; |
1344 | } |
1358 | } |
1345 | else |
1359 | else |
1346 | { |
1360 | { |
1347 | BaroAtUpperLimit = 1; |
1361 | BaroAtUpperLimit = 1; |
1348 | } |
1362 | } |
1349 | } |
1363 | } |
1350 | else |
1364 | else |
1351 | { |
1365 | { |
1352 | BaroAtUpperLimit = 0; |
1366 | BaroAtUpperLimit = 0; |
1353 | BaroAtLowerLimit = 0; |
1367 | BaroAtLowerLimit = 0; |
1354 | } |
1368 | } |
1355 | } |
1369 | } |
1356 | else // delay, because of expanding the Baro-Range |
1370 | else // delay, because of expanding the Baro-Range |
1357 | { |
1371 | { |
1358 | // now clear the D-values |
1372 | // now clear the D-values |
1359 | SummenHoehe = HoehenWert * SM_FILTER; |
1373 | SummenHoehe = HoehenWert * SM_FILTER; |
1360 | VarioMeter = 0; |
1374 | VarioMeter = 0; |
1361 | BaroExpandActive--; |
1375 | BaroExpandActive--; |
1362 | } |
1376 | } |
1363 | 1377 | ||
1364 | // if height control is activated by an rc channel |
1378 | // if height control is activated by an rc channel |
1365 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1379 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1366 | { // check if parameter is less than activation threshold |
1380 | { // check if parameter is less than activation threshold |
1367 | if(Parameter_MaxHoehe < 50) // for 3 or 2-state switch height control is disabled in lowest position |
1381 | if(Parameter_MaxHoehe < 50) // for 3 or 2-state switch height control is disabled in lowest position |
1368 | { //height control not active |
1382 | { //height control not active |
1369 | if(!delay--) |
1383 | if(!delay--) |
1370 | { |
1384 | { |
1371 | HoehenReglerAktiv = 0; // disable height control |
1385 | HoehenReglerAktiv = 0; // disable height control |
1372 | SollHoehe = HoehenWert; // update SetPoint with current reading |
1386 | SollHoehe = HoehenWert; // update SetPoint with current reading |
1373 | delay = 1; |
1387 | delay = 1; |
1374 | } |
1388 | } |
1375 | } |
1389 | } |
1376 | else |
1390 | else |
1377 | { //height control is activated |
1391 | { //height control is activated |
1378 | HoehenReglerAktiv = 1; // enable height control |
1392 | HoehenReglerAktiv = 1; // enable height control |
1379 | delay = 200; |
1393 | delay = 200; |
1380 | } |
1394 | } |
1381 | } |
1395 | } |
1382 | else // no switchable height control |
1396 | else // no switchable height control |
1383 | { |
1397 | { |
1384 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1398 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_MaxHoehe) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1385 | HoehenReglerAktiv = 1; |
1399 | HoehenReglerAktiv = 1; |
1386 | } |
1400 | } |
1387 | 1401 | ||
1388 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1402 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1389 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1403 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1390 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
1404 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
1391 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
1405 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
1392 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1406 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1393 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
1407 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
1394 | VarioCharacter = ' '; |
1408 | VarioCharacter = ' '; |
1395 | if(HoehenReglerAktiv && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1409 | if(HoehenReglerAktiv && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1396 | { |
1410 | { |
1397 | #define HEIGHT_TRIM_UP 0x01 |
1411 | #define HEIGHT_TRIM_UP 0x01 |
1398 | #define HEIGHT_TRIM_DOWN 0x02 |
1412 | #define HEIGHT_TRIM_DOWN 0x02 |
1399 | static unsigned char HeightTrimmingFlag = 0x00; |
1413 | static unsigned char HeightTrimmingFlag = 0x00; |
1400 | 1414 | ||
1401 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1415 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1402 | // Holger original version |
1416 | // Holger original version |
1403 | // start of height control algorithm |
1417 | // start of height control algorithm |
1404 | // the height control is only an attenuation of the actual gas stick. |
1418 | // the height control is only an attenuation of the actual gas stick. |
1405 | // I.e. it will work only if the gas stick is higher than the hover gas |
1419 | // I.e. it will work only if the gas stick is higher than the hover gas |
1406 | // and the hover height will be allways larger than height setpoint. |
1420 | // and the hover height will be allways larger than height setpoint. |
1407 | if((EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) || !(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1421 | if((EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) || !(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1408 | { // old version |
1422 | { // old version |
1409 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1423 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1410 | HeightTrimming = 0; |
1424 | HeightTrimming = 0; |
1411 | } |
1425 | } |
1412 | else |
1426 | else |
1413 | { |
1427 | { |
1414 | // alternative height control |
1428 | // alternative height control |
1415 | // PD-Control with respect to hoover point |
1429 | // PD-Control with respect to hoover point |
1416 | // the thrust loss out of horizontal attitude is compensated |
1430 | // the thrust loss out of horizontal attitude is compensated |
1417 | // the setpoint will be fine adjusted with the gas stick position |
1431 | // the setpoint will be fine adjusted with the gas stick position |
1418 | if(FCFlags & FCFLAG_FLY) // trim setpoint only when flying |
1432 | if(FCFlags & FCFLAG_FLY) // trim setpoint only when flying |
1419 | { // gas stick is above hoover point |
1433 | { // gas stick is above hoover point |
1420 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1434 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1421 | { |
1435 | { |
1422 | if(HeightTrimmingFlag & HEIGHT_TRIM_DOWN) |
1436 | if(HeightTrimmingFlag & HEIGHT_TRIM_DOWN) |
1423 | { |
1437 | { |
1424 | HeightTrimmingFlag &= ~HEIGHT_TRIM_DOWN; |
1438 | HeightTrimmingFlag &= ~HEIGHT_TRIM_DOWN; |
1425 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1439 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1426 | } |
1440 | } |
1427 | HeightTrimmingFlag |= HEIGHT_TRIM_UP; |
1441 | HeightTrimmingFlag |= HEIGHT_TRIM_UP; |
1428 | HeightTrimming += abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1442 | HeightTrimming += abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1429 | VarioCharacter = '+'; |
1443 | VarioCharacter = '+'; |
1430 | } // gas stick is below hoover point |
1444 | } // gas stick is below hoover point |
1431 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) |
1445 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) |
1432 | { |
1446 | { |
1433 | if(HeightTrimmingFlag & HEIGHT_TRIM_UP) |
1447 | if(HeightTrimmingFlag & HEIGHT_TRIM_UP) |
1434 | { |
1448 | { |
1435 | HeightTrimmingFlag &= ~HEIGHT_TRIM_UP; |
1449 | HeightTrimmingFlag &= ~HEIGHT_TRIM_UP; |
1436 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1450 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1437 | } |
1451 | } |
1438 | HeightTrimmingFlag |= HEIGHT_TRIM_DOWN; |
1452 | HeightTrimmingFlag |= HEIGHT_TRIM_DOWN; |
1439 | HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1453 | HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1440 | VarioCharacter = '-'; |
1454 | VarioCharacter = '-'; |
1441 | } |
1455 | } |
1442 | else // Gas Stick in Hover Range |
1456 | else // Gas Stick in Hover Range |
1443 | { |
1457 | { |
1444 | if(HeightTrimmingFlag & (HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN)) |
1458 | if(HeightTrimmingFlag & (HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN)) |
1445 | { |
1459 | { |
1446 | HeightTrimmingFlag &= ~(HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN); |
1460 | HeightTrimmingFlag &= ~(HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN); |
1447 | HeightTrimming = 0; |
1461 | HeightTrimming = 0; |
1448 | SollHoehe = HoehenWert; // update setpoint to current height |
1462 | SollHoehe = HoehenWert; // update setpoint to current height |
1449 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1463 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1450 | if(!StartTrigger && HoehenWert > 50) |
1464 | if(!StartTrigger && HoehenWert > 50) |
1451 | { |
1465 | { |
1452 | StartTrigger = 1; |
1466 | StartTrigger = 1; |
1453 | } |
1467 | } |
1454 | } |
1468 | } |
1455 | VarioCharacter = '='; |
1469 | VarioCharacter = '='; |
1456 | } |
1470 | } |
1457 | // Trim height set point |
1471 | // Trim height set point |
1458 | if(abs(HeightTrimming) > 512) |
1472 | if(abs(HeightTrimming) > 512) |
1459 | { |
1473 | { |
1460 | SollHoehe += (HeightTrimming * EE_Parameter.Hoehe_Verstaerkung)/(5 * 512 / 2); // move setpoint |
1474 | SollHoehe += (HeightTrimming * EE_Parameter.Hoehe_Verstaerkung)/(5 * 512 / 2); // move setpoint |
1461 | HeightTrimming = 0; |
1475 | HeightTrimming = 0; |
1462 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1476 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1463 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1477 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1464 | //update hoover gas stick value when setpoint is shifted |
1478 | //update hoover gas stick value when setpoint is shifted |
1465 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1479 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1466 | { |
1480 | { |
1467 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1481 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1468 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1482 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1469 | if(StickGasHover < 70) StickGasHover = 70; |
1483 | if(StickGasHover < 70) StickGasHover = 70; |
1470 | else if(StickGasHover > 150) StickGasHover = 150; |
1484 | else if(StickGasHover > 150) StickGasHover = 150; |
1471 | } |
1485 | } |
1472 | } |
1486 | } |
1473 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1487 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1474 | } //if FCFlags & MKFCFLAG_FLY |
1488 | } //if FCFlags & MKFCFLAG_FLY |
1475 | else |
1489 | else |
1476 | { |
1490 | { |
1477 | SollHoehe = HoehenWert - 400; |
1491 | SollHoehe = HoehenWert - 400; |
1478 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1492 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1479 | else StickGasHover = 120; |
1493 | else StickGasHover = 120; |
1480 | HoverGas = GasMischanteil; |
1494 | HoverGas = GasMischanteil; |
1481 | } |
1495 | } |
1482 | HCGas = HoverGas; // take hover gas (neutral point) |
1496 | HCGas = HoverGas; // take hover gas (neutral point) |
1483 | } |
1497 | } |
1484 | if(HoehenWert > SollHoehe || !(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1498 | if(HoehenWert > SollHoehe || !(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1485 | { |
1499 | { |
1486 | // from this point the Heigth Control Algorithm is identical for both versions |
1500 | // from this point the Heigth Control Algorithm is identical for both versions |
1487 | if(BaroExpandActive) // baro range expanding active |
1501 | if(BaroExpandActive) // baro range expanding active |
1488 | { |
1502 | { |
1489 | HCGas = HoverGas; // hover while expanding baro adc range |
1503 | HCGas = HoverGas; // hover while expanding baro adc range |
1490 | HeightDeviation = 0; |
1504 | HeightDeviation = 0; |
1491 | } // EOF // baro range expanding active |
1505 | } // EOF // baro range expanding active |
1492 | else // valid data from air pressure sensor |
1506 | else // valid data from air pressure sensor |
1493 | { |
1507 | { |
1494 | // ------------------------- P-Part ---------------------------- |
1508 | // ------------------------- P-Part ---------------------------- |
1495 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1509 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1496 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1510 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1497 | HeightDeviation = (int)(tmp_long); // positive when too high |
1511 | HeightDeviation = (int)(tmp_long); // positive when too high |
1498 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1512 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1499 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1513 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1500 | GasReduction = tmp_long; |
1514 | GasReduction = tmp_long; |
1501 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1515 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1502 | tmp_int = VarioMeter / 8; |
1516 | tmp_int = VarioMeter / 8; |
1503 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1517 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1504 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1518 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1505 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
1519 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
1506 | if(HeightTrimmingFlag) tmp_int /= 4; // reduce d-part while trimming setpoint |
1520 | if(HeightTrimmingFlag) tmp_int /= 4; // reduce d-part while trimming setpoint |
1507 | else |
1521 | else |
1508 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1522 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1509 | GasReduction += tmp_int; |
1523 | GasReduction += tmp_int; |
1510 | } // EOF no baro range expanding |
1524 | } // EOF no baro range expanding |
1511 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1525 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1512 | if(Parameter_Hoehe_ACC_Wirkung) |
1526 | if(Parameter_Hoehe_ACC_Wirkung) |
1513 | { |
1527 | { |
1514 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
1528 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
1515 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1529 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1516 | GasReduction += tmp_long; |
1530 | GasReduction += tmp_long; |
1517 | } |
1531 | } |
1518 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1532 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1519 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1533 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1520 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1534 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1521 | GasReduction += tmp_int; |
1535 | GasReduction += tmp_int; |
1522 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1536 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1523 | // ------------------------ ---------------------------------- |
1537 | // ------------------------ ---------------------------------- |
1524 | HCGas -= GasReduction; |
1538 | HCGas -= GasReduction; |
1525 | // limit deviation from hoover point within the target region |
1539 | // limit deviation from hoover point within the target region |
1526 | if(!HeightTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1540 | if(!HeightTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1527 | { |
1541 | { |
1528 | unsigned int tmp; |
1542 | unsigned int tmp; |
1529 | tmp = abs(HeightDeviation); |
1543 | tmp = abs(HeightDeviation); |
1530 | if(tmp <= 60) |
1544 | if(tmp <= 60) |
1531 | { |
1545 | { |
1532 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
1546 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
1533 | } |
1547 | } |
1534 | else |
1548 | else |
1535 | { |
1549 | { |
1536 | tmp = (tmp - 60) / 32; |
1550 | tmp = (tmp - 60) / 32; |
1537 | if(tmp > 15) tmp = 15; |
1551 | if(tmp > 15) tmp = 15; |
1538 | if(HeightDeviation > 0) |
1552 | if(HeightDeviation > 0) |
1539 | { |
1553 | { |
1540 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1554 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1541 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
1555 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
1542 | } |
1556 | } |
1543 | else |
1557 | else |
1544 | { |
1558 | { |
1545 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
1559 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
1546 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
1560 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
1547 | } |
1561 | } |
1548 | } |
1562 | } |
1549 | } |
1563 | } |
1550 | // strech control output by inverse attitude projection 1/cos |
1564 | // strech control output by inverse attitude projection 1/cos |
1551 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
1565 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
1552 | tmp_long2 = (int32_t)HCGas; |
1566 | tmp_long2 = (int32_t)HCGas; |
1553 | tmp_long2 *= 8192L; |
1567 | tmp_long2 *= 8192L; |
1554 | tmp_long2 /= CosAttitude; |
1568 | tmp_long2 /= CosAttitude; |
1555 | HCGas = (int16_t)tmp_long2; |
1569 | HCGas = (int16_t)tmp_long2; |
1556 | // update height control gas averaging |
1570 | // update height control gas averaging |
1557 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
1571 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
1558 | // limit height control gas pd-control output |
1572 | // limit height control gas pd-control output |
1559 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
1573 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
1560 | // set GasMischanteil to HeightControlGasFilter |
1574 | // set GasMischanteil to HeightControlGasFilter |
1561 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) |
1575 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) |
1562 | { // old version |
1576 | { // old version |
1563 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
1577 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
1564 | GasMischanteil = FilterHCGas; |
1578 | GasMischanteil = FilterHCGas; |
1565 | } |
1579 | } |
1566 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
1580 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
1567 | } |
1581 | } |
1568 | }// EOF height control active |
1582 | }// EOF height control active |
1569 | else // HC not active |
1583 | else // HC not active |
1570 | { |
1584 | { |
1571 | //update hoover gas stick value when HC is not active |
1585 | //update hoover gas stick value when HC is not active |
1572 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1586 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1573 | { |
1587 | { |
1574 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
1588 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
1575 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1589 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1576 | } |
1590 | } |
1577 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1591 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1578 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
1592 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
1579 | FilterHCGas = GasMischanteil; |
1593 | FilterHCGas = GasMischanteil; |
1580 | } |
1594 | } |
1581 | 1595 | ||
1582 | // Hover gas estimation by averaging gas control output on small z-velocities |
1596 | // Hover gas estimation by averaging gas control output on small z-velocities |
1583 | // this is done only if height contol option is selected in global config and aircraft is flying |
1597 | // this is done only if height contol option is selected in global config and aircraft is flying |
1584 | if((FCFlags & FCFLAG_FLY))// && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1598 | if((FCFlags & FCFLAG_FLY))// && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1585 | { |
1599 | { |
1586 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1600 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1587 | if(StartTrigger == 1) StartTrigger = 2; |
1601 | if(StartTrigger == 1) StartTrigger = 2; |
1588 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1602 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1589 | tmp_long2 *= CosAttitude; // apply attitude projection |
1603 | tmp_long2 *= CosAttitude; // apply attitude projection |
1590 | tmp_long2 /= 8192; |
1604 | tmp_long2 /= 8192; |
1591 | // average vertical projected thrust |
1605 | // average vertical projected thrust |
1592 | if(modell_fliegt < 4000) // the first 8 seconds |
1606 | if(modell_fliegt < 4000) // the first 8 seconds |
1593 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1607 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1594 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1608 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1595 | HoverGasFilter += 16L * tmp_long2; |
1609 | HoverGasFilter += 16L * tmp_long2; |
1596 | } |
1610 | } |
1597 | if(modell_fliegt < 8000) // the first 16 seconds |
1611 | if(modell_fliegt < 8000) // the first 16 seconds |
1598 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1612 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1599 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1613 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1600 | HoverGasFilter += 4L * tmp_long2; |
1614 | HoverGasFilter += 4L * tmp_long2; |
1601 | } |
1615 | } |
1602 | else //later |
1616 | else //later |
- | 1617 | ||
- | 1618 | ||
1603 | if(abs(VarioMeter) < 100) // only on small vertical speed |
1619 | if(abs(VarioMeter) < 100) // only on small vertical speed |
1604 | { |
1620 | { |
1605 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1621 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1606 | HoverGasFilter += tmp_long2; |
1622 | HoverGasFilter += tmp_long2; |
1607 | } |
1623 | } |
- | 1624 | ||
- | 1625 | ||
1608 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1626 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1609 | if(EE_Parameter.Hoehe_HoverBand) |
1627 | if(EE_Parameter.Hoehe_HoverBand) |
1610 | { |
1628 | { |
1611 | int16_t band; |
1629 | int16_t band; |
1612 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1630 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1613 | HoverGasMin = HoverGas - band; |
1631 | HoverGasMin = HoverGas - band; |
1614 | HoverGasMax = HoverGas + band; |
1632 | HoverGasMax = HoverGas + band; |
1615 | } |
1633 | } |
1616 | else |
1634 | else |
1617 | { // no limit |
1635 | { // no limit |
1618 | HoverGasMin = 0; |
1636 | HoverGasMin = 0; |
1619 | HoverGasMax = 1023; |
1637 | HoverGasMax = 1023; |
1620 | } |
1638 | } |
1621 | } |
1639 | } |
1622 | else |
1640 | else |
1623 | { |
1641 | { |
1624 | StartTrigger = 0; |
1642 | StartTrigger = 0; |
1625 | HoverGasFilter = 0; |
1643 | HoverGasFilter = 0; |
1626 | HoverGas = 0; |
1644 | HoverGas = 0; |
1627 | } |
1645 | } |
1628 | }// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL |
1646 | }// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL |
1629 | // limit gas to parameter setting |
1647 | // limit gas to parameter setting |
1630 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
1648 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
1631 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1649 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1632 | 1650 | ||
1633 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1651 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1634 | // all BL-Ctrl connected? |
1652 | // all BL-Ctrl connected? |
1635 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1653 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1636 | if(MissingMotor || Capacity.MinOfMaxPWM != 255) |
1654 | if(MissingMotor || Capacity.MinOfMaxPWM != 255) |
1637 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) |
1655 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) |
1638 | { |
1656 | { |
1639 | modell_fliegt = 1; |
1657 | modell_fliegt = 1; |
1640 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
1658 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
1641 | } |
1659 | } |
1642 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1660 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1643 | // + Mischer und PI-Regler |
1661 | // + Mischer und PI-Regler |
1644 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1662 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1645 | DebugOut.Analog[7] = GasMischanteil; |
1663 | DebugOut.Analog[7] = GasMischanteil; |
1646 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1664 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1647 | // Gier-Anteil |
1665 | // Gier-Anteil |
1648 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1666 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1649 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1667 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1650 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
1668 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
1651 | if(GasMischanteil > MIN_GIERGAS) |
1669 | if(GasMischanteil > MIN_GIERGAS) |
1652 | { |
1670 | { |
1653 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1671 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1654 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
1672 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
1655 | } |
1673 | } |
1656 | else |
1674 | else |
1657 | { |
1675 | { |
1658 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1676 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1659 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
1677 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
1660 | } |
1678 | } |
1661 | tmp_int = MAX_GAS*STICK_GAIN; |
1679 | tmp_int = MAX_GAS*STICK_GAIN; |
1662 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
1680 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
1663 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
1681 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
1664 | 1682 | ||
1665 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1683 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1666 | // Nick-Achse |
1684 | // Nick-Achse |
1667 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1685 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1668 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1686 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1669 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1687 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1670 | else SummeNick += DiffNick; // I-Anteil bei HH |
1688 | else SummeNick += DiffNick; // I-Anteil bei HH |
1671 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1689 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1672 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1690 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1673 | pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8 + SummeNick / Ki; // PI-Regler für Nick |
1691 | pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8 + SummeNick / Ki; // PI-Regler für Nick |
1674 | // Motor Vorn |
1692 | // Motor Vorn |
1675 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1693 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1676 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1694 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1677 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
1695 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
1678 | 1696 | ||
1679 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1697 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1680 | // Roll-Achse |
1698 | // Roll-Achse |
1681 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1699 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1682 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1700 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
1683 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
1701 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
1684 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1702 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
1685 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1703 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
1686 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1704 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
1687 | pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8 + SummeRoll / Ki; // PI-Regler für Roll |
1705 | pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8 + SummeRoll / Ki; // PI-Regler für Roll |
1688 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1706 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1689 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1707 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
1690 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
1708 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
1691 | 1709 | ||
1692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1710 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1693 | // Universal Mixer |
1711 | // Universal Mixer |
1694 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1712 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1695 | for(i=0; i<MAX_MOTORS; i++) |
1713 | for(i=0; i<MAX_MOTORS; i++) |
1696 | { |
1714 | { |
1697 | signed int tmp_int; |
1715 | signed int tmp_int; |
1698 | if(Mixer.Motor[i][0] > 0) |
1716 | if(Mixer.Motor[i][0] > 0) |
1699 | { |
1717 | { |
1700 | // Gas |
1718 | // Gas |
1701 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1719 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
1702 | // Nick |
1720 | // Nick |
1703 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
1721 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
1704 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
1722 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
1705 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
1723 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
1706 | // Roll |
1724 | // Roll |
1707 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
1725 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
1708 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
1726 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
1709 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
1727 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
1710 | // Gier |
1728 | // Gier |
1711 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
1729 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
1712 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
1730 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
1713 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
1731 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
1714 | 1732 | ||
1715 | 1733 | ||
1716 | 1734 | ||
1717 | 1735 | ||
1718 | 1736 | ||
1719 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
1737 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
1720 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // MotorSmoothing |
1738 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // MotorSmoothing |
1721 | // Arthur P: the original code allowed the motor value to drop to 0 or negative values |
1739 | // Arthur P: the original code allowed the motor value to drop to 0 or negative values |
1722 | // straight off, i.e. could amplify an intended decrease excessively while upregulation |
1740 | // straight off, i.e. could amplify an intended decrease excessively while upregulation |
1723 | // is dampened. The modification would still allow immediate drop below intended value |
1741 | // is dampened. The modification would still allow immediate drop below intended value |
1724 | // but would dampen this. This would still allow for airbraking of the prop to have effect |
1742 | // but would dampen this. This would still allow for airbraking of the prop to have effect |
1725 | // but it might lead to less sudden excessive drops in rpm with only gradual recovery. |
1743 | // but it might lead to less sudden excessive drops in rpm with only gradual recovery. |
1726 | // 090807 Arthur P: Due to problems with uart.c which still refers to user parameter 1 and 2 and |
1744 | // 090807 Arthur P: Due to problems with uart.c which still refers to user parameter 1 and 2 and |
1727 | // possible timing issues with the shutter interval load, removed the shutter interval functions |
1745 | // possible timing issues with the shutter interval load, removed the shutter interval functions |
1728 | // and switched to use of userparam6 for the motor smoothing. |
1746 | // and switched to use of userparam6 for the motor smoothing. |
1729 | // 091114 Inserted modification into 0.76g source code. |
1747 | // 091114 Inserted modification into 0.76g source code. |
1730 | // 20100804 Modified v.0.80d code where motorsmoothing is no longer a separate function. |
1748 | // 20100804 Modified v.0.80d code where motorsmoothing is no longer a separate function. |
1731 | // Downsmoothing either uses default v.0.7x+ 150% downstep (user para 7 == 0), |
1749 | // Downsmoothing either uses default v.0.7x+ 150% downstep (user para 7 == 0), |
1732 | // 50% downstep (user para 7 == 1 or 2), or downsteps of x% (userpara7 ==): |
1750 | // 50% downstep (user para 7 == 1 or 2), or downsteps of x% (userpara7 ==): |
1733 | // 66.6% (3), 75% (4), 80% (5), 90% (10), 95% (20), 97.5% (40), 98% (50), 99% (100). |
1751 | // 66.6% (3), 75% (4), 80% (5), 90% (10), 95% (20), 97.5% (40), 98% (50), 99% (100). |
1734 | else |
1752 | else |
1735 | { |
1753 | { |
1736 | if(Parameter_UserParam7 < 2) |
1754 | if(Parameter_UserParam7 < 2) |
1737 | { // Original function |
1755 | { // Original function |
1738 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; |
1756 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; |
1739 | } |
1757 | } |
1740 | else |
1758 | else |
1741 | { |
1759 | { |
1742 | // If userpara7 >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
1760 | // If userpara7 >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
1743 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/Parameter_UserParam7); |
1761 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/Parameter_UserParam7); |
1744 | } |
1762 | } |
1745 | } |
1763 | } |
1746 | 1764 | ||
1747 | 1765 | ||
1748 | 1766 | ||
1749 | LIMIT_MIN_MAX(tmp_int,MIN_GAS * 4,MAX_GAS * 4); |
1767 | LIMIT_MIN_MAX(tmp_int,MIN_GAS * 4,MAX_GAS * 4); |
1750 | Motor[i].SetPoint = tmp_int / 4; |
1768 | Motor[i].SetPoint = tmp_int / 4; |
1751 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
1769 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
1752 | tmp_motorwert[i] = tmp_int; |
1770 | tmp_motorwert[i] = tmp_int; |
1753 | } |
1771 | } |
1754 | else |
1772 | else |
1755 | { |
1773 | { |
1756 | Motor[i].SetPoint = 0; |
1774 | Motor[i].SetPoint = 0; |
1757 | Motor[i].SetPointLowerBits = 0; |
1775 | Motor[i].SetPointLowerBits = 0; |
1758 | } |
1776 | } |
1759 | } |
1777 | } |
1760 | } |
1778 | } |
1761 | 1779 |