Rev 2045 | Rev 2049 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2045 | Rev 2048 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
2 | // + Copyright (c) 04.2007 Holger Buss |
- | |
3 | // + Nur für den privaten Gebrauch |
- | |
4 | // + www.MikroKopter.com |
- | |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
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. |
- | |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
- | |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
- | |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
- | |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
- | |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
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 |
- | |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
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" |
- | |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
- | |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
- | |
21 | // + Benutzung auf eigene Gefahr |
- | |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
- | |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
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 |
- | |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
- | |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
- | |
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 |
- | |
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 |
- | |
34 | // + for non-commercial use (directly or indirectly) |
- | |
35 | // + Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
- | |
36 | // + with our written permission |
- | |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
- | |
38 | // + clearly linked as origin |
- | |
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" |
- | |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
- | |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
- | |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
- | |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
- | |
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 |
- | |
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 |
- | |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
- | |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
52 | #include <stdlib.h> |
1 | #include <stdlib.h> |
53 | #include "controlMixer.h" |
2 | #include "controlMixer.h" |
54 | #include "rc.h" |
3 | #include "rc.h" |
55 | #include "heightControl.h" |
4 | #include "heightControl.h" |
56 | #include "attitudeControl.h" |
5 | #include "attitudeControl.h" |
57 | #include "externalControl.h" |
6 | #include "externalControl.h" |
- | 7 | #include "compassControl.h" |
|
58 | #include "naviControl.h" |
8 | #include "naviControl.h" |
59 | #include "configuration.h" |
9 | #include "configuration.h" |
60 | #include "attitude.h" |
10 | #include "attitude.h" |
61 | #include "commands.h" |
11 | #include "commands.h" |
62 | #include "output.h" |
12 | #include "output.h" |
Line 131... | Line 81... | ||
131 | 81 | ||
132 | uint8_t controlMixer_getSignalQuality(void) { |
82 | uint8_t controlMixer_getSignalQuality(void) { |
133 | uint8_t rcQ = RC_getSignalQuality(); |
83 | uint8_t rcQ = RC_getSignalQuality(); |
Line 134... | Line -... | ||
134 | uint8_t ecQ = EC_getSignalQuality(); |
- | |
135 | - | ||
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; |
84 | uint8_t ecQ = EC_getSignalQuality(); |
138 | 85 | ||
139 | // This needs not be the only correct solution... |
86 | // This needs not be the only correct solution... |
Line 140... | Line 87... | ||
140 | return rcQ > ecQ ? rcQ : ecQ; |
87 | return rcQ > ecQ ? rcQ : ecQ; |
Line 164... | Line 111... | ||
164 | tmp >>= CADAMPING; |
111 | tmp >>= CADAMPING; |
165 | controlActivity = tmp; |
112 | controlActivity = tmp; |
166 | } |
113 | } |
Line 167... | Line 114... | ||
167 | 114 | ||
168 | /* |
115 | /* |
- | 116 | * Update the variables indicating stick position from the sum of R/C, GPS and external control |
|
- | 117 | * and whatever other controls we invented in the meantime... |
|
- | 118 | * Update variables. |
|
169 | * Update the variables indicating stick position from the sum of R/C, GPS and external control. |
119 | * Decode commands but do not execute them. |
- | 120 | */ |
|
- | 121 | int16_t tempPRTY[4]; |
|
170 | */ |
122 | |
171 | void controlMixer_periodicTask(void) { |
123 | void controlMixer_periodicTask(void) { |
172 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
124 | // calculate Stick inputs by rc channels (P) and changing of rc channels (D) |
173 | // TODO: If no signal --> zero. |
125 | // TODO: If no signal --> zero. |
Line 174... | Line 126... | ||
174 | int16_t tempThrottle; |
126 | // HC_periodicTask(); |
175 | 127 | ||
Line 176... | Line 128... | ||
176 | // takes almost no time... |
128 | // This will init the values (not just add to them). |
177 | RC_periodicTask(); |
129 | RC_periodicTaskAndPRTY(tempPRTY); |
Line 178... | Line 130... | ||
178 | 130 | ||
179 | // takes almost no time... |
131 | // Add external control to RC |
Line 180... | Line 132... | ||
180 | EC_periodicTask(); |
132 | EC_periodicTaskAndPRTY(tempPRTY); |
181 | 133 | ||
Line 182... | Line 134... | ||
182 | // takes about 80 usec. |
134 | // Add navigations control to RC and external control. |
183 | HC_periodicTask(); |
135 | navigation_periodicTaskAndPRTY(tempPRTY); |
Line 184... | Line 136... | ||
184 | 136 | ||
- | 137 | // Add compass control (could also have been before navi, they are independent) |
|
Line 185... | Line 138... | ||
185 | int16_t* RC_PRTY = RC_getPRTY(); |
138 | CC_periodicTaskAndPRTY(tempPRTY); |
186 | int16_t* EC_PRTY = EC_getPRTY(); |
- | |
187 | 139 | ||
188 | debugOut.analog[29] = RC_PRTY[CONTROL_PITCH]; |
140 | // Add height control (could also have been before navi and/or compass, they are independent) |
189 | debugOut.analog[30] = RC_PRTY[CONTROL_ROLL]; |
141 | HC_periodicTaskAndPRTY(tempPRTY); |
190 | 142 | ||
Line 191... | Line 143... | ||
191 | int16_t naviSticks[] = {RC_PRTY[CONTROL_PITCH] + EC_PRTY[CONTROL_PITCH], RC_PRTY[CONTROL_ROLL] + EC_PRTY[CONTROL_ROLL]}; |
143 | // Add attitude control (could also have been before navi and/or compass, they are independent) |
Line 192... | Line -... | ||
192 | - | ||
193 | navigation_periodicTask(&naviSticks); |
144 | AC_getPRTY(tempPRTY); |
194 | - | ||
195 | updateControlAndMeasureControlActivity(CONTROL_PITCH, naviSticks[CONTROL_PITCH]); |
145 | |
196 | updateControlAndMeasureControlActivity(CONTROL_ROLL, naviSticks[CONTROL_ROLL]); |
146 | // Commit results to global variable and also measure control activity. |
197 | updateControlAndMeasureControlActivity(CONTROL_YAW, RC_PRTY[CONTROL_YAW] + EC_PRTY[CONTROL_YAW]); |
147 | updateControlAndMeasureControlActivity(CONTROL_PITCH, tempPRTY[CONTROL_PITCH]); |
198 | dampenControlActivity(); |
148 | updateControlAndMeasureControlActivity(CONTROL_ROLL, tempPRTY[CONTROL_ROLL]); |
199 | 149 | updateControlAndMeasureControlActivity(CONTROL_YAW, tempPRTY[CONTROL_YAW]); |
|
Line 222... | Line 172... | ||
222 | else controlYaw = 0; |
172 | else controlYaw = 0; |
223 | } |
173 | } |
224 | */ |
174 | */ |
Line 225... | Line 175... | ||
225 | 175 | ||
226 | /* |
176 | /* |
227 | * Record maxima |
177 | * Record maxima. Predecessor of the control activity stuff. |
228 | for (axis = PITCH; axis <= ROLL; axis++) { |
178 | for (axis = PITCH; axis <= ROLL; axis++) { |
229 | if (abs(control[axis] / CONTROL_SCALING) > maxControl[axis]) { |
179 | if (abs(control[axis] / CONTROL_SCALING) > maxControl[axis]) { |
230 | maxControl[axis] = abs(control[axis]) / CONTROL_SCALING; |
180 | maxControl[axis] = abs(control[axis]) / CONTROL_SCALING; |
231 | if (maxControl[axis] > 100) |
181 | if (maxControl[axis] > 100) |
232 | maxControl[axis] = 100; |
182 | maxControl[axis] = 100; |
233 | } else if (maxControl[axis]) |
183 | } else if (maxControl[axis]) |
234 | maxControl[axis]--; |
184 | maxControl[axis]--; |
235 | } |
185 | } |
Line -... | Line 186... | ||
- | 186 | */ |
|
236 | */ |
187 | |
237 | 188 | // Decode commands. |
|
238 | uint8_t rcCommand = (RC_getSignalQuality() >= SIGNAL_OK) ? RC_getCommand() |
189 | uint8_t rcCommand = (RC_getSignalQuality() >= SIGNAL_OK) ? RC_getCommand() |
239 | : COMMAND_NONE; |
190 | : COMMAND_NONE; |
Line 252... | Line 203... | ||
252 | // Both sources have no command, or one or both are out. |
203 | // Both sources have no command, or one or both are out. |
253 | // Just set to false. There is no reason to check if the none-command was repeated anyway. |
204 | // Just set to false. There is no reason to check if the none-command was repeated anyway. |
254 | isCommandRepeated = 0; |
205 | isCommandRepeated = 0; |
255 | lastCommand = COMMAND_NONE; |
206 | lastCommand = COMMAND_NONE; |
256 | } |
207 | } |
257 | - | ||
258 | //if (rcCommand != COMMAND_NONE) debugOut.digital[0] |= DEBUG_SIGNAL; else debugOut.digital[0] &= ~DEBUG_SIGNAL; |
- | |
259 | //if (isCommandRepeated) debugOut.digital[1] |= DEBUG_SIGNAL; else debugOut.digital[1] &= ~DEBUG_SIGNAL; |
- | |
260 | } |
- | |
261 | - | ||
262 | // TODO: Integrate into command system. |
- | |
263 | uint8_t controlMixer_testCompassCalState(void) { |
- | |
264 | return RC_testCompassCalState(); |
- | |
265 | } |
208 | } |