mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-07-27 04:12:10 +08:00
ab6d192714
* init * some fixes * move * more * old navd helpers * bring back cereal * fix linting * more * add to cereal first * sp events * lint * implement in long plan * fixme-sp * refactor state machine * wrong state * start refactor controller * some type hints * init these * enable debug print * ui? ui! * print them out * fix spinner import * fix path * let's use gps chips directly for now * service missing * publish events * no nav for now * need to sub * no car state speed yet * missed event * Car: `CarStateSP` * fix tests * bring back car state speed limit * fix * use old controller for now * fix * fix source * type hints * none for now * formatting * more * create directory if does not exist * mypy my bt * policy param catch exceptions * handle all params with exceptions * more * single method * define types in init * rename * simpler op enabled check * more mypy stuff * rename * no need for brake pressed * don't reset if gas pressed * type hint all * type hint all * back to upstream * in another pr * no longer need data type * qlog * slc in another pr * use horizontal accuracy * set core affinity for all realtime processes * unused * sort * unused * type hint and slight cleanup * from old implementation * use directly * combine pm * slight more cleanup * type hints * even more type hint * lint * more cleanup * even less * license
52 lines
2.0 KiB
Python
52 lines
2.0 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 platform
|
|
|
|
from openpilot.common.params import Params
|
|
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.params = Params()
|
|
self.mem_params = Params("/dev/shm/params") if platform.system() != "Darwin" else self.params
|
|
|
|
def update_location(self) -> None:
|
|
if self.last_position is None or self.last_altitude is None:
|
|
return
|
|
|
|
params = {
|
|
"latitude": self.last_position.latitude,
|
|
"longitude": self.last_position.longitude,
|
|
"altitude": self.last_altitude,
|
|
}
|
|
|
|
self.mem_params.put("LastGPSPosition", json.dumps(params))
|
|
|
|
def get_current_speed_limit(self) -> float:
|
|
return float(self.mem_params.get("MapSpeedLimit", encoding='utf8') or 0.0)
|
|
|
|
def get_current_road_name(self) -> str:
|
|
return self.mem_params.get("RoadName", encoding='utf8') or ""
|
|
|
|
def get_next_speed_limit_and_distance(self) -> 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)
|
|
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
|