|
|
@ -1,14 +1,16 @@ |
|
|
|
from common.numpy_fast import clip, interp |
|
|
|
from common.numpy_fast import clip, interp |
|
|
|
from selfdrive.car.tesla.teslacan import TeslaCAN |
|
|
|
|
|
|
|
from opendbc.can.packer import CANPacker |
|
|
|
from opendbc.can.packer import CANPacker |
|
|
|
from selfdrive.car.tesla.values import CANBUS, CarControllerParams |
|
|
|
from selfdrive.car.tesla.teslacan import TeslaCAN |
|
|
|
|
|
|
|
from selfdrive.car.tesla.values import DBC, CANBUS, CarControllerParams |
|
|
|
|
|
|
|
|
|
|
|
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.last_angle = 0 |
|
|
|
self.last_angle = 0 |
|
|
|
|
|
|
|
self.long_control_counter = 0 |
|
|
|
self.packer = CANPacker(dbc_name) |
|
|
|
self.packer = CANPacker(dbc_name) |
|
|
|
self.tesla_can = TeslaCAN(dbc_name, self.packer) |
|
|
|
self.pt_packer = CANPacker(DBC[CP.carFingerprint]['pt']) |
|
|
|
|
|
|
|
self.tesla_can = TeslaCAN(self.packer, self.pt_packer) |
|
|
|
|
|
|
|
|
|
|
|
def update(self, enabled, CS, frame, actuators, cruise_cancel): |
|
|
|
def update(self, enabled, CS, frame, actuators, cruise_cancel): |
|
|
|
can_sends = [] |
|
|
|
can_sends = [] |
|
|
@ -34,6 +36,16 @@ class CarController(): |
|
|
|
self.last_angle = apply_angle |
|
|
|
self.last_angle = apply_angle |
|
|
|
can_sends.append(self.tesla_can.create_steering_control(apply_angle, lkas_enabled, frame)) |
|
|
|
can_sends.append(self.tesla_can.create_steering_control(apply_angle, lkas_enabled, frame)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Longitudinal control (40Hz) |
|
|
|
|
|
|
|
if self.CP.openpilotLongitudinalControl and ((frame % 5) in [0, 2]): |
|
|
|
|
|
|
|
target_accel = actuators.accel |
|
|
|
|
|
|
|
target_speed = max(CS.out.vEgo + (target_accel * CarControllerParams.ACCEL_TO_SPEED_MULTIPLIER), 0) |
|
|
|
|
|
|
|
max_accel = 0 if target_accel < 0 else target_accel |
|
|
|
|
|
|
|
min_accel = 0 if target_accel > 0 else target_accel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
can_sends.extend(self.tesla_can.create_longitudinal_commands(CS.acc_state, target_speed, min_accel, max_accel, self.long_control_counter)) |
|
|
|
|
|
|
|
self.long_control_counter += 1 |
|
|
|
|
|
|
|
|
|
|
|
# Cancel on user steering override, since there is no steering torque blending |
|
|
|
# Cancel on user steering override, since there is no steering torque blending |
|
|
|
if hands_on_fault: |
|
|
|
if hands_on_fault: |
|
|
|
cruise_cancel = True |
|
|
|
cruise_cancel = True |
|
|
@ -46,7 +58,7 @@ class CarController(): |
|
|
|
# Spam every possible counter value, otherwise it might not be accepted |
|
|
|
# Spam every possible counter value, otherwise it might not be accepted |
|
|
|
for counter in range(16): |
|
|
|
for counter in range(16): |
|
|
|
can_sends.append(self.tesla_can.create_action_request(CS.msg_stw_actn_req, cruise_cancel, CANBUS.chassis, counter)) |
|
|
|
can_sends.append(self.tesla_can.create_action_request(CS.msg_stw_actn_req, cruise_cancel, CANBUS.chassis, counter)) |
|
|
|
can_sends.append(self.tesla_can.create_action_request(CS.msg_stw_actn_req, cruise_cancel, CANBUS.autopilot, counter)) |
|
|
|
can_sends.append(self.tesla_can.create_action_request(CS.msg_stw_actn_req, cruise_cancel, CANBUS.autopilot_chassis, counter)) |
|
|
|
|
|
|
|
|
|
|
|
# TODO: HUD control |
|
|
|
# TODO: HUD control |
|
|
|
|
|
|
|
|
|
|
|