Skip to content

Commit

Permalink
Use app.storage.user to preselect last automation and field (#41)
Browse files Browse the repository at this point in the history
* implement turn_by and turn_knives_to methods

* use new methods in puncher class

* implement reference speeds

* Update hardware configuration for ff12_config_rb32 and u4_config_rb28 eith tornado reference speeds

* Fix turn_knives_to method in TornadoHardware class

* Fix reference to knive stop in CoinCollecting class

* rename ref_t and ref_b to ref_knife_stop and ref_knive_ground

* typo

* Add turns parameter to punch method in Puncher class

* formatting and logging

* fix persistence restore issues

* add forgotten input

* add more categories for weed and crop

* better line breaks

* cleanup

* Refactor field_friend_hardware.py to update knife stop and ground pin names

* Update hardware.py and puncher.py for speed adjustments

* backup rb28

* Update camera crop settings in config/u4_config_rb28/camera.py

* Fix typo in Field class area method

* Fix error handling in PlantLocator class

* tmp remove of rows as obstacles

* fix binding of minimum_turning_radius

* Fix typo in worked_area_label text formatting

* remove buggy persistence of gnss

* Refactor prune method in PlantProvider class to use separate variables for max age of weeds and crops

* backup rb28

* Add settings for dual mechanism workflow

* add settings to operation.py

* change rendering of plant objects in plant_objects.py

* implement gnss correction by antenna offset

* Fix error handling in PlantLocator class

* Add driver settings to operation.py

* Update max age of weeds in prune method of PlantProvider class

* Implement antenna offset for GNSS correction

* Refactor obstacle creation in Weeding class to include row polygons

* Refactor plant_provider.py to use async/await for adding weeds and crops

* Refactor driver settings in Weeding class

* Refactor field_planner.py to remove unused imports and dependencies

* Add driver settings for weeding automation in operation.py

* fix field_friend_object.py to update second_tool move coordinates

* backup rb28

* Update antenna offset for GNSS correction in params.py

* backup for u3

* backup rb27

* Refactor operation.py to add driver settings for weeding automation

* Refactor operation.py to add driver settings for weeding automation

* Update healthcheck configuration in docker-compose.yml

* provide antenna offset for u5 and u6

* Update antenna offset for GNSS correction in params.py for U5

* revert change because in real robots we want persistence to overwrite the settings (see zauberzeug/rosys#106)

* formatting of ui.run

* fix name

* formatting of operation.py

* use app.storage.user to preselect last automation and field

* provide storage secret

* Provide map buttons to center on robot and toggle basemap (#42)

* provide map buttons to center on robot and toggle basemap

* improved max zoom

---------

Co-authored-by: Miguel <[email protected]>
Co-authored-by: Johannes-Thiel <[email protected]>
  • Loading branch information
3 people authored May 6, 2024
1 parent 306241b commit daf235f
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 144 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ __pycache__/
detector/
*.env
*.swp
site/
site/
.nicegui/
1 change: 1 addition & 0 deletions .syncignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ config.hjson
sync.sh
nicegui
rosys
.nicegui
81 changes: 55 additions & 26 deletions field_friend/interface/components/leaflet_map.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

import logging
import uuid
from typing import TYPE_CHECKING, Dict, List, Union
from typing import TYPE_CHECKING

import numpy as np
import rosys
import rosys.geometry
from nicegui import elements, events, ui
from nicegui import app, events, ui
from nicegui.elements.leaflet_layers import TileLayer

from ...automations import Field
from .key_controls import KeyControls

if TYPE_CHECKING:
Expand All @@ -34,28 +33,22 @@ def __init__(self, system: 'System', draw_tools: bool) -> None:
},
'edit': False,
}
self.center_point = [51.983159, 7.434212]
center_point = [51.983159, 7.434212]
if self.field_provider.active_field is None:
self.center_point = [51.983159, 7.434212]
center_point = [51.983159, 7.434212]
else:
if len(self.field_provider.active_field.outline_wgs84) > 0:
self.center_point = self.field_provider.active_field.outline_wgs84[0]
center_point = self.field_provider.active_field.outline_wgs84[0]
self.m: ui.leaflet
if draw_tools:
self.m = ui.leaflet(center=(self.center_point[0], self.center_point[1]),
self.m = ui.leaflet(center=(center_point[0], center_point[1]),
zoom=13, draw_control=self.draw_control)
else:
self.m = ui.leaflet(center=(self.center_point[0], self.center_point[1]),
self.m = ui.leaflet(center=(center_point[0], center_point[1]),
zoom=13)

self.m.clear_layers()
self.m.tile_layer(
url_template=r'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
options={
'maxZoom': 21,
'attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
},
)

self.current_basemap: TileLayer | None = None
self.toggle_basemap()
self.field_layers: list[list] = []
self.robot_marker = None
self.drawn_marker = None
Expand Down Expand Up @@ -101,6 +94,14 @@ def handle_draw(e: events.GenericEventArguments):
m.on('draw:created', handle_draw)
self.gnss.ROBOT_POSITION_LOCATED.register(self.update_robot_position)

def buttons(self) -> None:
"""Builds additional buttons to interact with the map."""
ui.button(icon='my_location', on_click=self.zoom_to_robot).props('dense flat')
ui.button(icon='satellite', on_click=self.toggle_basemap).props('dense flat') \
.bind_visibility_from(self, 'current_basemap', lambda x: x is not None and 'openstreetmap' not in x.url_template)
ui.button(icon='map', on_click=self.toggle_basemap).props('dense flat') \
.bind_visibility_from(self, 'current_basemap', lambda x: x is not None and 'openstreetmap' in x.url_template)

def set_simulated_reference(self, latlon, dialog):
dialog.close()
self.m.remove_layer(self.drawn_marker)
Expand Down Expand Up @@ -167,11 +168,39 @@ def update_robot_position(self) -> None:
self.robot_marker.run_method(':setIcon', icon)
self.robot_marker.move(self.gnss.record.latitude, self.gnss.record.longitude)

def change_basemap(self) -> None:
return
# TODO: add a button in leaflet map to change basemap layer and implement the functionality here

# this is the ESRI satellite image as free satellite image
# Esri_WorldImagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
# attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
# })
def zoom_to_robot(self) -> None:
self.m.center = (self.gnss.record.latitude, self.gnss.record.longitude)
self.m.set_zoom(self.current_basemap.options['maxZoom'] - 1)

def toggle_basemap(self) -> None:
use_satellite = app.storage.user.get('use_satellite', False)
if self.current_basemap is not None:
self.m.remove_layer(self.current_basemap)
use_satellite = not use_satellite
app.storage.user['use_satellite'] = use_satellite
if use_satellite:
# ESRI satellite image provides free usage
self.current_basemap = self.m.tile_layer(
url_template='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
options={
'maxZoom': 21,
'attribution': 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
})
# self.current_basemap = self.m.tile_layer(
# url_template=r'http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
# options={
# 'maxZoom': 20,
# 'subdomains': ['mt0', 'mt1', 'mt2', 'mt3'],
# 'attribution': '&copy; <a href="https://maps.google.com">Google Maps</a>'
# },
# )
else:
self.current_basemap = self.m.tile_layer(
url_template=r'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
options={
'maxZoom': 20,
'attribution': '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
},
)
if self.current_basemap.options['maxZoom'] - 1 < self.m.zoom:
self.m.set_zoom(self.current_basemap.options['maxZoom'] - 1)
Loading

0 comments on commit daf235f

Please sign in to comment.