Skip to content

Commit

Permalink
remove punch check (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalzauberzeug committed Aug 28, 2024
1 parent 41cdfc4 commit 4a6bd9d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 164 deletions.
137 changes: 0 additions & 137 deletions field_friend/automations/implements/punch_dialog.py

This file was deleted.

2 changes: 1 addition & 1 deletion field_friend/automations/implements/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def get_stretch(self, max_distance: float) -> float:
return self.WORKING_DISTANCE
if stretch < 0:
stretch = 0
if stretch < max_distance and await self.ask_for_punch(closest_crop_id):
if stretch < max_distance:
self.next_punch_y_position = closest_crop_position.y
return stretch
return self.WORKING_DISTANCE
Expand Down
26 changes: 1 addition & 25 deletions field_friend/automations/implements/weeding_implement.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from ...hardware import ChainAxis
from .implement import Implement
from .punch_dialog import PunchDialog

if TYPE_CHECKING:
from system import System
Expand All @@ -34,7 +33,6 @@ def __init__(self, name: str, system: 'System', persistence_key: str = 'weeding
self.puncher = system.puncher
self.cultivated_crop: str | None = None
self.crop_safety_distance: float = 0.01
self.with_punch_check: bool = False

# dual mechanism
self.with_drilling: bool = False
Expand All @@ -50,7 +48,6 @@ def __init__(self, name: str, system: 'System', persistence_key: str = 'weeding
self.last_punches: deque[rosys.geometry.Point] = deque(maxlen=5)
self.next_punch_y_position: float = 0

self.punch_dialog: PunchDialog | None = None
rosys.on_repeat(self._update_time_and_distance, 0.1)

async def prepare(self) -> bool:
Expand Down Expand Up @@ -169,8 +166,7 @@ def backup(self) -> dict:
'with_chopping': self.with_chopping,
'chop_if_no_crops': self.chop_if_no_crops,
'cultivated_crop': self.cultivated_crop,
'crop_safety_distance': self.crop_safety_distance,
'with_punch_check': self.with_punch_check,
'crop_safety_distance': self.crop_safety_distance
}

def restore(self, data: dict[str, Any]) -> None:
Expand All @@ -179,7 +175,6 @@ def restore(self, data: dict[str, Any]) -> None:
self.chop_if_no_crops = data.get('chop_if_no_crops', self.chop_if_no_crops)
self.cultivated_crop = data.get('cultivated_crop', self.cultivated_crop)
self.crop_safety_distance = data.get('crop_safety_distance', self.crop_safety_distance)
self.with_punch_check = data.get('with_punch_check', self.with_punch_check)

def clear(self) -> None:
self.crops_to_handle = {}
Expand Down Expand Up @@ -214,22 +209,3 @@ def settings_ui(self):
.classes('w-24') \
.bind_value(self, 'crop_safety_distance') \
.tooltip('Set the crop safety distance for the weeding automation')
ui.checkbox('With punch check', value=True) \
.bind_value(self, 'with_punch_check') \
.tooltip('Set the weeding automation to check for punch')
self.punch_dialog = PunchDialog(self.system)

async def ask_for_punch(self, plant_id: str | None = None) -> bool:
if not self.with_punch_check or plant_id is None or self.punch_dialog is None:
return True
self.punch_dialog.target_plant = self.system.plant_provider.get_plant_by_id(plant_id)
result: str | None = None
try:
result = await asyncio.wait_for(self.punch_dialog, timeout=self.punch_dialog.timeout)
if result == 'Yes':
self.log.info('punching was allowed')
return True
except asyncio.TimeoutError:
self.punch_dialog.close()
self.log.warning('punch was not allowed')
return False
2 changes: 1 addition & 1 deletion field_friend/automations/implements/weeding_screw.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def get_stretch(self, max_distance: float) -> float:
stretch = 0
self.log.info(f'Targeting weed {next_weed_id} which is {stretch} away at world: '
f'{weed_world_position}, local: {next_weed_position}')
if stretch < max_distance and await self.ask_for_punch(next_weed_id):
if stretch < max_distance:
self.next_punch_y_position = next_weed_position.y
return stretch
else:
Expand Down

0 comments on commit 4a6bd9d

Please sign in to comment.