2023-09-27 15:45:31 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from cereal import car
|
2023-11-17 23:53:40 +00:00
|
|
|
from openpilot.common.params import Params
|
|
|
|
from openpilot.common.realtime import Priority, config_realtime_process
|
2024-02-21 23:02:43 +00:00
|
|
|
from openpilot.common.swaglog import cloudlog
|
2025-03-08 09:09:31 +00:00
|
|
|
from openpilot.selfdrive.controls.lib.ldw import LaneDepartureWarning
|
2023-11-17 23:53:40 +00:00
|
|
|
from openpilot.selfdrive.controls.lib.longitudinal_planner import LongitudinalPlanner
|
2024-09-03 16:09:00 +09:00
|
|
|
from openpilot.selfdrive.controls.lib.lateral_planner import LateralPlanner
|
2023-09-27 15:45:31 -07:00
|
|
|
import cereal.messaging as messaging
|
2024-09-03 16:09:00 +09:00
|
|
|
from openpilot.selfdrive.carrot.carrot_functions import CarrotPlanner
|
2023-09-27 15:45:31 -07:00
|
|
|
|
2025-03-08 09:09:31 +00:00
|
|
|
|
|
|
|
def main():
|
2023-09-27 15:45:31 -07:00
|
|
|
config_realtime_process(5, Priority.CTRL_LOW)
|
|
|
|
|
|
|
|
cloudlog.info("plannerd is waiting for CarParams")
|
|
|
|
params = Params()
|
2025-03-08 09:09:31 +00:00
|
|
|
CP = messaging.log_from_bytes(params.get("CarParams", block=True), car.CarParams)
|
|
|
|
cloudlog.info("plannerd got CarParams: %s", CP.brand)
|
2023-09-27 15:45:31 -07:00
|
|
|
|
2025-03-08 09:09:31 +00:00
|
|
|
ldw = LaneDepartureWarning()
|
2023-09-27 15:45:31 -07:00
|
|
|
longitudinal_planner = LongitudinalPlanner(CP)
|
2024-09-03 16:09:00 +09:00
|
|
|
lateral_planner = LateralPlanner(CP, debug=False)
|
|
|
|
|
|
|
|
pm = messaging.PubMaster(['longitudinalPlan', 'driverAssistance', 'lateralPlan'])
|
|
|
|
sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'liveParameters', 'radarState', 'modelV2', 'selfdriveState', 'carrotMan'],
|
2024-02-21 23:02:43 +00:00
|
|
|
poll='modelV2', ignore_avg_freq=['radarState'])
|
2024-09-03 16:09:00 +09:00
|
|
|
carrot = CarrotPlanner()
|
2023-09-27 15:45:31 -07:00
|
|
|
|
|
|
|
while True:
|
|
|
|
sm.update()
|
|
|
|
if sm.updated['modelV2']:
|
2024-09-03 16:09:00 +09:00
|
|
|
lateral_planner.update(sm, carrot)
|
|
|
|
lateral_planner.publish(sm, pm, carrot)
|
|
|
|
longitudinal_planner.update(sm, carrot)
|
|
|
|
longitudinal_planner.publish(sm, pm, carrot)
|
2023-09-27 15:45:31 -07:00
|
|
|
|
2025-03-08 09:09:31 +00:00
|
|
|
ldw.update(sm.frame, sm['modelV2'], sm['carState'], sm['carControl'])
|
|
|
|
msg = messaging.new_message('driverAssistance')
|
|
|
|
msg.valid = sm.all_checks(['carState', 'carControl', 'modelV2', 'liveParameters'])
|
|
|
|
msg.driverAssistance.leftLaneDeparture = ldw.left
|
|
|
|
msg.driverAssistance.rightLaneDeparture = ldw.right
|
|
|
|
pm.send('driverAssistance', msg)
|
2023-09-27 15:45:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|