mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-11-03 10:37:52 +08:00
slight more cleanup
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user