|
|
@ -4,6 +4,15 @@ from selfdrive.car.ford.values import CANBUS |
|
|
|
HUDControl = car.CarControl.HUDControl |
|
|
|
HUDControl = car.CarControl.HUDControl |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def calculate_lat_ctl2_checksum(mode: int, counter: int, dat: bytearray): |
|
|
|
|
|
|
|
checksum = mode + counter |
|
|
|
|
|
|
|
checksum += dat[2] + ((dat[3] & 0xE0) >> 5) # curvature |
|
|
|
|
|
|
|
checksum += dat[6] + ((dat[7] & 0xE0) >> 5) # curvature rate |
|
|
|
|
|
|
|
checksum += (dat[3] & 0x1F) + ((dat[4] & 0xFC) >> 2) # path angle |
|
|
|
|
|
|
|
checksum += (dat[4] & 0x3) + dat[5] # path offset |
|
|
|
|
|
|
|
return 0xFF - (checksum & 0xFF) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_lka_msg(packer): |
|
|
|
def create_lka_msg(packer): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Creates an empty CAN message for the Ford LKA Command. |
|
|
|
Creates an empty CAN message for the Ford LKA Command. |
|
|
@ -16,7 +25,8 @@ def create_lka_msg(packer): |
|
|
|
return packer.make_can_msg("Lane_Assist_Data1", CANBUS.main, {}) |
|
|
|
return packer.make_can_msg("Lane_Assist_Data1", CANBUS.main, {}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_lat_ctl_msg(packer, lat_active: bool, path_offset: float, path_angle: float, curvature: float, curvature_rate: float): |
|
|
|
def create_lat_ctl_msg(packer, lat_active: bool, path_offset: float, path_angle: float, curvature: float, |
|
|
|
|
|
|
|
curvature_rate: float): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Creates a CAN message for the Ford TJA/LCA Command. |
|
|
|
Creates a CAN message for the Ford TJA/LCA Command. |
|
|
|
|
|
|
|
|
|
|
@ -55,6 +65,38 @@ def create_lat_ctl_msg(packer, lat_active: bool, path_offset: float, path_angle: |
|
|
|
return packer.make_can_msg("LateralMotionControl", CANBUS.main, values) |
|
|
|
return packer.make_can_msg("LateralMotionControl", CANBUS.main, values) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_lat_ctl2_msg(packer, mode: int, path_offset: float, path_angle: float, curvature: float, |
|
|
|
|
|
|
|
curvature_rate: float, counter: int): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Create a CAN message for the new Ford Lane Centering command. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This message is used on the CAN FD platform and replaces the old LateralMotionControl message. It is similar but has |
|
|
|
|
|
|
|
additional signals for a counter and checksum. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Frequency is 20Hz. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
values = { |
|
|
|
|
|
|
|
"LatCtl_D2_Rq": mode, # Mode: 0=None, 1=PathFollowingLimitedMode, 2=PathFollowingExtendedMode, |
|
|
|
|
|
|
|
# 3=SafeRampOut, 4-7=NotUsed [0|7] |
|
|
|
|
|
|
|
"LatCtlRampType_D_Rq": 0, # 0=Slow, 1=Medium, 2=Fast, 3=Immediate [0|3] |
|
|
|
|
|
|
|
"LatCtlPrecision_D_Rq": 1, # 0=Comfortable, 1=Precise, 2/3=NotUsed [0|3] |
|
|
|
|
|
|
|
"LatCtlPathOffst_L_Actl": path_offset, # [-5.12|5.11] meter |
|
|
|
|
|
|
|
"LatCtlPath_An_Actl": path_angle, # [-0.5|0.5235] radians |
|
|
|
|
|
|
|
"LatCtlCurv_No_Actl": curvature, # [-0.02|0.02094] 1/meter |
|
|
|
|
|
|
|
"LatCtlCrv_NoRate2_Actl": curvature_rate, # [-0.001024|0.001023] 1/meter^2 |
|
|
|
|
|
|
|
"HandsOffCnfm_B_Rq": 0, # 0=Inactive, 1=Active [0|1] |
|
|
|
|
|
|
|
"LatCtlPath_No_Cnt": counter, # [0|15] |
|
|
|
|
|
|
|
"LatCtlPath_No_Cs": 0, # [0|255] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# calculate checksum |
|
|
|
|
|
|
|
dat = packer.make_can_msg("LateralMotionControl2", CANBUS.main, values)[2] |
|
|
|
|
|
|
|
values["LatCtlPath_No_Cs"] = calculate_lat_ctl2_checksum(mode, counter, dat) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return packer.make_can_msg("LateralMotionControl2", CANBUS.main, values) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_acc_command(packer, long_active: bool, gas: float, accel: float, precharge_brake: bool, decel: bool): |
|
|
|
def create_acc_command(packer, long_active: bool, gas: float, accel: float, precharge_brake: bool, decel: bool): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Creates a CAN message for the Ford ACC Command. |
|
|
|
Creates a CAN message for the Ford ACC Command. |
|
|
|