Rev 2045 | Rev 2049 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2045 | Rev 2048 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + Nur für den privaten Gebrauch |
3 | // + Nur für den privaten Gebrauch |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt werden |
18 | // + eindeutig als Ursprung verlinkt werden |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Benutzung auf eigene Gefahr |
21 | // + Benutzung auf eigene Gefahr |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
25 | // + mit unserer Zustimmung zulässig |
25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
30 | // + this list of conditions and the following disclaimer. |
30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
32 | // + from this software without specific prior written permission. |
32 | // + from this software without specific prior written permission. |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
34 | // + for non-commercial use (directly or indirectly) |
34 | // + for non-commercial use (directly or indirectly) |
35 | // + Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + with our written permission |
36 | // + with our written permission |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
38 | // + clearly linked as origin |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | 51 | ||
52 | #include <stdlib.h> |
52 | #include <stdlib.h> |
53 | #include <avr/io.h> |
53 | #include <avr/io.h> |
54 | #include "eeprom.h" |
54 | #include "eeprom.h" |
55 | #include "flight.h" |
55 | #include "flight.h" |
56 | #include "output.h" |
56 | #include "output.h" |
57 | 57 | ||
58 | // Necessary for external control and motor test |
58 | // Necessary for external control and motor test |
59 | #include "uart0.h" |
59 | #include "uart0.h" |
60 | #include "twimaster.h" |
60 | #include "twimaster.h" |
61 | #include "attitude.h" |
61 | #include "attitude.h" |
62 | #include "controlMixer.h" |
62 | #include "controlMixer.h" |
63 | #include "commands.h" |
63 | #include "commands.h" |
64 | 64 | ||
65 | #define CHECK_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;} |
65 | #define CHECK_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;} |
66 | 66 | ||
67 | /* |
67 | /* |
68 | * These are no longer maintained, just left at 0. The original implementation just summed the acc. |
68 | * These are no longer maintained, just left at 0. The original implementation just summed the acc. |
69 | * value to them every 2 ms. No filtering or anything. Just a case for an eventual overflow?? Hey??? |
69 | * value to them every 2 ms. No filtering or anything. Just a case for an eventual overflow?? Hey??? |
70 | */ |
70 | */ |
71 | // int16_t naviAccPitch = 0, naviAccRoll = 0, naviCntAcc = 0; |
71 | // int16_t naviAccPitch = 0, naviAccRoll = 0, naviCntAcc = 0; |
72 | 72 | ||
73 | uint8_t gyroPFactor, gyroIFactor; // the PD factors for the attitude control |
73 | uint8_t gyroPFactor, gyroIFactor; // the PD factors for the attitude control |
74 | uint8_t yawPFactor, yawIFactor; // the PD factors for the yaw control |
74 | uint8_t yawPFactor, yawIFactor; // the PD factors for the yaw control |
75 | 75 | ||
76 | // Some integral weight constant... |
76 | // Some integral weight constant... |
77 | uint16_t Ki = 10300 / 33; |
77 | uint16_t Ki = 10300 / 33; |
78 | 78 | ||
79 | /************************************************************************/ |
79 | /************************************************************************/ |
80 | /* Filter for motor value smoothing (necessary???) */ |
80 | /* Filter for motor value smoothing (necessary???) */ |
81 | /************************************************************************/ |
81 | /************************************************************************/ |
82 | int16_t motorFilter(int16_t newvalue, int16_t oldvalue) { |
82 | int16_t motorFilter(int16_t newvalue, int16_t oldvalue) { |
83 | switch (staticParams.motorSmoothing) { |
83 | switch (staticParams.motorSmoothing) { |
84 | case 0: |
84 | case 0: |
85 | return newvalue; |
85 | return newvalue; |
86 | case 1: |
86 | case 1: |
87 | return (oldvalue + newvalue) / 2; |
87 | return (oldvalue + newvalue) / 2; |
88 | case 2: |
88 | case 2: |
89 | if (newvalue > oldvalue) |
89 | if (newvalue > oldvalue) |
90 | return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new |
90 | return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new |
91 | else |
91 | else |
92 | return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old |
92 | return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old |
93 | case 3: |
93 | case 3: |
94 | if (newvalue < oldvalue) |
94 | if (newvalue < oldvalue) |
95 | return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new |
95 | return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new |
96 | else |
96 | else |
97 | return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old |
97 | return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old |
98 | default: |
98 | default: |
99 | return newvalue; |
99 | return newvalue; |
100 | } |
100 | } |
101 | } |
101 | } |
102 | 102 | ||
103 | /************************************************************************/ |
103 | /************************************************************************/ |
104 | /* Neutral Readings */ |
104 | /* Neutral Readings */ |
105 | /************************************************************************/ |
105 | /************************************************************************/ |
106 | void flight_setNeutral() { |
106 | void flight_setNeutral() { |
107 | MKFlags |= MKFLAG_CALIBRATE; |
107 | MKFlags |= MKFLAG_CALIBRATE; |
108 | // not really used here any more. |
108 | // not really used here any more. |
109 | /* |
109 | /* |
110 | dynamicParams.KalmanK = -1; |
110 | dynamicParams.KalmanK = -1; |
111 | dynamicParams.KalmanMaxDrift = 0; |
111 | dynamicParams.KalmanMaxDrift = 0; |
112 | dynamicParams.KalmanMaxFusion = 32; |
112 | dynamicParams.KalmanMaxFusion = 32; |
113 | */ |
113 | */ |
114 | controlMixer_initVariables(); |
114 | controlMixer_initVariables(); |
115 | } |
115 | } |
116 | 116 | ||
117 | void setFlightParameters(uint8_t _Ki, uint8_t _gyroPFactor, |
117 | void setFlightParameters(uint8_t _Ki, uint8_t _gyroPFactor, |
118 | uint8_t _gyroIFactor, uint8_t _yawPFactor, uint8_t _yawIFactor) { |
118 | uint8_t _gyroIFactor, uint8_t _yawPFactor, uint8_t _yawIFactor) { |
119 | Ki = 10300 / _Ki; |
119 | Ki = 10300 / _Ki; |
120 | gyroPFactor = _gyroPFactor; |
120 | gyroPFactor = _gyroPFactor; |
121 | gyroIFactor = _gyroIFactor; |
121 | gyroIFactor = _gyroIFactor; |
122 | yawPFactor = _yawPFactor; |
122 | yawPFactor = _yawPFactor; |
123 | yawIFactor = _yawIFactor; |
123 | yawIFactor = _yawIFactor; |
124 | } |
124 | } |
125 | 125 | ||
126 | void setNormalFlightParameters(void) { |
126 | void setNormalFlightParameters(void) { |
127 | setFlightParameters( |
127 | setFlightParameters( |
128 | staticParams.IFactor, |
128 | staticParams.IFactor, |
129 | dynamicParams.gyroP, |
129 | dynamicParams.gyroP, |
130 | staticParams.bitConfig & CFG_HEADING_HOLD ? 0 : dynamicParams.gyroI, |
130 | staticParams.bitConfig & CFG_HEADING_HOLD ? 0 : dynamicParams.gyroI, |
131 | dynamicParams.gyroP, |
131 | dynamicParams.gyroP, |
132 | staticParams.yawIFactor |
132 | staticParams.yawIFactor |
133 | ); |
133 | ); |
134 | } |
134 | } |
135 | 135 | ||
136 | void setStableFlightParameters(void) { |
136 | void setStableFlightParameters(void) { |
137 | setFlightParameters(33, 90, 120, 90, 120); |
137 | setFlightParameters(33, 90, 120, 90, 120); |
138 | } |
138 | } |
139 | 139 | ||
140 | /************************************************************************/ |
140 | /************************************************************************/ |
141 | /* Main Flight Control */ |
141 | /* Main Flight Control */ |
142 | /************************************************************************/ |
142 | /************************************************************************/ |
143 | void flight_control(void) { |
143 | void flight_control(void) { |
144 | int16_t tmp_int; |
144 | int16_t tmp_int; |
145 | // Mixer Fractions that are combined for Motor Control |
145 | // Mixer Fractions that are combined for Motor Control |
146 | int16_t yawTerm, throttleTerm, term[2]; |
146 | int16_t yawTerm, throttleTerm, term[2]; |
147 | 147 | ||
148 | // PID controller variables |
148 | // PID controller variables |
149 | int16_t PDPart[2],/* DPart[2],*/ PDPartYaw /*, DPartYaw */; |
149 | int16_t PDPart[2],/* DPart[2],*/ PDPartYaw /*, DPartYaw */; |
150 | static int32_t IPart[2] = { 0, 0 }; |
150 | static int32_t IPart[2] = { 0, 0 }; |
151 | static uint16_t emergencyFlightTime; |
151 | static uint16_t emergencyFlightTime; |
152 | static int8_t debugDataTimer = 1; |
152 | static int8_t debugDataTimer = 1; |
153 | 153 | ||
154 | // High resolution motor values for smoothing of PID motor outputs |
154 | // High resolution motor values for smoothing of PID motor outputs |
155 | static int16_t motorFilters[MAX_MOTORS]; |
155 | static int16_t motorFilters[MAX_MOTORS]; |
156 | 156 | ||
157 | uint8_t i, axis; |
157 | uint8_t i, axis; |
158 | 158 | ||
159 | throttleTerm = controls[CONTROL_THROTTLE]; |
159 | throttleTerm = controls[CONTROL_THROTTLE]; |
160 | 160 | ||
161 | // This check removed. Is done on a per-motor basis, after output matrix multiplication. |
161 | // This check removed. Is done on a per-motor basis, after output matrix multiplication. |
162 | if (throttleTerm < staticParams.minThrottle + 10) |
162 | if (throttleTerm < staticParams.minThrottle + 10) |
163 | throttleTerm = staticParams.minThrottle + 10; |
163 | throttleTerm = staticParams.minThrottle + 10; |
164 | else if (throttleTerm > staticParams.maxThrottle - 20) |
164 | else if (throttleTerm > staticParams.maxThrottle - 20) |
165 | throttleTerm = (staticParams.maxThrottle - 20); |
165 | throttleTerm = (staticParams.maxThrottle - 20); |
166 | 166 | ||
167 | /************************************************************************/ |
167 | /************************************************************************/ |
168 | /* RC-signal is bad */ |
168 | /* RC-signal is bad */ |
169 | /* This part could be abstracted, as having yet another control input */ |
169 | /* This part could be abstracted, as having yet another control input */ |
170 | /* to the control mixer: An emergency autopilot control. */ |
170 | /* to the control mixer: An emergency autopilot control. */ |
171 | /************************************************************************/ |
171 | /************************************************************************/ |
172 | 172 | ||
173 | if (controlMixer_getSignalQuality() <= SIGNAL_BAD) { // the rc-frame signal is not reveived or noisy |
173 | if (controlMixer_getSignalQuality() <= SIGNAL_BAD) { // the rc-frame signal is not reveived or noisy |
174 | if (controlMixer_didReceiveSignal) beepRCAlarm(); |
174 | if (controlMixer_didReceiveSignal) beepRCAlarm(); |
175 | if (emergencyFlightTime) { |
175 | if (emergencyFlightTime) { |
176 | // continue emergency flight |
176 | // continue emergency flight |
177 | emergencyFlightTime--; |
177 | emergencyFlightTime--; |
178 | if (isFlying > 256) { |
178 | if (isFlying > 256) { |
179 | // We're probably still flying. Descend slowly. |
179 | // We're probably still flying. Descend slowly. |
180 | throttleTerm = staticParams.emergencyThrottle; // Set emergency throttle |
180 | throttleTerm = staticParams.emergencyThrottle; // Set emergency throttle |
181 | MKFlags |= (MKFLAG_EMERGENCY_FLIGHT); // Set flag for emergency landing |
181 | MKFlags |= (MKFLAG_EMERGENCY_FLIGHT); // Set flag for emergency landing |
182 | setStableFlightParameters(); |
182 | setStableFlightParameters(); |
183 | } else { |
183 | } else { |
184 | MKFlags &= ~(MKFLAG_MOTOR_RUN); // Probably not flying, and bad R/C signal. Kill motors. |
184 | MKFlags &= ~(MKFLAG_MOTOR_RUN); // Probably not flying, and bad R/C signal. Kill motors. |
185 | } |
185 | } |
186 | } else { |
186 | } else { |
187 | // end emergency flight (just cut the motors???) |
187 | // end emergency flight (just cut the motors???) |
188 | MKFlags &= ~(MKFLAG_MOTOR_RUN | MKFLAG_EMERGENCY_FLIGHT); |
188 | MKFlags &= ~(MKFLAG_MOTOR_RUN | MKFLAG_EMERGENCY_FLIGHT); |
189 | } |
189 | } |
190 | } else { |
190 | } else { |
191 | // signal is acceptable |
191 | // signal is acceptable |
192 | if (controlMixer_getSignalQuality() > SIGNAL_BAD) { |
192 | if (controlMixer_getSignalQuality() > SIGNAL_BAD) { |
193 | // Reset emergency landing control variables. |
193 | // Reset emergency landing control variables. |
194 | MKFlags &= ~(MKFLAG_EMERGENCY_FLIGHT); // clear flag for emergency landing |
194 | MKFlags &= ~(MKFLAG_EMERGENCY_FLIGHT); // clear flag for emergency landing |
195 | // The time is in whole seconds. |
195 | // The time is in whole seconds. |
196 | emergencyFlightTime = (uint16_t) staticParams.emergencyFlightDuration * 488; |
196 | emergencyFlightTime = (uint16_t) staticParams.emergencyFlightDuration * 488; |
197 | } |
197 | } |
198 | 198 | ||
199 | // If some throttle is given, and the motor-run flag is on, increase the probability that we are flying. |
199 | // If some throttle is given, and the motor-run flag is on, increase the probability that we are flying. |
200 | if (throttleTerm > 40 && (MKFlags & MKFLAG_MOTOR_RUN)) { |
200 | if (throttleTerm > 40 && (MKFlags & MKFLAG_MOTOR_RUN)) { |
201 | // increment flight-time counter until overflow. |
201 | // increment flight-time counter until overflow. |
202 | if (isFlying != 0xFFFF) |
202 | if (isFlying != 0xFFFF) |
203 | isFlying++; |
203 | isFlying++; |
204 | } else |
204 | } else |
205 | /* |
205 | /* |
206 | * When standing on the ground, do not apply I controls and zero the yaw stick. |
206 | * When standing on the ground, do not apply I controls and zero the yaw stick. |
207 | * Probably to avoid integration effects that will cause the copter to spin |
207 | * Probably to avoid integration effects that will cause the copter to spin |
208 | * or flip when taking off. |
208 | * or flip when taking off. |
209 | */ |
209 | */ |
210 | if (isFlying < 256) { |
210 | if (isFlying < 256) { |
211 | IPart[PITCH] = IPart[ROLL] = 0; |
211 | IPart[PITCH] = IPart[ROLL] = 0; |
212 | PDPartYaw = 0; |
212 | PDPartYaw = 0; |
213 | if (isFlying == 250) { |
213 | if (isFlying == 250) { |
214 | // HC_setGround(); |
214 | // HC_setGround(); |
215 | updateCompassCourse = 1; |
215 | attitude_resetHeadingToMagnetic(); |
- | 216 | // Set target heading to the one just gotten off compass. |
|
216 | yawAngleDiff = 0; |
217 | targetHeading = heading; |
217 | } |
218 | } |
218 | } else { |
219 | } else { |
219 | // Set fly flag. TODO: Hmmm what can we trust - the isFlying counter or the flag? |
220 | // Set fly flag. TODO: Hmmm what can we trust - the isFlying counter or the flag? |
220 | // Answer: The counter. The flag is not read from anywhere anyway... except the NC maybe. |
221 | // Answer: The counter. The flag is not read from anywhere anyway... except the NC maybe. |
221 | MKFlags |= (MKFLAG_FLY); |
222 | MKFlags |= (MKFLAG_FLY); |
222 | } |
223 | } |
223 | 224 | ||
224 | commands_handleCommands(); |
225 | commands_handleCommands(); |
225 | setNormalFlightParameters(); |
226 | setNormalFlightParameters(); |
226 | } // end else (not bad signal case) |
227 | } // end else (not bad signal case) |
227 | 228 | ||
228 | /************************************************************************/ |
229 | /************************************************************************/ |
229 | /* Yawing */ |
230 | /* Yawing */ |
230 | /************************************************************************/ |
231 | /************************************************************************/ |
- | 232 | /* |
|
231 | if (abs(controls[CONTROL_YAW]) > 4 * staticParams.stickYawP) { // yaw stick is activated |
233 | if (abs(controls[CONTROL_YAW]) > 4 * staticParams.stickYawP) { // yaw stick is activated |
232 | ignoreCompassTimer = 1000; |
234 | ignoreCompassTimer = 1000; |
233 | if (!(staticParams.bitConfig & CFG_COMPASS_FIX)) { |
235 | if (!(staticParams.bitConfig & CFG_COMPASS_FIX)) { |
234 | updateCompassCourse = 1; |
236 | //targetHeading = heading; |
- | 237 | // YGBSM!!! |
|
235 | } |
238 | } |
236 | } |
239 | } |
- | 240 | */ |
|
237 | - | ||
238 | // yawControlRate = controlYaw; |
- | |
239 | // Trim drift of yawAngleDiff with controlYaw. |
- | |
240 | // TODO: We want NO feedback of control related stuff to the attitude related stuff. |
- | |
241 | // This seems to be used as: Difference desired <--> real heading. |
241 | |
242 | yawAngleDiff -= controls[CONTROL_YAW]; |
- | |
243 | - | ||
244 | // limit the effect |
- | |
245 | CHECK_MIN_MAX(yawAngleDiff, -50000, 50000); |
- | |
246 | - | ||
247 | /************************************************************************/ |
- | |
248 | /* Compass is currently not supported. */ |
- | |
249 | /************************************************************************/ |
242 | targetHeading -= controls[CONTROL_YAW]; |
250 | if (staticParams.bitConfig & (CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE)) { |
- | |
251 | updateCompass(); |
243 | |
252 | } |
244 | debugOut.analog[28] = targetHeading; |
253 | 245 | ||
254 | #if defined (USE_NAVICTRL) |
246 | #if defined (USE_NAVICTRL) |
255 | /************************************************************************/ |
247 | /************************************************************************/ |
256 | /* GPS is currently not supported. */ |
248 | /* GPS is currently not supported. */ |
257 | /************************************************************************/ |
249 | /************************************************************************/ |
258 | if(staticParams.GlobalConfig & CFG_GPS_ACTIVE) { |
250 | if(staticParams.GlobalConfig & CFG_GPS_ACTIVE) { |
259 | GPS_Main(); |
251 | GPS_Main(); |
260 | MKFlags &= ~(MKFLAG_CALIBRATE | MKFLAG_START); |
252 | MKFlags &= ~(MKFLAG_CALIBRATE | MKFLAG_START); |
261 | } else { |
253 | } else { |
262 | } |
254 | } |
263 | #endif |
255 | #endif |
264 | // end part 1: 750-800 usec. |
256 | // end part 1: 750-800 usec. |
265 | // start part 3: 350 - 400 usec. |
257 | // start part 3: 350 - 400 usec. |
266 | #define SENSOR_LIMIT (4096 * 4) |
258 | #define SENSOR_LIMIT (4096 * 4) |
267 | /************************************************************************/ |
259 | /************************************************************************/ |
268 | 260 | ||
269 | /* Calculate control feedback from angle (gyro integral) */ |
261 | /* Calculate control feedback from angle (gyro integral) */ |
270 | /* and angular velocity (gyro signal) */ |
262 | /* and angular velocity (gyro signal) */ |
271 | /************************************************************************/ |
263 | /************************************************************************/ |
272 | // The P-part is the P of the PID controller. That's the angle integrals (not rates). |
264 | // The P-part is the P of the PID controller. That's the angle integrals (not rates). |
273 | for (axis = PITCH; axis <= ROLL; axis++) { |
265 | for (axis = PITCH; axis <= ROLL; axis++) { |
274 | PDPart[axis] = angle[axis] * gyroIFactor / (44000 / CONTROL_SCALING); // P-Part - Proportional to Integral |
266 | PDPart[axis] = attitude[axis] * gyroIFactor / (44000 / CONTROL_SCALING); // P-Part - Proportional to Integral |
275 | PDPart[axis] += ((int32_t) rate_PID[axis] * gyroPFactor / (256L / CONTROL_SCALING)); |
267 | PDPart[axis] += ((int32_t) rate_PID[axis] * gyroPFactor / (256L / CONTROL_SCALING)); |
276 | PDPart[axis] += (differential[axis] * (int16_t) dynamicParams.gyroD) / 16; |
268 | PDPart[axis] += (differential[axis] * (int16_t) dynamicParams.gyroD) / 16; |
277 | CHECK_MIN_MAX(PDPart[axis], -SENSOR_LIMIT, SENSOR_LIMIT); |
269 | CHECK_MIN_MAX(PDPart[axis], -SENSOR_LIMIT, SENSOR_LIMIT); |
278 | } |
270 | } |
- | 271 | ||
- | 272 | int32_t headingDiff = heading - targetHeading; // apparently yaw is reverse on output. |
|
- | 273 | if (headingDiff > YAWOVER180) headingDiff -= YAWOVER360; |
|
- | 274 | else if (headingDiff <= -YAWOVER180) headingDiff += YAWOVER360; |
|
- | 275 | ||
- | 276 | // TODO: Not quite right: We want to limit targetHeading to be max. 50000 from heading. This is the wrong var. fixed. |
|
- | 277 | CHECK_MIN_MAX(headingDiff, -50000, 50000); |
|
- | 278 | debugOut.analog[29] = headingDiff; |
|
279 | 279 | ||
280 | PDPartYaw = (int32_t) (yawAngleDiff * yawIFactor) / (2 * (44000 / CONTROL_SCALING)); |
280 | PDPartYaw = (int32_t) (headingDiff * yawIFactor) / (2 * (44000 / CONTROL_SCALING)); |
281 | PDPartYaw += (int32_t) (yawRate * 2 * (int32_t) yawPFactor) / (256L / CONTROL_SCALING); |
281 | PDPartYaw += (int32_t) (yawRate * 2 * (int32_t) yawPFactor) / (256L / CONTROL_SCALING); |
282 | 282 | ||
283 | // limit control feedback |
283 | // limit control feedback |
284 | // CHECK_MIN_MAX(PDPartYaw, -SENSOR_LIMIT, SENSOR_LIMIT); |
284 | // CHECK_MIN_MAX(PDPartYaw, -SENSOR_LIMIT, SENSOR_LIMIT); |
285 | 285 | ||
286 | /* |
286 | /* |
287 | * Compose throttle term. |
287 | * Compose throttle term. |
288 | * If a Bl-Ctrl is missing, prevent takeoff. |
288 | * If a Bl-Ctrl is missing, prevent takeoff. |
289 | */ |
289 | */ |
290 | if (missingMotor) { |
290 | if (missingMotor) { |
291 | // if we are in the lift off condition. Hmmmmmm when is throttleTerm == 0 anyway??? |
291 | // if we are in the lift off condition. Hmmmmmm when is throttleTerm == 0 anyway??? |
292 | if (isFlying > 1 && isFlying < 50 && throttleTerm > 0) |
292 | if (isFlying > 1 && isFlying < 50 && throttleTerm > 0) |
293 | isFlying = 1; // keep within lift off condition |
293 | isFlying = 1; // keep within lift off condition |
294 | throttleTerm = staticParams.minThrottle; // reduce gas to min to avoid lift of |
294 | throttleTerm = staticParams.minThrottle; // reduce gas to min to avoid lift of |
295 | } |
295 | } |
296 | 296 | ||
297 | // Scale up to higher resolution. Hmm why is it not (from controlMixer and down) scaled already? |
297 | // Scale up to higher resolution. Hmm why is it not (from controlMixer and down) scaled already? |
298 | throttleTerm *= CONTROL_SCALING; |
298 | throttleTerm *= CONTROL_SCALING; |
299 | 299 | ||
300 | /* |
300 | /* |
301 | * Compose yaw term. |
301 | * Compose yaw term. |
302 | * The yaw term is limited: Absolute value is max. = the throttle term / 2. |
302 | * The yaw term is limited: Absolute value is max. = the throttle term / 2. |
303 | * However, at low throttle the yaw term is limited to a fixed value, |
303 | * However, at low throttle the yaw term is limited to a fixed value, |
304 | * and at high throttle it is limited by the throttle reserve (the difference |
304 | * and at high throttle it is limited by the throttle reserve (the difference |
305 | * between current throttle and maximum throttle). |
305 | * between current throttle and maximum throttle). |
306 | */ |
306 | */ |
307 | #define MIN_YAWGAS (40 * CONTROL_SCALING) // yaw also below this gas value |
307 | #define MIN_YAWGAS (40 * CONTROL_SCALING) // yaw also below this gas value |
308 | yawTerm = PDPartYaw - controls[CONTROL_YAW] * CONTROL_SCALING; |
308 | yawTerm = PDPartYaw - controls[CONTROL_YAW] * CONTROL_SCALING; |
309 | // Limit yawTerm |
309 | // Limit yawTerm |
310 | debugOut.digital[0] &= ~DEBUG_CLIP; |
310 | debugOut.digital[0] &= ~DEBUG_CLIP; |
311 | if (throttleTerm > MIN_YAWGAS) { |
311 | if (throttleTerm > MIN_YAWGAS) { |
312 | if (yawTerm < -throttleTerm / 2) { |
312 | if (yawTerm < -throttleTerm / 2) { |
313 | debugOut.digital[0] |= DEBUG_CLIP; |
313 | debugOut.digital[0] |= DEBUG_CLIP; |
314 | yawTerm = -throttleTerm / 2; |
314 | yawTerm = -throttleTerm / 2; |
315 | } else if (yawTerm > throttleTerm / 2) { |
315 | } else if (yawTerm > throttleTerm / 2) { |
316 | debugOut.digital[0] |= DEBUG_CLIP; |
316 | debugOut.digital[0] |= DEBUG_CLIP; |
317 | yawTerm = throttleTerm / 2; |
317 | yawTerm = throttleTerm / 2; |
318 | } |
318 | } |
319 | } else { |
319 | } else { |
320 | if (yawTerm < -MIN_YAWGAS / 2) { |
320 | if (yawTerm < -MIN_YAWGAS / 2) { |
321 | debugOut.digital[0] |= DEBUG_CLIP; |
321 | debugOut.digital[0] |= DEBUG_CLIP; |
322 | yawTerm = -MIN_YAWGAS / 2; |
322 | yawTerm = -MIN_YAWGAS / 2; |
323 | } else if (yawTerm > MIN_YAWGAS / 2) { |
323 | } else if (yawTerm > MIN_YAWGAS / 2) { |
324 | debugOut.digital[0] |= DEBUG_CLIP; |
324 | debugOut.digital[0] |= DEBUG_CLIP; |
325 | yawTerm = MIN_YAWGAS / 2; |
325 | yawTerm = MIN_YAWGAS / 2; |
326 | } |
326 | } |
327 | } |
327 | } |
328 | 328 | ||
329 | tmp_int = staticParams.maxThrottle * CONTROL_SCALING; |
329 | tmp_int = staticParams.maxThrottle * CONTROL_SCALING; |
330 | if (yawTerm < -(tmp_int - throttleTerm)) { |
330 | if (yawTerm < -(tmp_int - throttleTerm)) { |
331 | yawTerm = -(tmp_int - throttleTerm); |
331 | yawTerm = -(tmp_int - throttleTerm); |
332 | debugOut.digital[0] |= DEBUG_CLIP; |
332 | debugOut.digital[0] |= DEBUG_CLIP; |
333 | } else if (yawTerm > (tmp_int - throttleTerm)) { |
333 | } else if (yawTerm > (tmp_int - throttleTerm)) { |
334 | yawTerm = (tmp_int - throttleTerm); |
334 | yawTerm = (tmp_int - throttleTerm); |
335 | debugOut.digital[0] |= DEBUG_CLIP; |
335 | debugOut.digital[0] |= DEBUG_CLIP; |
336 | } |
336 | } |
337 | 337 | ||
338 | // CHECK_MIN_MAX(yawTerm, -(tmp_int - throttleTerm), (tmp_int - throttleTerm)); |
338 | // CHECK_MIN_MAX(yawTerm, -(tmp_int - throttleTerm), (tmp_int - throttleTerm)); |
339 | debugOut.digital[1] &= ~DEBUG_CLIP; |
339 | debugOut.digital[1] &= ~DEBUG_CLIP; |
340 | for (axis = PITCH; axis <= ROLL; axis++) { |
340 | for (axis = PITCH; axis <= ROLL; axis++) { |
341 | /* |
341 | /* |
342 | * Compose pitch and roll terms. This is finally where the sticks come into play. |
342 | * Compose pitch and roll terms. This is finally where the sticks come into play. |
343 | */ |
343 | */ |
344 | if (gyroIFactor) { |
344 | if (gyroIFactor) { |
345 | // Integration mode: Integrate (angle - stick) = the difference between angle and stick pos. |
345 | // Integration mode: Integrate (angle - stick) = the difference between angle and stick pos. |
346 | // That means: Holding the stick a little forward will, at constant flight attitude, cause this to grow (decline??) over time. |
346 | // That means: Holding the stick a little forward will, at constant flight attitude, cause this to grow (decline??) over time. |
347 | // TODO: Find out why this seems to be proportional to stick position - not integrating it at all. |
347 | // TODO: Find out why this seems to be proportional to stick position - not integrating it at all. |
348 | IPart[axis] += PDPart[axis] - controls[axis]; // Integrate difference between P part (the angle) and the stick pos. |
348 | IPart[axis] += PDPart[axis] - controls[axis]; // Integrate difference between P part (the angle) and the stick pos. |
349 | } else { |
349 | } else { |
350 | // "HH" mode: Integrate (rate - stick) = the difference between rotation rate and stick pos. |
350 | // "HH" mode: Integrate (rate - stick) = the difference between rotation rate and stick pos. |
351 | // To keep up with a full stick PDPart should be about 156... |
351 | // To keep up with a full stick PDPart should be about 156... |
352 | IPart[axis] += PDPart[axis] - controls[axis]; // With gyroIFactor == 0, PDPart is really just a D-part. Integrate D-part (the rot. rate) and the stick pos. |
352 | IPart[axis] += PDPart[axis] - controls[axis]; // With gyroIFactor == 0, PDPart is really just a D-part. Integrate D-part (the rot. rate) and the stick pos. |
353 | } |
353 | } |
354 | 354 | ||
355 | tmp_int = (int32_t) ((int32_t) dynamicParams.dynamicStability |
355 | tmp_int = (int32_t) ((int32_t) dynamicParams.dynamicStability |
356 | * (int32_t) (throttleTerm + abs(yawTerm) / 2)) / 64; |
356 | * (int32_t) (throttleTerm + abs(yawTerm) / 2)) / 64; |
357 | 357 | ||
358 | // TODO: From which planet comes the 16000? |
358 | // TODO: From which planet comes the 16000? |
359 | CHECK_MIN_MAX(IPart[axis], -(CONTROL_SCALING * 16000L), (CONTROL_SCALING * 16000L)); |
359 | CHECK_MIN_MAX(IPart[axis], -(CONTROL_SCALING * 16000L), (CONTROL_SCALING * 16000L)); |
360 | // Add (P, D) parts minus stick pos. to the scaled-down I part. |
360 | // Add (P, D) parts minus stick pos. to the scaled-down I part. |
361 | term[axis] = PDPart[axis] - controls[axis] + IPart[axis] / Ki; // PID-controller for pitch |
361 | term[axis] = PDPart[axis] - controls[axis] + IPart[axis] / Ki; // PID-controller for pitch |
362 | term[axis] += (dynamicParams.levelCorrection[axis] - 128); |
362 | term[axis] += (dynamicParams.levelCorrection[axis] - 128); |
363 | /* |
363 | /* |
364 | * Apply "dynamic stability" - that is: Limit pitch and roll terms to a growing function of throttle and yaw(!). |
364 | * Apply "dynamic stability" - that is: Limit pitch and roll terms to a growing function of throttle and yaw(!). |
365 | * The higher the dynamic stability parameter, the wider the bounds. 64 seems to be a kind of unity |
365 | * The higher the dynamic stability parameter, the wider the bounds. 64 seems to be a kind of unity |
366 | * (max. pitch or roll term is the throttle value). |
366 | * (max. pitch or roll term is the throttle value). |
367 | * TODO: Why a growing function of yaw? |
367 | * TODO: Why a growing function of yaw? |
368 | */ |
368 | */ |
369 | if (term[axis] < -tmp_int) { |
369 | if (term[axis] < -tmp_int) { |
370 | debugOut.digital[1] |= DEBUG_CLIP; |
370 | debugOut.digital[1] |= DEBUG_CLIP; |
371 | } else if (term[axis] > tmp_int) { |
371 | } else if (term[axis] > tmp_int) { |
372 | debugOut.digital[1] |= DEBUG_CLIP; |
372 | debugOut.digital[1] |= DEBUG_CLIP; |
373 | } |
373 | } |
374 | } |
374 | } |
375 | 375 | ||
376 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
376 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
377 | // Universal Mixer |
377 | // Universal Mixer |
378 | // Each (pitch, roll, throttle, yaw) term is in the range [0..255 * CONTROL_SCALING]. |
378 | // Each (pitch, roll, throttle, yaw) term is in the range [0..255 * CONTROL_SCALING]. |
379 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
379 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
380 | 380 | ||
381 | debugOut.analog[3] = rate_ATT[PITCH]; |
381 | debugOut.analog[3] = rate_ATT[PITCH]; |
382 | debugOut.analog[4] = rate_ATT[ROLL]; |
382 | debugOut.analog[4] = rate_ATT[ROLL]; |
383 | debugOut.analog[5] = yawRate; |
383 | debugOut.analog[5] = yawRate; |
384 | 384 | ||
385 | debugOut.analog[6] = filteredAcc[PITCH]; |
385 | debugOut.analog[6] = filteredAcc[PITCH]; |
386 | debugOut.analog[7] = filteredAcc[ROLL]; |
386 | debugOut.analog[7] = filteredAcc[ROLL]; |
387 | debugOut.analog[8] = filteredAcc[Z]; |
387 | debugOut.analog[8] = filteredAcc[Z]; |
388 | 388 | ||
389 | debugOut.analog[13] = term[PITCH]; |
389 | debugOut.analog[13] = term[PITCH]; |
390 | debugOut.analog[14] = term[ROLL]; |
390 | debugOut.analog[14] = term[ROLL]; |
391 | debugOut.analog[15] = yawTerm; |
391 | debugOut.analog[15] = yawTerm; |
392 | debugOut.analog[16] = throttleTerm; |
392 | debugOut.analog[16] = throttleTerm; |
393 | 393 | ||
394 | for (i = 0; i < MAX_MOTORS; i++) { |
394 | for (i = 0; i < MAX_MOTORS; i++) { |
395 | int32_t tmp; |
395 | int32_t tmp; |
396 | uint8_t throttle; |
396 | uint8_t throttle; |
397 | 397 | ||
398 | tmp = (int32_t)throttleTerm * mixerMatrix.motor[i][MIX_THROTTLE]; |
398 | tmp = (int32_t)throttleTerm * mixerMatrix.motor[i][MIX_THROTTLE]; |
399 | tmp += (int32_t)term[PITCH] * mixerMatrix.motor[i][MIX_PITCH]; |
399 | tmp += (int32_t)term[PITCH] * mixerMatrix.motor[i][MIX_PITCH]; |
400 | tmp += (int32_t)term[ROLL] * mixerMatrix.motor[i][MIX_ROLL]; |
400 | tmp += (int32_t)term[ROLL] * mixerMatrix.motor[i][MIX_ROLL]; |
401 | tmp += (int32_t)yawTerm * mixerMatrix.motor[i][MIX_YAW]; |
401 | tmp += (int32_t)yawTerm * mixerMatrix.motor[i][MIX_YAW]; |
402 | tmp = tmp >> 6; |
402 | tmp = tmp >> 6; |
403 | motorFilters[i] = motorFilter(tmp, motorFilters[i]); |
403 | motorFilters[i] = motorFilter(tmp, motorFilters[i]); |
404 | // Now we scale back down to a 0..255 range. |
404 | // Now we scale back down to a 0..255 range. |
405 | tmp = motorFilters[i] / MOTOR_SCALING; |
405 | tmp = motorFilters[i] / MOTOR_SCALING; |
406 | 406 | ||
407 | // So this was the THIRD time a throttle was limited. But should the limitation |
407 | // So this was the THIRD time a throttle was limited. But should the limitation |
408 | // apply to the common throttle signal (the one used for setting the "power" of |
408 | // apply to the common throttle signal (the one used for setting the "power" of |
409 | // all motors together) or should it limit the throttle set for each motor, |
409 | // all motors together) or should it limit the throttle set for each motor, |
410 | // including mix components of pitch, roll and yaw? I think only the common |
410 | // including mix components of pitch, roll and yaw? I think only the common |
411 | // throttle should be limited. |
411 | // throttle should be limited. |
412 | // --> WRONG. This caused motors to stall completely in tight maneuvers. |
412 | // --> WRONG. This caused motors to stall completely in tight maneuvers. |
413 | // Apply to individual signals instead. |
413 | // Apply to individual signals instead. |
414 | CHECK_MIN_MAX(tmp, 1, 255); |
414 | CHECK_MIN_MAX(tmp, 1, 255); |
415 | throttle = tmp; |
415 | throttle = tmp; |
416 | 416 | ||
417 | // if (i < 4) debugOut.analog[22 + i] = throttle; |
417 | // if (i < 4) debugOut.analog[22 + i] = throttle; |
418 | 418 | ||
419 | if ((MKFlags & MKFLAG_MOTOR_RUN) && mixerMatrix.motor[i][MIX_THROTTLE] > 0) { |
419 | if ((MKFlags & MKFLAG_MOTOR_RUN) && mixerMatrix.motor[i][MIX_THROTTLE] > 0) { |
420 | motor[i].throttle = throttle; |
420 | motor[i].throttle = throttle; |
421 | } else if (motorTestActive) { |
421 | } else if (motorTestActive) { |
422 | motor[i].throttle = motorTest[i]; |
422 | motor[i].throttle = motorTest[i]; |
423 | } else { |
423 | } else { |
424 | motor[i].throttle = 0; |
424 | motor[i].throttle = 0; |
425 | } |
425 | } |
426 | } |
426 | } |
427 | 427 | ||
428 | I2C_Start(TWI_STATE_MOTOR_TX); |
428 | I2C_Start(TWI_STATE_MOTOR_TX); |
429 | 429 | ||
430 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
430 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
431 | // Debugging |
431 | // Debugging |
432 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
432 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
433 | if (!(--debugDataTimer)) { |
433 | if (!(--debugDataTimer)) { |
434 | debugDataTimer = 24; // update debug outputs at 488 / 24 = 20.3 Hz. |
434 | debugDataTimer = 24; // update debug outputs at 488 / 24 = 20.3 Hz. |
435 | debugOut.analog[0] = angle[PITCH] / (GYRO_DEG_FACTOR_PITCHROLL/10); // in 0.1 deg |
435 | debugOut.analog[0] = attitude[PITCH] / (GYRO_DEG_FACTOR_PITCHROLL/10); // in 0.1 deg |
436 | debugOut.analog[1] = angle[ROLL] / (GYRO_DEG_FACTOR_PITCHROLL/10); // in 0.1 deg |
436 | debugOut.analog[1] = attitude[ROLL] / (GYRO_DEG_FACTOR_PITCHROLL/10); // in 0.1 deg |
437 | debugOut.analog[2] = yawGyroHeading / GYRO_DEG_FACTOR_YAW; |
437 | debugOut.analog[2] = heading / GYRO_DEG_FACTOR_YAW; |
438 | } |
438 | } |
439 | } |
439 | } |
440 | 440 |