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