Rev 2039 | Rev 2048 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2039 | Rev 2045 | ||
---|---|---|---|
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 und nicht-kommerziellen Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur f�r den privaten und 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 Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
18 | // + eindeutig als Ursprung verlinkt und genannt 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 |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include <stdlib.h> |
52 | #include <stdlib.h> |
53 | #include "controlMixer.h" |
53 | #include "controlMixer.h" |
54 | #include "rc.h" |
54 | #include "rc.h" |
55 | #include "heightControl.h" |
55 | #include "heightControl.h" |
56 | #include "attitudeControl.h" |
56 | #include "attitudeControl.h" |
57 | #include "externalControl.h" |
57 | #include "externalControl.h" |
58 | #include "naviControl.h" |
58 | #include "naviControl.h" |
59 | #include "configuration.h" |
59 | #include "configuration.h" |
60 | #include "attitude.h" |
60 | #include "attitude.h" |
61 | #include "commands.h" |
61 | #include "commands.h" |
62 | #include "output.h" |
62 | #include "output.h" |
63 | 63 | ||
64 | // uint16_t maxControl[2] = { 0, 0 }; |
64 | // uint16_t maxControl[2] = { 0, 0 }; |
65 | uint16_t controlActivity = 0; |
65 | uint16_t controlActivity = 0; |
66 | int16_t controls[4] = { 0, 0, 0, 0 }; |
66 | int16_t controls[4] = { 0, 0, 0, 0 }; |
67 | 67 | ||
68 | // Internal variables for reading commands made with an R/C stick. |
68 | // Internal variables for reading commands made with an R/C stick. |
69 | uint8_t lastCommand = COMMAND_NONE; |
69 | uint8_t lastCommand = COMMAND_NONE; |
70 | uint8_t lastArgument; |
70 | uint8_t lastArgument; |
71 | 71 | ||
72 | uint8_t isCommandRepeated = 0; |
72 | uint8_t isCommandRepeated = 0; |
73 | uint8_t controlMixer_didReceiveSignal = 0; |
73 | uint8_t controlMixer_didReceiveSignal = 0; |
74 | 74 | ||
75 | /* |
75 | /* |
76 | * This could be expanded to take arguments from ohter sources than the RC |
76 | * This could be expanded to take arguments from ohter sources than the RC |
77 | * (read: Custom MK RC project) |
77 | * (read: Custom MK RC project) |
78 | */ |
78 | */ |
79 | uint8_t controlMixer_getArgument(void) { |
79 | uint8_t controlMixer_getArgument(void) { |
80 | return lastArgument; |
80 | return lastArgument; |
81 | } |
81 | } |
82 | 82 | ||
83 | /* |
83 | /* |
84 | * This could be expanded to take calibrate / start / stop commands from ohter sources |
84 | * This could be expanded to take calibrate / start / stop commands from ohter sources |
85 | * than the R/C (read: Custom MK R/C project) |
85 | * than the R/C (read: Custom MK R/C project) |
86 | */ |
86 | */ |
87 | uint8_t controlMixer_getCommand(void) { |
87 | uint8_t controlMixer_getCommand(void) { |
88 | return lastCommand; |
88 | return lastCommand; |
89 | } |
89 | } |
90 | 90 | ||
91 | uint8_t controlMixer_isCommandRepeated(void) { |
91 | uint8_t controlMixer_isCommandRepeated(void) { |
92 | return isCommandRepeated; |
92 | return isCommandRepeated; |
93 | } |
93 | } |
94 | 94 | ||
95 | void controlMixer_setNeutral() { |
95 | void controlMixer_setNeutral() { |
96 | for (uint8_t i=0; i<VARIABLE_COUNT; i++) { |
96 | for (uint8_t i=0; i<VARIABLE_COUNT; i++) { |
97 | variables[i] = 0; |
97 | variables[i] = 0; |
98 | } |
98 | } |
99 | EC_setNeutral(); |
99 | EC_setNeutral(); |
100 | HC_setGround(); |
100 | HC_setGround(); |
101 | } |
101 | } |
102 | 102 | ||
103 | /* |
103 | /* |
104 | * Set the potientiometer values to the momentary values of the respective R/C channels. |
104 | * Set the potientiometer values to the momentary values of the respective R/C channels. |
105 | * No slew rate limitation. |
105 | * No slew rate limitation. |
106 | */ |
106 | */ |
107 | void controlMixer_initVariables(void) { |
107 | void controlMixer_initVariables(void) { |
108 | uint8_t i; |
108 | uint8_t i; |
109 | for (i=0; i < VARIABLE_COUNT; i++) { |
109 | for (i=0; i < VARIABLE_COUNT; i++) { |
110 | variables[i] = RC_getVariable(i); |
110 | variables[i] = RC_getVariable(i); |
111 | } |
111 | } |
112 | } |
112 | } |
113 | 113 | ||
114 | /* |
114 | /* |
115 | * Update potentiometer values with limited slew rate. Could be made faster if desired. |
115 | * Update potentiometer values with limited slew rate. Could be made faster if desired. |
116 | * TODO: It assumes R/C as source. Not necessarily true. |
116 | * TODO: It assumes R/C as source. Not necessarily true. |
117 | */ |
117 | */ |
118 | void controlMixer_updateVariables(void) { |
118 | void controlMixer_updateVariables(void) { |
119 | uint8_t i; |
119 | uint8_t i; |
120 | int16_t targetvalue; |
120 | int16_t targetvalue; |
121 | for (i=0; i < VARIABLE_COUNT; i++) { |
121 | for (i=0; i < VARIABLE_COUNT; i++) { |
122 | targetvalue = RC_getVariable(i); |
122 | targetvalue = RC_getVariable(i); |
123 | if (targetvalue < 0) |
123 | if (targetvalue < 0) |
124 | targetvalue = 0; |
124 | targetvalue = 0; |
125 | if (variables[i] < targetvalue && variables[i] < 255) |
125 | if (variables[i] < targetvalue && variables[i] < 255) |
126 | variables[i]++; |
126 | variables[i]++; |
127 | else if (variables[i] > 0 && variables[i] > targetvalue) |
127 | else if (variables[i] > 0 && variables[i] > targetvalue) |
128 | variables[i]--; |
128 | variables[i]--; |
129 | } |
129 | } |
130 | } |
130 | } |
131 | 131 | ||
132 | uint8_t controlMixer_getSignalQuality(void) { |
132 | uint8_t controlMixer_getSignalQuality(void) { |
133 | uint8_t rcQ = RC_getSignalQuality(); |
133 | uint8_t rcQ = RC_getSignalQuality(); |
134 | uint8_t ecQ = EC_getSignalQuality(); |
134 | uint8_t ecQ = EC_getSignalQuality(); |
135 | 135 | ||
136 | if (rcQ < SIGNAL_GOOD) debugOut.digital[0] |= DEBUG_SIGNAL; else debugOut.digital[0] &= ~DEBUG_SIGNAL; |
136 | if (rcQ < SIGNAL_GOOD) debugOut.digital[0] |= DEBUG_SIGNAL; else debugOut.digital[0] &= ~DEBUG_SIGNAL; |
137 | if (ecQ < SIGNAL_GOOD) debugOut.digital[1] |= DEBUG_SIGNAL; else debugOut.digital[1] &= ~DEBUG_SIGNAL; |
137 | if (ecQ < SIGNAL_GOOD) debugOut.digital[1] |= DEBUG_SIGNAL; else debugOut.digital[1] &= ~DEBUG_SIGNAL; |
138 | 138 | ||
139 | // This needs not be the only correct solution... |
139 | // This needs not be the only correct solution... |
140 | return rcQ > ecQ ? rcQ : ecQ; |
140 | return rcQ > ecQ ? rcQ : ecQ; |
141 | } |
141 | } |
142 | 142 | ||
143 | void updateControlAndMeasureControlActivity(uint8_t index, int16_t newValue) { |
143 | void updateControlAndMeasureControlActivity(uint8_t index, int16_t newValue) { |
144 | int16_t tmp = controls[index]; |
144 | int16_t tmp = controls[index]; |
145 | controls[index] = newValue; |
145 | controls[index] = newValue; |
146 | 146 | ||
147 | tmp -= newValue; |
147 | tmp -= newValue; |
148 | tmp /= 2; |
148 | tmp /= 2; |
149 | tmp = tmp * tmp; |
149 | tmp = tmp * tmp; |
150 | // tmp += (newValue >= 0) ? newValue : -newValue; |
150 | // tmp += (newValue >= 0) ? newValue : -newValue; |
151 | /* |
151 | /* |
152 | if (controlActivity + (uint16_t)tmp >= controlActivity) |
152 | if (controlActivity + (uint16_t)tmp >= controlActivity) |
153 | controlActivity += tmp; |
153 | controlActivity += tmp; |
154 | else controlActivity = 0xffff; |
154 | else controlActivity = 0xffff; |
155 | */ |
155 | */ |
156 | if (controlActivity + (uint16_t)tmp < 32768) |
156 | if (controlActivity + (uint16_t)tmp < 32768) |
157 | controlActivity += tmp; |
157 | controlActivity += tmp; |
158 | } |
158 | } |
159 | 159 | ||
160 | #define CADAMPING 10 |
160 | #define CADAMPING 10 |
161 | void dampenControlActivity(void) { |
161 | void dampenControlActivity(void) { |
162 | uint32_t tmp = controlActivity; |
162 | uint32_t tmp = controlActivity; |
163 | tmp *= ((1<<CADAMPING)-1); |
163 | tmp *= ((1<<CADAMPING)-1); |
164 | tmp >>= CADAMPING; |
164 | tmp >>= CADAMPING; |
165 | controlActivity = tmp; |
165 | controlActivity = tmp; |
166 | } |
166 | } |
167 | 167 | ||
168 | /* |
168 | /* |
169 | * Update the variables indicating stick position from the sum of R/C, GPS and external control. |
169 | * Update the variables indicating stick position from the sum of R/C, GPS and external control. |
170 | */ |
170 | */ |
171 | void controlMixer_periodicTask(void) { |
171 | void controlMixer_periodicTask(void) { |
172 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
172 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
173 | // TODO: If no signal --> zero. |
173 | // TODO: If no signal --> zero. |
174 | int16_t tempThrottle; |
174 | int16_t tempThrottle; |
175 | 175 | ||
176 | // takes almost no time... |
176 | // takes almost no time... |
177 | RC_periodicTask(); |
177 | RC_periodicTask(); |
178 | 178 | ||
179 | // takes almost no time... |
179 | // takes almost no time... |
180 | EC_periodicTask(); |
180 | EC_periodicTask(); |
181 | 181 | ||
182 | // takes about 80 usec. |
182 | // takes about 80 usec. |
183 | HC_periodicTask(); |
183 | HC_periodicTask(); |
184 | 184 | ||
185 | int16_t* RC_PRTY = RC_getPRTY(); |
185 | int16_t* RC_PRTY = RC_getPRTY(); |
186 | int16_t* EC_PRTY = EC_getPRTY(); |
186 | int16_t* EC_PRTY = EC_getPRTY(); |
- | 187 | ||
- | 188 | debugOut.analog[29] = RC_PRTY[CONTROL_PITCH]; |
|
- | 189 | debugOut.analog[30] = RC_PRTY[CONTROL_ROLL]; |
|
187 | 190 | ||
188 | int16_t naviSticks[] = {RC_PRTY[CONTROL_PITCH] + EC_PRTY[CONTROL_PITCH], RC_PRTY[CONTROL_ROLL] + EC_PRTY[CONTROL_ROLL]}; |
191 | int16_t naviSticks[] = {RC_PRTY[CONTROL_PITCH] + EC_PRTY[CONTROL_PITCH], RC_PRTY[CONTROL_ROLL] + EC_PRTY[CONTROL_ROLL]}; |
189 | 192 | ||
190 | navigation_periodicTask(&naviSticks); |
193 | navigation_periodicTask(&naviSticks); |
191 | 194 | ||
192 | updateControlAndMeasureControlActivity(CONTROL_PITCH, naviSticks[CONTROL_PITCH]); |
195 | updateControlAndMeasureControlActivity(CONTROL_PITCH, naviSticks[CONTROL_PITCH]); |
193 | updateControlAndMeasureControlActivity(CONTROL_ROLL, naviSticks[CONTROL_ROLL]); |
196 | updateControlAndMeasureControlActivity(CONTROL_ROLL, naviSticks[CONTROL_ROLL]); |
194 | updateControlAndMeasureControlActivity(CONTROL_YAW, RC_PRTY[CONTROL_YAW] + EC_PRTY[CONTROL_YAW]); |
197 | updateControlAndMeasureControlActivity(CONTROL_YAW, RC_PRTY[CONTROL_YAW] + EC_PRTY[CONTROL_YAW]); |
195 | dampenControlActivity(); |
198 | dampenControlActivity(); |
196 | 199 | ||
197 | debugOut.analog[17] = controlActivity/10; |
200 | debugOut.analog[17] = controlActivity/10; |
198 | 201 | ||
199 | tempThrottle = HC_getThrottle(RC_PRTY[CONTROL_THROTTLE] + EC_PRTY[CONTROL_THROTTLE]); |
202 | tempThrottle = HC_getThrottle(RC_PRTY[CONTROL_THROTTLE] + EC_PRTY[CONTROL_THROTTLE]); |
200 | controls[CONTROL_THROTTLE] = AC_getThrottle(tempThrottle); |
203 | controls[CONTROL_THROTTLE] = AC_getThrottle(tempThrottle); |
201 | 204 | ||
202 | if (controlMixer_getSignalQuality() >= SIGNAL_GOOD) { |
205 | if (controlMixer_getSignalQuality() >= SIGNAL_GOOD) { |
203 | controlMixer_updateVariables(); |
206 | controlMixer_updateVariables(); |
204 | controlMixer_didReceiveSignal = 1; |
207 | controlMixer_didReceiveSignal = 1; |
205 | } else { // Signal is not OK |
208 | } else { // Signal is not OK |
206 | // Could handle switch to emergency flight here. |
209 | // Could handle switch to emergency flight here. |
207 | // throttle is handled elsewhere. |
210 | // throttle is handled elsewhere. |
208 | } |
211 | } |
209 | 212 | ||
210 | // We can safely do this even with a bad signal - the variables will not have been updated then. |
213 | // We can safely do this even with a bad signal - the variables will not have been updated then. |
211 | configuration_applyVariablesToParams(); |
214 | configuration_applyVariablesToParams(); |
212 | 215 | ||
213 | // part1a end. |
216 | // part1a end. |
214 | 217 | ||
215 | /* This is not really necessary with the dead-band feature on all sticks (see rc.c) |
218 | /* This is not really necessary with the dead-band feature on all sticks (see rc.c) |
216 | if(staticParams.GlobalConfig & (CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE)) { |
219 | if(staticParams.GlobalConfig & (CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE)) { |
217 | if (controlYaw > 2) controlYaw-= 2; |
220 | if (controlYaw > 2) controlYaw-= 2; |
218 | else if (controlYaw< -2) controlYaw += 2; |
221 | else if (controlYaw< -2) controlYaw += 2; |
219 | else controlYaw = 0; |
222 | else controlYaw = 0; |
220 | } |
223 | } |
221 | */ |
224 | */ |
222 | 225 | ||
223 | /* |
226 | /* |
224 | * Record maxima |
227 | * Record maxima |
225 | for (axis = PITCH; axis <= ROLL; axis++) { |
228 | for (axis = PITCH; axis <= ROLL; axis++) { |
226 | if (abs(control[axis] / CONTROL_SCALING) > maxControl[axis]) { |
229 | if (abs(control[axis] / CONTROL_SCALING) > maxControl[axis]) { |
227 | maxControl[axis] = abs(control[axis]) / CONTROL_SCALING; |
230 | maxControl[axis] = abs(control[axis]) / CONTROL_SCALING; |
228 | if (maxControl[axis] > 100) |
231 | if (maxControl[axis] > 100) |
229 | maxControl[axis] = 100; |
232 | maxControl[axis] = 100; |
230 | } else if (maxControl[axis]) |
233 | } else if (maxControl[axis]) |
231 | maxControl[axis]--; |
234 | maxControl[axis]--; |
232 | } |
235 | } |
233 | */ |
236 | */ |
234 | 237 | ||
235 | uint8_t rcCommand = (RC_getSignalQuality() >= SIGNAL_OK) ? RC_getCommand() |
238 | uint8_t rcCommand = (RC_getSignalQuality() >= SIGNAL_OK) ? RC_getCommand() |
236 | : COMMAND_NONE; |
239 | : COMMAND_NONE; |
237 | uint8_t ecCommand = (EC_getSignalQuality() >= SIGNAL_OK) ? EC_getCommand() |
240 | uint8_t ecCommand = (EC_getSignalQuality() >= SIGNAL_OK) ? EC_getCommand() |
238 | : COMMAND_NONE; |
241 | : COMMAND_NONE; |
239 | 242 | ||
240 | if (rcCommand != COMMAND_NONE) { |
243 | if (rcCommand != COMMAND_NONE) { |
241 | isCommandRepeated = (lastCommand == rcCommand); |
244 | isCommandRepeated = (lastCommand == rcCommand); |
242 | lastCommand = rcCommand; |
245 | lastCommand = rcCommand; |
243 | lastArgument = RC_getArgument(); |
246 | lastArgument = RC_getArgument(); |
244 | } else if (ecCommand != COMMAND_NONE) { |
247 | } else if (ecCommand != COMMAND_NONE) { |
245 | isCommandRepeated = (lastCommand == ecCommand); |
248 | isCommandRepeated = (lastCommand == ecCommand); |
246 | lastCommand = ecCommand; |
249 | lastCommand = ecCommand; |
247 | lastArgument = EC_getArgument(); |
250 | lastArgument = EC_getArgument(); |
248 | } else { |
251 | } else { |
249 | // Both sources have no command, or one or both are out. |
252 | // Both sources have no command, or one or both are out. |
250 | // Just set to false. There is no reason to check if the none-command was repeated anyway. |
253 | // Just set to false. There is no reason to check if the none-command was repeated anyway. |
251 | isCommandRepeated = 0; |
254 | isCommandRepeated = 0; |
252 | lastCommand = COMMAND_NONE; |
255 | lastCommand = COMMAND_NONE; |
253 | } |
256 | } |
254 | 257 | ||
255 | //if (rcCommand != COMMAND_NONE) debugOut.digital[0] |= DEBUG_SIGNAL; else debugOut.digital[0] &= ~DEBUG_SIGNAL; |
258 | //if (rcCommand != COMMAND_NONE) debugOut.digital[0] |= DEBUG_SIGNAL; else debugOut.digital[0] &= ~DEBUG_SIGNAL; |
256 | //if (isCommandRepeated) debugOut.digital[1] |= DEBUG_SIGNAL; else debugOut.digital[1] &= ~DEBUG_SIGNAL; |
259 | //if (isCommandRepeated) debugOut.digital[1] |= DEBUG_SIGNAL; else debugOut.digital[1] &= ~DEBUG_SIGNAL; |
257 | } |
260 | } |
258 | 261 | ||
259 | // TODO: Integrate into command system. |
262 | // TODO: Integrate into command system. |
260 | uint8_t controlMixer_testCompassCalState(void) { |
263 | uint8_t controlMixer_testCompassCalState(void) { |
261 | return RC_testCompassCalState(); |
264 | return RC_testCompassCalState(); |
262 | } |
265 | } |
263 | 266 |