2020-01-17 12:48:30 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
from cereal import car
|
2023-08-20 20:49:55 -07:00
|
|
|
from openpilot.common.params import Params
|
|
|
|
|
from openpilot.common.realtime import Priority, config_realtime_process
|
2023-12-06 17:27:51 -08:00
|
|
|
from openpilot.common.swaglog import cloudlog
|
2024-09-06 15:30:14 -07:00
|
|
|
from openpilot.selfdrive.controls.lib.ldw import LaneDepartureWarning
|
2023-08-20 20:49:55 -07:00
|
|
|
from openpilot.selfdrive.controls.lib.longitudinal_planner import LongitudinalPlanner
|
2020-01-17 12:48:30 -08:00
|
|
|
import cereal.messaging as messaging
|
|
|
|
|
|
|
|
|
|
|
2024-09-06 15:30:14 -07:00
|
|
|
def main():
|
2022-06-02 15:20:51 +02:00
|
|
|
config_realtime_process(5, Priority.CTRL_LOW)
|
2020-01-17 12:48:30 -08:00
|
|
|
|
|
|
|
|
cloudlog.info("plannerd is waiting for CarParams")
|
2021-04-08 12:56:47 -07:00
|
|
|
params = Params()
|
2024-07-09 04:50:31 +08:00
|
|
|
CP = messaging.log_from_bytes(params.get("CarParams", block=True), car.CarParams)
|
2020-01-17 12:48:30 -08:00
|
|
|
cloudlog.info("plannerd got CarParams: %s", CP.carName)
|
|
|
|
|
|
2024-09-06 15:30:14 -07:00
|
|
|
ldw = LaneDepartureWarning()
|
2022-09-06 21:52:34 -07:00
|
|
|
longitudinal_planner = LongitudinalPlanner(CP)
|
2024-09-06 15:30:14 -07:00
|
|
|
pm = messaging.PubMaster(['longitudinalPlan', 'driverAssistance'])
|
2024-09-03 14:40:23 -07:00
|
|
|
sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2', 'selfdriveState'],
|
2024-02-12 10:11:37 -08:00
|
|
|
poll='modelV2', ignore_avg_freq=['radarState'])
|
2020-01-17 12:48:30 -08:00
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
sm.update()
|
2021-01-14 18:43:50 -08:00
|
|
|
if sm.updated['modelV2']:
|
2021-11-26 07:57:39 -06:00
|
|
|
longitudinal_planner.update(sm)
|
2021-03-12 06:08:51 +01:00
|
|
|
longitudinal_planner.publish(sm, pm)
|
2024-06-11 21:31:10 -07:00
|
|
|
|
2024-09-06 15:30:14 -07:00
|
|
|
ldw.update(sm.frame, sm['modelV2'], sm['carState'], sm['carControl'])
|
|
|
|
|
msg = messaging.new_message('driverAssistance')
|
|
|
|
|
msg.valid = sm.all_checks(['carState', 'carControl', 'modelV2'])
|
|
|
|
|
msg.driverAssistance.leftLaneDeparture = ldw.left
|
|
|
|
|
msg.driverAssistance.rightLaneDeparture = ldw.right
|
|
|
|
|
pm.send('driverAssistance', msg)
|
2020-01-17 12:48:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|