diff --git a/field_friend/automations/field_provider.py b/field_friend/automations/field_provider.py index 33fcd2b3..ef724d75 100644 --- a/field_friend/automations/field_provider.py +++ b/field_friend/automations/field_provider.py @@ -1,5 +1,4 @@ import logging -import os import uuid from typing import Any, Optional @@ -71,13 +70,6 @@ def clear_fields(self) -> None: self.FIELDS_CHANGED.emit() self.invalidate() - def update_reference(self) -> None: - if self.gnss.current is None: - rosys.notify('No GNSS position available.') - return - localization.reference = self.gnss.current.location - os.utime('main.py') - def create_obstacle(self, field: Field, points: list[GeoPoint] = []) -> FieldObstacle: obstacle = FieldObstacle(id=f'{str(uuid.uuid4())}', name=f'obstacle_{len(field.obstacles)+1}', points=points) field.obstacles.append(obstacle) diff --git a/field_friend/automations/navigation/navigation.py b/field_friend/automations/navigation/navigation.py index efbee416..49903484 100644 --- a/field_friend/automations/navigation/navigation.py +++ b/field_friend/automations/navigation/navigation.py @@ -27,7 +27,6 @@ def __init__(self, system: 'System', implement: Implement) -> None: self.log = logging.getLogger('field_friend.navigation') self.driver = system.driver self.odometer = system.odometer - self.field_provider = system.field_provider self.gnss = system.gnss self.kpi_provider = system.kpi_provider self.plant_provider = system.plant_provider @@ -49,7 +48,7 @@ async def start(self) -> None: return await self.gnss.update_robot_pose() if self.gnss.current.location.distance(localization.reference) > 2000.0: - self.reference_alert_dialog.open() + self.gnss.reference_alert_dialog.open() return self.start_position = self.odometer.prediction.point if isinstance(self.driver.wheels, rosys.hardware.WheelsSimulation) and not rosys.is_test: @@ -137,12 +136,6 @@ def create_simulation(self) -> None: pass def settings_ui(self) -> None: - with ui.dialog() as self.reference_alert_dialog, ui.card(): - ui.label('The reference is to far away from the current position which would lead to issues in the navigation. Do you want to set it now?') - with ui.row(): - ui.button("Update reference", on_click=self.field_provider.update_reference).props("outline color=warning") \ - .tooltip("Set current position as geo reference and restart the system").classes("ml-auto").style("display: block; margin-top:auto; margin-bottom: auto;") - ui.button('Cancel', on_click=self.reference_alert_dialog.close) ui.number('Linear Speed', step=0.01, min=0.01, max=1.0, format='%.2f', on_change=self.request_backup) \ .props('dense outlined') \ .classes('w-24') \ diff --git a/field_friend/interface/components/field_planner.py b/field_friend/interface/components/field_planner.py index 822974ef..9747b2c0 100644 --- a/field_friend/interface/components/field_planner.py +++ b/field_friend/interface/components/field_planner.py @@ -54,7 +54,7 @@ def __init__(self, system: 'System', leaflet: leaflet_map) -> None: with ui.row(): ui.button('Clear fields', on_click=self.clear_field_dialog.open).props("outline color=warning") \ .tooltip("Delete all fields").classes("ml-auto").style("display: block; margin-top:auto; margin-bottom: auto;") - ui.button("Update reference", on_click=self.field_provider.update_reference).props("outline color=warning") \ + ui.button("Update reference", on_click=self.gnss.update_reference).props("outline color=warning") \ .tooltip("Set current position as geo reference and restart the system").classes("ml-auto").style("display: block; margin-top:auto; margin-bottom: auto;") self.show_field_settings() self.show_object_settings() diff --git a/field_friend/interface/pages/main_page.py b/field_friend/interface/pages/main_page.py index b1a6d102..d7bc5886 100644 --- a/field_friend/interface/pages/main_page.py +++ b/field_friend/interface/pages/main_page.py @@ -21,6 +21,7 @@ def page() -> None: def content(self, devmode) -> None: page_height = '50vh' if devmode else 'calc(100vh - 170px)' ui.colors(primary='#6E93D6', secondary='#53B689', accent='#111B1E', positive='#53B689') + self.system.gnss.reference_warning_dialog() with ui.row().style(f'height:{page_height}; width: calc(100vw - 2rem); flex-wrap: nowrap;'): with ui.column().classes('h-full w-1/2 p-2'): leaflet = leaflet_map(self.system, False) diff --git a/field_friend/localization/gnss.py b/field_friend/localization/gnss.py index cc7cc552..c70874b4 100644 --- a/field_friend/localization/gnss.py +++ b/field_friend/localization/gnss.py @@ -1,11 +1,12 @@ from __future__ import annotations import logging +import os from abc import ABC, abstractmethod from copy import deepcopy from dataclasses import dataclass from typing import Any, Optional - +from nicegui import ui import numpy as np import rosys @@ -146,3 +147,18 @@ def restore(self, data: dict[str, Any]) -> None: self.needed_poses = data.get('needed_poses', self.needed_poses) self.min_seconds_between_updates = data.get('min_seconds_between_updates', self.min_seconds_between_updates) self.ensure_gnss = data.get('ensure_gnss', self.ensure_gnss) + + def update_reference(self) -> None: + if self.current is None: + rosys.notify('No GNSS position available.') + return + localization.reference = self.current.location + os.utime('main.py') + + def reference_warning_dialog(self) -> None: + with ui.dialog() as self.reference_alert_dialog, ui.card(): + ui.label('The reference is to far away from the current position which would lead to issues in the navigation. Do you want to set it now?') + with ui.row(): + ui.button("Update reference", on_click=self.update_reference).props("outline color=warning") \ + .tooltip("Set current position as geo reference and restart the system").classes("ml-auto").style("display: block; margin-top:auto; margin-bottom: auto;") + ui.button('Cancel', on_click=self.reference_alert_dialog.close)