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