2020-01-17 13:48:30 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from cereal import car
|
|
|
|
from common.params import Params
|
2020-10-02 18:18:18 -06:00
|
|
|
from common.realtime import Priority, config_realtime_process
|
2020-01-17 13:48:30 -07:00
|
|
|
from selfdrive.swaglog import cloudlog
|
2021-02-03 20:57:30 -07:00
|
|
|
from selfdrive.controls.lib.longitudinal_planner import Planner
|
|
|
|
from selfdrive.controls.lib.lateral_planner import LateralPlanner
|
2021-04-08 13:56:47 -06:00
|
|
|
from selfdrive.hardware import TICI
|
2020-01-17 13:48:30 -07:00
|
|
|
import cereal.messaging as messaging
|
|
|
|
|
|
|
|
|
|
|
|
def plannerd_thread(sm=None, pm=None):
|
2021-04-09 05:41:43 -06:00
|
|
|
config_realtime_process(5 if TICI else 2, Priority.CTRL_LOW)
|
2020-01-17 13:48:30 -07:00
|
|
|
|
|
|
|
cloudlog.info("plannerd is waiting for CarParams")
|
2021-04-08 13:56:47 -06:00
|
|
|
params = Params()
|
|
|
|
CP = car.CarParams.from_bytes(params.get("CarParams", block=True))
|
2020-01-17 13:48:30 -07:00
|
|
|
cloudlog.info("plannerd got CarParams: %s", CP.carName)
|
|
|
|
|
2021-04-09 02:32:31 -06:00
|
|
|
use_lanelines = not params.get_bool('EndToEndToggle')
|
|
|
|
wide_camera = params.get_bool('EnableWideCamera') if TICI else False
|
|
|
|
|
2021-05-18 11:52:53 -06:00
|
|
|
cloudlog.event("e2e mode", on=use_lanelines)
|
|
|
|
|
2021-03-11 22:08:51 -07:00
|
|
|
longitudinal_planner = Planner(CP)
|
2021-04-08 13:56:47 -06:00
|
|
|
lateral_planner = LateralPlanner(CP, use_lanelines=use_lanelines, wide_camera=wide_camera)
|
2020-01-17 13:48:30 -07:00
|
|
|
|
|
|
|
if sm is None:
|
2021-03-11 22:08:51 -07:00
|
|
|
sm = messaging.SubMaster(['carState', 'controlsState', 'radarState', 'modelV2'],
|
2021-04-21 02:59:26 -06:00
|
|
|
poll=['radarState', 'modelV2'], ignore_avg_freq=['radarState'])
|
2020-01-17 13:48:30 -07:00
|
|
|
|
|
|
|
if pm is None:
|
2021-09-09 15:09:09 -06:00
|
|
|
pm = messaging.PubMaster(['longitudinalPlan', 'lateralPlan'])
|
2020-01-17 13:48:30 -07:00
|
|
|
|
|
|
|
while True:
|
|
|
|
sm.update()
|
|
|
|
|
2021-01-14 19:43:50 -07:00
|
|
|
if sm.updated['modelV2']:
|
2021-11-26 06:57:39 -07:00
|
|
|
lateral_planner.update(sm)
|
2021-03-11 22:08:51 -07:00
|
|
|
lateral_planner.publish(sm, pm)
|
2021-11-26 06:57:39 -07:00
|
|
|
longitudinal_planner.update(sm)
|
2021-03-11 22:08:51 -07:00
|
|
|
longitudinal_planner.publish(sm, pm)
|
2020-01-17 13:48:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
def main(sm=None, pm=None):
|
|
|
|
plannerd_thread(sm, pm)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|