openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.6 KiB

from cereal import car
from opendbc.can.packer import CANPacker
5 years ago
from selfdrive.car import apply_toyota_steer_torque_limits
from selfdrive.car.chrysler.chryslercan import create_lkas_hud, create_lkas_command, create_wheel_buttons
from selfdrive.car.chrysler.values import CAR, CarControllerParams
5 years ago
class CarController:
def __init__(self, dbc_name, CP, VM):
self.CP = CP
5 years ago
self.apply_steer_last = 0
self.frame = 0
self.prev_lkas_frame = -1
5 years ago
self.hud_count = 0
self.car_fingerprint = CP.carFingerprint
5 years ago
self.gone_fast_yet = False
self.steer_rate_limited = False
self.packer = CANPacker(dbc_name)
def update(self, CC, CS):
5 years ago
# this seems needed to avoid steering faults and to force the sync with the EPS counter
if self.prev_lkas_frame == CS.lkas_counter:
return car.CarControl.Actuators.new_message(), []
5 years ago
actuators = CC.actuators
5 years ago
# steer torque
new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX))
5 years ago
apply_steer = apply_toyota_steer_torque_limits(new_steer, self.apply_steer_last,
CS.out.steeringTorqueEps, CarControllerParams)
5 years ago
self.steer_rate_limited = new_steer != apply_steer
moving_fast = CS.out.vEgo > self.CP.minSteerSpeed # for status message
if CS.out.vEgo > (self.CP.minSteerSpeed - 0.5): # for command high bit
5 years ago
self.gone_fast_yet = True
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):
5 years ago
self.gone_fast_yet = False # < 14.5m/s stock turns off this bit, but fine down to 13.5
lkas_active = moving_fast and CC.enabled
5 years ago
if not lkas_active:
apply_steer = 0
self.apply_steer_last = apply_steer
can_sends = []
# *** control msgs ***
5 years ago
if CC.cruiseControl.cancel:
can_sends.append(create_wheel_buttons(self.packer, CS.button_counter + 1, cancel=True))
5 years ago
# LKAS_HEARTBIT is forwarded by Panda so no need to send it here.
# frame is 100Hz (0.01s period)
if self.frame % 25 == 0: # 0.25s period
if CS.lkas_car_model != -1:
can_sends.append(create_lkas_hud(self.packer, CS.out.gearShifter, lkas_active,
CC.hudControl.visualAlert, self.hud_count, CS.lkas_car_model))
5 years ago
self.hud_count += 1
can_sends.append(create_lkas_command(self.packer, int(apply_steer), self.gone_fast_yet, CS.lkas_counter))
5 years ago
self.frame += 1
self.prev_lkas_frame = CS.lkas_counter
5 years ago
new_actuators = actuators.copy()
new_actuators.steer = apply_steer / CarControllerParams.STEER_MAX
return new_actuators, can_sends