From 457cc3b0502d8891936db635cc654bce5494c556 Mon Sep 17 00:00:00 2001 From: Lukas Baecker Date: Tue, 26 Nov 2024 16:38:53 +0100 Subject: [PATCH] check for nearest row and do not start if robot is placed wrong --- field_friend/automations/field_provider.py | 9 ++++++++- field_friend/automations/navigation/field_navigation.py | 8 +++++++- field_friend/interface/components/field_creator.py | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/field_friend/automations/field_provider.py b/field_friend/automations/field_provider.py index 80a84175..26c0329e 100644 --- a/field_friend/automations/field_provider.py +++ b/field_friend/automations/field_provider.py @@ -161,4 +161,11 @@ def get_rows_to_work_on(self) -> list[Row]: for bed in self.selected_beds: for row_index in range(self.selected_field.row_count): row_indices.append((bed - 1) * self.selected_field.row_count + row_index) - return [row for i, row in enumerate(self.selected_field.rows) if i in row_indices] + rows_to_work_on = [row for i, row in enumerate(self.selected_field.rows) if i in row_indices] + return rows_to_work_on + + def is_row_in_selected_beds(self, row_index: int) -> bool: + if not self._only_specific_beds: + return True + bed_index = row_index // self.selected_field.row_count + 1 + return bed_index in self.selected_beds diff --git a/field_friend/automations/navigation/field_navigation.py b/field_friend/automations/navigation/field_navigation.py index ab160e26..51f43d8b 100644 --- a/field_friend/automations/navigation/field_navigation.py +++ b/field_friend/automations/navigation/field_navigation.py @@ -72,7 +72,10 @@ async def prepare(self) -> bool: if not len(row.points) >= 2: rosys.notify(f'Row {idx} on field {self.field.name} has not enough points', 'negative') return False - self.row_index = self.field.rows.index(self.get_nearest_row()) + nearest_row = self.get_nearest_row() + if nearest_row is None: + return False + self.row_index = self.field.rows.index(nearest_row) self._state = State.APPROACHING_ROW_START self.plant_provider.clear() @@ -97,6 +100,9 @@ def get_nearest_row(self) -> Row: self.odometer.prediction.point).distance(self.odometer.prediction.point)) self.log.info(f'Nearest row is {row.name}') self.row_index = self.field.rows.index(row) + if not self.field_provider.is_row_in_selected_beds(self.row_index): + rosys.notify('Please place the robot in front of a selected bed\'s row', 'negative') + return None return row def set_start_and_end_points(self): diff --git a/field_friend/interface/components/field_creator.py b/field_friend/interface/components/field_creator.py index eff263a2..415b4160 100644 --- a/field_friend/interface/components/field_creator.py +++ b/field_friend/interface/components/field_creator.py @@ -239,7 +239,7 @@ def ab_line_map(self) -> None: self.m.set_zoom(18) def update_robot_position(self, position: GeoPoint, dialog=None) -> None: - if isinstance(self.m, ui.leaflet): + if hasattr(self, 'm') and self.m and isinstance(self.m, ui.leaflet): self.robot_marker = self.robot_marker or self.m.marker(latlng=position.tuple) icon = 'L.icon({iconUrl: "assets/robot_position_side.png", iconSize: [24,24], iconAnchor:[12,12]})' self.robot_marker.run_method(':setIcon', icon)