Skip to content

Commit

Permalink
Allow recording weeding action in timelapse video (#155)
Browse files Browse the repository at this point in the history
* allow recording weeding action in timelapse video

* fix name

* fix name

---------

Co-authored-by: Pascal Schade <[email protected]>
  • Loading branch information
rodja and pascalzauberzeug committed Aug 29, 2024
1 parent 4a6bd9d commit f409de5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
16 changes: 13 additions & 3 deletions field_friend/automations/implements/weeding_implement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, name: str, system: 'System', persistence_key: str = 'weeding
self.system = system
self.kpi_provider = system.kpi_provider
self.puncher = system.puncher
self.record_video = False
self.cultivated_crop: str | None = None
self.crop_safety_distance: float = 0.01

Expand Down Expand Up @@ -63,17 +64,21 @@ async def prepare(self) -> bool:
async def finish(self) -> None:
self.system.plant_locator.pause()
await self.system.field_friend.stop()
await self.system.timelapse_recorder.compress_video()
await super().finish()

async def activate(self):
await self.system.field_friend.flashlight.turn_on()
await self.puncher.clear_view()
self.system.plant_locator.resume()
await rosys.sleep(3)
self.system.plant_locator.resume()
if self.record_video:
self.system.timelapse_recorder.camera = self.system.camera_provider.first_connected_camera
await super().activate()

async def deactivate(self):
await super().deactivate()
self.system.timelapse_recorder.camera = None
await self.system.field_friend.flashlight.turn_off()
self.system.plant_locator.pause()
self.kpi_provider.increment_weeding_kpi('rows_weeded')
Expand All @@ -94,7 +99,7 @@ async def _check_hardware_ready(self) -> bool:
rosys.notify('E-Stop is active, aborting', 'negative')
self.log.error('E-Stop is active, aborting')
return False
camera = next((camera for camera in self.system.camera_provider.cameras.values() if camera.is_connected), None)
camera = self.system.camera_provider.first_connected_camera
if not camera:
rosys.notify('no camera connected')
return False
Expand Down Expand Up @@ -166,7 +171,8 @@ 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
'crop_safety_distance': self.crop_safety_distance,
'record_video': self.record_video,
}

def restore(self, data: dict[str, Any]) -> None:
Expand All @@ -175,6 +181,7 @@ 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.record_video = data.get('record_video', self.record_video)

def clear(self) -> None:
self.crops_to_handle = {}
Expand Down Expand Up @@ -209,3 +216,6 @@ 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('record video', on_change=self.request_backup) \
.bind_value(self, 'record_video') \
.tooltip('Set the weeding automation to record video')
4 changes: 4 additions & 0 deletions field_friend/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def watch_robot() -> None:
self.automator = rosys.automation.Automator(self.steerer, on_interrupt=self.field_friend.stop)
self.automation_watcher = AutomationWatcher(self)
self.monitoring = Recorder(self)
self.timelapse_recorder = rosys.analysis.TimelapseRecorder()
self.timelapse_recorder.frame_info_builder = lambda _: f'{self.version}, {self.current_navigation.name}, tags: {", ".join(self.plant_locator.tags)}'
rosys.NEW_NOTIFICATION.register(self.timelapse_recorder.notify)
rosys.on_startup(self.timelapse_recorder.compress_video) # NOTE: cleanup JPEGs from before last shutdown
self.field_navigation = RowsOnFieldNavigation(self, self.monitoring)
self.straight_line_navigation = StraightLineNavigation(self, self.monitoring)
self.follow_crops_navigation = FollowCropsNavigation(self, self.monitoring)
Expand Down
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

from dotenv import load_dotenv
from nicegui import app, ui
from rosys.analysis import logging_page
from rosys.analysis import logging_page, videos_page

import field_friend.log_configuration as log_configuration
from field_friend import interface
from field_friend.interface.components import header_bar, status_drawer, system_bar
from field_friend.system import System


logger = log_configuration.configure()
app.add_static_files('/assets', 'assets')

Expand Down Expand Up @@ -46,6 +47,7 @@ def status():
return {'status': 'ok'}

logging_page(['field_friend', 'rosys']) # /logging
videos_page() # /videos


app.on_startup(startup)
Expand Down

0 comments on commit f409de5

Please sign in to comment.