Skip to content

Commit

Permalink
Move GNSS distance to reference check to field navigation (#273)
Browse files Browse the repository at this point in the history
We mostly use straight line indoors without a sufficient gnss signal, so
the navigation fails.
This PR just warns the user when using a normal navigation without valid
gnss. When running the field navigation it fails, because we definitely
need it there.
  • Loading branch information
pascalzauberzeug authored Jan 31, 2025
1 parent cc7d39c commit 01e02af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
7 changes: 7 additions & 0 deletions field_friend/automations/navigation/field_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..field import Field, Row
from ..implements.implement import Implement
from ..implements.weeding_implement import WeedingImplement
from .navigation import WorkflowException, is_reference_valid
from .straight_line_navigation import StraightLineNavigation

if TYPE_CHECKING:
Expand Down Expand Up @@ -55,6 +56,12 @@ def current_row(self) -> Row:
assert self.field
return self.rows_to_work_on[self.row_index]

@track
async def start(self) -> None:
if not is_reference_valid(self.gnss):
raise WorkflowException('reference to far away from robot')
await super().start()

async def prepare(self) -> bool:
await super().prepare()
self.field = self.field_provider.get_field(self.field_id)
Expand Down
23 changes: 12 additions & 11 deletions field_friend/automations/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
from ...system import System


def is_reference_valid(gnss: Gnss, *, max_distance: float = 5000.0) -> bool:
if GeoReference.current is None:
return False
if gnss.last_measurement is None:
return False
if gnss.last_measurement.gps_quality == 0:
return False
return gnss.last_measurement.point.distance(GeoReference.current.origin) <= max_distance


class WorkflowException(Exception):
pass

Expand Down Expand Up @@ -62,7 +52,8 @@ async def start(self) -> None:
self.log.error('Preparation failed')
return
if not is_reference_valid(self.gnss):
raise WorkflowException('reference to far away from robot')
rosys.notify('GNSS not available or reference too far away', 'warning')
await rosys.sleep(3)
self.start_position = self.robot_locator.pose.point
if isinstance(self.driver.wheels, rosys.hardware.WheelsSimulation) and not rosys.is_test:
self.create_simulation()
Expand Down Expand Up @@ -150,3 +141,13 @@ def settings_ui(self) -> None:
.classes('w-24') \
.bind_value(self, 'linear_speed_limit') \
.tooltip(f'Forward speed limit in m/s (default: {self.LINEAR_SPEED_LIMIT:.2f})')


def is_reference_valid(gnss: Gnss, *, max_distance: float = 5000.0) -> bool:
if GeoReference.current is None:
return False
if gnss.last_measurement is None:
return False
if gnss.last_measurement.gps_quality == 0:
return False
return gnss.last_measurement.point.distance(GeoReference.current.origin) <= max_distance

0 comments on commit 01e02af

Please sign in to comment.