Skip to content

Commit 0afac87

Browse files
committed
Support custom launch in sub missions
1 parent a4a8c7f commit 0afac87

3 files changed

Lines changed: 60 additions & 11 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: flightplanning
22
Type: Package
3-
Title: UAV Flight Planning
4-
Version: 0.8.4
3+
Title: Hivemapper/UAV Flight Planning
4+
Version: 0.8.14
55
Authors@R: c(
66
person("Caio", "Hamamura", email = "caiohamamura@gmail.com", role = c("aut", "cre")),
77
person("Danilo Roberti Alves de", "Almeida", email = "daniloflorestas@gmail.com", role = c("aut")),
@@ -22,5 +22,3 @@ License: MIT + file LICENSE
2222
Encoding: UTF-8
2323
LazyData: true
2424
RoxygenNote: 7.1.0
25-
URL: https://github.com/caiohamamura/flightplanning-R
26-
BugReports: https://github.com/caiohamamura/flightplanning-R/issues

R/main.R

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,62 @@ litchi.plan = function(roi, output,
249249

250250

251251
# Check if launch point has been specified before inserting it as way-point 1
252-
if ((launch[1] == 0) && (launch[2] == 0)) {
253-
message("No launch point specified")
252+
hasCustomLaunch = (launch[1] != 0) || (launch[2] != 0)
253+
if (hasCustomLaunch) {
254+
message("Launch point specified ", launch)
255+
p0x = launch[[1]][1]
256+
p0y = launch[[2]][1]
257+
258+
lookAt = 1
259+
while (lookAt <= length(waypoints)) {
260+
p1x = waypoints[lookAt, 1]
261+
p1y = waypoints[lookAt, 2]
262+
dx = p1x - p0x
263+
dy = p1y - p0y
264+
distance = sqrt(dx ** 2 + dy ** 2)
265+
266+
needsInterp = distance > max.waypoints.distance
267+
if (needsInterp) {
268+
nPtsToAdd = floor(distance / max.waypoints.distance)
269+
newSegDist = distance / nPtsToAdd
270+
271+
ptsToAdd = data.frame(
272+
x = numeric(nPtsToAdd + 1),
273+
y = numeric(nPtsToAdd + 1),
274+
isCurve = FALSE,
275+
takePhoto = FALSE
276+
)
277+
message('a', nPtsToAdd)
278+
ptsToAdd[1,] <- c(launch[1], launch[2], FALSE, FALSE)
279+
for (j in 1:nPtsToAdd) {
280+
281+
message('b', j)
282+
ptsToAdd[j + 1,] <- c(p0x + (j / (nPtsToAdd + 1)) * dx, p0y + (j / (nPtsToAdd + 1)) * dy, FALSE, FALSE)
283+
}
284+
285+
286+
message('c')
287+
waypoints = rbind(waypoints[0:lookAt-1,], ptsToAdd, waypoints[lookAt:length(waypoints),])
288+
} else {
289+
ptsToAdd = data.frame(
290+
x = numeric(1),
291+
y = numeric(1),
292+
isCurve = FALSE,
293+
takePhoto = FALSE
294+
)
295+
296+
message('d')
297+
ptsToAdd[1,] <- c(launch[1], launch[2], FALSE, FALSE)
298+
299+
message('e')
300+
waypoints = rbind(waypoints[0:lookAt-1,], ptsToAdd, waypoints[lookAt:length(waypoints),])
301+
}
302+
303+
lookAt = MAX_WAYPOINTS + lookAt
304+
}
305+
message(waypoints)
254306
} else {
255-
launchdf = data.frame(launch[1], launch[2], FALSE, FALSE)
256-
names(launchdf) = c("x", "y", "isCurve", "takePhoto")
257-
tempdf = rbind(launchdf, waypoints)
258-
waypoints = tempdf
307+
message("No launch point specified")
259308
}
260309

261310

@@ -313,11 +362,13 @@ litchi.plan = function(roi, output,
313362

314363
dfLitchi$split = rep(1:nBreaks, diff(c(0, waypointsBreak, finalSize)))
315364
splits = split.data.frame(dfLitchi, f = dfLitchi$split)
365+
316366
if (nrow(waypoints) > MAX_WAYPOINTS) {
317367
message("Your flight was split into ", length(splits), " sub-flights,
318368
because the number of waypoints ", nrow(waypoints), " exceeds the maximum of ", MAX_WAYPOINTS, ".")
319369
}
320370
else {
371+
# XXX flight time doesn't include custom launch point stuff
321372
message("Your flight was split into ", length(splits), " sub-flights,
322373
because the total flight time of ", round(totalFlightTime, 2), " minutes exceeds the max of ", max.flight.time, " minutes.")
323374
}

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' @description
44
#' Calculates the minimum oriented bounding box using the
5-
#' rotating claipers algorithm.
5+
#' rotating calipers algorithm.
66
#' Credits go to Daniel Wollschlaeger <https://github.com/ramnathv>
77
#'
88
#' @param xy A matrix of xy values from which to calculate the minimum oriented

0 commit comments

Comments
 (0)