mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-02 06:03:43 +08:00
b64d5a0fa4
* simpler approach pls * fix
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
"""
|
|
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
|
|
|
|
This file is part of sunnypilot and is licensed under the MIT License.
|
|
See the LICENSE.md file in the root directory for more details.
|
|
"""
|
|
import json
|
|
import math
|
|
import platform
|
|
|
|
from openpilot.common.params import Params
|
|
from openpilot.common.realtime import DT_MDL
|
|
from openpilot.sunnypilot.mapd.live_map_data.base_map_data import BaseMapData
|
|
from openpilot.sunnypilot.navd.helpers import Coordinate
|
|
|
|
|
|
class OsmMapData(BaseMapData):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.mem_params = Params("/dev/shm/params") if platform.system() != "Darwin" else self.params
|
|
|
|
def update_location(self) -> None:
|
|
gps = self.sm[self.gps_location_service]
|
|
gps_ok = self.sm.recv_frame[self.gps_location_service] > 0 and (self.sm.frame - self.sm.recv_frame[self.gps_location_service]) * DT_MDL < 2.0
|
|
|
|
if gps_ok:
|
|
self.last_bearing = gps.bearingDeg * 180/math.pi
|
|
self.last_position = Coordinate(gps.latitude, gps.longitude)
|
|
|
|
if not gps_ok and self.sm['livePose'].inputsOK:
|
|
return
|
|
|
|
if self.last_position is None:
|
|
return
|
|
|
|
params = {
|
|
"latitude": self.last_position.latitude,
|
|
"longitude": self.last_position.longitude,
|
|
"bearing": self.last_bearing,
|
|
}
|
|
|
|
self.mem_params.put("LastGPSPosition", json.dumps(params))
|
|
|
|
def get_current_speed_limit(self) -> float:
|
|
return float(self.mem_params.get("MapSpeedLimit") or 0.0)
|
|
|
|
def get_current_road_name(self) -> str:
|
|
return str(self.mem_params.get("RoadName") or "")
|
|
|
|
def get_next_speed_limit_and_distance(self) -> tuple[float, float]:
|
|
next_speed_limit_section_str = self.mem_params.get("NextMapSpeedLimit")
|
|
next_speed_limit_section = next_speed_limit_section_str if next_speed_limit_section_str else {}
|
|
next_speed_limit = next_speed_limit_section.get('speedlimit', 0.0)
|
|
next_speed_limit_latitude = next_speed_limit_section.get('latitude')
|
|
next_speed_limit_longitude = next_speed_limit_section.get('longitude')
|
|
next_speed_limit_distance = 0.0
|
|
|
|
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_position or Coordinate(0, 0)).distance_to(next_speed_limit_coordinates)
|
|
|
|
return next_speed_limit, next_speed_limit_distance
|