Skip to content

Commit

Permalink
check for nearest row and do not start if robot is placed wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBaecker committed Nov 26, 2024
1 parent 171474f commit 457cc3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion field_friend/automations/field_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion field_friend/automations/navigation/field_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion field_friend/interface/components/field_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 457cc3b

Please sign in to comment.