Skip to content

Commit

Permalink
refactor: one single function to retrieve the current proximity warni…
Browse files Browse the repository at this point in the history
…ng threshold
  • Loading branch information
ntamas committed Jul 9, 2023
1 parent 2f3c939 commit 038a7a3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/modules/sbstudio/plugin/model/safety_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,10 @@ def _refresh_overlay(self) -> None:
)

overlay.markers = markers


def get_proximity_warning_threshold(context: Context) -> float:
"""Shortcut to return the current proximity warning threshold, irrespectively
of whether proximity warnings are enabled or not.
"""
return float(context.scene.skybrush.safety_check.proximity_warning_threshold)
4 changes: 2 additions & 2 deletions src/modules/sbstudio/plugin/operators/land.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sbstudio.plugin.api import get_api
from sbstudio.plugin.constants import Collections
from sbstudio.plugin.model.formation import create_formation
from sbstudio.plugin.model.safety_check import get_proximity_warning_threshold
from sbstudio.plugin.utils.evaluator import create_position_evaluator

from .base import StoryboardOperator
Expand Down Expand Up @@ -108,10 +109,9 @@ def _run(self, storyboard, *, context) -> bool:
# Ask the API to figure out the start times and durations for each drone
# TODO(ntamas): spindown time!
fps = context.scene.render.fps
min_distance = context.scene.skybrush.safety_check.proximity_warning_threshold
delays, durations = get_api().plan_landing(
source,
min_distance=min_distance,
min_distance=get_proximity_warning_threshold(context),
velocity=self.velocity,
target_altitude=self.altitude,
spindown_time=self.spindown_time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from bpy.props import EnumProperty

from sbstudio.plugin.model.safety_check import get_proximity_warning_threshold
from sbstudio.plugin.utils.collections import sort_collection
from sbstudio.plugin.utils.evaluator import create_position_evaluator

Expand Down Expand Up @@ -132,9 +133,7 @@ def _execute_on_formation_ENSURE_SAFETY_DISTANCE(
skipped: List[int] = []
result: List[int] = []

dist_threshold: float = (
context.scene.skybrush.safety_check.proximity_warning_threshold
)
dist_threshold: float = get_proximity_warning_threshold(context)

while queue:
# Reset the mask
Expand Down
3 changes: 2 additions & 1 deletion src/modules/sbstudio/plugin/operators/return_to_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from sbstudio.plugin.constants import Collections
from sbstudio.plugin.model.formation import create_formation
from sbstudio.plugin.model.safety_check import get_proximity_warning_threshold

from .base import StoryboardOperator
from .takeoff import create_helper_formation_for_takeoff_and_landing
Expand Down Expand Up @@ -91,7 +92,7 @@ def _run(self, storyboard, *, context) -> bool:
frame=first_frame,
base_altitude=self.altitude,
layer_height=self.altitude_shift,
min_distance=context.scene.skybrush.safety_check.proximity_warning_threshold,
min_distance=get_proximity_warning_threshold(context),
)

diffs = [
Expand Down
4 changes: 2 additions & 2 deletions src/modules/sbstudio/plugin/operators/takeoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from bpy.props import BoolProperty, FloatProperty, IntProperty
from bpy.types import Context, Object
from math import ceil
from typing import List

from sbstudio.plugin.api import get_api
from sbstudio.plugin.constants import Collections
from sbstudio.plugin.model.formation import create_formation
from sbstudio.plugin.model.safety_check import get_proximity_warning_threshold
from sbstudio.plugin.model.storyboard import Storyboard
from sbstudio.plugin.utils.evaluator import create_position_evaluator

Expand Down Expand Up @@ -107,7 +107,7 @@ def _run(self, storyboard: Storyboard, *, context) -> bool:
frame=self.start_frame,
base_altitude=self.altitude,
layer_height=self.altitude_shift,
min_distance=context.scene.skybrush.safety_check.proximity_warning_threshold,
min_distance=get_proximity_warning_threshold(context),
)

# Calculate the Z distance to travel for each drone
Expand Down

0 comments on commit 038a7a3

Please sign in to comment.