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