slight more cleanup

This commit is contained in:
Jason Wen
2025-06-06 22:43:42 -04:00
parent 6a8f31636a
commit 70ef1c0fd5
2 changed files with 10 additions and 14 deletions
@@ -25,7 +25,7 @@ class BaseMapData(ABC):
pass
@abstractmethod
def get_next_speed_limit_and_distance(self) -> tuple[float, float]:
def get_next_speed_limit_and_distance(self, current_location: Coordinate | None) -> tuple[float, float]:
pass
@abstractmethod
@@ -60,7 +60,7 @@ class BaseMapData(ABC):
def publish(self) -> None:
speed_limit = self.get_current_speed_limit()
current_road_name = self.get_current_road_name()
next_speed_limit, next_speed_limit_distance = self.get_next_speed_limit_and_distance()
next_speed_limit, next_speed_limit_distance = self.get_next_speed_limit_and_distance(self._last_gps)
mapd_sp_send = messaging.new_message('liveMapDataSP')
mapd_sp_send.valid = self._is_gps_data_valid()
+8 -12
View File
@@ -9,31 +9,27 @@ from openpilot.sunnypilot.mapd.live_map_data.base_map_data import BaseMapData
class OsmMapData(BaseMapData):
def __init__(self):
super().__init__()
self.last_gps = Coordinate(0.0, 0.0)
self.params = Params()
self.mem_params = Params("/dev/shm/params") if platform.system() != "Darwin" else self.params
def update_location(self, current_location: Coordinate | None) -> None:
self.last_gps = current_location
if not self.last_gps:
if not current_location:
return
last_gps_position_for_osm = {
"latitude": self.last_gps.latitude,
"longitude": self.last_gps.longitude,
"bearing": self.last_gps.annotations.get("bearingDeg", 0)
"latitude": current_location.latitude,
"longitude": current_location.longitude,
"bearing": current_location.annotations.get("bearingDeg", 0)
}
self.mem_params.put("LastGPSPosition", json.dumps(last_gps_position_for_osm))
def get_current_speed_limit(self) -> float:
speed_limit = self.mem_params.get("MapSpeedLimit", encoding='utf8')
return float(speed_limit) if speed_limit else 0.0
return float(self.mem_params.get("MapSpeedLimit", encoding='utf8') or 0.0)
def get_current_road_name(self) -> str:
current_road_name = self.mem_params.get("RoadName", encoding='utf8')
return current_road_name if current_road_name else ""
return self.mem_params.get("RoadName", encoding='utf8') or ""
def get_next_speed_limit_and_distance(self) -> tuple[float, float]:
def get_next_speed_limit_and_distance(self, current_location: Coordinate | None) -> tuple[float, float]:
next_speed_limit_section_str = self.mem_params.get("NextMapSpeedLimit", encoding='utf8')
next_speed_limit_section = json.loads(next_speed_limit_section_str) if next_speed_limit_section_str else {}
next_speed_limit = next_speed_limit_section.get('speedlimit', 0.0)
@@ -43,6 +39,6 @@ class OsmMapData(BaseMapData):
if next_speed_limit_latitude and next_speed_limit_longitude:
next_speed_limit_coordinates = Coordinate(next_speed_limit_latitude, next_speed_limit_longitude)
next_speed_limit_distance = (self.last_gps or Coordinate(0, 0)).distance_to(next_speed_limit_coordinates)
next_speed_limit_distance = (current_location or Coordinate(0, 0)).distance_to(next_speed_limit_coordinates)
return next_speed_limit, next_speed_limit_distance