Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distanced Reference Warning Dialog #172

Merged
merged 14 commits into from
Sep 25, 2024
Merged
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
5 changes: 5 additions & 0 deletions field_friend/automations/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import rosys
from nicegui import ui

from ... import localization
from ..implements import Implement

if TYPE_CHECKING:
Expand Down Expand Up @@ -46,6 +47,9 @@ async def start(self) -> None:
self.log.error('Preparation failed')
return
await self.gnss.update_robot_pose()
if self.gnss.current.location.distance(localization.reference) > 2000.0:
LukasBaecker marked this conversation as resolved.
Show resolved Hide resolved
self.gnss.reference_alert_dialog.open()
raise WorkflowException('reference to far away from robot')
self.start_position = self.odometer.prediction.point
if isinstance(self.driver.wheels, rosys.hardware.WheelsSimulation) and not rosys.is_test:
self.create_simulation()
Expand All @@ -65,6 +69,7 @@ async def start(self) -> None:
except WorkflowException as e:
self.kpi_provider.increment_weeding_kpi('automation_stopped')
self.log.error(f'WorkflowException: {e}')
rosys.notify(f'An exception occurred during automation: {e}', 'negative')
finally:
self.kpi_provider.increment_weeding_kpi('weeding_completed')
await self.implement.finish()
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: 18 additions & 0 deletions field_friend/localization/gnss.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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

import numpy as np
import rosys
from nicegui import ui

from .. import localization
from .geo_point import GeoPoint
Expand Down Expand Up @@ -61,6 +63,7 @@ def __init__(self, odometer: rosys.driving.Odometer, antenna_offset: float) -> N
self.needs_backup = False
rosys.on_repeat(self.check_gnss, 0.01)
rosys.on_repeat(self.try_connection, 3.0)
self.reference_alert_dialog = None

@abstractmethod
async def try_connection(self) -> None:
Expand Down Expand Up @@ -146,3 +149,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)
Loading