Files
sunnypilot/selfdrive/controls/plannerd.py
T
Jason Wen 0372bf8e11 UI: E2E longitudinal status icon and prompt chime (#23)
* UI: Display E2E Longitudinal status icon

* don't forget init

* take these out

* and this

* can't leave this

* spam the event

* publish here instead

* try this now

* expose the toggle

* Spam all the time!!!

* Spam all the time with this!

* see if this works

* new way to trigger

* fix

* another one

* more to it

* more of that

* move to car controls instead

* no longer needed

* 20 hz

* unnecessary

* send like this pls

* move to long planner

* let's see what it looks like first

* don't alert yet lol

* re-enable and try out prompt!

* move chime event to longitudinal_planner

* AlertStatus to userPrompt

* Add more reset conditions

* less conditions to test first

* louder sound

* permanent alert

* LOUDER SON!

* use stock prompt

* Revert "less conditions to test first"

This reverts commit b24a096e65e80f303f7d92072cdf273a30dd37e2.

* remove lead car take off alert (in separate PR)

* cleanup

* longer

* Nicki Minaj Model (#28218)

* New model: 2ff7490f-8a2f-4c0d-87a8-b0fa3a4a6a71

* Updated model_replay_ref_commit

(cherry picked from commit 328b5d9d47)

* use the event

* move logic to c++

* cleanup

* no prompt border

* use brake light from car state

* lead car take off event

* lead car take off event

* always reset last distance

* show border when prompted

* remove lead car take off alert (in separate PR)

* don't prompt when lead car detected

* Revert "Nicki Minaj Model (#28218)"

This reverts commit b25e96c9d8fe0ac3a93c97eec2e91064c12a5649.

* bad sounds

* simpler

---------

Co-authored-by: Mitchell Goff <mitchellgoffpc@gmail.com>
2023-05-27 13:32:05 -04:00

68 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python3
import numpy as np
from cereal import car
from common.params import Params
from common.realtime import Priority, config_realtime_process
from system.swaglog import cloudlog
from selfdrive.modeld.constants import T_IDXS
from selfdrive.controls.lib.longitudinal_planner import LongitudinalPlanner
from selfdrive.controls.lib.lateral_planner import LateralPlanner
import cereal.messaging as messaging
def cumtrapz(x, t):
return np.concatenate([[0], np.cumsum(((x[0:-1] + x[1:])/2) * np.diff(t))])
def publish_ui_plan(sm, pm, lateral_planner, longitudinal_planner):
plan_odo = cumtrapz(longitudinal_planner.v_desired_trajectory_full, T_IDXS)
model_odo = cumtrapz(lateral_planner.v_plan, T_IDXS)
ui_send = messaging.new_message('uiPlan')
ui_send.valid = sm.all_checks(service_list=['carState', 'controlsState', 'modelV2'])
uiPlan = ui_send.uiPlan
uiPlan.frameId = sm['modelV2'].frameId
uiPlan.position.x = np.interp(plan_odo, model_odo, lateral_planner.lat_mpc.x_sol[:,0]).tolist()
uiPlan.position.y = np.interp(plan_odo, model_odo, lateral_planner.lat_mpc.x_sol[:,1]).tolist()
uiPlan.position.z = np.interp(plan_odo, model_odo, lateral_planner.path_xyz[:,2]).tolist()
uiPlan.accel = longitudinal_planner.a_desired_trajectory_full.tolist()
pm.send('uiPlan', ui_send)
def plannerd_thread(sm=None, pm=None):
config_realtime_process(5, Priority.CTRL_LOW)
cloudlog.info("plannerd is waiting for CarParams")
params = Params()
CP = car.CarParams.from_bytes(params.get("CarParams", block=True))
cloudlog.info("plannerd got CarParams: %s", CP.carName)
use_lanelines = False
wide_camera = params.get_bool('WideCameraOnly')
cloudlog.event("e2e mode", on=use_lanelines)
longitudinal_planner = LongitudinalPlanner(CP)
lateral_planner = LateralPlanner(CP, use_lanelines=use_lanelines, wide_camera=wide_camera)
if sm is None:
sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2', 'longitudinalPlan', 'lateralPlan', 'liveMapData', 'navInstruction', 'e2eLongState'],
poll=['radarState', 'modelV2'], ignore_avg_freq=['radarState'])
if pm is None:
pm = messaging.PubMaster(['longitudinalPlan', 'lateralPlan', 'uiPlan'])
while True:
sm.update()
if sm.updated['modelV2']:
lateral_planner.update(sm)
lateral_planner.publish(sm, pm)
longitudinal_planner.update(sm)
longitudinal_planner.publish(sm, pm)
publish_ui_plan(sm, pm, lateral_planner, longitudinal_planner)
def main(sm=None, pm=None):
plannerd_thread(sm, pm)
if __name__ == "__main__":
main()