Rev 122 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 122 | Rev 123 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Flight Control |
2 | Flight Control |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 04.2007 Holger Buss |
5 | // + Copyright (c) 04.2007 Holger Buss |
6 | // + Nur für den privaten Gebrauch |
6 | // + Nur für den privaten Gebrauch |
7 | // + www.MikroKopter.com |
7 | // + www.MikroKopter.com |
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
9 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
10 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
11 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
12 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
13 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Verkauf von Luftbildaufnahmen, usw. |
14 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
17 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
19 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
20 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + eindeutig als Ursprung verlinkt werden |
21 | // + eindeutig als Ursprung verlinkt werden |
22 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
22 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
23 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Benutzung auf eigene Gefahr |
24 | // + Benutzung auf eigene Gefahr |
25 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
25 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
27 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + mit unserer Zustimmung zulässig |
28 | // + mit unserer Zustimmung zulässig |
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + this list of conditions and the following disclaimer. |
33 | // + this list of conditions and the following disclaimer. |
34 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
34 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + from this software without specific prior written permission. |
35 | // + from this software without specific prior written permission. |
36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
37 | // + for non-commercial use (directly or indirectly) |
37 | // + for non-commercial use (directly or indirectly) |
38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + with our written permission |
39 | // + with our written permission |
40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + clearly linked as origin |
41 | // + clearly linked as origin |
42 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
42 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
43 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
43 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
44 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
44 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
45 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
46 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
47 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
48 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
49 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
50 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
51 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
52 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
53 | // + POSSIBILITY OF SUCH DAMAGE. |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
54 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | 55 | ||
56 | #include "main.h" |
56 | #include "main.h" |
57 | 57 | ||
58 | unsigned char h,m,s; |
58 | unsigned char h,m,s; |
59 | volatile unsigned char Timeout = 0; |
59 | volatile unsigned char Timeout = 0; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
60 | volatile int MesswertNick,MesswertRoll,MesswertGier; |
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
61 | volatile int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0; |
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
62 | volatile int Mittelwert_AccNick, Mittelwert_AccRoll,Mittelwert_AccHoch, NeutralAccX=0, NeutralAccY=0; |
63 | volatile float NeutralAccZ = 0; |
63 | volatile float NeutralAccZ = 0; |
64 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
64 | unsigned char CosinusNickWinkel = 0, CosinusRollWinkel = 0; |
65 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
65 | volatile long IntegralNick = 0,IntegralNick2 = 0; |
66 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
66 | volatile long IntegralRoll = 0,IntegralRoll2 = 0; |
67 | volatile long Integral_Gier = 0; |
67 | volatile long Integral_Gier = 0; |
68 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
68 | volatile long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0; |
69 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
69 | volatile long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0; |
70 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
70 | volatile long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; |
71 | volatile long Mess_Integral_Hoch = 0; |
71 | volatile long Mess_Integral_Hoch = 0; |
72 | volatile int KompassValue = 0; |
72 | volatile int KompassValue = 0; |
73 | volatile int KompassStartwert = 0; |
73 | volatile int KompassStartwert = 0; |
74 | volatile int KompassRichtung = 0; |
74 | volatile int KompassRichtung = 0; |
75 | unsigned char MAX_GAS,MIN_GAS; |
75 | unsigned char MAX_GAS,MIN_GAS; |
76 | unsigned char Notlandung = 0; |
76 | unsigned char Notlandung = 0; |
77 | unsigned char HoehenReglerAktiv = 0; |
77 | unsigned char HoehenReglerAktiv = 0; |
78 | static int SignalSchlecht = 0; |
78 | static int SignalSchlecht = 0; |
79 | 79 | ||
80 | float GyroFaktor; |
80 | float GyroFaktor; |
81 | float IntegralFaktor; |
81 | float IntegralFaktor; |
82 | 82 | ||
83 | volatile int DiffNick,DiffRoll; |
83 | volatile int DiffNick,DiffRoll; |
84 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
84 | int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0; |
85 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
85 | volatile unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
86 | unsigned char MotorWert[5]; |
86 | unsigned char MotorWert[5]; |
87 | volatile unsigned char SenderOkay = 0; |
87 | volatile unsigned char SenderOkay = 0; |
88 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
88 | int StickNick = 0,StickRoll = 0,StickGier = 0; |
89 | char MotorenEin = 0; |
89 | char MotorenEin = 0; |
90 | int HoehenWert = 0; |
90 | int HoehenWert = 0; |
91 | int SollHoehe = 0; |
91 | int SollHoehe = 0; |
- | 92 | int w,v; |
|
92 | 93 | ||
93 | float Kp = FAKTOR_P; |
94 | float Kp = FAKTOR_P; |
94 | float Ki = FAKTOR_I; |
95 | float Ki = FAKTOR_I; |
95 | 96 | ||
96 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
97 | unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
97 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
98 | unsigned char Parameter_MaxHoehe = 251; // Wert : 0-250 |
98 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
99 | unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
99 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
100 | unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
100 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
101 | unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
101 | unsigned char Parameter_Gyro_P = 50; // Wert : 10-250 |
102 | unsigned char Parameter_Gyro_P = 50; // Wert : 10-250 |
102 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
103 | unsigned char Parameter_Gyro_I = 150; // Wert : 0-250 |
103 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
104 | unsigned char Parameter_Gier_P = 2; // Wert : 1-20 |
104 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
105 | unsigned char Parameter_I_Faktor = 10; // Wert : 1-20 |
105 | unsigned char Parameter_UserParam1 = 0; |
106 | unsigned char Parameter_UserParam1 = 0; |
106 | unsigned char Parameter_UserParam2 = 0; |
107 | unsigned char Parameter_UserParam2 = 0; |
107 | unsigned char Parameter_UserParam3 = 0; |
108 | unsigned char Parameter_UserParam3 = 0; |
108 | unsigned char Parameter_UserParam4 = 0; |
109 | unsigned char Parameter_UserParam4 = 0; |
109 | unsigned char Parameter_ServoNickControl = 100; |
110 | unsigned char Parameter_ServoNickControl = 100; |
110 | struct mk_param_struct EE_Parameter; |
111 | struct mk_param_struct EE_Parameter; |
111 | 112 | ||
112 | void Piep(unsigned char Anzahl) |
113 | void Piep(unsigned char Anzahl) |
113 | { |
114 | { |
114 | while(Anzahl--) |
115 | while(Anzahl--) |
115 | { |
116 | { |
116 | if(MotorenEin) return; //auf keinen Fall im Flug! |
117 | if(MotorenEin) return; //auf keinen Fall im Flug! |
117 | beeptime = 100; |
118 | beeptime = 100; |
118 | Delay_ms(250); |
119 | Delay_ms(250); |
119 | } |
120 | } |
120 | } |
121 | } |
121 | 122 | ||
122 | //############################################################################ |
123 | //############################################################################ |
123 | // Nullwerte ermitteln |
124 | // Nullwerte ermitteln |
124 | void SetNeutral(void) |
125 | void SetNeutral(void) |
125 | //############################################################################ |
126 | //############################################################################ |
126 | { |
127 | { |
127 | unsigned int timer; |
128 | unsigned int timer; |
128 | NeutralAccX = 0; |
129 | NeutralAccX = 0; |
129 | NeutralAccY = 0; |
130 | NeutralAccY = 0; |
130 | NeutralAccZ = 0; |
131 | NeutralAccZ = 0; |
131 | AdNeutralNick = 0; |
132 | AdNeutralNick = 0; |
132 | AdNeutralRoll = 0; |
133 | AdNeutralRoll = 0; |
133 | AdNeutralGier = 0; |
134 | AdNeutralGier = 0; |
134 | CalibrierMittelwert(); |
135 | CalibrierMittelwert(); |
135 | timer = SetDelay(5); |
136 | timer = SetDelay(5); |
136 | while (!CheckDelay(timer)); |
137 | while (!CheckDelay(timer)); |
137 | CalibrierMittelwert(); |
138 | CalibrierMittelwert(); |
138 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
139 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
139 | { |
140 | { |
140 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
141 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
141 | } |
142 | } |
142 | AdNeutralNick= abs(MesswertNick); |
143 | AdNeutralNick= abs(MesswertNick); |
143 | AdNeutralRoll= abs(MesswertRoll); |
144 | AdNeutralRoll= abs(MesswertRoll); |
144 | AdNeutralGier= abs(MesswertGier); |
145 | AdNeutralGier= abs(MesswertGier); |
145 | // Salvo 1.9.2007 ACC mit festen neutralwerten ***** |
146 | // Salvo 1.9.2007 ACC mit festen neutralwerten ***** |
146 | if (ACC_NEUTRAL_FIXED > 0) |
147 | if (ACC_NEUTRAL_FIXED > 0) |
147 | { |
148 | { |
148 | NeutralAccX = ACC_X_NEUTRAL; |
149 | NeutralAccX = ACC_X_NEUTRAL; |
149 | NeutralAccY = ACC_Y_NEUTRAL; |
150 | NeutralAccY = ACC_Y_NEUTRAL; |
150 | } |
151 | } |
151 | else |
152 | else |
152 | { // Automatisch bei Offsetabgleich ermitteln |
153 | { // Automatisch bei Offsetabgleich ermitteln |
153 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
154 | NeutralAccY = abs(Mittelwert_AccRoll) / ACC_AMPLIFY; |
154 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
155 | NeutralAccX = abs(Mittelwert_AccNick) / ACC_AMPLIFY; |
155 | } |
156 | } |
156 | // Salvo End |
157 | // Salvo End |
157 | NeutralAccZ = Aktuell_az; |
158 | NeutralAccZ = Aktuell_az; |
158 | Mess_IntegralNick = 0; |
159 | Mess_IntegralNick = 0; |
159 | Mess_IntegralNick2 = 0; |
160 | Mess_IntegralNick2 = 0; |
160 | Mess_IntegralRoll = 0; |
161 | Mess_IntegralRoll = 0; |
161 | Mess_IntegralRoll2 = 0; |
162 | Mess_IntegralRoll2 = 0; |
162 | Mess_Integral_Gier = 0; |
163 | Mess_Integral_Gier = 0; |
163 | MesswertNick = 0; |
164 | MesswertNick = 0; |
164 | MesswertRoll = 0; |
165 | MesswertRoll = 0; |
165 | MesswertGier = 0; |
166 | MesswertGier = 0; |
166 | StartLuftdruck = Luftdruck; |
167 | StartLuftdruck = Luftdruck; |
167 | HoeheD = 0; |
168 | HoeheD = 0; |
168 | Mess_Integral_Hoch = 0; |
169 | Mess_Integral_Hoch = 0; |
169 | KompassStartwert = KompassValue; |
170 | KompassStartwert = KompassValue; |
170 | GPS_Neutral(); |
171 | GPS_Neutral(); |
171 | beeptime = 50; |
172 | beeptime = 50; |
172 | } |
173 | } |
173 | 174 | ||
174 | //############################################################################ |
175 | //############################################################################ |
175 | // Bildet den Mittelwert aus den Messwerten |
176 | // Bildet den Mittelwert aus den Messwerten |
176 | void Mittelwert(void) |
177 | void Mittelwert(void) |
177 | //############################################################################ |
178 | //############################################################################ |
178 | { |
179 | { |
179 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
180 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
180 | ANALOG_OFF; |
181 | ANALOG_OFF; |
181 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
182 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
182 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
183 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
183 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
184 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
184 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
185 | if(messanzahl_AccNick) Mittelwert_AccNick = ((long)Mittelwert_AccNick * 7 + ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick)) / 8L; |
185 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
186 | if(messanzahl_AccRoll) Mittelwert_AccRoll = ((long)Mittelwert_AccRoll * 7 + ((ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll)) / 8L; |
186 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
187 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)Mittelwert_AccHoch * 7 + ((long)accumulate_AccHoch) / messanzahl_AccHoch) / 8L; |
187 | AccumulateNick = 0; MessanzahlNick = 0; |
188 | AccumulateNick = 0; MessanzahlNick = 0; |
188 | AccumulateRoll = 0; MessanzahlRoll = 0; |
189 | AccumulateRoll = 0; MessanzahlRoll = 0; |
189 | AccumulateGier = 0; MessanzahlGier = 0; |
190 | AccumulateGier = 0; MessanzahlGier = 0; |
190 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
191 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
191 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
192 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
192 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
193 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
193 | Integral_Gier = Mess_Integral_Gier; |
194 | Integral_Gier = Mess_Integral_Gier; |
194 | // Integral_Gier2 = Mess_Integral_Gier2; |
195 | // Integral_Gier2 = Mess_Integral_Gier2; |
195 | IntegralNick = Mess_IntegralNick; |
196 | IntegralNick = Mess_IntegralNick; |
196 | IntegralRoll = Mess_IntegralRoll; |
197 | IntegralRoll = Mess_IntegralRoll; |
197 | IntegralNick2 = Mess_IntegralNick2; |
198 | IntegralNick2 = Mess_IntegralNick2; |
198 | IntegralRoll2 = Mess_IntegralRoll2; |
199 | IntegralRoll2 = Mess_IntegralRoll2; |
199 | // ADC einschalten |
200 | // ADC einschalten |
200 | ANALOG_ON; |
201 | ANALOG_ON; |
201 | 202 | ||
202 | //------------------------------------------------------------------------------ |
203 | //------------------------------------------------------------------------------ |
203 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
204 | if(MesswertNick > 200) MesswertNick += 4 * (MesswertNick - 200); |
204 | else |
205 | else |
205 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
206 | if(MesswertNick < -200) MesswertNick += 4 * (MesswertNick + 200); |
206 | 207 | ||
207 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
208 | if(MesswertRoll > 200) MesswertRoll += 4 * (MesswertRoll - 200); |
208 | else |
209 | else |
209 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
210 | if(MesswertRoll < -200) MesswertRoll += 4 * (MesswertRoll + 200); |
210 | //------------------------------------------------------------------------------ |
211 | //------------------------------------------------------------------------------ |
211 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
212 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
212 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
213 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
213 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
214 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
214 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
215 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
215 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
216 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
216 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
217 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
217 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
218 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
218 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
219 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
219 | } |
220 | } |
220 | 221 | ||
221 | //############################################################################ |
222 | //############################################################################ |
222 | // Messwerte beim Ermitteln der Nullage |
223 | // Messwerte beim Ermitteln der Nullage |
223 | void CalibrierMittelwert(void) |
224 | void CalibrierMittelwert(void) |
224 | //############################################################################ |
225 | //############################################################################ |
225 | { |
226 | { |
226 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
227 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
227 | ANALOG_OFF; |
228 | ANALOG_OFF; |
228 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
229 | if(MessanzahlNick) (MesswertNick = AccumulateNick / MessanzahlNick); |
229 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
230 | if(MessanzahlRoll) (MesswertRoll = AccumulateRoll / MessanzahlRoll); |
230 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
231 | if(MessanzahlGier) (MesswertGier = AccumulateGier / MessanzahlGier); |
231 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
232 | if(messanzahl_AccNick) Mittelwert_AccNick = ((ACC_AMPLIFY * (long)accumulate_AccNick) / messanzahl_AccNick); |
232 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
233 | if(messanzahl_AccRoll) Mittelwert_AccRoll = (ACC_AMPLIFY * (long)accumulate_AccRoll) / messanzahl_AccRoll; |
233 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
234 | if(messanzahl_AccHoch) Mittelwert_AccHoch = ((long)accumulate_AccHoch) / messanzahl_AccHoch; |
234 | AccumulateNick = 0; MessanzahlNick = 0; |
235 | AccumulateNick = 0; MessanzahlNick = 0; |
235 | AccumulateRoll = 0; MessanzahlRoll = 0; |
236 | AccumulateRoll = 0; MessanzahlRoll = 0; |
236 | AccumulateGier = 0; MessanzahlGier = 0; |
237 | AccumulateGier = 0; MessanzahlGier = 0; |
237 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
238 | accumulate_AccRoll = 0;messanzahl_AccRoll = 0; |
238 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
239 | accumulate_AccNick = 0;messanzahl_AccNick = 0; |
239 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
240 | accumulate_AccHoch = 0;messanzahl_AccHoch = 0; |
240 | // ADC einschalten |
241 | // ADC einschalten |
241 | ANALOG_ON; |
242 | ANALOG_ON; |
242 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
243 | if(Poti1 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110) Poti1++; else if(Poti1 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 110 && Poti1) Poti1--; |
243 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
244 | if(Poti2 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110) Poti2++; else if(Poti2 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 110 && Poti2) Poti2--; |
244 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
245 | if(Poti3 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110) Poti3++; else if(Poti3 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI3]] + 110 && Poti3) Poti3--; |
245 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
246 | if(Poti4 < PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110) Poti4++; else if(Poti4 > PPM_in[EE_Parameter.Kanalbelegung[K_POTI4]] + 110 && Poti4) Poti4--; |
246 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
247 | if(Poti1 < 0) Poti1 = 0; else if(Poti1 > 255) Poti1 = 255; |
247 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
248 | if(Poti2 < 0) Poti2 = 0; else if(Poti2 > 255) Poti2 = 255; |
248 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
249 | if(Poti3 < 0) Poti3 = 0; else if(Poti3 > 255) Poti3 = 255; |
249 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
250 | if(Poti4 < 0) Poti4 = 0; else if(Poti4 > 255) Poti4 = 255; |
250 | } |
251 | } |
251 | 252 | ||
252 | //############################################################################ |
253 | //############################################################################ |
253 | // Senden der Motorwerte per I2C-Bus |
254 | // Senden der Motorwerte per I2C-Bus |
254 | void SendMotorData(void) |
255 | void SendMotorData(void) |
255 | //############################################################################ |
256 | //############################################################################ |
256 | { |
257 | { |
257 | if(MOTOR_OFF || !MotorenEin) |
258 | if(MOTOR_OFF || !MotorenEin) |
258 | { |
259 | { |
259 | Motor_Hinten = 0; |
260 | Motor_Hinten = 0; |
260 | Motor_Vorne = 0; |
261 | Motor_Vorne = 0; |
261 | Motor_Rechts = 0; |
262 | Motor_Rechts = 0; |
262 | Motor_Links = 0; |
263 | Motor_Links = 0; |
263 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
264 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
264 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
265 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
265 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
266 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
266 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
267 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
267 | } |
268 | } |
268 | 269 | ||
269 | DebugOut.Analog[12] = Motor_Vorne; |
270 | DebugOut.Analog[12] = Motor_Vorne; |
270 | DebugOut.Analog[13] = Motor_Hinten; |
271 | DebugOut.Analog[13] = Motor_Hinten; |
271 | DebugOut.Analog[14] = Motor_Links; |
272 | DebugOut.Analog[14] = Motor_Links; |
272 | DebugOut.Analog[15] = Motor_Rechts; |
273 | DebugOut.Analog[15] = Motor_Rechts; |
273 | 274 | ||
274 | //Start I2C Interrupt Mode |
275 | //Start I2C Interrupt Mode |
275 | twi_state = 0; |
276 | twi_state = 0; |
276 | motor = 0; |
277 | motor = 0; |
277 | i2c_start(); |
278 | i2c_start(); |
278 | } |
279 | } |
279 | 280 | ||
280 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
281 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
281 | // + Konstanten |
282 | // + Konstanten |
282 | // + 0-250 -> normale Werte |
283 | // + 0-250 -> normale Werte |
283 | // + 251 -> Poti1 |
284 | // + 251 -> Poti1 |
284 | // + 252 -> Poti2 |
285 | // + 252 -> Poti2 |
285 | // + 253 -> Poti3 |
286 | // + 253 -> Poti3 |
286 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
287 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
287 | void DefaultKonstanten1(void) |
288 | void DefaultKonstanten1(void) |
288 | { |
289 | { |
289 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
290 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
290 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
291 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
291 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
292 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
292 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
293 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
293 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
294 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
294 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
295 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
295 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
296 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
296 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
297 | EE_Parameter.Kanalbelegung[K_POTI4] = 8; |
297 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
298 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV | CFG_KOMPASS_FIX;//0x01; |
298 | EE_Parameter.Hoehe_MinGas = 30; |
299 | EE_Parameter.Hoehe_MinGas = 30; |
299 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
300 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
300 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
301 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
301 | EE_Parameter.Luftdruck_D = 70; // Wert : 0-250 |
302 | EE_Parameter.Luftdruck_D = 70; // Wert : 0-250 |
302 | EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250 |
303 | EE_Parameter.Hoehe_ACC_Wirkung = 30; // Wert : 0-250 |
303 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
304 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
304 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
305 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
305 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
306 | EE_Parameter.Stick_D = 8; //8 // Wert : 0-64 |
306 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
307 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
307 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
308 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
308 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
309 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
309 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
310 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
310 | EE_Parameter.KompassWirkung = 64; // Wert : 0-250 |
311 | EE_Parameter.KompassWirkung = 64; // Wert : 0-250 |
311 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
312 | EE_Parameter.Gyro_P = 120; //80 // Wert : 0-250 |
312 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
313 | EE_Parameter.Gyro_I = 150; // Wert : 0-250 |
313 | EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250 |
314 | EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250 |
314 | EE_Parameter.NotGas = 80; // Wert : 0-250 // Gaswert bei Empangsverlust |
315 | EE_Parameter.NotGas = 80; // Wert : 0-250 // Gaswert bei Empangsverlust |
315 | EE_Parameter.NotGasZeit = 50; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
316 | EE_Parameter.NotGasZeit = 50; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
316 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
317 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
317 | EE_Parameter.I_Faktor = 5; |
318 | EE_Parameter.I_Faktor = 5; |
318 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
319 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
319 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
320 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
320 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
321 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
321 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
322 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
322 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
323 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
323 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
324 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
324 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
325 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
325 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
326 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
326 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
327 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
327 | EE_Parameter.ServoNickRefresh = 5; |
328 | EE_Parameter.ServoNickRefresh = 5; |
328 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
329 | memcpy(EE_Parameter.Name, "Normal\0", 12); |
329 | } |
330 | } |
330 | 331 | ||
331 | void DefaultKonstanten2(void) |
332 | void DefaultKonstanten2(void) |
332 | { |
333 | { |
333 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
334 | EE_Parameter.Kanalbelegung[K_NICK] = 1; |
334 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
335 | EE_Parameter.Kanalbelegung[K_ROLL] = 2; |
335 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
336 | EE_Parameter.Kanalbelegung[K_GAS] = 3; |
336 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
337 | EE_Parameter.Kanalbelegung[K_GIER] = 4; |
337 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
338 | EE_Parameter.Kanalbelegung[K_POTI1] = 5; |
338 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
339 | EE_Parameter.Kanalbelegung[K_POTI2] = 6; |
339 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
340 | EE_Parameter.Kanalbelegung[K_POTI3] = 7; |
340 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
341 | EE_Parameter.GlobalConfig = 0;//CFG_HOEHENREGELUNG | /*CFG_HOEHEN_SCHALTER |*/ CFG_KOMPASS_AKTIV;//0x01; |
341 | EE_Parameter.Hoehe_MinGas = 30; |
342 | EE_Parameter.Hoehe_MinGas = 30; |
342 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
343 | EE_Parameter.MaxHoehe = 251; // Wert : 0-32 251 -> Poti1 |
343 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
344 | EE_Parameter.Hoehe_P = 10; // Wert : 0-32 |
344 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
345 | EE_Parameter.Luftdruck_D = 50; // Wert : 0-250 |
345 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
346 | EE_Parameter.Hoehe_ACC_Wirkung = 50; // Wert : 0-250 |
346 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
347 | EE_Parameter.Hoehe_Verstaerkung = 2; // Wert : 0-50 |
347 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
348 | EE_Parameter.Stick_P = 4; //2 // Wert : 1-6 |
348 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
349 | EE_Parameter.Stick_D = 0; //8 // Wert : 0-64 |
349 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
350 | EE_Parameter.Gier_P = 16; // Wert : 1-20 |
350 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
351 | EE_Parameter.Gas_Min = 15; // Wert : 0-32 |
351 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
352 | EE_Parameter.Gas_Max = 250; // Wert : 33-250 |
352 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
353 | EE_Parameter.GyroAccFaktor = 26; // Wert : 1-64 |
353 | EE_Parameter.KompassWirkung = 64; // Wert : 0-250 |
354 | EE_Parameter.KompassWirkung = 64; // Wert : 0-250 |
354 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
355 | EE_Parameter.Gyro_P = 175; //80 // Wert : 0-250 |
355 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
356 | EE_Parameter.Gyro_I = 175; // Wert : 0-250 |
356 | EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250 |
357 | EE_Parameter.UnterspannungsWarnung = 100; // Wert : 0-250 |
357 | EE_Parameter.NotGas = 80; // Wert : 0-250 // Gaswert bei Empangsverlust |
358 | EE_Parameter.NotGas = 80; // Wert : 0-250 // Gaswert bei Empangsverlust |
358 | EE_Parameter.NotGasZeit = 50; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
359 | EE_Parameter.NotGasZeit = 50; // Wert : 0-250 // Zeit bis auf NotGas geschaltet wird, wg. Rx-Problemen |
359 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
360 | EE_Parameter.UfoAusrichtung = 0; // X oder + Formation |
360 | EE_Parameter.I_Faktor = 5; |
361 | EE_Parameter.I_Faktor = 5; |
361 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
362 | EE_Parameter.UserParam1 = 0; //zur freien Verwendung |
362 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
363 | EE_Parameter.UserParam2 = 0; //zur freien Verwendung |
363 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
364 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
364 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
365 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
365 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
366 | EE_Parameter.UserParam3 = 0; //zur freien Verwendung |
366 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
367 | EE_Parameter.UserParam4 = 0; //zur freien Verwendung |
367 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
368 | EE_Parameter.ServoNickControl = 100; // Wert : 0-250 // Stellung des Servos |
368 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
369 | EE_Parameter.ServoNickComp = 40; // Wert : 0-250 // Einfluss Gyro/Servo |
369 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
370 | EE_Parameter.ServoNickCompInvert = 0; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
370 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
371 | EE_Parameter.ServoNickMin = 50; // Wert : 0-250 // Anschlag |
371 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
372 | EE_Parameter.ServoNickMax = 150; // Wert : 0-250 // Anschlag |
372 | EE_Parameter.ServoNickRefresh = 5; |
373 | EE_Parameter.ServoNickRefresh = 5; |
373 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
374 | memcpy(EE_Parameter.Name, "Kamera\0", 12); |
374 | } |
375 | } |
375 | 376 | ||
376 | 377 | ||
377 | //############################################################################ |
378 | //############################################################################ |
378 | // Trägt ggf. das Poti als Parameter ein |
379 | // Trägt ggf. das Poti als Parameter ein |
379 | void ParameterZuordnung(void) |
380 | void ParameterZuordnung(void) |
380 | //############################################################################ |
381 | //############################################################################ |
381 | { |
382 | { |
382 | 383 | ||
383 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
384 | #define CHK_POTI(b,a,min,max) { if(a > 250) { if(a == 251) b = Poti1; else if(a == 252) b = Poti2; else if(a == 253) b = Poti3; else if(a == 254) b = Poti4;} else b = a; if(b <= min) b = min; else if(b >= max) b = max;} |
384 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
385 | CHK_POTI(Parameter_MaxHoehe,EE_Parameter.MaxHoehe,0,255); |
385 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
386 | CHK_POTI(Parameter_Luftdruck_D,EE_Parameter.Luftdruck_D,0,100); |
386 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
387 | CHK_POTI(Parameter_Hoehe_P,EE_Parameter.Hoehe_P,0,100); |
387 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
388 | CHK_POTI(Parameter_Hoehe_ACC_Wirkung,EE_Parameter.Hoehe_ACC_Wirkung,0,255); |
388 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
389 | CHK_POTI(Parameter_KompassWirkung,EE_Parameter.KompassWirkung,0,255); |
389 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
390 | CHK_POTI(Parameter_Gyro_P,EE_Parameter.Gyro_P,10,255); |
390 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
391 | CHK_POTI(Parameter_Gyro_I,EE_Parameter.Gyro_I,0,255); |
391 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
392 | CHK_POTI(Parameter_I_Faktor,EE_Parameter.I_Faktor,0,255); |
392 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
393 | CHK_POTI(Parameter_UserParam1,EE_Parameter.UserParam1,0,255); |
393 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
394 | CHK_POTI(Parameter_UserParam2,EE_Parameter.UserParam2,0,255); |
394 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
395 | CHK_POTI(Parameter_UserParam3,EE_Parameter.UserParam3,0,255); |
395 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
396 | CHK_POTI(Parameter_UserParam4,EE_Parameter.UserParam4,0,255); |
396 | 397 | ||
397 | unsigned char ServoNickComp; // Wert : 0-250 // Einfluss Gyro/Servo |
398 | unsigned char ServoNickComp; // Wert : 0-250 // Einfluss Gyro/Servo |
398 | unsigned char ServoNickCompInvert; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
399 | unsigned char ServoNickCompInvert; // Wert : 0-250 // Richtung Einfluss Gyro/Servo |
399 | unsigned char ServoNickMin; // Wert : 0-250 // Anschlag |
400 | unsigned char ServoNickMin; // Wert : 0-250 // Anschlag |
400 | unsigned char ServoNickMax; // Wert : 0-250 // Anschlag |
401 | unsigned char ServoNickMax; // Wert : 0-250 // Anschlag |
401 | 402 | ||
402 | 403 | ||
403 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
404 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
404 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
405 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
405 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
406 | CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl,0,255); |
406 | 407 | ||
407 | Ki = (float) Parameter_I_Faktor * 0.0001; |
408 | Ki = (float) Parameter_I_Faktor * 0.0001; |
408 | MAX_GAS = EE_Parameter.Gas_Max; |
409 | MAX_GAS = EE_Parameter.Gas_Max; |
409 | MIN_GAS = EE_Parameter.Gas_Min; |
410 | MIN_GAS = EE_Parameter.Gas_Min; |
410 | } |
411 | } |
411 | 412 | ||
412 | 413 | ||
413 | //############################################################################ |
414 | //############################################################################ |
414 | // |
415 | // |
415 | void MotorRegler(void) |
416 | void MotorRegler(void) |
416 | //############################################################################ |
417 | //############################################################################ |
417 | { |
418 | { |
418 | int motorwert,pd_ergebnis,h,tmp_int; |
419 | int motorwert,pd_ergebnis,h,tmp_int; |
419 | int GierMischanteil,GasMischanteil; |
420 | int GierMischanteil,GasMischanteil; |
420 | static long SummeNick=0,SummeRoll=0; |
421 | static long SummeNick=0,SummeRoll=0; |
421 | static long sollGier = 0,tmp_long,tmp_long2; |
422 | static long sollGier = 0,tmp_long,tmp_long2; |
422 | static int IntegralFehlerNick = 0; |
423 | static int IntegralFehlerNick = 0; |
423 | static int IntegralFehlerRoll = 0; |
424 | static int IntegralFehlerRoll = 0; |
424 | static unsigned int RcLostTimer; |
425 | static unsigned int RcLostTimer; |
425 | static unsigned char delay_neutral = 0; |
426 | static unsigned char delay_neutral = 0; |
426 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
427 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
427 | static unsigned int modell_fliegt = 0; |
428 | static unsigned int modell_fliegt = 0; |
428 | static int hoehenregler = 0; |
429 | static int hoehenregler = 0; |
429 | static char TimerWerteausgabe = 0; |
430 | static char TimerWerteausgabe = 0; |
430 | static char NeueKompassRichtungMerken = 0; |
431 | static char NeueKompassRichtungMerken = 0; |
431 | Mittelwert(); |
432 | Mittelwert(); |
432 | 433 | ||
433 | GRN_ON; |
434 | GRN_ON; |
434 | 435 | ||
435 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
436 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
436 | // Gaswert ermitteln |
437 | // Gaswert ermitteln |
437 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
438 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
438 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
439 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
439 | if(GasMischanteil < 0) GasMischanteil = 0; |
440 | if(GasMischanteil < 0) GasMischanteil = 0; |
440 | 441 | ||
441 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
442 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
442 | // Emfang schlecht |
443 | // Emfang schlecht |
443 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
444 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
444 | if(SenderOkay < 100) |
445 | if(SenderOkay < 100) |
445 | { |
446 | { |
446 | if(!PcZugriff) beeptime = 500; |
447 | if(!PcZugriff) beeptime = 500; |
447 | if(RcLostTimer) RcLostTimer--; |
448 | if(RcLostTimer) RcLostTimer--; |
448 | else |
449 | else |
449 | { |
450 | { |
450 | MotorenEin = 0; |
451 | MotorenEin = 0; |
451 | Notlandung = 0; |
452 | Notlandung = 0; |
452 | } |
453 | } |
453 | ROT_ON; |
454 | ROT_ON; |
454 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
455 | if(modell_fliegt > 2000) // wahrscheinlich in der Luft --> langsam absenken |
455 | { |
456 | { |
456 | GasMischanteil = EE_Parameter.NotGas; |
457 | GasMischanteil = EE_Parameter.NotGas; |
457 | Notlandung = 1; |
458 | Notlandung = 1; |
458 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
459 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
459 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
460 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
460 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
461 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
461 | /* Poti1 = 65; |
462 | /* Poti1 = 65; |
462 | Poti2 = 48; |
463 | Poti2 = 48; |
463 | Poti3 = 0; |
464 | Poti3 = 0; |
464 | */ } |
465 | */ } |
465 | else MotorenEin = 0; |
466 | else MotorenEin = 0; |
466 | } |
467 | } |
467 | else |
468 | else |
468 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
469 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
469 | // Emfang gut |
470 | // Emfang gut |
470 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
471 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
471 | if(SenderOkay > 140) |
472 | if(SenderOkay > 140) |
472 | { |
473 | { |
473 | Notlandung = 0; |
474 | Notlandung = 0; |
474 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
475 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
475 | if(GasMischanteil > 40) |
476 | if(GasMischanteil > 40) |
476 | { |
477 | { |
477 | if(modell_fliegt < 0xffff) modell_fliegt++; |
478 | if(modell_fliegt < 0xffff) modell_fliegt++; |
478 | } |
479 | } |
479 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
480 | if((modell_fliegt < 200) || (GasMischanteil < 40)) |
480 | { |
481 | { |
481 | SummeNick = 0; |
482 | SummeNick = 0; |
482 | SummeRoll = 0; |
483 | SummeRoll = 0; |
483 | Mess_Integral_Gier = 0; |
484 | Mess_Integral_Gier = 0; |
484 | Mess_Integral_Gier2 = 0; |
485 | Mess_Integral_Gier2 = 0; |
485 | } |
486 | } |
486 | if((GasMischanteil > 200) && MotorenEin == 0) |
487 | if((GasMischanteil > 200) && MotorenEin == 0) |
487 | { |
488 | { |
488 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
489 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
489 | // auf Nullwerte kalibrieren |
490 | // auf Nullwerte kalibrieren |
490 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
491 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
491 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
492 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
492 | { |
493 | { |
493 | unsigned char setting; |
494 | unsigned char setting; |
494 | if(++delay_neutral > 200) // nicht sofort |
495 | if(++delay_neutral > 200) // nicht sofort |
495 | { |
496 | { |
496 | GRN_OFF; |
497 | GRN_OFF; |
497 | SetNeutral(); |
498 | SetNeutral(); |
498 | MotorenEin = 0; |
499 | MotorenEin = 0; |
499 | delay_neutral = 0; |
500 | delay_neutral = 0; |
500 | modell_fliegt = 0; |
501 | modell_fliegt = 0; |
501 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
502 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
502 | { |
503 | { |
503 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
504 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
504 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
505 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
505 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
506 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
506 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
507 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
507 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
508 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
508 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
509 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], setting); // aktiven Datensatz merken |
509 | } |
510 | } |
510 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
511 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
511 | Piep(GetActiveParamSetNumber()); |
512 | Piep(GetActiveParamSetNumber()); |
512 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
513 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
513 | { |
514 | { |
514 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
515 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
515 | } |
516 | } |
516 | } |
517 | } |
517 | } |
518 | } |
518 | else delay_neutral = 0; |
519 | else delay_neutral = 0; |
519 | } |
520 | } |
520 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
521 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
521 | // Gas ist unten |
522 | // Gas ist unten |
522 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
523 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
523 | if(GasMischanteil < 35) |
524 | if(GasMischanteil < 35) |
524 | { |
525 | { |
525 | // Starten |
526 | // Starten |
526 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
527 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
527 | { |
528 | { |
528 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
529 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
529 | // Einschalten |
530 | // Einschalten |
530 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
531 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
531 | if(++delay_einschalten > 200) |
532 | if(++delay_einschalten > 200) |
532 | { |
533 | { |
533 | delay_einschalten = 200; |
534 | delay_einschalten = 200; |
534 | modell_fliegt = 1; |
535 | modell_fliegt = 1; |
535 | MotorenEin = 1; |
536 | MotorenEin = 1; |
536 | sollGier = 0; |
537 | sollGier = 0; |
537 | Mess_Integral_Gier = 0; |
538 | Mess_Integral_Gier = 0; |
538 | Mess_Integral_Gier2 = 0; |
539 | Mess_Integral_Gier2 = 0; |
539 | Mess_IntegralNick = 0; |
540 | Mess_IntegralNick = 0; |
540 | Mess_IntegralRoll = 0; |
541 | Mess_IntegralRoll = 0; |
541 | Mess_IntegralNick2 = IntegralNick; |
542 | Mess_IntegralNick2 = IntegralNick; |
542 | Mess_IntegralRoll2 = IntegralRoll; |
543 | Mess_IntegralRoll2 = IntegralRoll; |
543 | SummeNick = 0; |
544 | SummeNick = 0; |
544 | SummeRoll = 0; |
545 | SummeRoll = 0; |
545 | } |
546 | } |
546 | } |
547 | } |
547 | else delay_einschalten = 0; |
548 | else delay_einschalten = 0; |
548 | //Auf Neutralwerte setzen |
549 | //Auf Neutralwerte setzen |
549 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
550 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
550 | // Auschalten |
551 | // Auschalten |
551 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
552 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
552 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
553 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
553 | { |
554 | { |
554 | if(++delay_ausschalten > 200) // nicht sofort |
555 | if(++delay_ausschalten > 200) // nicht sofort |
555 | { |
556 | { |
556 | MotorenEin = 0; |
557 | MotorenEin = 0; |
557 | delay_ausschalten = 200; |
558 | delay_ausschalten = 200; |
558 | modell_fliegt = 0; |
559 | modell_fliegt = 0; |
559 | } |
560 | } |
560 | } |
561 | } |
561 | else delay_ausschalten = 0; |
562 | else delay_ausschalten = 0; |
562 | } |
563 | } |
563 | } |
564 | } |
564 | 565 | ||
565 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
566 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
566 | // neue Werte von der Funke |
567 | // neue Werte von der Funke |
567 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
568 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
568 | if(!NewPpmData-- || Notlandung) |
569 | if(!NewPpmData-- || Notlandung) |
569 | { |
570 | { |
570 | ParameterZuordnung(); |
571 | ParameterZuordnung(); |
571 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
572 | StickNick = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P; |
572 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
573 | StickNick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
573 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
574 | StickRoll = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P; |
574 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
575 | StickRoll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
575 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
576 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
576 | 577 | ||
577 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
578 | GyroFaktor = ((float)Parameter_Gyro_P + 10.0) / 256.0; |
578 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
579 | IntegralFaktor = ((float) Parameter_Gyro_I) / 44000; |
579 | 580 | ||
580 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
581 | if(EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
581 | if(GyroFaktor < 0) GyroFaktor = 0; |
582 | if(GyroFaktor < 0) GyroFaktor = 0; |
582 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
583 | if(IntegralFaktor < 0) IntegralFaktor = 0; |
583 | } |
584 | } |
584 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
585 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
585 | // Bei Empfangsausfall im Flug |
586 | // Bei Empfangsausfall im Flug |
586 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
587 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
587 | if(Notlandung) |
588 | if(Notlandung) |
588 | { |
589 | { |
589 | StickGier = 0; |
590 | StickGier = 0; |
590 | StickNick = 0; |
591 | StickNick = 0; |
591 | StickRoll = 0; |
592 | StickRoll = 0; |
592 | GyroFaktor = 0.1; |
593 | GyroFaktor = 0.1; |
593 | IntegralFaktor = 0.005; |
594 | IntegralFaktor = 0.005; |
594 | } |
595 | } |
595 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
596 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
596 | // Gyro-Drift kompensieren |
597 | // Gyro-Drift kompensieren |
597 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
598 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
598 | #define DRIFT_FAKTOR 3 |
599 | #define DRIFT_FAKTOR 3 |
599 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
600 | if(ZaehlMessungen >= 1000 / DRIFT_FAKTOR) |
600 | { |
601 | { |
601 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
602 | IntegralFehlerNick = IntegralNick2 - IntegralNick; |
602 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
603 | IntegralFehlerRoll = IntegralRoll2 - IntegralRoll; |
603 | ZaehlMessungen = 0; |
604 | ZaehlMessungen = 0; |
- | 605 | // Salvo 1.9.2007 ************************* |
|
- | 606 | // Abgleich Roll und Nick Gyro nur, wenn nahezu waagrechte Lage |
|
- | 607 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
|
- | 608 | w = (abs(Mittelwert_AccNick)); |
|
- | 609 | v = (abs(Mittelwert_AccRoll)); |
|
- | 610 | ANALOG_ON; // ADC einschalten |
|
- | 611 | if ((w < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) |
|
- | 612 | { |
|
604 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
613 | if(IntegralFehlerNick > 500/DRIFT_FAKTOR) AdNeutralNick++; |
605 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
614 | if(IntegralFehlerNick < -500/DRIFT_FAKTOR) AdNeutralNick--; |
606 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
615 | if(IntegralFehlerRoll > 500/DRIFT_FAKTOR) AdNeutralRoll++; |
607 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
616 | if(IntegralFehlerRoll < -500/DRIFT_FAKTOR) AdNeutralRoll--; |
- | 617 | } |
|
- | 618 | // Salvo End |
|
- | 619 | ||
608 | // Salvo 31.8.2007 Abgleich Giergyro nur wenn Kompass aktiv und ok ist *********************** |
620 | // Salvo 31.8.2007 Abgleich Giergyro nur wenn Kompass aktiv und ok ist *********************** |
609 | // Ohne Kompass wird die Gyrodrift durch die Driftkompensation nur verschlimmert |
621 | // Ohne Kompass wird die Pseudo-Gyrodrift durch die Driftkompensation nur verschlimmert |
610 | // Ohne Driftkompensation ist die Gierachse wesentlich stabiler |
622 | // Ohne Driftkompensation ist die Gierachse wesentlich stabiler |
611 | if ((EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (!SignalSchlecht)) |
623 | if ((EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV) && (!SignalSchlecht)) |
612 | { |
624 | { |
613 | if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; |
625 | if(Mess_Integral_Gier2 > 500/DRIFT_FAKTOR) AdNeutralGier--; |
614 | if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; |
626 | if(Mess_Integral_Gier2 <-500/DRIFT_FAKTOR) AdNeutralGier++; |
615 | } |
627 | } |
616 | else |
628 | else |
617 | { |
629 | { |
618 | Mess_Integral_Gier2 = 0; |
630 | Mess_Integral_Gier2 = 0; |
619 | } |
631 | } |
620 | // Salvo End *********************** |
632 | // Salvo End *********************** |
621 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
633 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
622 | Mess_IntegralNick2 = IntegralNick; |
634 | Mess_IntegralNick2 = IntegralNick; |
623 | Mess_IntegralRoll2 = IntegralRoll; |
635 | Mess_IntegralRoll2 = IntegralRoll; |
624 | Mess_Integral_Gier2 = Integral_Gier; |
636 | Mess_Integral_Gier2 = Integral_Gier; |
625 | ANALOG_ON; // ADC einschalten |
637 | ANALOG_ON; // ADC einschalten |
626 | } |
638 | } |
627 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
639 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
628 | // Integrale auf ACC-Signal abgleichen |
640 | // Integrale auf ACC-Signal abgleichen |
629 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
641 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
630 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
642 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick) / 16; |
631 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
643 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll) / 16; |
632 | #define AUSGLEICH 500 |
644 | #define AUSGLEICH 500 |
633 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
645 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
634 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
646 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
635 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
647 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
636 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
648 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
- | 649 | ||
637 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
650 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
- | 651 | // Salvo 1.9.2007 Volle Korrektur nur wenn waagrechte Lage, sonst abgeschawecht ***************** |
|
- | 652 | w = (abs(Mittelwert_AccNick)); |
|
- | 653 | v = (abs(Mittelwert_AccRoll)); |
|
- | 654 | if ((w < ACC_WAAGRECHT_LIMIT) && (v < ACC_WAAGRECHT_LIMIT)) |
|
- | 655 | { |
|
638 | Mess_IntegralNick -= tmp_long; |
656 | Mess_IntegralNick -= tmp_long; |
639 | Mess_IntegralRoll -= tmp_long2; |
657 | Mess_IntegralRoll -= tmp_long2; |
- | 658 | } |
|
- | 659 | else if ((w < 2 * ACC_WAAGRECHT_LIMIT) && (v < 2 * ACC_WAAGRECHT_LIMIT)) |
|
- | 660 | { |
|
- | 661 | Mess_IntegralNick -= tmp_long/8; |
|
- | 662 | Mess_IntegralRoll -= tmp_long/8; |
|
- | 663 | } |
|
- | 664 | else if ((w < 4 * ACC_WAAGRECHT_LIMIT) && (v < 4 * ACC_WAAGRECHT_LIMIT)) |
|
- | 665 | { |
|
- | 666 | Mess_IntegralNick -= tmp_long/16; |
|
- | 667 | Mess_IntegralRoll -= tmp_long/16; |
|
- | 668 | } |
|
- | 669 | else |
|
- | 670 | { |
|
- | 671 | Mess_IntegralNick -= tmp_long/32; |
|
- | 672 | Mess_IntegralRoll -= tmp_long2/32; |
|
- | 673 | } |
|
- | 674 | // Salvo End *********************** |
|
640 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
675 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
641 | // Gieren |
676 | // Gieren |
642 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
677 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
643 | sollGier = StickGier; |
678 | sollGier = StickGier; |
644 | if(abs(StickGier) > 35) |
679 | if(abs(StickGier) > 35) |
645 | { |
680 | { |
646 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
681 | if(!(EE_Parameter.GlobalConfig & CFG_KOMPASS_FIX)) NeueKompassRichtungMerken = 1; |
647 | } |
682 | } |
648 | tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo |
683 | tmp_int = EE_Parameter.Gier_P * (sollGier * abs(sollGier)) / 256; // expo |
649 | Mess_Integral_Gier -= tmp_int; |
684 | Mess_Integral_Gier -= tmp_int; |
650 | if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000; // begrenzen |
685 | if(Mess_Integral_Gier > 30000) Mess_Integral_Gier = 30000; // begrenzen |
651 | if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000; |
686 | if(Mess_Integral_Gier <-30000) Mess_Integral_Gier =-30000; |
652 | // Salvo Gewolltes Gieren ignorieren 30.8.2007 ********************** |
687 | // Salvo Gewolltes Gieren ignorieren 30.8.2007 ********************** |
653 | Mess_Integral_Gier2 -= tmp_int; |
688 | Mess_Integral_Gier2 -= tmp_int; |
654 | // Salvo End ************************* |
689 | // Salvo End ************************* |
655 | ANALOG_ON; // ADC einschalten |
690 | ANALOG_ON; // ADC einschalten |
656 | 691 | ||
657 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
658 | // Kompass |
693 | // Kompass |
659 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
694 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
660 | //KompassValue = 12; |
695 | //KompassValue = 12; |
661 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
696 | if(KompassValue && (EE_Parameter.GlobalConfig & CFG_KOMPASS_AKTIV)) |
662 | { |
697 | { |
663 | int w,v; |
- | |
664 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
698 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
665 | v = abs(IntegralRoll /512); |
699 | v = abs(IntegralRoll /512); |
666 | if(v > w) w = v; // grösste Neigung ermitteln |
700 | if(v > w) w = v; // grösste Neigung ermitteln |
667 | if(w < 20 && NeueKompassRichtungMerken && !SignalSchlecht) |
701 | if(w < 20 && NeueKompassRichtungMerken && !SignalSchlecht) |
668 | { |
702 | { |
669 | KompassStartwert = KompassValue; |
703 | KompassStartwert = KompassValue; |
670 | NeueKompassRichtungMerken = 0; |
704 | NeueKompassRichtungMerken = 0; |
671 | } |
705 | } |
672 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
706 | w = (w * Parameter_KompassWirkung) / 64; // auf die Wirkung normieren |
673 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
707 | w = Parameter_KompassWirkung - w; // Wirkung ggf drosseln |
674 | if(w > 0) |
708 | if(w > 0) |
675 | { |
709 | { |
676 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
710 | ANALOG_OFF; // ADC ausschalten, damit die Werte sich nicht während der Berechnung ändern |
677 | 711 | ||
678 | // Salvo 30.8.2007 Winkelbegrenzung ********************** |
712 | // Salvo 30.8.2007 Winkelbegrenzung ********************** |
679 | if ((!SignalSchlecht) ) |
713 | if ((!SignalSchlecht) ) |
680 | { |
714 | { |
681 | if (abs(KompassRichtung) < 135 ) |
715 | if (abs(KompassRichtung) < 135 ) |
682 | { |
716 | { |
683 | Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
717 | Mess_Integral_Gier += (KompassRichtung * w) / 32; // nach Kompass ausrichten |
684 | } |
718 | } |
685 | } |
719 | } |
686 | // Salvo End ************************* |
720 | // Salvo End ************************* |
687 | 721 | ||
688 | ANALOG_ON; // ADC einschalten |
722 | ANALOG_ON; // ADC einschalten |
689 | if(SignalSchlecht) SignalSchlecht--; |
723 | if(SignalSchlecht) SignalSchlecht--; |
690 | } |
724 | } |
691 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
725 | else SignalSchlecht = 500; // so lange das Signal taub stellen --> ca. 1 sek |
692 | } |
726 | } |
693 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
727 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
694 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
728 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
695 | 729 | ||
696 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
730 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
697 | // Debugwerte zuordnen |
731 | // Debugwerte zuordnen |
698 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
732 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
699 | DebugOut.Sekunden++; |
733 | DebugOut.Sekunden++; |
700 | if(!TimerWerteausgabe--) |
734 | if(!TimerWerteausgabe--) |
701 | { |
735 | { |
702 | TimerWerteausgabe = 49; |
736 | TimerWerteausgabe = 49; |
703 | // DebugOut.Analog[0] = MesswertNick; |
737 | // DebugOut.Analog[0] = MesswertNick; |
704 | // DebugOut.Analog[1] = MesswertRoll; |
738 | // DebugOut.Analog[1] = MesswertRoll; |
705 | // DebugOut.Analog[2] = MesswertGier; |
739 | // DebugOut.Analog[2] = MesswertGier; |
706 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
740 | DebugOut.Analog[0] = IntegralNick / EE_Parameter.GyroAccFaktor; |
707 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
741 | DebugOut.Analog[1] = IntegralRoll / EE_Parameter.GyroAccFaktor; |
708 | DebugOut.Analog[2] = Mittelwert_AccNick; |
742 | DebugOut.Analog[2] = Mittelwert_AccNick; |
709 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
743 | DebugOut.Analog[3] = Mittelwert_AccRoll; |
710 | DebugOut.Analog[4] = MesswertGier; |
744 | DebugOut.Analog[4] = MesswertGier; |
711 | DebugOut.Analog[5] = HoehenWert; |
745 | DebugOut.Analog[5] = HoehenWert; |
712 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
746 | DebugOut.Analog[6] = (Mess_Integral_Hoch / 512); |
713 | DebugOut.Analog[7] = GasMischanteil; |
747 | DebugOut.Analog[7] = GasMischanteil; |
714 | DebugOut.Analog[8] = KompassValue; |
748 | DebugOut.Analog[8] = KompassValue; |
715 | DebugOut.Analog[9] = Mess_Integral_Gier2; |
749 | DebugOut.Analog[9] = tmp_long; |
- | 750 | DebugOut.Analog[10] = tmp_long2; |
|
716 | // DebugOut.Analog[9] = SollHoehe; |
751 | // DebugOut.Analog[9] = SollHoehe; |
717 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
752 | // DebugOut.Analog[10] = Mess_Integral_Gier / 128; |
718 | // DebugOut.Analog[11] = KompassStartwert; |
753 | // DebugOut.Analog[11] = KompassStartwert; |
719 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
754 | // DebugOut.Analog[10] = Parameter_Gyro_I; |
720 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
755 | // DebugOut.Analog[10] = EE_Parameter.Gyro_I; |
721 | // DebugOut.Analog[9] = KompassRichtung; |
756 | // DebugOut.Analog[9] = KompassRichtung; |
722 | // DebugOut.Analog[10] = GasMischanteil; |
757 | // DebugOut.Analog[10] = GasMischanteil; |
723 | // DebugOut.Analog[3] = HoeheD * 32; |
758 | // DebugOut.Analog[3] = HoeheD * 32; |
724 | // DebugOut.Analog[4] = hoehenregler; |
759 | // DebugOut.Analog[4] = hoehenregler; |
725 | } |
760 | } |
726 | 761 | ||
727 | 762 | ||
728 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
763 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
729 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
764 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
730 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
765 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
731 | MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
766 | MesswertNick = IntegralNick * IntegralFaktor + MesswertNick * GyroFaktor; |
732 | MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
767 | MesswertRoll = IntegralRoll * IntegralFaktor + MesswertRoll * GyroFaktor; |
733 | MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
768 | MesswertGier = MesswertGier * (GyroFaktor/2) + Integral_Gier * IntegralFaktor; |
734 | 769 | ||
735 | // Maximalwerte abfangen |
770 | // Maximalwerte abfangen |
736 | #define MAX_SENSOR 2048 |
771 | #define MAX_SENSOR 2048 |
737 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
772 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
738 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
773 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
739 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
774 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
740 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
775 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
741 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
776 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
742 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
777 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
743 | 778 | ||
744 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
779 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
745 | // Höhenregelung |
780 | // Höhenregelung |
746 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
781 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
747 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
782 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
748 | //OCR0B = 180 - (Poti1 + 120) / 4; |
783 | //OCR0B = 180 - (Poti1 + 120) / 4; |
749 | //DruckOffsetSetting = OCR0B; |
784 | //DruckOffsetSetting = OCR0B; |
750 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
785 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung |
751 | { |
786 | { |
752 | int tmp_int; |
787 | int tmp_int; |
753 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
788 | if(EE_Parameter.GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
754 | { |
789 | { |
755 | if(Parameter_MaxHoehe < 50) |
790 | if(Parameter_MaxHoehe < 50) |
756 | { |
791 | { |
757 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
792 | SollHoehe = HoehenWert - 20; // Parameter_MaxHoehe ist der PPM-Wert des Schalters |
758 | HoehenReglerAktiv = 0; |
793 | HoehenReglerAktiv = 0; |
759 | } |
794 | } |
760 | else |
795 | else |
761 | HoehenReglerAktiv = 1; |
796 | HoehenReglerAktiv = 1; |
762 | } |
797 | } |
763 | else |
798 | else |
764 | { |
799 | { |
765 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
800 | SollHoehe = Parameter_MaxHoehe * EE_Parameter.Hoehe_Verstaerkung - 20; |
766 | HoehenReglerAktiv = 1; |
801 | HoehenReglerAktiv = 1; |
767 | } |
802 | } |
768 | 803 | ||
769 | if(Notlandung) SollHoehe = 0; |
804 | if(Notlandung) SollHoehe = 0; |
770 | h = HoehenWert; |
805 | h = HoehenWert; |
771 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
806 | if((h > SollHoehe) && HoehenReglerAktiv) // zu hoch --> drosseln |
772 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
807 | { h = ((h - SollHoehe) * (int) Parameter_Hoehe_P) / 16; // Differenz bestimmen --> P-Anteil |
773 | h = GasMischanteil - h; // vom Gas abziehen |
808 | h = GasMischanteil - h; // vom Gas abziehen |
774 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
809 | h -= (HoeheD * Parameter_Luftdruck_D)/8; // D-Anteil |
775 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
810 | tmp_int = ((Mess_Integral_Hoch / 512) * (signed long) Parameter_Hoehe_ACC_Wirkung) / 32; |
776 | if(tmp_int > 50) tmp_int = 50; |
811 | if(tmp_int > 50) tmp_int = 50; |
777 | else if(tmp_int < -50) tmp_int = -50; |
812 | else if(tmp_int < -50) tmp_int = -50; |
778 | h -= tmp_int; |
813 | h -= tmp_int; |
779 | hoehenregler = (hoehenregler*15 + h) / 16; |
814 | hoehenregler = (hoehenregler*15 + h) / 16; |
780 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
815 | if(hoehenregler < EE_Parameter.Hoehe_MinGas) // nicht unter MIN |
781 | { |
816 | { |
782 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
817 | if(GasMischanteil >= EE_Parameter.Hoehe_MinGas) hoehenregler = EE_Parameter.Hoehe_MinGas; |
783 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
818 | if(GasMischanteil < EE_Parameter.Hoehe_MinGas) hoehenregler = GasMischanteil; |
784 | } |
819 | } |
785 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
820 | if(hoehenregler > GasMischanteil) hoehenregler = GasMischanteil; // nicht mehr als Gas |
786 | GasMischanteil = hoehenregler; |
821 | GasMischanteil = hoehenregler; |
787 | } |
822 | } |
788 | } |
823 | } |
789 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
824 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
790 | // + Mischer und PI-Regler |
825 | // + Mischer und PI-Regler |
791 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
826 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
792 | 827 | ||
793 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
828 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
794 | // Gier-Anteil |
829 | // Gier-Anteil |
795 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
830 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
796 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
831 | GierMischanteil = MesswertGier - sollGier; // Regler für Gier |
797 | if(GierMischanteil > 100) GierMischanteil = 100; |
832 | if(GierMischanteil > 100) GierMischanteil = 100; |
798 | if(GierMischanteil < -100) GierMischanteil = -100; |
833 | if(GierMischanteil < -100) GierMischanteil = -100; |
799 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
834 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
800 | // Nick-Achse |
835 | // Nick-Achse |
801 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
836 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
802 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
837 | DiffNick = Kp * (MesswertNick - (StickNick - GPS_Nick)); // Differenz bestimmen |
803 | SummeNick += DiffNick; // I-Anteil |
838 | SummeNick += DiffNick; // I-Anteil |
804 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
839 | if(SummeNick > 0) SummeNick-= (abs(SummeNick)/256 + 1); else SummeNick += abs(SummeNick)/256 + 1; |
805 | if(SummeNick > 16000) SummeNick = 16000; |
840 | if(SummeNick > 16000) SummeNick = 16000; |
806 | if(SummeNick < -16000) SummeNick = -16000; |
841 | if(SummeNick < -16000) SummeNick = -16000; |
807 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
842 | pd_ergebnis = DiffNick + Ki * SummeNick; // PI-Regler für Nick |
808 | // Motor Vorn |
843 | // Motor Vorn |
809 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
844 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; // Mischer |
810 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
845 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
811 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
846 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
812 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
847 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
813 | Motor_Vorne = motorwert; |
848 | Motor_Vorne = motorwert; |
814 | // Motor Heck |
849 | // Motor Heck |
815 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
850 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
816 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
851 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
817 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
852 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
818 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
853 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
819 | Motor_Hinten = motorwert; |
854 | Motor_Hinten = motorwert; |
820 | 855 | ||
821 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
856 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
822 | // Roll-Achse |
857 | // Roll-Achse |
823 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
858 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
824 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
859 | DiffRoll = Kp * (MesswertRoll - (StickRoll - GPS_Roll)); // Differenz bestimmen |
825 | SummeRoll += DiffRoll; // I-Anteil |
860 | SummeRoll += DiffRoll; // I-Anteil |
826 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
861 | if(SummeRoll > 0) SummeRoll-= (abs(SummeRoll)/256 + 1); else SummeRoll += abs(SummeRoll)/256 + 1; |
827 | if(SummeRoll > 16000) SummeRoll = 16000; |
862 | if(SummeRoll > 16000) SummeRoll = 16000; |
828 | if(SummeRoll < -16000) SummeRoll = -16000; |
863 | if(SummeRoll < -16000) SummeRoll = -16000; |
829 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
864 | pd_ergebnis = DiffRoll + Ki * SummeRoll; // PI-Regler für Roll |
830 | // Motor Links |
865 | // Motor Links |
831 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
866 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
832 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
867 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
833 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
868 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
834 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
869 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
835 | Motor_Links = motorwert; |
870 | Motor_Links = motorwert; |
836 | // Motor Rechts |
871 | // Motor Rechts |
837 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
872 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
838 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
873 | if ((motorwert < 0) | (GasMischanteil < 10)) motorwert = 0; |
839 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
874 | else if(motorwert > MAX_GAS) motorwert = MAX_GAS; |
840 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
875 | if (motorwert < MIN_GAS) motorwert = MIN_GAS; |
841 | Motor_Rechts = motorwert; |
876 | Motor_Rechts = motorwert; |
842 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
877 | // +++++++++++++++++++++++++++++++++++++++++++++++ |
843 | 878 | ||
844 | } |
879 | } |
845 | 880 | ||
846 | 881 |