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