Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
41 | ingob | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
||
171 | ingob | 6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
41 | ingob | 7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
||
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
10 | // + 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. |
||
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
15 | // + Verkauf von Luftbildaufnahmen, usw. |
||
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
17 | // + 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 |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + 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" |
||
22 | // + eindeutig als Ursprung verlinkt werden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
25 | // + Benutzung auf eigene Gefahr |
||
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
171 | ingob | 28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
41 | ingob | 29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
34 | // + 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 |
||
36 | // + from this software without specific prior written permission. |
||
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
||
38 | // + for non-commercial use (directly or indirectly) |
||
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
40 | // + with our written permission |
||
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
42 | // + clearly linked as origin |
||
171 | ingob | 43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
41 | ingob | 44 | // |
45 | // + 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 |
||
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
53 | // + 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 |
||
55 | // + POSSIBILITY OF SUCH DAMAGE. |
||
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
57 | |||
58 | #include <string.h> |
||
59 | #include "91x_lib.h" |
||
60 | #include "waypoints.h" |
||
61 | #include "uart1.h" |
||
62 | |||
63 | // the waypoints list |
||
280 | killagreg | 64 | #define MAX_LIST_LEN 31 |
227 | killagreg | 65 | |
280 | killagreg | 66 | Point_t PointList[MAX_LIST_LEN]; |
67 | u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
||
68 | u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
||
69 | u8 WPCount = 0; // number of waypoints |
||
70 | u8 PointCount = 0; // number of wp in the list can be maximal equal to MAX_LIST_LEN |
||
283 | holgerb | 71 | u8 POICount = 0; |
41 | ingob | 72 | |
280 | killagreg | 73 | u8 WPActive = TRUE; |
74 | |||
75 | u8 PointList_Init(void) |
||
41 | ingob | 76 | { |
280 | killagreg | 77 | return PointList_Clear(); |
41 | ingob | 78 | } |
79 | |||
280 | killagreg | 80 | u8 PointList_Clear(void) |
41 | ingob | 81 | { |
82 | u8 i; |
||
227 | killagreg | 83 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
84 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
||
280 | killagreg | 85 | WPCount = 0; // no waypoints |
283 | holgerb | 86 | POICount = 0; |
280 | killagreg | 87 | PointCount = 0; // no contents |
88 | WPActive = TRUE; |
||
89 | NaviData.WaypointNumber = WPCount; |
||
90 | NaviData.WaypointIndex = 0; |
||
41 | ingob | 91 | |
280 | killagreg | 92 | for(i = 0; i < MAX_LIST_LEN; i++) |
41 | ingob | 93 | { |
280 | killagreg | 94 | PointList[i].Position.Status = INVALID; |
95 | PointList[i].Position.Latitude = 0; |
||
96 | PointList[i].Position.Longitude = 0; |
||
97 | PointList[i].Position.Altitude = 0; |
||
98 | PointList[i].Heading = 361; // invalid value |
||
99 | PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
||
100 | PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
||
286 | killagreg | 101 | PointList[i].Type = POINT_TYPE_INVALID; |
280 | killagreg | 102 | PointList[i].Event_Flag = 0; // future implementation |
286 | killagreg | 103 | PointList[i].AltitudeRate = 0; // no change of setpoint |
41 | ingob | 104 | } |
105 | return TRUE; |
||
106 | } |
||
107 | |||
280 | killagreg | 108 | u8 PointList_GetCount(void) |
41 | ingob | 109 | { |
280 | killagreg | 110 | return PointCount; // number of points in the list |
41 | ingob | 111 | } |
112 | |||
280 | killagreg | 113 | u8 PointList_Append(Point_t* pPoint) |
41 | ingob | 114 | { |
280 | killagreg | 115 | if((PointCount < MAX_LIST_LEN) && (pPoint->Index == (PointCount + 1)) ) // there is still some space in the list and index points to next |
41 | ingob | 116 | { |
280 | killagreg | 117 | memcpy(&PointList[PointCount], pPoint, sizeof(Point_t)); // copy data to list entry // increment list length |
118 | if(PointList[PointCount].Type == POINT_TYPE_WP) WPCount++; |
||
283 | holgerb | 119 | if(PointList[PointCount].Type == POINT_TYPE_POI) POICount++; |
280 | killagreg | 120 | NaviData.WaypointNumber = WPCount; |
121 | PointCount++; |
||
122 | if(PointCount == 1) // only for the first entry |
||
277 | killagreg | 123 | { |
124 | // update POI index |
||
280 | killagreg | 125 | switch(PointList[WPIndex-1].Type) |
277 | killagreg | 126 | { |
127 | case POINT_TYPE_WP: |
||
280 | killagreg | 128 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
277 | killagreg | 129 | else POIIndex = 0; |
130 | break; |
||
131 | |||
132 | case POINT_TYPE_POI: |
||
133 | POIIndex = 1; |
||
283 | holgerb | 134 | POICount = 1; |
277 | killagreg | 135 | break; |
136 | |||
137 | default: |
||
138 | POIIndex = 0; |
||
139 | break; |
||
140 | } |
||
141 | } |
||
41 | ingob | 142 | return TRUE; |
143 | } |
||
144 | else return FALSE; |
||
145 | } |
||
146 | |||
227 | killagreg | 147 | // returns the pointer to the first waypoint within the list |
280 | killagreg | 148 | Point_t* PointList_WPBegin(void) |
41 | ingob | 149 | { |
277 | killagreg | 150 | u8 i; |
227 | killagreg | 151 | WPIndex = 0; // set list position invalid |
283 | holgerb | 152 | if(WPActive == FALSE) return(NULL); |
277 | killagreg | 153 | POIIndex = 0; // set invalid POI |
280 | killagreg | 154 | if(PointCount > 0) |
152 | killagreg | 155 | { |
225 | killagreg | 156 | // search for first wp in list |
280 | killagreg | 157 | for(i = 0; i <PointCount; i++) |
225 | killagreg | 158 | { |
280 | killagreg | 159 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
225 | killagreg | 160 | { |
227 | killagreg | 161 | WPIndex = i + 1; |
225 | killagreg | 162 | break; |
163 | } |
||
164 | } |
||
277 | killagreg | 165 | if(WPIndex) // found a WP in the list |
166 | { |
||
280 | killagreg | 167 | NaviData.WaypointIndex = 1; |
277 | killagreg | 168 | // update index to POI |
280 | killagreg | 169 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
277 | killagreg | 170 | else POIIndex = 0; |
280 | killagreg | 171 | return(&(PointList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list |
277 | killagreg | 172 | } |
173 | else // some points in the list but no WP found |
||
174 | { |
||
280 | killagreg | 175 | NaviData.WaypointIndex = 0; |
277 | killagreg | 176 | //Check for an existing POI |
280 | killagreg | 177 | for(i = 0; i < PointCount; i++) |
277 | killagreg | 178 | { |
280 | killagreg | 179 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
277 | killagreg | 180 | { |
181 | POIIndex = i + 1; |
||
182 | break; |
||
183 | } |
||
184 | } |
||
185 | return NULL; |
||
186 | } |
||
152 | killagreg | 187 | } |
277 | killagreg | 188 | else // no point in the list |
152 | killagreg | 189 | { |
277 | killagreg | 190 | POIIndex = 0; |
280 | killagreg | 191 | NaviData.WaypointIndex = 0; |
277 | killagreg | 192 | return NULL; |
227 | killagreg | 193 | } |
41 | ingob | 194 | } |
195 | |||
225 | killagreg | 196 | // returns the last waypoint |
280 | killagreg | 197 | Point_t* PointList_WPEnd(void) |
151 | killagreg | 198 | { |
277 | killagreg | 199 | |
200 | u8 i; |
||
227 | killagreg | 201 | WPIndex = 0; // set list position invalid |
277 | killagreg | 202 | POIIndex = 0; // set invalid |
283 | holgerb | 203 | |
280 | killagreg | 204 | if(WPActive == FALSE) return(NULL); |
277 | killagreg | 205 | |
280 | killagreg | 206 | if(PointCount > 0) |
151 | killagreg | 207 | { |
227 | killagreg | 208 | // search backward! |
280 | killagreg | 209 | for(i = 1; i <= PointCount; i++) |
225 | killagreg | 210 | { |
280 | killagreg | 211 | if((PointList[PointCount - i].Type == POINT_TYPE_WP) && (PointList[PointCount - i].Position.Status != INVALID)) |
225 | killagreg | 212 | { |
280 | killagreg | 213 | WPIndex = PointCount - i + 1; |
225 | killagreg | 214 | break; |
215 | } |
||
216 | } |
||
277 | killagreg | 217 | if(WPIndex) // found a WP within the list |
218 | { |
||
280 | killagreg | 219 | NaviData.WaypointIndex = WPCount; |
220 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
||
277 | killagreg | 221 | else POIIndex = 0; |
280 | killagreg | 222 | return(&(PointList[WPIndex-1])); |
277 | killagreg | 223 | } |
278 | killagreg | 224 | else // list contains some points but no WP in the list |
277 | killagreg | 225 | { |
226 | // search backward for a POI! |
||
280 | killagreg | 227 | for(i = 1; i <= PointCount; i++) |
277 | killagreg | 228 | { |
280 | killagreg | 229 | if((PointList[PointCount - i].Type == POINT_TYPE_POI) && (PointList[PointCount - i].Position.Status != INVALID)) |
277 | killagreg | 230 | { |
280 | killagreg | 231 | POIIndex = PointCount - i + 1; |
277 | killagreg | 232 | break; |
233 | } |
||
234 | } |
||
280 | killagreg | 235 | NaviData.WaypointIndex = 0; |
277 | killagreg | 236 | return NULL; |
237 | } |
||
151 | killagreg | 238 | } |
277 | killagreg | 239 | else // no point in the list |
227 | killagreg | 240 | { |
280 | killagreg | 241 | POIIndex = 0; |
242 | NaviData.WaypointIndex = 0; |
||
243 | return NULL; |
||
227 | killagreg | 244 | } |
151 | killagreg | 245 | } |
246 | |||
41 | ingob | 247 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
280 | killagreg | 248 | Point_t* PointList_WPNext(void) |
41 | ingob | 249 | { |
227 | killagreg | 250 | u8 wp_found = 0; |
280 | killagreg | 251 | if(WPActive == FALSE) return(NULL); |
227 | killagreg | 252 | |
280 | killagreg | 253 | if(WPIndex < PointCount) // if there is a next entry in the list |
41 | ingob | 254 | { |
227 | killagreg | 255 | u8 i; |
280 | killagreg | 256 | for(i = WPIndex; i < PointCount; i++) // start search for next at next list entry |
225 | killagreg | 257 | { |
280 | killagreg | 258 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
225 | killagreg | 259 | { |
227 | killagreg | 260 | wp_found = i+1; |
225 | killagreg | 261 | break; |
262 | } |
||
263 | } |
||
41 | ingob | 264 | } |
227 | killagreg | 265 | if(wp_found) |
266 | { |
||
267 | WPIndex = wp_found; // update list position |
||
280 | killagreg | 268 | NaviData.WaypointIndex++; |
269 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
||
227 | killagreg | 270 | else POIIndex = 0; |
280 | killagreg | 271 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
227 | killagreg | 272 | } |
277 | killagreg | 273 | else |
280 | killagreg | 274 | { // no next wp found |
275 | NaviData.WaypointIndex = 0; |
||
277 | killagreg | 276 | POIIndex = 0; |
277 | return(NULL); |
||
278 | } |
||
41 | ingob | 279 | } |
280 | killagreg | 280 | |
281 | void PointList_WPActive(u8 set) |
||
282 | { |
||
283 | if(set) WPActive = TRUE; |
||
284 | else WPActive = FALSE; |
||
285 | } |
||
41 | ingob | 286 | |
280 | killagreg | 287 | Point_t* PointList_GetAt(u8 index) |
92 | killagreg | 288 | { |
280 | killagreg | 289 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
92 | killagreg | 290 | else return(NULL); |
291 | } |
||
224 | killagreg | 292 | |
280 | killagreg | 293 | Point_t* PointList_GetPOI(void) |
224 | killagreg | 294 | { |
280 | killagreg | 295 | return PointList_GetAt(POIIndex); |
224 | killagreg | 296 | } |
297 |