mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-30 04:03:44 +08:00
Move car-specific changes to opendbc
This commit is contained in:
+1
-1
Submodule opendbc_repo updated: 71e45f46b2...992ef0a13c
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
import math
|
||||
from typing import SupportsFloat
|
||||
import time
|
||||
import threading
|
||||
|
||||
from cereal import car, log
|
||||
import cereal.messaging as messaging
|
||||
@@ -59,6 +61,8 @@ class Controls:
|
||||
data_services = list(self.sm.data.keys()) + ['selfdriveStateSP']
|
||||
self.sm = messaging.SubMaster(data_services, poll='selfdriveState')
|
||||
|
||||
self.enable_mads = self.params.get_bool("Mads")
|
||||
|
||||
def update(self):
|
||||
self.sm.update(15)
|
||||
if self.sm.updated["liveCalibration"]:
|
||||
@@ -165,6 +169,9 @@ class Controls:
|
||||
hudControl.leftLaneDepart = self.sm['driverAssistance'].leftLaneDeparture
|
||||
hudControl.rightLaneDepart = self.sm['driverAssistance'].rightLaneDeparture
|
||||
|
||||
sunnyLiveParams = CC.sunnyLiveParams
|
||||
sunnyLiveParams.enableMads = self.enable_mads
|
||||
|
||||
if self.sm['selfdriveState'].active:
|
||||
CO = self.sm['carOutput']
|
||||
if self.CP.steerControlType == car.CarParams.SteerControlType.angle:
|
||||
@@ -211,13 +218,25 @@ class Controls:
|
||||
cc_send.carControl = CC
|
||||
self.pm.send('carControl', cc_send)
|
||||
|
||||
def params_thread(self, evt):
|
||||
while not evt.is_set():
|
||||
self.enable_mads = self.params.get_bool("Mads")
|
||||
time.sleep(0.1)
|
||||
|
||||
def run(self):
|
||||
e = threading.Event()
|
||||
t = threading.Thread(target=self.params_thread, args=(e, ))
|
||||
rk = Ratekeeper(100, print_delay_threshold=None)
|
||||
while True:
|
||||
self.update()
|
||||
CC, lac_log = self.state_control()
|
||||
self.publish(CC, lac_log)
|
||||
rk.monitor_time()
|
||||
try:
|
||||
t.start()
|
||||
while True:
|
||||
self.update()
|
||||
CC, lac_log = self.state_control()
|
||||
self.publish(CC, lac_log)
|
||||
rk.monitor_time()
|
||||
finally:
|
||||
e.set()
|
||||
t.join()
|
||||
|
||||
def main():
|
||||
config_realtime_process(4, Priority.CTRL_HIGH)
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
from abc import abstractmethod
|
||||
from collections import namedtuple
|
||||
|
||||
from opendbc.car import DT_CTRL, structs
|
||||
from opendbc.car.can_definitions import CanData
|
||||
from opendbc.car.interfaces import CarStateBase, CarControllerBase
|
||||
|
||||
MadsDataSP = namedtuple("MadsDataSP",
|
||||
["enabled_toggle", "lat_active", "disengaging", "paused"])
|
||||
|
||||
|
||||
class CarControllerSP(CarControllerBase):
|
||||
def __init__(self, dbc_name: str, CP: structs.CarParams):
|
||||
super().__init__(dbc_name, CP)
|
||||
self.lat_disengage_blink = 0
|
||||
self.lat_disengage_init = False
|
||||
self.prev_lat_active = False
|
||||
|
||||
# display LFA "white_wheel" and LKAS "White car + lanes" when not CC.latActive
|
||||
def mads_status_update(self, CS: CarStateBase, CC: structs.CarControl) -> MadsDataSP:
|
||||
if CC.latActive:
|
||||
self.lat_disengage_init = False
|
||||
elif self.prev_lat_active:
|
||||
self.lat_disengage_init = True
|
||||
|
||||
if not self.lat_disengage_init:
|
||||
self.lat_disengage_blink = self.frame
|
||||
|
||||
paused = CC.madsActive and not CC.latActive
|
||||
disengaging = (self.frame - self.lat_disengage_blink) * DT_CTRL < 1.0 if self.lat_disengage_init else False
|
||||
|
||||
self.prev_lat_active = CC.latActive
|
||||
|
||||
return MadsDataSP(CS.mads_enabled_toggle, CC.latActive, disengaging, paused)
|
||||
|
||||
@abstractmethod
|
||||
def update(self, CC: structs.CarControl, CS: CarStateBase, now_nanos: int) -> tuple[structs.CarControl.Actuators, list[CanData]]:
|
||||
pass
|
||||
@@ -1,13 +0,0 @@
|
||||
from abc import ABC
|
||||
|
||||
from opendbc.car import structs
|
||||
|
||||
from openpilot.sunnypilot.mads.mads import MadsParams
|
||||
|
||||
|
||||
class CarStateBaseSP(ABC):
|
||||
def __init__(self, CP: structs.CarParams):
|
||||
self.alt_button = 0
|
||||
self.mads_enabled_toggle = MadsParams().read_param("Mads")
|
||||
|
||||
self.main_cruise_enabled = False
|
||||
Reference in New Issue
Block a user