Skip to content

Commit

Permalink
Merge branch 'main' into drive-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBaecker committed Jul 19, 2024
2 parents 19de0d0 + f00c03a commit ca89278
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
3 changes: 1 addition & 2 deletions field_friend/automations/automation_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def __init__(self, system: 'System') -> None:
rosys.on_repeat(self.try_resume, 0.1)
rosys.on_repeat(self.check_field_bounds, 1.0)
if self.field_friend.bumper:
self.field_friend.bumper.BUMPER_TRIGGERED.register(
lambda name: self.pause(f'Bumper {name} was triggered'))
self.field_friend.bumper.BUMPER_TRIGGERED.register(lambda name: self.pause(f'Bumper {name} was triggered'))
self.gnss.GNSS_CONNECTION_LOST.register(lambda: self.pause('GNSS connection lost'))
self.gnss.RTK_FIX_LOST.register(lambda: self.pause('GNSS RTK fix lost'))

Expand Down
15 changes: 7 additions & 8 deletions field_friend/automations/plant_locator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import asyncio
import logging
from typing import TYPE_CHECKING, Any, Optional
import aiohttp
from typing import TYPE_CHECKING, Any

import aiohttp
import rosys
from nicegui import ui
from nicegui.events import ValueChangeEventArguments
from rosys.vision import Autoupload

from ..vision import SimulatedCam
Expand Down Expand Up @@ -38,7 +36,7 @@ def __init__(self, system: 'System') -> None:
self.tags: list[str] = []
self.is_paused = True
self.autoupload: Autoupload = Autoupload.DISABLED
self.upload_images: bool = False
self.upload_images: bool = False
self.weed_category_names: list[str] = WEED_CATEGORY_NAME
self.crop_category_names: list[str] = CROP_CATEGORY_NAME
self.minimum_weed_confidence: float = MINIMUM_WEED_CONFIDENCE
Expand Down Expand Up @@ -140,14 +138,14 @@ def resume(self) -> None:

async def get_outbox_mode(self, port: int) -> bool:
# TODO: not needed right now, but can be used when this code is moved to the DetectorHardware code
url = f'http://localhost:{port}/outbox_mode'
url = f'http://localhost:{port}/outbox_mode'
async with aiohttp.request('GET', url) as response:
if response.status != 200:
self.log.error(f'Could not get outbox mode on port {port} - status code: {response.status}')
return None
response_text = await response.text()
return response_text == 'continuous_upload'

async def set_outbox_mode(self, value: bool, port: int) -> None:
url = f'http://localhost:{port}/outbox_mode'
async with aiohttp.request('PUT', url, data='continuous_upload' if value else 'stopped') as response:
Expand All @@ -172,7 +170,8 @@ def settings_ui(self) -> None:
.bind_value(self, 'autoupload') \
.classes('w-24').tooltip('Set the autoupload for the weeding automation')
if isinstance(self.detector, rosys.vision.DetectorHardware):
ui.checkbox('Upload images', on_change=self.request_backup).bind_value(self, 'upload_images').on('click', lambda: self.set_outbox_mode(value=self.upload_images, port=self.detector.port))
ui.checkbox('Upload images', on_change=self.request_backup).bind_value(self, 'upload_images') \
.on('click', lambda: self.set_outbox_mode(value=self.upload_images, port=self.detector.port))

@ui.refreshable
def chips():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ geopy
shapely
fiona
geopandas
rosys == 0.10.10
rosys == 0.11
uvicorn == 0.28.1
19 changes: 17 additions & 2 deletions tests/test_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from field_friend.automations import Field
from field_friend.automations.implements import Implement, Recorder
from field_friend.automations.navigation import StraightLineNavigation
from field_friend.localization import GnssSimulation


async def test_straight_line(system: System):
Expand All @@ -23,6 +24,21 @@ async def test_straight_line(system: System):
assert system.odometer.prediction.point.x == pytest.approx(system.straight_line_navigation.length, abs=0.1)


async def test_straight_line_with_failing_gnss(system: System, gnss: GnssSimulation, detector: rosys.vision.DetectorSimulation):
async def empty():
return None
create_new_record = gnss._create_new_record
system.automator.start()
await forward(5)
gnss._create_new_record = empty # type: ignore
await forward(0.5)
gnss._create_new_record = create_new_record
await forward(5)
assert system.automator.is_running
assert len(detector.simulated_objects) == 0
assert system.odometer.prediction.yaw_deg == pytest.approx(0, abs=1)


async def test_driving_to_exact_positions(system: System):
class Stopper(Implement):
def __init__(self, system: System) -> None:
Expand All @@ -35,13 +51,12 @@ async def get_stretch(self, max_distance: float) -> float:
self.current_stretch = random.uniform(0.02, max_distance)
return self.current_stretch

async def start_workflow(self) -> bool:
async def start_workflow(self) -> None:
self.workflow_started = True
deadline = rosys.time() + 1
while self.workflow_started and rosys.time() < deadline:
await rosys.sleep(0.1)
self.workflow_started = False
return True

system.current_implement = stopper = Stopper(system)
assert isinstance(system.current_navigation, StraightLineNavigation)
Expand Down

0 comments on commit ca89278

Please sign in to comment.