Rev 1 | Rev 52 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 41 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
- | 2 | /*#######################################################################################*/ |
|
- | 3 | ||
- | 4 | // IMPORTANT NOTE: |
|
- | 5 | ||
- | 6 | // This is only a dummy implementation for errorfree compiling of the NaviCtrl sources. |
|
- | 7 | ||
- | 8 | // The GPS navigation routines are NOT included ! |
|
- | 9 | ||
- | 10 | /*#######################################################################################*/ |
|
- | 11 | /*#######################################################################################*/ |
|
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
12 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
13 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
15 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch |
16 | // + Nur für den privaten Gebrauch |
7 | // + FOR NON COMMERCIAL USE ONLY |
17 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
18 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
20 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
21 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
22 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
23 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
24 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
25 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
27 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
28 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
30 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
31 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
32 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
34 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
35 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
36 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
37 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
38 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
39 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
40 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
41 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
42 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
43 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
44 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
45 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
46 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
47 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
48 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
49 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
50 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
51 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
52 | // + clearly linked as origin |
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
53 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
44 | // |
54 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
55 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
56 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
57 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
Line 50... | Line 60... | ||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
60 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
61 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
62 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
63 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
64 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
65 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
66 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 67 | #include <stdio.h> |
|
- | 68 | #include <stdlib.h> |
|
- | 69 | #include <math.h> |
|
- | 70 | #include "91x_lib.h" |
|
57 | #include "main.h" |
71 | #include "main.h" |
- | 72 | #include "uart1.h" |
|
- | 73 | #include "GPS.h" |
|
- | 74 | #include "timer.h" |
|
- | 75 | #include "spi_slave.h" |
|
- | 76 | #include "waypoints.h" |
|
- | 77 | #include "i2c.h" |
|
- | 78 | ||
- | 79 | ||
- | 80 | #define M_PI_180 (M_PI / 180.0f) |
|
- | 81 | #define GPS_UPDATETIME_MS 200 // 200ms is 5 Hz |
|
- | 82 | typedef enum |
|
- | 83 | { |
|
- | 84 | GPS_FLIGHT_MODE_UNDEF, |
|
- | 85 | GPS_FLIGHT_MODE_FREE, |
|
- | 86 | GPS_FLIGHT_MODE_AID, |
|
- | 87 | GPS_FLIGHT_MODE_WAYPOINT |
|
- | 88 | } GPS_FlightMode_t; |
|
- | 89 | ||
- | 90 | typedef struct |
|
- | 91 | { |
|
- | 92 | float Gain; |
|
- | 93 | float P; |
|
- | 94 | float I; |
|
- | 95 | float D; |
|
- | 96 | float A; |
|
- | 97 | float ACC; |
|
- | 98 | u8 MinSat; |
|
- | 99 | s8 StickThreshold; |
|
- | 100 | float WindCorrection; |
|
- | 101 | s32 OperatingRadius; |
|
- | 102 | u32 NaviAngleLimitation; |
|
- | 103 | GPS_FlightMode_t FlightMode; |
|
- | 104 | } __attribute__((packed)) GPS_Parameter_t; |
|
- | 105 | ||
- | 106 | typedef struct |
|
- | 107 | { |
|
- | 108 | Status_t Status; // invalid, newdata, processed |
|
- | 109 | s32 North; // in cm |
|
- | 110 | s32 East; // in cm |
|
- | 111 | s32 Bearing; // in deg |
|
- | 112 | s32 Distance; // in cm |
|
- | 113 | } __attribute__((packed)) GPS_Deviation_t; |
|
- | 114 | GPS_Deviation_t TargetDeviation; |
|
- | 115 | ||
- | 116 | GPS_Stick_t GPS_Stick; |
|
- | 117 | GPS_Parameter_t GPS_Parameter; |
|
- | 118 | ||
- | 119 | // the gps reference positions |
|
- | 120 | GPS_Pos_t GPS_HoldPosition = {0,0,0, INVALID}; // the hold position |
|
- | 121 | GPS_Pos_t GPS_HomePosition = {0,0,0, INVALID}; // the home position |
|
- | 122 | GPS_Pos_t * GPS_pTargetPosition = NULL; // pointer to the actual target position |
|
- | 123 | Waypoint_t* GPS_pWaypoint = NULL; // pointer to the actual waypoint |
|
- | 124 | ||
- | 125 | //------------------------------------------------------------- |
|
- | 126 | // Update GPSParamter |
|
- | 127 | void GPS_UpdateParameter(void) |
|
- | 128 | { |
|
- | 129 | static GPS_FlightMode_t FlightMode_Old = GPS_FLIGHT_MODE_UNDEF; |
|
- | 130 | // in case of bad receiving conditions |
|
- | 131 | if(FC.RC_Quality < 100) |
|
- | 132 | { // set fixed parameter |
|
- | 133 | GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
|
- | 134 | GPS_Parameter.Gain = (float) 100; |
|
- | 135 | GPS_Parameter.P = (float) 90; |
|
- | 136 | GPS_Parameter.I = (float) 90; |
|
- | 137 | GPS_Parameter.D = (float) 90; |
|
- | 138 | GPS_Parameter.A = (float) 90; |
|
- | 139 | GPS_Parameter.ACC = (float) 0; |
|
- | 140 | GPS_Parameter.MinSat = 6; |
|
- | 141 | GPS_Parameter.StickThreshold = 8; |
|
- | 142 | GPS_Parameter.WindCorrection = 0.0; |
|
- | 143 | GPS_Parameter.OperatingRadius = 0; // forces the aircraft to fly to home positon |
|
- | 144 | GPS_Parameter.NaviAngleLimitation = 125; |
|
- | 145 | } |
|
- | 146 | else |
|
- | 147 | { |
|
- | 148 | // update parameter from FC |
|
- | 149 | if(StopNavigation) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
|
- | 150 | else |
|
- | 151 | { |
|
- | 152 | if (Parameter.NaviGpsModeControl < 50) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_AID; |
|
- | 153 | else if(Parameter.NaviGpsModeControl < 180) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
|
- | 154 | else GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT; |
|
- | 155 | } |
|
- | 156 | GPS_Parameter.Gain = (float)Parameter.NaviGpsGain; |
|
- | 157 | GPS_Parameter.P = (float)Parameter.NaviGpsP; |
|
- | 158 | GPS_Parameter.I = (float)Parameter.NaviGpsI; |
|
- | 159 | GPS_Parameter.D = (float)Parameter.NaviGpsD; |
|
- | 160 | GPS_Parameter.A = (float)Parameter.NaviGpsD; |
|
- | 161 | GPS_Parameter.ACC = (float)Parameter.NaviGpsACC; |
|
- | 162 | GPS_Parameter.MinSat = (u8)Parameter.NaviGpsMinSat; |
|
- | 163 | GPS_Parameter.StickThreshold = (s8)Parameter.NaviStickThreshold; |
|
- | 164 | GPS_Parameter.WindCorrection = (float)Parameter.NaviWindCorrection; |
|
- | 165 | GPS_Parameter.OperatingRadius = (s32)Parameter.NaviOperatingRadius * 100; // conversion of m to cm |
|
- | 166 | GPS_Parameter.NaviAngleLimitation = (u32) Parameter.NaviAngleLimitation * 2; |
|
- | 167 | } |
|
- | 168 | // FlightMode changed? |
|
- | 169 | if(GPS_Parameter.FlightMode != FlightMode_Old) BeepTime = 100; // beep to indicate that mode has switched |
|
- | 170 | FlightMode_Old = GPS_Parameter.FlightMode; |
|
- | 171 | } |
|
Line 58... | Line 172... | ||
58 | 172 | ||
59 | u8 OsdBar; // Direction home for OSD |
173 | //------------------------------------------------------------- |
60 | s16 OsdDistance; // Distance home |
174 | // This function defines a good GPS signal condition |
- | 175 | u8 GPS_IsSignalOK(void) |
|
- | 176 | { |
|
61 | s16 GPS_Nick; |
177 | if( (GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.NumOfSats >= GPS_Parameter.MinSat)) return(1); |
- | 178 | else return(0); |
|
Line -... | Line 179... | ||
- | 179 | } |
|
- | 180 | ||
- | 181 | //------------------------------------------------------------ |
|
- | 182 | // Checks for manual control action |
|
- | 183 | u8 GPS_IsManuallyControlled(void) |
|
- | 184 | { |
|
- | 185 | if( ( (abs(FC.StickNick) > GPS_Parameter.StickThreshold) || (abs(FC.StickRoll) > GPS_Parameter.StickThreshold)) && (GPS_Parameter.StickThreshold > 0)) return 1; |
|
- | 186 | else return 0; |
|
- | 187 | } |
|
- | 188 | ||
- | 189 | //------------------------------------------------------------ |
|
- | 190 | // copy GPS position from source position to target position |
|
- | 191 | u8 GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt) |
|
- | 192 | { |
|
- | 193 | u8 retval = 0; |
|
- | 194 | if((pGPSPosSrc == NULL) || (pGPSPosTgt == NULL)) return(retval); // bad pointer |
|
- | 195 | // copy only valid positions |
|
- | 196 | if(pGPSPosSrc->Status != INVALID) |
|
- | 197 | { |
|
62 | s16 GPS_Roll; |
198 | // if the source GPS position is not invalid |
- | 199 | pGPSPosTgt->Longitude = pGPSPosSrc->Longitude; |
|
- | 200 | pGPSPosTgt->Latitude = pGPSPosSrc->Latitude; |
|
- | 201 | pGPSPosTgt->Altitude = pGPSPosSrc->Altitude; |
|
- | 202 | pGPSPosTgt->Status = NEWDATA; // mark data in target position as new |
|
- | 203 | retval = 1; |
|
- | 204 | } |
|
- | 205 | return(retval); |
|
- | 206 | } |
|
- | 207 | ||
- | 208 | //------------------------------------------------------------ |
|
- | 209 | // clear position data |
|
- | 210 | u8 GPS_ClearPosition(GPS_Pos_t * pGPSPos) |
|
- | 211 | { |
|
- | 212 | u8 retval = FALSE; |
|
- | 213 | if(pGPSPos == NULL) return(retval); // bad pointer |
|
- | 214 | else |
|
- | 215 | { |
|
- | 216 | pGPSPos->Longitude = 0; |
|
- | 217 | pGPSPos->Latitude = 0; |
|
- | 218 | pGPSPos->Altitude = 0; |
|
- | 219 | pGPSPos->Status = INVALID; |
|
- | 220 | retval = TRUE; |
|
- | 221 | } |
|
Line 63... | Line -... | ||
63 | - | ||
64 | struct str_GPSParameter GPSParameter; |
- | |
65 | - | ||
66 | #define GPS_MODE_FREE 0 |
- | |
67 | #define GPS_MODE_AID 1 |
- | |
Line 68... | Line 222... | ||
68 | #define GPS_MODE_HOLD 2 |
222 | return (retval); |
- | 223 | } |
|
- | 224 | ||
- | 225 | ||
- | 226 | //------------------------------------------------------------ |
|
- | 227 | void GPS_Neutral() |
|
- | 228 | { |
|
- | 229 | GPS_Stick.Nick = 0; |
|
69 | #define GPS_MODE_HOME 3 |
230 | GPS_Stick.Roll = 0; |
70 | u32 GpsFlightMode = GPS_MODE_FREE; |
231 | GPS_Stick.Yaw = 0; |
71 | 232 | } |
|
154 | else if (GPS_Data.Used_Sat < GPS_SAT_MIN && !(beep_rythm % 5)) BeepTime = 10; |
607 | NaviData.MKFlags = (u8)FC.MKFlags; |