Skip to content

Commit

Permalink
fix: do not call API during takeoff and landing for simple situations
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Jul 9, 2023
1 parent 4959e88 commit 16e3ddf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
24 changes: 16 additions & 8 deletions src/modules/sbstudio/plugin/operators/land.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from bpy.props import FloatProperty, IntProperty
from bpy.types import Context

from sbstudio.math.nearest_neighbors import find_nearest_neighbors
from sbstudio.plugin.api import get_api
from sbstudio.plugin.constants import Collections
from sbstudio.plugin.model.formation import create_formation
Expand Down Expand Up @@ -107,15 +108,22 @@ def _run(self, storyboard, *, context) -> bool:
return False

# Ask the API to figure out the start times and durations for each drone
# TODO(ntamas): spindown time!
fps = context.scene.render.fps
delays, durations = get_api().plan_landing(
source,
min_distance=get_proximity_warning_threshold(context),
velocity=self.velocity,
target_altitude=self.altitude,
spindown_time=self.spindown_time,
)
min_distance = get_proximity_warning_threshold(context)
_, _, dist = find_nearest_neighbors(target)
if dist < min_distance:
delays, durations = get_api().plan_landing(
source,
min_distance=min_distance,
velocity=self.velocity,
target_altitude=self.altitude,
spindown_time=self.spindown_time,
)
else:
# We can save an API call here
delays = [0] * len(source)
durations = [diff / self.velocity for diff in diffs]

delays = [int(ceil(delay * fps)) for delay in delays]
durations = [int(floor(duration * fps)) for duration in durations]
max_duration = max(
Expand Down
15 changes: 11 additions & 4 deletions src/modules/sbstudio/plugin/operators/takeoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from bpy.types import Context, Object
from math import ceil

from sbstudio.math.nearest_neighbors import find_nearest_neighbors
from sbstudio.plugin.api import get_api
from sbstudio.plugin.constants import Collections
from sbstudio.plugin.model.formation import create_formation
Expand Down Expand Up @@ -222,10 +223,16 @@ def create_helper_formation_for_takeoff_and_landing(

# Figure out how many phases we will need, based on the current safety
# threshold and the arrangement of the drones
groups = get_api().decompose_points(
source, min_distance=min_distance, method="balanced"
)
num_groups = max(groups) + 1
_, _, dist = find_nearest_neighbors(source)
if dist < min_distance:
groups = get_api().decompose_points(
source, min_distance=min_distance, method="balanced"
)
else:
# We can save an API call here
groups = [0] * len(source)

num_groups = max(groups) + 1 if groups else 0

# Prepare the points of the target formation to take off to
target = [
Expand Down

0 comments on commit 16e3ddf

Please sign in to comment.