Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5 | hbuss | 1 | /*####################################################################################### |
2 | Flight Control |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 04.2007 Holger Buss |
||
6 | // + Nur für den privaten Gebrauch |
||
7 | // + www.MikroKopter.com |
||
8 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
9 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
||
10 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
11 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
12 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
13 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
14 | // + Verkauf von Luftbildaufnahmen, usw. |
||
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
16 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
17 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
||
18 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
19 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
20 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
21 | // + eindeutig als Ursprung verlinkt werden |
||
22 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
23 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
24 | // + Benutzung auf eigene Gefahr |
||
25 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
27 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
28 | // + mit unserer Zustimmung zulässig |
||
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
30 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
32 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
33 | // + this list of conditions and the following disclaimer. |
||
34 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
35 | // + from this software without specific prior written permission. |
||
36 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
||
37 | // + for non-commercial use (directly or indirectly) |
||
38 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
39 | // + with our written permission |
||
40 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
41 | // + clearly linked as origin // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
||
42 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
43 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
44 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
45 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
46 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
47 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
48 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
49 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
50 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
51 | // + POSSIBILITY OF SUCH DAMAGE. |
||
52 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
53 | |||
1 | ingob | 54 | signed int OffsetN, OffsetR, OffsetZ; |
55 | /* |
||
56 | signed int CalTabelleHorizontalN[4] = {67,-450,77,-411}; // Vier Messwerte 90° Horizontal gedreht |
||
57 | signed int CalTabelleHorizontalR[4] = {-310,175,183,-333}; |
||
58 | signed int CalTabelleHorizontalZ[4] = {-100,-390,-400,100}; // Messwinkel des Z-Sensors auch horizontal gemessen |
||
59 | */ |
||
60 | signed int CalTabelleHorizontalN[4] = { 75,-180,-440,-166}; // Vier Messwerte 90° Horizontal gedreht |
||
61 | signed int CalTabelleHorizontalR[4] = { -5,-230, 66, 246}; |
||
62 | signed int CalTabelleHorizontalZ[4] = {-290,-280, 44, 33}; // Messwinkel des Z-Sensors auch horizontal gemessen |
||
63 | |||
64 | signed int RawMagnet1a,RawMagnet1b; // reine AD-Messung |
||
65 | signed int RawMagnet2a,RawMagnet2b; |
||
66 | signed int RawMagnet3a,RawMagnet3b; |
||
67 | signed int UncalMagnetN,UncalMagnetR,UncalMagnetZ; // Messwert-Delta ohne Offset- und Verstärker korrektur |
||
68 | signed int MagnetN,MagnetR,MagnetZ; // Kalibrierte Messerte |
||
69 | unsigned int PwmHeading = 0; |
||
70 | unsigned char PC_Connected = 0; |
||
3 | ingob | 71 | int Heading; |
1 | ingob | 72 | #include "main.h" |
73 | |||
74 | |||
75 | //############################################################################ |
||
76 | // |
||
77 | void Wait(unsigned char dauer) |
||
78 | //############################################################################ |
||
79 | { |
||
80 | dauer = (unsigned char)TCNT0 + dauer; |
||
81 | while((TCNT0 - dauer) & 0x80); |
||
82 | } |
||
83 | |||
84 | void CalcFields(void) |
||
85 | { |
||
86 | UncalMagnetN = (2 * UncalMagnetN + (RawMagnet1a - RawMagnet1b)) / 3; |
||
87 | UncalMagnetR = (2 * UncalMagnetR + (RawMagnet3a - RawMagnet3b)) / 3; |
||
88 | UncalMagnetZ = (2 * UncalMagnetZ + (RawMagnet2a - RawMagnet2b)) / 3; |
||
89 | MagnetN = UncalMagnetN - OffsetN; |
||
90 | MagnetR = UncalMagnetR - OffsetR; |
||
91 | MagnetZ = UncalMagnetZ - OffsetZ; |
||
92 | } |
||
93 | |||
94 | //------------------------------------------------------ |
||
95 | void CalcHeading(void) |
||
96 | { |
||
97 | double nick_rad, roll_rad, Hx, Hy, Cx, Cy, Cz; |
||
98 | float nick, roll, XEx, XEy, YEy, YEz, YE, XE, XrawCal, YrawCal, ZrawCal, XEz; |
||
99 | int heading, azimuthgrad; |
||
100 | |||
101 | nick_rad = ((double)WinkelOut.Winkel[0]) * M_PI / (double)(180); |
||
102 | roll_rad = ((double)WinkelOut.Winkel[1]) * M_PI / (double)(180); |
||
103 | //roll_rad = 0; nick_rad = 0; |
||
104 | |||
105 | /* |
||
106 | Cx = (double) (MicroMag.Axis[Y_AXIS] + CY_OFFSET) * 0.707f - (double) (MicroMag.Axis[X_AXIS]+ CX_OFFSET) * 0.707f; |
||
107 | Cy = ((double) (MicroMag.Axis[Y_AXIS]+ CY_OFFSET) * 0.707f + (double) (MicroMag.Axis[X_AXIS]+ CX_OFFSET) * 0.707f); |
||
108 | Cz = -MicroMag.Axis[Z_AXIS] + CZ_OFFSET; |
||
109 | */ |
||
110 | Cx = MagnetN; |
||
111 | Cy = MagnetR; |
||
112 | Cz = -MagnetZ; |
||
113 | |||
114 | Hx = Cx * (double)cos(nick_rad) + |
||
115 | Cy * (double)sin(nick_rad) * (double)sin(roll_rad) - |
||
116 | Cz * (double)sin(nick_rad) * (double)cos(roll_rad); |
||
117 | |||
118 | Hy = Cy * (double)cos(roll_rad) + |
||
119 | Cz * (double)sin(roll_rad); |
||
120 | |||
121 | |||
122 | if(Hx == 0 && Hy < 0) heading = 90; |
||
123 | else if(Hx == 0 && Hy > 0) heading = 270; |
||
124 | else if(Hx < 0) heading = 180 - (atan(Hy / Hx) * 180 / M_PI); |
||
125 | else if(Hx > 0 && Hy < 0) heading = - (atan(Hy / Hx) * 180 / M_PI); |
||
126 | else if(Hx > 0 && Hy > 0) heading = 360 - (atan(Hy / Hx) * 180 / M_PI); |
||
127 | |||
128 | // DebugOut.Analog[14] = heading; |
||
129 | // if (FromFlightCtrl.IntegralNick > 0) heading = heading + FromFlightCtrl.IntegralNick/60; |
||
130 | |||
131 | if(heading < 361) DebugOut.Analog[14] = heading; |
||
3 | ingob | 132 | Heading = heading; |
1 | ingob | 133 | PwmHeading = heading + 10; |
134 | // MicroMag.Heading = heading; |
||
135 | // DebugOut.Analog[14] = heading; |
||
136 | } |
||
137 | |||
138 | |||
139 | |||
140 | //############################################################################ |
||
141 | //Hauptprogramm |
||
142 | int main (void) |
||
143 | //############################################################################ |
||
144 | { |
||
145 | DDRC = 0x08; |
||
146 | PORTC = 0x08; |
||
147 | DDRD = 0xf4; |
||
148 | PORTD = 0xA0; |
||
149 | DDRB = 0x04; |
||
150 | PORTB = 0x35; |
||
151 | |||
152 | LED_ON; |
||
153 | |||
154 | UART_Init(); |
||
155 | Timer0_Init(); |
||
156 | ADC_Init(); |
||
3 | ingob | 157 | InitIC2_Slave(); |
1 | ingob | 158 | sei();//Globale Interrupts Einschalten |
159 | Debug_Timer = SetDelay(100); // Sendeintervall |
||
3 | ingob | 160 | |
1 | ingob | 161 | |
162 | OffsetN = (CalTabelleHorizontalN[0] + CalTabelleHorizontalN[1] + CalTabelleHorizontalN[2] + CalTabelleHorizontalN[3]) / 4; |
||
163 | OffsetR = (CalTabelleHorizontalR[0] + CalTabelleHorizontalR[1] + CalTabelleHorizontalR[2] + CalTabelleHorizontalR[3]) / 4; |
||
164 | OffsetZ = (CalTabelleHorizontalZ[0] + CalTabelleHorizontalZ[1] + CalTabelleHorizontalZ[2] + CalTabelleHorizontalZ[3]) / 4; |
||
165 | |||
3 | ingob | 166 | VersionInfo.Hauptversion = VERSION_HAUPTVERSION; |
167 | VersionInfo.Nebenversion = VERSION_NEBENVERSION; |
||
1 | ingob | 168 | VersionInfo.PCKompatibel = 7; |
169 | |||
170 | |||
171 | while (1) |
||
172 | { |
||
173 | LED_ON; |
||
174 | FLIP_LOW; |
||
175 | Delay_ms(2); |
||
176 | RawMagnet1a = MessAD(0); |
||
177 | RawMagnet2a = MessAD(1); |
||
178 | RawMagnet3a = MessAD(7); |
||
179 | Delay_ms(1); |
||
180 | LED_OFF; |
||
181 | FLIP_HIGH; |
||
182 | Delay_ms(2); |
||
183 | RawMagnet1b = MessAD(0); |
||
184 | RawMagnet2b = MessAD(1); |
||
185 | RawMagnet3b = MessAD(7); |
||
186 | Delay_ms(1); |
||
187 | |||
188 | CalcFields(); |
||
189 | DebugOut.Analog[0] = MagnetN; |
||
190 | DebugOut.Analog[1] = MagnetR; |
||
191 | DebugOut.Analog[2] = MagnetZ; |
||
192 | DebugOut.Analog[3] = UncalMagnetN; |
||
193 | DebugOut.Analog[4] = UncalMagnetR; |
||
194 | DebugOut.Analog[5] = UncalMagnetZ; |
||
195 | /* |
||
196 | DebugOut.Analog[3] = RawMagnet1a; |
||
197 | DebugOut.Analog[4] = RawMagnet1b; |
||
198 | DebugOut.Analog[5] = RawMagnet3a; |
||
199 | DebugOut.Analog[6] = RawMagnet3b;*/ |
||
200 | DebugOut.Analog[6] = WinkelOut.Winkel[0]; |
||
201 | DebugOut.Analog[7] = WinkelOut.Winkel[1]; |
||
202 | |||
5 | hbuss | 203 | DebugOut.Analog[8] = WinkelOut.UserParameter[0]; |
204 | DebugOut.Analog[9] = WinkelOut.UserParameter[1]; |
||
205 | DebugOut.Analog[10] = WinkelOut.UserParameter[2]; |
||
206 | DebugOut.Analog[11] = WinkelOut.UserParameter[3]; |
||
207 | |||
208 | |||
1 | ingob | 209 | CalcHeading(); |
210 | BearbeiteRxDaten(); |
||
211 | PC_Connected = 100; |
||
212 | if(PC_Connected) |
||
213 | { |
||
214 | PC_Connected--; |
||
215 | DatenUebertragung(); |
||
216 | DDRD |= 0x02; // TXD-Leitung |
||
217 | } |
||
218 | else |
||
219 | { |
||
220 | DDRD &= ~0x02; // TXD-Leitung |
||
221 | } |
||
222 | } // while(1) - Hauptschleife |
||
223 | } |
||
224 |