Skip to content

Commit

Permalink
moved update_reference to gnss.py, reference warning dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBaecker committed Sep 6, 2024
1 parent e3257e5 commit 8dfe43e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
8 changes: 0 additions & 8 deletions field_friend/automations/field_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import uuid
from typing import Any, Optional

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions field_friend/automations/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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') \
Expand Down
2 changes: 1 addition & 1 deletion field_friend/interface/components/field_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions field_friend/interface/pages/main_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion field_friend/localization/gnss.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 8dfe43e

Please sign in to comment.