mirror of https://github.com/commaai/openpilot.git
timed: use gps location packet for time (#33306)
* GPS helpers
* Use GPS socket in timed
* Use helper in controlsd
* Use updated and logMonoTime
* Helper type annot
* Not updated
* Increase time threashold
old-commit-hash: cf355ecf20
This commit is contained in:
parent
7bfd763291
commit
e154f03a12
|
@ -0,0 +1,8 @@
|
|||
from openpilot.common.params import Params
|
||||
|
||||
|
||||
def get_gps_location_service(params: Params) -> str:
|
||||
if params.get_bool("UbloxAvailable"):
|
||||
return "gpsLocationExternal"
|
||||
else:
|
||||
return "gpsLocation"
|
|
@ -17,6 +17,7 @@ from openpilot.common.numpy_fast import clip
|
|||
from openpilot.common.params import Params
|
||||
from openpilot.common.realtime import config_realtime_process, Priority, Ratekeeper, DT_CTRL
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
from openpilot.common.gps import get_gps_location_service
|
||||
|
||||
from opendbc.car.car_helpers import get_car_interface
|
||||
from openpilot.selfdrive.controls.lib.alertmanager import AlertManager, set_offroad_alert
|
||||
|
@ -79,10 +80,7 @@ class Controls:
|
|||
# Setup sockets
|
||||
self.pm = messaging.PubMaster(['controlsState', 'carControl', 'onroadEvents'])
|
||||
|
||||
if self.params.get_bool("UbloxAvailable"):
|
||||
self.gps_location_service = "gpsLocationExternal"
|
||||
else:
|
||||
self.gps_location_service = "gpsLocation"
|
||||
self.gps_location_service = get_gps_location_service(self.params)
|
||||
self.gps_packets = [self.gps_location_service]
|
||||
self.sensor_packets = ["accelerometer", "gyroscope"]
|
||||
self.camera_packets = ["roadCameraState", "driverCameraState", "wideRoadCameraState"]
|
||||
|
|
|
@ -7,6 +7,8 @@ from typing import NoReturn
|
|||
import cereal.messaging as messaging
|
||||
from openpilot.common.time import system_time_valid
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.common.gps import get_gps_location_service
|
||||
|
||||
|
||||
def set_time(new_time):
|
||||
|
@ -31,8 +33,11 @@ def main() -> NoReturn:
|
|||
AGNOS will also use NTP to update the time.
|
||||
"""
|
||||
|
||||
params = Params()
|
||||
gps_location_service = get_gps_location_service(params)
|
||||
|
||||
pm = messaging.PubMaster(['clocks'])
|
||||
sm = messaging.SubMaster(['liveLocationKalman'])
|
||||
sm = messaging.SubMaster([gps_location_service])
|
||||
while True:
|
||||
sm.update(1000)
|
||||
|
||||
|
@ -41,13 +46,13 @@ def main() -> NoReturn:
|
|||
msg.clocks.wallTimeNanos = time.time_ns()
|
||||
pm.send('clocks', msg)
|
||||
|
||||
llk = sm['liveLocationKalman']
|
||||
if not llk.gpsOK or (time.monotonic() - sm.logMonoTime['liveLocationKalman']/1e9) > 0.2:
|
||||
gps = sm[gps_location_service]
|
||||
if not sm.updated[gps_location_service] or (time.monotonic() - sm.logMonoTime[gps_location_service] / 1e9) > 2.0:
|
||||
continue
|
||||
|
||||
# set time
|
||||
# TODO: account for unixTimesatmpMillis being a (usually short) time in the past
|
||||
gps_time = datetime.datetime.fromtimestamp(llk.unixTimestampMillis / 1000.)
|
||||
gps_time = datetime.datetime.fromtimestamp(gps.unixTimestampMillis / 1000.)
|
||||
set_time(gps_time)
|
||||
|
||||
time.sleep(10)
|
||||
|
|
Loading…
Reference in New Issue