Chrysler: clean up CarController (#24337)

* clean up

* max range is 15

* use wheel buttons counter and clean up

* no

* try spamming 10 times with next counter value

* try 50 hz

* this is dead code

* revert behavior changes, just clean up

* revert more

* also that

* no multiline can creation

* sort imports
pull/24413/head
Shane Smiskol 3 years ago committed by GitHub
parent c994dfdd8a
commit 3f0b06b16e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 45
      selfdrive/car/chrysler/carcontroller.py
  2. 2
      selfdrive/car/chrysler/chryslercan.py
  3. 6
      selfdrive/car/chrysler/interface.py

@ -1,16 +1,16 @@
from cereal import car from cereal import car
from opendbc.can.packer import CANPacker
from selfdrive.car import apply_toyota_steer_torque_limits from selfdrive.car import apply_toyota_steer_torque_limits
from selfdrive.car.chrysler.chryslercan import create_lkas_hud, create_lkas_command, \ from selfdrive.car.chrysler.chryslercan import create_lkas_hud, create_lkas_command, create_wheel_buttons
create_wheel_buttons
from selfdrive.car.chrysler.values import CAR, CarControllerParams from selfdrive.car.chrysler.values import CAR, CarControllerParams
from opendbc.can.packer import CANPacker
class CarController():
class CarController:
def __init__(self, dbc_name, CP, VM): def __init__(self, dbc_name, CP, VM):
self.CP = CP self.CP = CP
self.apply_steer_last = 0 self.apply_steer_last = 0
self.ccframe = 0 self.frame = 0
self.prev_frame = -1 self.prev_lkas_frame = -1
self.hud_count = 0 self.hud_count = 0
self.car_fingerprint = CP.carFingerprint self.car_fingerprint = CP.carFingerprint
self.gone_fast_yet = False self.gone_fast_yet = False
@ -18,12 +18,13 @@ class CarController():
self.packer = CANPacker(dbc_name) self.packer = CANPacker(dbc_name)
def update(self, enabled, CS, actuators, pcm_cancel_cmd, hud_alert): def update(self, CC, CS):
# this seems needed to avoid steering faults and to force the sync with the EPS counter # this seems needed to avoid steering faults and to force the sync with the EPS counter
frame = CS.lkas_counter if self.prev_lkas_frame == CS.lkas_counter:
if self.prev_frame == frame:
return car.CarControl.Actuators.new_message(), [] return car.CarControl.Actuators.new_message(), []
actuators = CC.actuators
# steer torque # steer torque
new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX)) new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX))
apply_steer = apply_toyota_steer_torque_limits(new_steer, self.apply_steer_last, apply_steer = apply_toyota_steer_torque_limits(new_steer, self.apply_steer_last,
@ -36,7 +37,7 @@ class CarController():
elif self.car_fingerprint in (CAR.PACIFICA_2019_HYBRID, CAR.PACIFICA_2020, CAR.JEEP_CHEROKEE_2019): elif self.car_fingerprint in (CAR.PACIFICA_2019_HYBRID, CAR.PACIFICA_2020, CAR.JEEP_CHEROKEE_2019):
if CS.out.vEgo < (self.CP.minSteerSpeed - 3.0): if CS.out.vEgo < (self.CP.minSteerSpeed - 3.0):
self.gone_fast_yet = False # < 14.5m/s stock turns off this bit, but fine down to 13.5 self.gone_fast_yet = False # < 14.5m/s stock turns off this bit, but fine down to 13.5
lkas_active = moving_fast and enabled lkas_active = moving_fast and CC.enabled
if not lkas_active: if not lkas_active:
apply_steer = 0 apply_steer = 0
@ -45,28 +46,24 @@ class CarController():
can_sends = [] can_sends = []
#*** control msgs *** # *** control msgs ***
if pcm_cancel_cmd: if CC.cruiseControl.cancel:
# TODO: would be better to start from frame_2b3 # TODO: would be better to start from frame_2b3
new_msg = create_wheel_buttons(self.packer, self.ccframe, cancel=True) can_sends.append(create_wheel_buttons(self.packer, self.frame, cancel=True))
can_sends.append(new_msg)
# LKAS_HEARTBIT is forwarded by Panda so no need to send it here. # LKAS_HEARTBIT is forwarded by Panda so no need to send it here.
# frame is 100Hz (0.01s period) # frame is 100Hz (0.01s period)
if (self.ccframe % 25 == 0): # 0.25s period if self.frame % 25 == 0: # 0.25s period
if (CS.lkas_car_model != -1): if CS.lkas_car_model != -1:
new_msg = create_lkas_hud( can_sends.append(create_lkas_hud(self.packer, CS.out.gearShifter, lkas_active,
self.packer, CS.out.gearShifter, lkas_active, hud_alert, CC.hudControl.visualAlert, self.hud_count, CS.lkas_car_model))
self.hud_count, CS.lkas_car_model)
can_sends.append(new_msg)
self.hud_count += 1 self.hud_count += 1
new_msg = create_lkas_command(self.packer, int(apply_steer), self.gone_fast_yet, frame) can_sends.append(create_lkas_command(self.packer, int(apply_steer), self.gone_fast_yet, CS.lkas_counter))
can_sends.append(new_msg)
self.ccframe += 1 self.frame += 1
self.prev_frame = frame self.prev_lkas_frame = CS.lkas_counter
new_actuators = actuators.copy() new_actuators = actuators.copy()
new_actuators.steer = apply_steer / CarControllerParams.STEER_MAX new_actuators.steer = apply_steer / CarControllerParams.STEER_MAX

@ -52,6 +52,6 @@ def create_wheel_buttons(packer, frame, cancel=False):
# WHEEL_BUTTONS (571) Message sent to cancel ACC. # WHEEL_BUTTONS (571) Message sent to cancel ACC.
values = { values = {
"ACC_CANCEL": cancel, "ACC_CANCEL": cancel,
"COUNTER": frame % 10 "COUNTER": frame % 10 # FIXME: this counter is wrong
} }
return packer.make_can_msg("WHEEL_BUTTONS", 0, values) return packer.make_can_msg("WHEEL_BUTTONS", 0, values)

@ -65,8 +65,4 @@ class CarInterface(CarInterfaceBase):
# pass in a car.CarControl # pass in a car.CarControl
# to be called @ 100hz # to be called @ 100hz
def apply(self, c): def apply(self, c):
return self.CC.update(c, self.CS)
if (self.CS.frame == -1):
return car.CarControl.Actuators.new_message(), [] # if we haven't seen a frame 220, then do not update.
return self.CC.update(c.enabled, self.CS, c.actuators, c.cruiseControl.cancel, c.hudControl.visualAlert)

Loading…
Cancel
Save