Skip to content

Commit

Permalink
Mow path coordinates over api
Browse files Browse the repository at this point in the history
  • Loading branch information
EinEinfach committed Sep 2, 2024
1 parent d5deae9 commit a5ec4d9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CaSSAndRA/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

#Version:0.124.0 mapId and previewId inside of coords topic
#Version:0.125.0 Mow path coordinates over api
# package imports
import os
import sys
Expand Down
11 changes: 9 additions & 2 deletions CaSSAndRA/src/backend/comm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def create_robot_payload(self) -> None:
self.robotstate['position'] = dict(x=robot.position_x, y=robot.position_y)
self.robotstate['target'] = dict(x=robot.target_x, y=robot.target_y)
self.robotstate['angle'] = robot.position_delta
self.robotstate['mowPointIdx'] = int(robot.position_mow_point_index)
self.robotstate_json = json.dumps(self.robotstate)

def create_maps_payload(self) -> None:
Expand Down Expand Up @@ -82,6 +83,7 @@ def create_mow_parameters_payload(self) -> None:
def create_map_payload(self) -> None:
self.mapstate['mapId'] = current_map.map_id
self.mapstate['previewId'] = current_map.previewId
self.mapstate['mowPathId'] = current_map.mowpathId
self.mapstate['mowprogressIdxPercent'] = current_map.idx_perc
self.mapstate['mowprogressDistancePercent'] = current_map.distance_perc
self.mapstate_json = json.dumps(self.mapstate)
Expand All @@ -93,6 +95,10 @@ def create_current_map_coords_payload(self) -> None:
def create_preview_coords_payload(self) -> None:
self.coordsstate = current_map.preview_to_geojson()
self.coordsstate_json = json.dumps(self.coordsstate)

def create_mowpath_coords_payload(self) -> None:
self.coordsstate = current_map.mowpath_to_gejson()
self.coordsstate_json = json.dumps(self.coordsstate)

def update_payload(self) -> None:
self.create_api_payload()
Expand Down Expand Up @@ -416,8 +422,9 @@ def perform_coords_cmd(self, buffer) -> None:
if value == 'preview':
self.create_preview_coords_payload()
self.publish('coords', self.coordsstate_json)
if value == 'mowPaht':
pass
if value == 'mowPath':
self.create_mowpath_coords_payload()
self.publish('coords', self.coordsstate_json)


cassandra_api = API()
2 changes: 1 addition & 1 deletion CaSSAndRA/src/backend/data/appdata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
logger = logging.getLogger(__name__)

version = '0.124.0'
version = '0.125.0'
16 changes: 16 additions & 0 deletions CaSSAndRA/src/backend/data/mapdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,22 @@ def preview_to_geojson(self) -> dict:
logger.error('Could not export preview route to gejson')
logger.debug(f'{e}')
return dict()

def mowpath_to_gejson(self) -> dict:
try:
mowpath_for_export = self.mowpath
geojson = dict(type="FeatureCollection", features=[])
geojson['features'].append(dict(type='Feature', properties=dict(name='current mow path', id=self.mowpathId)))
if not mowpath_for_export.empty:
value = dict(type="Feature", properties=dict(name="mow path"), geometry=dict(dict(type="LineString", coordinates=[mowpath_for_export[['X', 'Y']].values.tolist()])))
else:
value = dict(type="Feature", properties=dict(name="mow path"), geometry=dict(dict(type="LineString", coordinates=[])))
geojson['features'].append(value)
return geojson
except Exception as e:
logger.error('Could not export mow path to geojson')
logger.debug(f'{e}')
return dict()

@dataclass
class Perimeters:
Expand Down

0 comments on commit a5ec4d9

Please sign in to comment.