@@ -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,
318368because 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,
322373because the total flight time of " , round(totalFlightTime , 2 ), " minutes exceeds the max of " , max.flight.time , " minutes." )
323374 }
0 commit comments