Files
dragonpilot/selfdrive/controls/plannerd.py

55 lines
1.4 KiB
Python
Raw Normal View History

2019-10-09 18:43:53 +00:00
#!/usr/bin/env python3
2019-06-06 04:38:45 +00:00
import gc
2019-02-20 01:39:02 +00:00
from cereal import car
from common.params import Params
2019-06-28 21:11:30 +00:00
from common.realtime import set_realtime_priority
2019-02-20 01:39:02 +00:00
from selfdrive.swaglog import cloudlog
from selfdrive.controls.lib.planner import Planner
from selfdrive.controls.lib.vehicle_model import VehicleModel
from selfdrive.controls.lib.pathplanner import PathPlanner
import selfdrive.messaging as messaging
2019-09-09 23:03:02 +00:00
def plannerd_thread(sm=None, pm=None):
2019-06-06 04:38:45 +00:00
gc.disable()
# start the loop
set_realtime_priority(2)
2019-02-20 01:39:02 +00:00
cloudlog.info("plannerd is waiting for CarParams")
CP = car.CarParams.from_bytes(Params().get("CarParams", block=True))
cloudlog.info("plannerd got CarParams: %s", CP.carName)
2019-09-09 23:03:02 +00:00
PL = Planner(CP)
2019-02-20 01:39:02 +00:00
PP = PathPlanner(CP)
VM = VehicleModel(CP)
2019-09-09 23:03:02 +00:00
if sm is None:
sm = messaging.SubMaster(['carState', 'controlsState', 'radarState', 'model', 'liveParameters'])
if pm is None:
pm = messaging.PubMaster(['plan', 'liveLongitudinalMpc', 'pathPlan', 'liveMpc'])
2019-06-28 21:11:30 +00:00
sm['liveParameters'].valid = True
sm['liveParameters'].sensorValid = True
sm['liveParameters'].steerRatio = CP.steerRatio
sm['liveParameters'].stiffnessFactor = 1.0
2019-02-20 01:39:02 +00:00
while True:
2019-06-28 21:11:30 +00:00
sm.update()
if sm.updated['model']:
2019-09-09 23:03:02 +00:00
PP.update(sm, pm, CP, VM)
2019-06-28 21:11:30 +00:00
if sm.updated['radarState']:
2019-09-09 23:03:02 +00:00
PL.update(sm, pm, CP, VM, PP)
2019-02-20 01:39:02 +00:00
2019-09-09 23:03:02 +00:00
def main(sm=None, pm=None):
plannerd_thread(sm, pm)
2019-02-20 01:39:02 +00:00
if __name__ == "__main__":
main()