Rev 1977 | Rev 1986 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1977 | Rev 1980 | ||
---|---|---|---|
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 <util/delay.h> |
52 | #include <util/delay.h> |
53 | #include <stddef.h> |
53 | #include <stddef.h> |
54 | #include <string.h> |
54 | #include <string.h> |
55 | #include "configuration.h" |
55 | #include "configuration.h" |
56 | #include "sensors.h" |
56 | #include "sensors.h" |
57 | #include "rc.h" |
57 | #include "rc.h" |
58 | #include "uart0.h" |
58 | #include "uart0.h" |
59 | 59 | ||
60 | int16_t variables[VARIABLE_COUNT]; |
60 | int16_t variables[VARIABLE_COUNT]; |
61 | paramset_t staticParams; |
61 | paramset_t staticParams; |
62 | channelMap_t channelMap; |
62 | channelMap_t channelMap; |
63 | mixerMatrix_t mixerMatrix; |
63 | mixerMatrix_t mixerMatrix; |
64 | volatile dynamicParam_t dynamicParams; |
64 | volatile dynamicParam_t dynamicParams; |
65 | 65 | ||
66 | uint8_t CPUType = ATMEGA644; |
66 | uint8_t CPUType = ATMEGA644; |
67 | uint8_t boardRelease = 13; |
67 | uint8_t boardRelease = 13; |
68 | uint8_t requiredMotors; |
68 | uint8_t requiredMotors; |
69 | 69 | ||
70 | // MK flags. TODO: Replace by enum. State machine. |
70 | // MK flags. TODO: Replace by enum. State machine. |
71 | uint16_t isFlying = 0; |
71 | uint16_t isFlying = 0; |
72 | volatile uint8_t MKFlags = 0; |
72 | volatile uint8_t MKFlags = 0; |
73 | 73 | ||
74 | /************************************************************************ |
74 | /************************************************************************ |
75 | * Map the parameter to pot values |
75 | * Map the parameter to pot values |
76 | * Replacing this code by the code below saved almost 1 kbyte. |
76 | * Replacing this code by the code below saved almost 1 kbyte. |
77 | ************************************************************************/ |
77 | ************************************************************************/ |
78 | 78 | ||
79 | void configuration_applyVariablesToParams(void) { |
79 | void configuration_applyVariablesToParams(void) { |
80 | uint8_t i; |
80 | uint8_t i; |
81 | #define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
81 | #define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
82 | #define SET_POT(b,a) { if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}} |
82 | #define SET_POT(b,a) { if (a<255) {if (a>=255-VARIABLE_COUNT) b=variables[a+VARIABLE_COUNT-255]; else b=a;}} |
83 | SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200); |
83 | SET_POT_MM(dynamicParams.gyroP, staticParams.gyroP, 5, 200); |
84 | SET_POT(dynamicParams.gyroI, staticParams.gyroI); |
84 | SET_POT(dynamicParams.gyroI, staticParams.gyroI); |
85 | SET_POT(dynamicParams.gyroD, staticParams.gyroD); |
85 | SET_POT(dynamicParams.gyroD, staticParams.gyroD); |
86 | SET_POT(dynamicParams.IFactor, staticParams.IFactor); |
86 | SET_POT(dynamicParams.IFactor, staticParams.IFactor); |
87 | SET_POT(dynamicParams.yawIFactor, staticParams.yawIFactor); |
87 | SET_POT(dynamicParams.yawIFactor, staticParams.yawIFactor); |
88 | SET_POT(dynamicParams.compassYawEffect,staticParams.compassYawEffect); |
88 | SET_POT(dynamicParams.compassYawEffect,staticParams.compassYawEffect); |
89 | 89 | ||
90 | SET_POT(dynamicParams.externalControl, staticParams.externalControl); |
90 | SET_POT(dynamicParams.externalControl, staticParams.externalControl); |
91 | SET_POT(dynamicParams.axisCoupling1, staticParams.axisCoupling1); |
91 | SET_POT(dynamicParams.axisCoupling1, staticParams.axisCoupling1); |
92 | SET_POT(dynamicParams.axisCoupling2, staticParams.axisCoupling2); |
92 | SET_POT(dynamicParams.axisCoupling2, staticParams.axisCoupling2); |
93 | SET_POT(dynamicParams.axisCouplingYawCorrection, staticParams.axisCouplingYawCorrection); |
93 | SET_POT(dynamicParams.axisCouplingYawCorrection, staticParams.axisCouplingYawCorrection); |
94 | SET_POT(dynamicParams.dynamicStability,staticParams.dynamicStability); |
94 | SET_POT(dynamicParams.dynamicStability,staticParams.dynamicStability); |
95 | SET_POT(dynamicParams.maxControlActivityForAcc,staticParams.maxControlActivityForAcc); |
95 | SET_POT(dynamicParams.maxAccVector,staticParams.maxAccVector); |
96 | 96 | ||
97 | SET_POT_MM(dynamicParams.heightP, staticParams.heightP,0,100); |
97 | SET_POT_MM(dynamicParams.heightP, staticParams.heightP,0,100); |
98 | SET_POT_MM(dynamicParams.heightD, staticParams.heightD,0,100); |
98 | SET_POT_MM(dynamicParams.heightD, staticParams.heightD,0,100); |
99 | SET_POT(dynamicParams.heightSetting,staticParams.heightSetting); |
99 | SET_POT(dynamicParams.heightSetting,staticParams.heightSetting); |
100 | SET_POT(dynamicParams.attitudeControl,staticParams.attitudeControl); |
100 | SET_POT(dynamicParams.attitudeControl,staticParams.attitudeControl); |
101 | 101 | ||
102 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
102 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
103 | SET_POT(dynamicParams.userParams[i],staticParams.userParams[i]); |
103 | SET_POT(dynamicParams.userParams[i],staticParams.userParams[i]); |
104 | } |
104 | } |
105 | 105 | ||
106 | SET_POT(dynamicParams.servoManualControl[0], staticParams.servoConfigurations[0].manualControl); |
106 | SET_POT(dynamicParams.servoManualControl[0], staticParams.servoConfigurations[0].manualControl); |
107 | SET_POT(dynamicParams.servoManualControl[1], staticParams.servoConfigurations[1].manualControl); |
107 | SET_POT(dynamicParams.servoManualControl[1], staticParams.servoConfigurations[1].manualControl); |
108 | 108 | ||
109 | SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255); |
109 | SET_POT_MM(dynamicParams.output0Timing, staticParams.outputFlash[0].timing,1,255); |
110 | SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255); |
110 | SET_POT_MM(dynamicParams.output1Timing, staticParams.outputFlash[1].timing,1,255); |
111 | } |
111 | } |
112 | 112 | ||
113 | const XLATION XLATIONS[] = { |
113 | const XLATION XLATIONS[] = { |
114 | {offsetof(paramset_t, heightSetting), offsetof(dynamicParam_t, heightSetting)}, |
114 | {offsetof(paramset_t, heightSetting), offsetof(dynamicParam_t, heightSetting)}, |
115 | }; |
115 | }; |
116 | 116 | ||
117 | const MMXLATION MMXLATIONS[] = { |
117 | const MMXLATION MMXLATIONS[] = { |
118 | {offsetof(paramset_t, heightD), offsetof(dynamicParam_t, heightD),0,100}, |
118 | {offsetof(paramset_t, heightD), offsetof(dynamicParam_t, heightD),0,100}, |
119 | }; |
119 | }; |
120 | 120 | ||
121 | uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
121 | uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
122 | uint8_t result; |
122 | uint8_t result; |
123 | if (src>=251) result = variables[src-251]; |
123 | if (src>=251) result = variables[src-251]; |
124 | else result = src; |
124 | else result = src; |
125 | if (result < min) result = min; |
125 | if (result < min) result = min; |
126 | else if (result > max) result = max; |
126 | else if (result > max) result = max; |
127 | return result; |
127 | return result; |
128 | } |
128 | } |
129 | 129 | ||
130 | void configuration_applyVariablesToParams_dead(void) { |
130 | void configuration_applyVariablesToParams_dead(void) { |
131 | uint8_t i, src; |
131 | uint8_t i, src; |
132 | uint8_t* pointerToTgt; |
132 | uint8_t* pointerToTgt; |
133 | for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
133 | for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
134 | src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
134 | src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
135 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
135 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
136 | if (src < 255) { |
136 | if (src < 255) { |
137 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
137 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
138 | } |
138 | } |
139 | } |
139 | } |
140 | 140 | ||
141 | for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
141 | for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
142 | src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
142 | src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
143 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
143 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
144 | if (src < 255) { |
144 | if (src < 255) { |
145 | *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
145 | *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
146 | } |
146 | } |
147 | } |
147 | } |
148 | 148 | ||
149 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
149 | for (i=0; i<sizeof(staticParams.userParams); i++) { |
150 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, userParams) + i)); |
150 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, userParams) + i)); |
151 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, userParams) + i); |
151 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, userParams) + i); |
152 | if (src < 255) { |
152 | if (src < 255) { |
153 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
153 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
154 | } |
154 | } |
155 | } |
155 | } |
156 | } |
156 | } |
157 | 157 | ||
158 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
158 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
159 | uint8_t CPUType = ATMEGA644; |
159 | uint8_t CPUType = ATMEGA644; |
160 | //if((UCSR1A == 0x20) && (UCSR1C == 0x06)) CPUType = ATMEGA644P; // initial Values for 644P after reset |
160 | //if((UCSR1A == 0x20) && (UCSR1C == 0x06)) CPUType = ATMEGA644P; // initial Values for 644P after reset |
161 | return CPUType; |
161 | return CPUType; |
162 | } |
162 | } |
163 | 163 | ||
164 | /* |
164 | /* |
165 | * Automatic detection of hardware components is not supported in this development-oriented |
165 | * Automatic detection of hardware components is not supported in this development-oriented |
166 | * FC firmware. It would go against the point of it: To enable alternative hardware |
166 | * FC firmware. It would go against the point of it: To enable alternative hardware |
167 | * configurations with otherwise unsupported components. Instead, one should write |
167 | * configurations with otherwise unsupported components. Instead, one should write |
168 | * custom code + adjust constants for the new hardware, and include the relevant code |
168 | * custom code + adjust constants for the new hardware, and include the relevant code |
169 | * from the makefile. |
169 | * from the makefile. |
170 | * However - we still do detect the board release. Reason: Otherwise it would be too |
170 | * However - we still do detect the board release. Reason: Otherwise it would be too |
171 | * tedious to have to modify the code for how to turn on and off LEDs when deploying |
171 | * tedious to have to modify the code for how to turn on and off LEDs when deploying |
172 | * on different HW version.... |
172 | * on different HW version.... |
173 | */ |
173 | */ |
174 | 174 | ||
175 | uint8_t getBoardRelease(void) { |
175 | uint8_t getBoardRelease(void) { |
176 | uint8_t boardRelease = 13; |
176 | uint8_t boardRelease = 13; |
177 | // the board release is coded via the pull up or down the 2 status LED |
177 | // the board release is coded via the pull up or down the 2 status LED |
178 | 178 | ||
179 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
179 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
180 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
180 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
181 | 181 | ||
182 | _delay_loop_2(1000); // make some delay |
182 | _delay_loop_2(1000); // make some delay |
183 | 183 | ||
184 | switch( PINB & ((1<<PINB1)|(1<<PINB0))) { |
184 | switch( PINB & ((1<<PINB1)|(1<<PINB0))) { |
185 | case 0x00: |
185 | case 0x00: |
186 | boardRelease = 10; // 1.0 |
186 | boardRelease = 10; // 1.0 |
187 | break; |
187 | break; |
188 | case 0x01: |
188 | case 0x01: |
189 | boardRelease = 11; // 1.1 or 1.2 |
189 | boardRelease = 11; // 1.1 or 1.2 |
190 | break; |
190 | break; |
191 | case 0x02: |
191 | case 0x02: |
192 | boardRelease = 20; // 2.0 |
192 | boardRelease = 20; // 2.0 |
193 | break; |
193 | break; |
194 | case 0x03: |
194 | case 0x03: |
195 | boardRelease = 13; // 1.3 |
195 | boardRelease = 13; // 1.3 |
196 | break; |
196 | break; |
197 | default: |
197 | default: |
198 | break; |
198 | break; |
199 | } |
199 | } |
200 | // set LED ports as output |
200 | // set LED ports as output |
201 | DDRB |= (1<<DDB1)|(1<<DDB0); |
201 | DDRB |= (1<<DDB1)|(1<<DDB0); |
202 | RED_OFF; |
202 | RED_OFF; |
203 | GRN_OFF; |
203 | GRN_OFF; |
204 | return boardRelease; |
204 | return boardRelease; |
205 | } |
205 | } |
206 | 206 | ||
207 | void setOtherDefaults(void) { |
207 | void setOtherDefaults(void) { |
208 | // Height Control |
208 | // Height Control |
209 | staticParams.heightP = 10; |
209 | staticParams.heightP = 10; |
210 | staticParams.heightD = 30; |
210 | staticParams.heightD = 30; |
211 | staticParams.heightSetting = 251; |
211 | staticParams.heightSetting = 251; |
212 | staticParams.heightControlMaxThrottleChange = 10; |
212 | staticParams.heightControlMaxThrottleChange = 10; |
213 | staticParams.heightSlewRate = 4; |
213 | staticParams.heightSlewRate = 4; |
214 | 214 | ||
215 | // Control |
215 | // Control |
216 | staticParams.stickP = 8; |
216 | staticParams.stickP = 8; |
217 | staticParams.stickD = 12; |
217 | staticParams.stickD = 12; |
218 | staticParams.stickYawP = 12; |
218 | staticParams.stickYawP = 12; |
219 | staticParams.stickThrottleD = 12; |
219 | staticParams.stickThrottleD = 12; |
220 | staticParams.minThrottle = 8; |
220 | staticParams.minThrottle = 8; |
221 | staticParams.maxThrottle = 230; |
221 | staticParams.maxThrottle = 230; |
222 | staticParams.externalControl = 0; |
222 | staticParams.externalControl = 0; |
223 | 223 | ||
224 | // IMU |
224 | // IMU |
225 | staticParams.gyroPIDFilterConstant = 1; |
225 | staticParams.gyroPIDFilterConstant = 1; |
226 | staticParams.gyroATTFilterConstant = 1; |
226 | staticParams.gyroATTFilterConstant = 1; |
227 | staticParams.gyroDFilterConstant = 1; |
227 | staticParams.gyroDFilterConstant = 1; |
228 | staticParams.accFilterConstant = 10; |
228 | staticParams.accFilterConstant = 10; |
229 | 229 | ||
230 | staticParams.gyroP = 60; |
230 | staticParams.gyroP = 60; |
231 | staticParams.gyroI = 80; |
231 | staticParams.gyroI = 80; |
232 | staticParams.gyroD = 4; |
232 | staticParams.gyroD = 4; |
233 | 233 | ||
234 | // set by gyro-specific code: gyro_setDefaults(). |
234 | // set by gyro-specific code: gyro_setDefaults(). |
235 | // staticParams.zerothOrderCorrection = |
235 | // staticParams.zerothOrderCorrection = |
236 | // staticParams.driftCompDivider = |
236 | // staticParams.driftCompDivider = |
237 | // staticParams.driftCompLimit = |
237 | // staticParams.driftCompLimit = |
238 | 238 | ||
239 | staticParams.axisCoupling1 = 90; |
239 | staticParams.axisCoupling1 = 90; |
240 | staticParams.axisCoupling2 = 67; |
240 | staticParams.axisCoupling2 = 67; |
241 | staticParams.axisCouplingYawCorrection = 0; |
241 | staticParams.axisCouplingYawCorrection = 0; |
242 | staticParams.dynamicStability = 50; |
242 | staticParams.dynamicStability = 50; |
243 | staticParams.IFactor = 32; |
243 | staticParams.IFactor = 32; |
244 | staticParams.yawIFactor = 100; |
244 | staticParams.yawIFactor = 100; |
245 | staticParams.compassYawEffect = 128; |
245 | staticParams.compassYawEffect = 128; |
246 | 246 | ||
247 | // Servos |
247 | // Servos |
- | 248 | staticParams.servoCount = 7; |
|
- | 249 | staticParams.servoManualMaxSpeed = 10; |
|
248 | for (uint8_t i=0; i<2; i++) { |
250 | for (uint8_t i=0; i<2; i++) { |
249 | staticParams.servoConfigurations[i].manualControl = 128; |
251 | staticParams.servoConfigurations[i].manualControl = 128; |
250 | staticParams.servoConfigurations[i].manualMaxSpeed = 10; |
- | |
251 | staticParams.servoConfigurations[i].compensationFactor = 100; |
252 | staticParams.servoConfigurations[i].stabilizationFactor = 0; |
252 | staticParams.servoConfigurations[i].minValue = 32; |
253 | staticParams.servoConfigurations[i].minValue = 32; |
253 | staticParams.servoConfigurations[i].maxValue = 224; |
254 | staticParams.servoConfigurations[i].maxValue = 224; |
254 | staticParams.servoConfigurations[i].flags = 0; |
255 | staticParams.servoConfigurations[i].flags = 0; |
255 | } |
256 | } |
256 | staticParams.servoCount = 7; |
- | |
257 | 257 | ||
258 | // Battery warning and emergency flight |
258 | // Battery warning and emergency flight |
259 | staticParams.batteryVoltageWarning = 101; // 3.7 each for 3S |
259 | staticParams.batteryVoltageWarning = 101; // 3.7 each for 3S |
260 | staticParams.emergencyThrottle = 35; |
260 | staticParams.emergencyThrottle = 35; |
261 | staticParams.emergencyFlightDuration = 30; |
261 | staticParams.emergencyFlightDuration = 30; |
262 | 262 | ||
263 | // Outputs |
263 | // Outputs |
264 | staticParams.outputFlash[0].bitmask = 1; //0b01011111; |
264 | staticParams.outputFlash[0].bitmask = 1; //0b01011111; |
265 | staticParams.outputFlash[0].timing = 15; |
265 | staticParams.outputFlash[0].timing = 15; |
266 | staticParams.outputFlash[1].bitmask = 3; //0b11110011; |
266 | staticParams.outputFlash[1].bitmask = 3; //0b11110011; |
267 | staticParams.outputFlash[1].timing = 15; |
267 | staticParams.outputFlash[1].timing = 15; |
268 | 268 | ||
269 | staticParams.outputDebugMask = 16; |
269 | staticParams.outputDebugMask = 0; |
270 | staticParams.outputOptions = 8; |
270 | staticParams.outputOptions = 8; |
271 | } |
271 | } |
272 | 272 | ||
273 | /***************************************************/ |
273 | /***************************************************/ |
274 | /* Default Values for parameter set 1 */ |
274 | /* Default Values for parameter set 1 */ |
275 | /***************************************************/ |
275 | /***************************************************/ |
276 | void paramSet_default(uint8_t setnumber) { |
276 | void paramSet_default(uint8_t setnumber) { |
277 | setOtherDefaults(); |
277 | setOtherDefaults(); |
278 | gyro_setDefaultParameters(); |
278 | gyro_setDefaultParameters(); |
279 | 279 | ||
280 | for (uint8_t i=0; i<8; i++) { |
280 | for (uint8_t i=0; i<8; i++) { |
281 | staticParams.userParams[i] = 0; |
281 | staticParams.userParams[i] = 0; |
282 | } |
282 | } |
283 | 283 | ||
284 | staticParams.bitConfig = |
284 | staticParams.bitConfig = |
285 | CFG_GYRO_SATURATION_PREVENTION | CFG_HEADING_HOLD; |
285 | CFG_GYRO_SATURATION_PREVENTION | CFG_HEADING_HOLD; |
286 | 286 | ||
287 | memcpy(staticParams.name, "Default\0", 6); |
287 | memcpy(staticParams.name, "Default\0", 6); |
288 | } |
288 | } |
289 | 289 | ||
290 | /***************************************************/ |
290 | /***************************************************/ |
291 | /* Default Values for Mixer Table */ |
291 | /* Default Values for Mixer Table */ |
292 | /***************************************************/ |
292 | /***************************************************/ |
293 | void mixerMatrix_default(void) { // Quadro |
293 | void mixerMatrix_default(void) { // Quadro |
294 | uint8_t i; |
294 | uint8_t i; |
295 | // mixerMatric.revision = EEMIXER_REVISION; |
295 | // mixerMatric.revision = EEMIXER_REVISION; |
296 | // clear mixer table (but preset throttle) |
296 | // clear mixer table (but preset throttle) |
297 | for (i = 0; i < 16; i++) { |
297 | for (i = 0; i < 16; i++) { |
298 | mixerMatrix.motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0; |
298 | mixerMatrix.motor[i][MIX_THROTTLE] = i < 4 ? 64 : 0; |
299 | mixerMatrix.motor[i][MIX_PITCH] = 0; |
299 | mixerMatrix.motor[i][MIX_PITCH] = 0; |
300 | mixerMatrix.motor[i][MIX_ROLL] = 0; |
300 | mixerMatrix.motor[i][MIX_ROLL] = 0; |
301 | mixerMatrix.motor[i][MIX_YAW] = 0; |
301 | mixerMatrix.motor[i][MIX_YAW] = 0; |
302 | } |
302 | } |
303 | // default = Quadro |
303 | // default = Quadro |
304 | mixerMatrix.motor[0][MIX_PITCH] = +64; |
304 | mixerMatrix.motor[0][MIX_PITCH] = +64; |
305 | mixerMatrix.motor[0][MIX_YAW] = +64; |
305 | mixerMatrix.motor[0][MIX_YAW] = +64; |
306 | mixerMatrix.motor[1][MIX_PITCH] = -64; |
306 | mixerMatrix.motor[1][MIX_PITCH] = -64; |
307 | mixerMatrix.motor[1][MIX_YAW] = +64; |
307 | mixerMatrix.motor[1][MIX_YAW] = +64; |
308 | mixerMatrix.motor[2][MIX_ROLL] = -64; |
308 | mixerMatrix.motor[2][MIX_ROLL] = -64; |
309 | mixerMatrix.motor[2][MIX_YAW] = -64; |
309 | mixerMatrix.motor[2][MIX_YAW] = -64; |
310 | mixerMatrix.motor[3][MIX_ROLL] = +64; |
310 | mixerMatrix.motor[3][MIX_ROLL] = +64; |
311 | mixerMatrix.motor[3][MIX_YAW] = -64; |
311 | mixerMatrix.motor[3][MIX_YAW] = -64; |
312 | memcpy(mixerMatrix.name, "Quadro\0", 7); |
312 | memcpy(mixerMatrix.name, "Quadro\0", 7); |
313 | } |
313 | } |
314 | 314 | ||
315 | /***************************************************/ |
315 | /***************************************************/ |
316 | /* Default Values for R/C Channels */ |
316 | /* Default Values for R/C Channels */ |
317 | /***************************************************/ |
317 | /***************************************************/ |
318 | void channelMap_default(void) { |
318 | void channelMap_default(void) { |
319 | channelMap.channels[CH_PITCH] = 1; |
319 | channelMap.channels[CH_PITCH] = 1; |
320 | channelMap.channels[CH_ROLL] = 0; |
320 | channelMap.channels[CH_ROLL] = 0; |
321 | channelMap.channels[CH_THROTTLE] = 2; |
321 | channelMap.channels[CH_THROTTLE] = 2; |
322 | channelMap.channels[CH_YAW] = 3; |
322 | channelMap.channels[CH_YAW] = 3; |
323 | channelMap.channels[CH_POTS + 0] = 4; |
323 | channelMap.channels[CH_POTS + 0] = 4; |
324 | channelMap.channels[CH_POTS + 1] = 5; |
324 | channelMap.channels[CH_POTS + 1] = 5; |
325 | channelMap.channels[CH_POTS + 2] = 6; |
325 | channelMap.channels[CH_POTS + 2] = 6; |
326 | channelMap.channels[CH_POTS + 3] = 7; |
326 | channelMap.channels[CH_POTS + 3] = 7; |
327 | } |
327 | } |
328 | 328 | ||
329 | 329 |