-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwaypointGenerator.cpp
166 lines (156 loc) · 6.28 KB
/
waypointGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// Academic License - for use in teaching, academic research, and meeting
// course requirements at degree granting institutions only. Not for
// government, commercial, or other organizational use.
// File: waypointGenerator.cpp
//
// MATLAB Coder version : 4.1
// C/C++ source code generated on : 02-May-2019 23:20:30
//
// Include Files
#include "waypointGenerator.h"
#include "waypointGenerator_emxutil.h"
// Function Definitions
//
// Inputs:
// vertPoints: number of vertical points required, found by doing width/TurnRadius
// topLeft: top left point of the search area, array [x_TL, y_TL]
// botRight: bot right point of the search area, array [x_BL, y_BL]
// botLeftGPs: array for lat and long of bot left point
// Arguments : const double topLeft[2]
// const double botRight[2]
// double vertPoints
// const double botLeftGPS[2]
// emxArray_real_T *SearchPattern
// Return Type : void
//
void waypointGenerator(const double topLeft[2], const double botRight[2], double
vertPoints, const double botLeftGPS[2], emxArray_real_T *SearchPattern)
{
emxArray_real_T *left_waypoints;
emxArray_real_T *mid_waypoints;
emxArray_real_T *right_waypoints;
double botMid_idx_0;
double botMid_idx_1;
double x_distance_iteration;
double y_distance_iteration;
int i0;
int i1;
int i;
double d0;
int direction;
double d1;
emxInit_real_T(&left_waypoints, 2);
emxInit_real_T(&mid_waypoints, 2);
emxInit_real_T(&right_waypoints, 2);
// Function assumes Cartesian plane, then converts to geodetic coordinates
// In C++ code, use gpsDistance function to find top left and bot right
// points using bot left as a reference point for deltaLat and deltaLong
botMid_idx_0 = botRight[0] / 2.0;
botMid_idx_1 = botRight[1] / 2.0;
x_distance_iteration = topLeft[0] / vertPoints;
y_distance_iteration = topLeft[1] / vertPoints;
i0 = (int)vertPoints;
i1 = left_waypoints->size[0] * left_waypoints->size[1];
left_waypoints->size[0] = i0;
left_waypoints->size[1] = 2;
emxEnsureCapacity_real_T(left_waypoints, i1);
i1 = mid_waypoints->size[0] * mid_waypoints->size[1];
mid_waypoints->size[0] = i0;
mid_waypoints->size[1] = 2;
emxEnsureCapacity_real_T(mid_waypoints, i1);
i1 = right_waypoints->size[0] * right_waypoints->size[1];
right_waypoints->size[0] = i0;
right_waypoints->size[1] = 2;
emxEnsureCapacity_real_T(right_waypoints, i1);
for (i = 0; i < i0; i++) {
d0 = x_distance_iteration * (1.0 + (double)i);
left_waypoints->data[i] = d0;
d1 = y_distance_iteration * (1.0 + (double)i);
left_waypoints->data[i + left_waypoints->size[0]] = d1;
mid_waypoints->data[i] = botMid_idx_0 + d0;
mid_waypoints->data[i + mid_waypoints->size[0]] = botMid_idx_1 + d1;
right_waypoints->data[i] = botRight[0] + d0;
right_waypoints->data[i + right_waypoints->size[0]] = botRight[1] + d1;
}
x_distance_iteration = 3.0 * vertPoints;
i1 = SearchPattern->size[0] * SearchPattern->size[1];
direction = (int)x_distance_iteration;
SearchPattern->size[0] = direction;
SearchPattern->size[1] = 2;
emxEnsureCapacity_real_T(SearchPattern, i1);
direction <<= 1;
for (i1 = 0; i1 < direction; i1++) {
SearchPattern->data[i1] = 0.0;
}
direction = 1;
y_distance_iteration = 3.0;
SearchPattern->data[0] = 0.0;
SearchPattern->data[SearchPattern->size[0]] = 0.0;
SearchPattern->data[1] = botMid_idx_0;
SearchPattern->data[1 + SearchPattern->size[0]] = botMid_idx_1;
SearchPattern->data[2] = botRight[0];
SearchPattern->data[2 + SearchPattern->size[0]] = botRight[1];
for (i = 0; i < i0; i++) {
if (direction == 0) {
SearchPattern->data[(int)(y_distance_iteration + 1.0) - 1] =
left_waypoints->data[i];
SearchPattern->data[((int)(y_distance_iteration + 1.0) +
SearchPattern->size[0]) - 1] = left_waypoints->data[i
+ left_waypoints->size[0]];
SearchPattern->data[(int)(y_distance_iteration + 2.0) - 1] =
mid_waypoints->data[i];
SearchPattern->data[((int)(y_distance_iteration + 2.0) +
SearchPattern->size[0]) - 1] = mid_waypoints->data[i
+ mid_waypoints->size[0]];
SearchPattern->data[(int)(y_distance_iteration + 3.0) - 1] =
right_waypoints->data[i];
SearchPattern->data[((int)(y_distance_iteration + 3.0) +
SearchPattern->size[0]) - 1] = right_waypoints->
data[i + right_waypoints->size[0]];
direction = 1;
y_distance_iteration += 3.0;
} else {
i1 = (int)(y_distance_iteration + 1.0);
SearchPattern->data[i1 - 1] = right_waypoints->data[i];
SearchPattern->data[(i1 + SearchPattern->size[0]) - 1] =
right_waypoints->data[i + right_waypoints->size[0]];
i1 = (int)(y_distance_iteration + 2.0);
SearchPattern->data[i1 - 1] = mid_waypoints->data[i];
SearchPattern->data[(i1 + SearchPattern->size[0]) - 1] =
mid_waypoints->data[i + mid_waypoints->size[0]];
i1 = (int)(y_distance_iteration + 3.0);
SearchPattern->data[i1 - 1] = left_waypoints->data[i];
SearchPattern->data[(i1 + SearchPattern->size[0]) - 1] =
left_waypoints->data[i + left_waypoints->size[0]];
direction = 0;
y_distance_iteration += 3.0;
}
}
emxFree_real_T(&right_waypoints);
emxFree_real_T(&mid_waypoints);
emxFree_real_T(&left_waypoints);
i0 = (int)(x_distance_iteration + 3.0);
for (i = 0; i < i0; i++) {
x_distance_iteration = SearchPattern->data[i];
// INPUT:
// deltaX: desired x distance (in m). This x up in cartesian coordinates
// deltaY: desired y distance (in m). This y is West/East direction
// pos: Current position [lat,lon]
// This function uses the NED frame with +x = North = dLat
// and +y = East = dLon
// km
// To meters
// coordinate offset in Radians
SearchPattern->data[i] = botLeftGPS[0] + SearchPattern->data[i +
SearchPattern->size[0]] * 0.001 / 6378.037 * 57.295779513082323;
SearchPattern->data[i + SearchPattern->size[0]] = botLeftGPS[1] +
x_distance_iteration * 0.001 / 6378.037 * 57.295779513082323;
}
// [lattrk, longtrk] = track(SearchPattern); %checks waypoints path if so desired
}
//
// File trailer for waypointGenerator.cpp
//
// [EOF]
//