Rev 1805 | Rev 1887 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1805 | Rev 1868 | ||
---|---|---|---|
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 (nicht-kommerziellen) Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (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 sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt werden |
18 | // + eindeutig als Ursprung verlinkt 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 excample: 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// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
49 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | #include <util/delay.h> |
51 | #include <util/delay.h> |
52 | #include <avr/eeprom.h> |
52 | #include <avr/eeprom.h> |
53 | #include <stddef.h> |
53 | #include <stddef.h> |
54 | #include "configuration.h" |
54 | #include "configuration.h" |
55 | #include "eeprom.h" |
55 | #include "eeprom.h" |
56 | #include "timer0.h" |
56 | #include "timer0.h" |
57 | 57 | ||
58 | int16_t variables[8] = {0,0,0,0,0,0,0,0}; |
58 | int16_t variables[8] = {0,0,0,0,0,0,0,0}; |
59 | dynamicParam_t dynamicParams = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0}; |
59 | dynamicParam_t dynamicParams = {48,251,16,58,64,8,150,150,2,10,{0,0,0,0,0,0,0,0},100,70,90,65,64,100,0,0,0}; |
60 | uint8_t CPUType = ATMEGA644; |
60 | uint8_t CPUType = ATMEGA644; |
61 | uint8_t BoardRelease = 13; |
61 | uint8_t BoardRelease = 13; |
62 | 62 | ||
63 | /************************************************************************ |
63 | /************************************************************************ |
64 | * Map the parameter to pot values |
64 | * Map the parameter to pot values |
65 | * Replacing this code by the code below saved almost 1 kbyte. |
65 | * Replacing this code by the code below saved almost 1 kbyte. |
66 | ************************************************************************/ |
66 | ************************************************************************/ |
67 | 67 | ||
68 | void configuration_applyVariablesToParams(void) { |
68 | void configuration_applyVariablesToParams(void) { |
69 | uint8_t i; |
69 | uint8_t i; |
70 | #define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
70 | #define SET_POT_MM(b,a,min,max) {if (a<255) {if (a>=251) b=variables[a-251]; else b=a;} if(b<=min) b=min; else if(b>=max) b=max;} |
71 | #define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}} |
71 | #define SET_POT(b,a) { if (a<255) {if (a>=251) b=variables[a-251]; else b=a;}} |
72 | SET_POT(dynamicParams.MaxHeight,staticParams.MaxHeight); |
72 | SET_POT(dynamicParams.MaxHeight,staticParams.MaxHeight); |
73 | SET_POT_MM(dynamicParams.HeightD,staticParams.HeightD,0,100); |
73 | SET_POT_MM(dynamicParams.HeightD,staticParams.HeightD,0,100); |
74 | SET_POT_MM(dynamicParams.HeightP,staticParams.HeightP,0,100); |
74 | SET_POT_MM(dynamicParams.HeightP,staticParams.HeightP,0,100); |
75 | SET_POT(dynamicParams.Height_ACC_Effect,staticParams.Height_ACC_Effect); |
75 | SET_POT(dynamicParams.Height_ACC_Effect,staticParams.Height_ACC_Effect); |
76 | SET_POT(dynamicParams.CompassYawEffect,staticParams.CompassYawEffect); |
76 | SET_POT(dynamicParams.CompassYawEffect,staticParams.CompassYawEffect); |
77 | SET_POT_MM(dynamicParams.GyroP,staticParams.GyroP,10,255); |
77 | SET_POT_MM(dynamicParams.GyroP,staticParams.GyroP,10,255); |
78 | SET_POT(dynamicParams.GyroI,staticParams.GyroI); |
78 | SET_POT(dynamicParams.GyroI,staticParams.GyroI); |
79 | SET_POT(dynamicParams.GyroD,staticParams.GyroD); |
79 | SET_POT(dynamicParams.GyroD,staticParams.GyroD); |
80 | SET_POT(dynamicParams.IFactor,staticParams.IFactor); |
80 | SET_POT(dynamicParams.IFactor,staticParams.IFactor); |
81 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
81 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
82 | SET_POT(dynamicParams.UserParams[i],staticParams.UserParams1[i]); |
82 | SET_POT(dynamicParams.UserParams[i],staticParams.UserParams1[i]); |
83 | } |
83 | } |
84 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
84 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
85 | SET_POT(dynamicParams.UserParams[i + sizeof(staticParams.UserParams1)], staticParams.UserParams2[i]); |
85 | SET_POT(dynamicParams.UserParams[i + sizeof(staticParams.UserParams1)], staticParams.UserParams2[i]); |
86 | } |
86 | } |
87 | SET_POT(dynamicParams.ServoPitchControl,staticParams.ServoPitchControl); |
87 | SET_POT(dynamicParams.ServoPitchControl,staticParams.ServoPitchControl); |
88 | SET_POT(dynamicParams.LoopGasLimit,staticParams.LoopGasLimit); |
88 | SET_POT(dynamicParams.LoopGasLimit,staticParams.LoopGasLimit); |
89 | SET_POT(dynamicParams.AxisCoupling1,staticParams.AxisCoupling1); |
89 | SET_POT(dynamicParams.AxisCoupling1,staticParams.AxisCoupling1); |
90 | SET_POT(dynamicParams.AxisCoupling2,staticParams.AxisCoupling2); |
90 | SET_POT(dynamicParams.AxisCoupling2,staticParams.AxisCoupling2); |
91 | SET_POT(dynamicParams.AxisCouplingYawCorrection,staticParams.AxisCouplingYawCorrection); |
91 | SET_POT(dynamicParams.AxisCouplingYawCorrection,staticParams.AxisCouplingYawCorrection); |
92 | SET_POT(dynamicParams.DynamicStability,staticParams.DynamicStability); |
92 | SET_POT(dynamicParams.DynamicStability,staticParams.DynamicStability); |
93 | SET_POT_MM(dynamicParams.J16Timing,staticParams.J16Timing,1,255); |
93 | SET_POT_MM(dynamicParams.J16Timing,staticParams.J16Timing,1,255); |
94 | SET_POT_MM(dynamicParams.J17Timing,staticParams.J17Timing,1,255); |
94 | SET_POT_MM(dynamicParams.J17Timing,staticParams.J17Timing,1,255); |
95 | 95 | ||
96 | #if defined (USE_NAVICTRL) |
96 | #if defined (USE_NAVICTRL) |
97 | SET_POT(dynamicParams.NaviGpsModeControl,staticParams.NaviGpsModeControl); |
97 | SET_POT(dynamicParams.NaviGpsModeControl,staticParams.NaviGpsModeControl); |
98 | SET_POT(dynamicParams.NaviGpsGain,staticParams.NaviGpsGain); |
98 | SET_POT(dynamicParams.NaviGpsGain,staticParams.NaviGpsGain); |
99 | SET_POT(dynamicParams.NaviGpsP,staticParams.NaviGpsP); |
99 | SET_POT(dynamicParams.NaviGpsP,staticParams.NaviGpsP); |
100 | SET_POT(dynamicParams.NaviGpsI,staticParams.NaviGpsI); |
100 | SET_POT(dynamicParams.NaviGpsI,staticParams.NaviGpsI); |
101 | SET_POT(dynamicParams.NaviGpsD,staticParams.NaviGpsD); |
101 | SET_POT(dynamicParams.NaviGpsD,staticParams.NaviGpsD); |
102 | SET_POT(dynamicParams.NaviGpsACC,staticParams.NaviGpsACC); |
102 | SET_POT(dynamicParams.NaviGpsACC,staticParams.NaviGpsACC); |
103 | SET_POT_MM(dynamicParams.NaviOperatingRadius,staticParams.NaviOperatingRadius,10, 255); |
103 | SET_POT_MM(dynamicParams.NaviOperatingRadius,staticParams.NaviOperatingRadius,10, 255); |
104 | SET_POT(dynamicParams.NaviWindCorrection,staticParams.NaviWindCorrection); |
104 | SET_POT(dynamicParams.NaviWindCorrection,staticParams.NaviWindCorrection); |
105 | SET_POT(dynamicParams.NaviSpeedCompensation,staticParams.NaviSpeedCompensation); |
105 | SET_POT(dynamicParams.NaviSpeedCompensation,staticParams.NaviSpeedCompensation); |
106 | #endif |
106 | #endif |
107 | SET_POT(dynamicParams.ExternalControl,staticParams.ExternalControl); |
107 | SET_POT(dynamicParams.ExternalControl,staticParams.ExternalControl); |
108 | } |
108 | } |
109 | 109 | ||
110 | const XLATION XLATIONS[] = { |
110 | const XLATION XLATIONS[] = { |
111 | {offsetof(paramset_t, MaxHeight), offsetof(dynamicParam_t, MaxHeight)}, |
111 | {offsetof(paramset_t, MaxHeight), offsetof(dynamicParam_t, MaxHeight)}, |
112 | {offsetof(paramset_t, Height_ACC_Effect), offsetof(dynamicParam_t, Height_ACC_Effect)}, |
112 | {offsetof(paramset_t, Height_ACC_Effect), offsetof(dynamicParam_t, Height_ACC_Effect)}, |
113 | {offsetof(paramset_t, CompassYawEffect), offsetof(dynamicParam_t, CompassYawEffect)}, |
113 | {offsetof(paramset_t, CompassYawEffect), offsetof(dynamicParam_t, CompassYawEffect)}, |
114 | {offsetof(paramset_t, GyroI), offsetof(dynamicParam_t, GyroI)}, |
114 | {offsetof(paramset_t, GyroI), offsetof(dynamicParam_t, GyroI)}, |
115 | {offsetof(paramset_t, GyroD), offsetof(dynamicParam_t, GyroD)}, |
115 | {offsetof(paramset_t, GyroD), offsetof(dynamicParam_t, GyroD)}, |
116 | {offsetof(paramset_t, IFactor), offsetof(dynamicParam_t, IFactor)}, |
116 | {offsetof(paramset_t, IFactor), offsetof(dynamicParam_t, IFactor)}, |
117 | {offsetof(paramset_t, ServoPitchControl), offsetof(dynamicParam_t, ServoPitchControl)}, |
117 | {offsetof(paramset_t, ServoPitchControl), offsetof(dynamicParam_t, ServoPitchControl)}, |
118 | {offsetof(paramset_t, LoopGasLimit), offsetof(dynamicParam_t, LoopGasLimit)}, |
118 | {offsetof(paramset_t, LoopGasLimit), offsetof(dynamicParam_t, LoopGasLimit)}, |
119 | {offsetof(paramset_t, AxisCoupling1), offsetof(dynamicParam_t, AxisCoupling1)}, |
119 | {offsetof(paramset_t, AxisCoupling1), offsetof(dynamicParam_t, AxisCoupling1)}, |
120 | {offsetof(paramset_t, AxisCoupling2), offsetof(dynamicParam_t, AxisCoupling2)}, |
120 | {offsetof(paramset_t, AxisCoupling2), offsetof(dynamicParam_t, AxisCoupling2)}, |
121 | {offsetof(paramset_t, AxisCouplingYawCorrection), offsetof(dynamicParam_t, AxisCouplingYawCorrection)}, |
121 | {offsetof(paramset_t, AxisCouplingYawCorrection), offsetof(dynamicParam_t, AxisCouplingYawCorrection)}, |
122 | {offsetof(paramset_t, DynamicStability), offsetof(dynamicParam_t, DynamicStability)}, |
122 | {offsetof(paramset_t, DynamicStability), offsetof(dynamicParam_t, DynamicStability)}, |
123 | {offsetof(paramset_t, NaviGpsModeControl), |
123 | {offsetof(paramset_t, NaviGpsModeControl), |
124 | offsetof(dynamicParam_t, NaviGpsModeControl)}, |
124 | offsetof(dynamicParam_t, NaviGpsModeControl)}, |
125 | {offsetof(paramset_t, NaviGpsGain), offsetof(dynamicParam_t, NaviGpsGain)}, |
125 | {offsetof(paramset_t, NaviGpsGain), offsetof(dynamicParam_t, NaviGpsGain)}, |
126 | {offsetof(paramset_t, NaviGpsP), offsetof(dynamicParam_t, NaviGpsP)}, |
126 | {offsetof(paramset_t, NaviGpsP), offsetof(dynamicParam_t, NaviGpsP)}, |
127 | {offsetof(paramset_t, NaviGpsI), offsetof(dynamicParam_t, NaviGpsI)}, |
127 | {offsetof(paramset_t, NaviGpsI), offsetof(dynamicParam_t, NaviGpsI)}, |
128 | {offsetof(paramset_t, NaviGpsD), offsetof(dynamicParam_t, NaviGpsD)}, |
128 | {offsetof(paramset_t, NaviGpsD), offsetof(dynamicParam_t, NaviGpsD)}, |
129 | {offsetof(paramset_t, NaviGpsACC), offsetof(dynamicParam_t, NaviGpsACC)}, |
129 | {offsetof(paramset_t, NaviGpsACC), offsetof(dynamicParam_t, NaviGpsACC)}, |
130 | {offsetof(paramset_t, NaviWindCorrection), offsetof(dynamicParam_t, NaviWindCorrection)}, |
130 | {offsetof(paramset_t, NaviWindCorrection), offsetof(dynamicParam_t, NaviWindCorrection)}, |
131 | {offsetof(paramset_t, NaviSpeedCompensation), offsetof(dynamicParam_t, NaviSpeedCompensation)}, |
131 | {offsetof(paramset_t, NaviSpeedCompensation), offsetof(dynamicParam_t, NaviSpeedCompensation)}, |
132 | {offsetof(paramset_t, ExternalControl), offsetof(dynamicParam_t, ExternalControl)} |
132 | {offsetof(paramset_t, ExternalControl), offsetof(dynamicParam_t, ExternalControl)} |
133 | }; |
133 | }; |
134 | 134 | ||
135 | const MMXLATION MMXLATIONS[] = { |
135 | const MMXLATION MMXLATIONS[] = { |
136 | {offsetof(paramset_t, HeightD), offsetof(dynamicParam_t, HeightD),0,100}, |
136 | {offsetof(paramset_t, HeightD), offsetof(dynamicParam_t, HeightD),0,100}, |
137 | {offsetof(paramset_t, HeightP), offsetof(dynamicParam_t, HeightD),0,150}, |
137 | {offsetof(paramset_t, HeightP), offsetof(dynamicParam_t, HeightD),0,150}, |
138 | {offsetof(paramset_t, GyroP), offsetof(dynamicParam_t, GyroP),0,255}, |
138 | {offsetof(paramset_t, GyroP), offsetof(dynamicParam_t, GyroP),0,255}, |
139 | {offsetof(paramset_t, J16Timing), offsetof(dynamicParam_t, J16Timing),1,255}, |
139 | {offsetof(paramset_t, J16Timing), offsetof(dynamicParam_t, J16Timing),1,255}, |
140 | {offsetof(paramset_t, J17Timing), offsetof(dynamicParam_t, J17Timing),1,255}, |
140 | {offsetof(paramset_t, J17Timing), offsetof(dynamicParam_t, J17Timing),1,255}, |
141 | {offsetof(paramset_t, NaviOperatingRadius), offsetof(dynamicParam_t, NaviOperatingRadius),10,255} |
141 | {offsetof(paramset_t, NaviOperatingRadius), offsetof(dynamicParam_t, NaviOperatingRadius),10,255} |
142 | }; |
142 | }; |
143 | 143 | ||
144 | uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
144 | uint8_t configuration_applyVariableToParam(uint8_t src, uint8_t min, uint8_t max) { |
145 | uint8_t result; |
145 | uint8_t result; |
146 | if (src>=251) result = variables[src-251]; |
146 | if (src>=251) result = variables[src-251]; |
147 | else result = src; |
147 | else result = src; |
148 | if (result < min) result = min; |
148 | if (result < min) result = min; |
149 | else if (result > max) result = max; |
149 | else if (result > max) result = max; |
150 | return result; |
150 | return result; |
151 | } |
151 | } |
152 | 152 | ||
153 | void configuration_applyVariablesToParams_dead(void) { |
153 | void configuration_applyVariablesToParams_dead(void) { |
154 | uint8_t i, src; |
154 | uint8_t i, src; |
155 | uint8_t* pointerToTgt; |
155 | uint8_t* pointerToTgt; |
156 | for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
156 | for(i=0; i<sizeof(XLATIONS)/sizeof(XLATION); i++) { |
157 | src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
157 | src = *((uint8_t*)(&staticParams + XLATIONS[i].sourceIdx)); |
158 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
158 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
159 | if (src < 255) { |
159 | if (src < 255) { |
160 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
160 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
161 | } |
161 | } |
162 | } |
162 | } |
163 | 163 | ||
164 | for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
164 | for(i=0; i<sizeof(MMXLATIONS)/sizeof(MMXLATION); i++) { |
165 | src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
165 | src = *((uint8_t*)(&staticParams + MMXLATIONS[i].sourceIdx)); |
166 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
166 | pointerToTgt = (uint8_t*)(&dynamicParams + XLATIONS[i].targetIdx); |
167 | if (src < 255) { |
167 | if (src < 255) { |
168 | *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
168 | *pointerToTgt = configuration_applyVariableToParam(src, MMXLATIONS[i].min, MMXLATIONS[i].max); |
169 | } |
169 | } |
170 | } |
170 | } |
171 | 171 | ||
172 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
172 | for (i=0; i<sizeof(staticParams.UserParams1); i++) { |
173 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams1) + i)); |
173 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams1) + i)); |
174 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + i); |
174 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + i); |
175 | if (src < 255) { |
175 | if (src < 255) { |
176 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
176 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
177 | } |
177 | } |
178 | } |
178 | } |
179 | 179 | ||
180 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
180 | for (i=0; i<sizeof(staticParams.UserParams2); i++) { |
181 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams2) + i)); |
181 | src = *((uint8_t*)(&staticParams + offsetof(paramset_t, UserParams2) + i)); |
182 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + sizeof(staticParams.UserParams1) + i); |
182 | pointerToTgt = (uint8_t*)(&dynamicParams + offsetof(dynamicParam_t, UserParams) + sizeof(staticParams.UserParams1) + i); |
183 | if (src < 255) { |
183 | if (src < 255) { |
184 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
184 | *pointerToTgt = configuration_applyVariableToParam(src, 0, 255); |
185 | } |
185 | } |
186 | } |
186 | } |
187 | } |
187 | } |
188 | 188 | ||
189 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
189 | uint8_t getCPUType(void) { // works only after reset or power on when the registers have default values |
190 | uint8_t CPUType = ATMEGA644; |
190 | uint8_t CPUType = ATMEGA644; |
191 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
191 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
192 | return CPUType; |
192 | return CPUType; |
193 | } |
193 | } |
194 | 194 | ||
195 | /* |
195 | /* |
196 | * Automatic detection of hardware components is not supported in this development-oriented |
196 | * Automatic detection of hardware components is not supported in this development-oriented |
197 | * FC firmware. It would go against the point of it: To enable alternative hardware |
197 | * FC firmware. It would go against the point of it: To enable alternative hardware |
198 | * configurations with otherwise unsupported components. Instead, one should write |
198 | * configurations with otherwise unsupported components. Instead, one should write |
199 | * custom code + adjust constants for the new hardware, and include the relevant code |
199 | * custom code + adjust constants for the new hardware, and include the relevant code |
200 | * from the makefile. |
200 | * from the makefile. |
201 | * However - we still do detect the board release. Reason: Otherwise it would be too |
201 | * However - we still do detect the board release. Reason: Otherwise it would be too |
202 | * tedious to have to modify the code for how to turn on and off LEDs when deploying |
202 | * tedious to have to modify the code for how to turn on and off LEDs when deploying |
203 | * on different HW version.... |
203 | * on different HW version.... |
204 | */ |
204 | */ |
205 | 205 | ||
206 | uint8_t getBoardRelease(void) { |
206 | uint8_t getBoardRelease(void) { |
207 | uint8_t BoardRelease = 13; |
207 | uint8_t BoardRelease = 13; |
208 | // the board release is coded via the pull up or down the 2 status LED |
208 | // the board release is coded via the pull up or down the 2 status LED |
209 | 209 | ||
210 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
210 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
211 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
211 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
212 | 212 | ||
213 | _delay_loop_2(1000); // make some delay |
213 | _delay_loop_2(1000); // make some delay |
214 | 214 | ||
215 | switch( PINB & ((1<<PINB1)|(1<<PINB0))) { |
215 | switch( PINB & ((1<<PINB1)|(1<<PINB0))) { |
216 | case 0x00: |
216 | case 0x00: |
217 | BoardRelease = 10; // 1.0 |
217 | BoardRelease = 10; // 1.0 |
218 | break; |
218 | break; |
219 | case 0x01: |
219 | case 0x01: |
220 | BoardRelease = 11; // 1.1 or 1.2 |
220 | BoardRelease = 11; // 1.1 or 1.2 |
221 | break; |
221 | break; |
222 | case 0x02: |
222 | case 0x02: |
223 | BoardRelease = 20; // 2.0 |
223 | BoardRelease = 20; // 2.0 |
224 | break; |
224 | break; |
225 | case 0x03: |
225 | case 0x03: |
226 | BoardRelease = 13; // 1.3 |
226 | BoardRelease = 13; // 1.3 |
227 | break; |
227 | break; |
228 | default: |
228 | default: |
229 | break; |
229 | break; |
230 | } |
230 | } |
231 | // set LED ports as output |
231 | // set LED ports as output |
232 | DDRB |= (1<<DDB1)|(1<<DDB0); |
232 | DDRB |= (1<<DDB1)|(1<<DDB0); |
233 | RED_ON; |
233 | RED_ON; |
234 | GRN_OFF; |
234 | GRN_OFF; |
235 | return BoardRelease; |
235 | return BoardRelease; |
236 | } |
236 | } |
237 | 237 | ||
238 | void beep(uint16_t millis) { |
238 | void beep(uint16_t millis) { |
239 | BeepTime = millis; |
239 | BeepTime = millis; |
240 | } |
240 | } |
241 | 241 | ||
242 | /* |
242 | /* |
243 | * Make [numbeeps] beeps. |
243 | * Make [numbeeps] beeps. |
244 | */ |
244 | */ |
245 | void beepNumber(uint8_t numbeeps) { |
245 | void beepNumber(uint8_t numbeeps) { |
246 | while(numbeeps--) { |
246 | while(numbeeps--) { |
247 | if(MKFlags & MKFLAG_MOTOR_RUN) return; //auf keinen Fall bei laufenden Motoren! |
247 | if(MKFlags & MKFLAG_MOTOR_RUN) return; //auf keinen Fall bei laufenden Motoren! |
248 | beep(100); // 0.1 second |
248 | beep(100); // 0.1 second |
249 | Delay_ms(250); // blocks 250 ms as pause to next beep, |
249 | Delay_ms(250); // blocks 250 ms as pause to next beep, |
250 | // this will block the flight control loop, |
250 | // this will block the flight control loop, |
251 | // therefore do not use this function if motors are running |
251 | // therefore do not use this function if motors are running |
252 | } |
252 | } |
253 | } |
253 | } |
254 | 254 | ||
255 | /* |
255 | /* |
256 | * Beep the R/C alarm signal |
256 | * Beep the R/C alarm signal |
257 | */ |
257 | */ |
258 | void beepRCAlarm(void) { |
258 | void beepRCAlarm(void) { |
259 | if(BeepModulation == 0xFFFF) { // If not already beeping an alarm signal (?) |
259 | if(BeepModulation == 0xFFFF) { // If not already beeping an alarm signal (?) |
260 | BeepTime = 15000; // 1.5 seconds |
260 | BeepTime = 15000; // 1.5 seconds |
261 | BeepModulation = 0x0C00; |
261 | BeepModulation = 0x0C00; |
262 | } |
262 | } |
263 | } |
263 | } |
264 | 264 | ||
265 | /* |
265 | /* |
266 | * Beep the I2C bus error signal |
266 | * Beep the I2C bus error signal |
267 | */ |
267 | */ |
268 | void beepI2CAlarm(void) { |
268 | void beepI2CAlarm(void) { |
269 | if((BeepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN)) { |
269 | if((BeepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN)) { |
270 | BeepTime = 10000; // 1 second |
270 | BeepTime = 10000; // 1 second |
271 | BeepModulation = 0x0080; |
271 | BeepModulation = 0x0080; |
272 | } |
272 | } |
273 | } |
273 | } |
274 | 274 | ||
275 | /* |
275 | /* |
276 | * Beep the battery low alarm signal |
276 | * Beep the battery low alarm signal |
277 | */ |
277 | */ |
278 | void beepBatteryAlarm(void) { |
278 | void beepBatteryAlarm(void) { |
279 | BeepModulation = 0x0300; |
279 | BeepModulation = 0x0300; |
280 | if(!BeepTime) { |
280 | if(!BeepTime) { |
281 | BeepTime = 6000; // 0.6 seconds |
281 | BeepTime = 6000; // 0.6 seconds |
282 | } |
282 | } |
283 | } |
283 | } |
284 | 284 | ||
285 | /* |
285 | /* |
286 | * Beep the EEPROM checksum alarm |
286 | * Beep the EEPROM checksum alarm |
287 | */ |
287 | */ |
288 | void beepEEPROMAlarm(void) { |
288 | void beepEEPROMAlarm(void) { |
289 | BeepModulation = 0x0007; |
289 | BeepModulation = 0x0007; |
290 | if(!BeepTime) { |
290 | if(!BeepTime) { |
291 | BeepTime = 6000; // 0.6 seconds |
291 | BeepTime = 6000; // 0.6 seconds |
292 | } |
292 | } |
293 | } |
293 | } |
294 | 294 |