nopenpilot/selfdrive/car/toyota/toyotacan.py

106 lines
2.6 KiB
Python

def create_ipas_steer_command(packer, steer, enabled, apgs_enabled):
"""Creates a CAN message for the Toyota Steer Command."""
if steer < 0:
direction = 3
elif steer > 0:
direction = 1
else:
direction = 2
mode = 3 if enabled else 1
values = {
"STATE": mode,
"DIRECTION_CMD": direction,
"ANGLE": steer,
"SET_ME_X10": 0x10,
"SET_ME_X40": 0x40
}
if apgs_enabled:
return packer.make_can_msg("STEERING_IPAS", 0, values)
else:
return packer.make_can_msg("STEERING_IPAS_COMMA", 0, values)
def create_steer_command(packer, steer, steer_req, raw_cnt):
"""Creates a CAN message for the Toyota Steer Command."""
values = {
"STEER_REQUEST": steer_req,
"STEER_TORQUE_CMD": steer,
"COUNTER": raw_cnt,
"SET_ME_1": 1,
}
return packer.make_can_msg("STEERING_LKA", 0, values)
def create_lta_steer_command(packer, steer, steer_req, raw_cnt, angle):
"""Creates a CAN message for the Toyota LTA Steer Command."""
values = {
"COUNTER": raw_cnt,
"SETME_X3": 3,
"PERCENTAGE" : 100,
"SETME_X64": 0x64,
"ANGLE": angle,
"STEER_ANGLE_CMD": steer,
"STEER_REQUEST": steer_req,
"BIT": 0,
}
return packer.make_can_msg("STEERING_LTA", 0, values)
def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead):
# TODO: find the exact canceling bit that does not create a chime
values = {
"ACCEL_CMD": accel,
"SET_ME_X01": 1,
"DISTANCE": 0,
"MINI_CAR": lead,
"SET_ME_X3": 3,
"SET_ME_1": 1,
"RELEASE_STANDSTILL": not standstill_req,
"CANCEL_REQ": pcm_cancel,
}
return packer.make_can_msg("ACC_CONTROL", 0, values)
def create_acc_cancel_command(packer):
values = {
"GAS_RELEASED": 0,
"CRUISE_ACTIVE": 0,
"STANDSTILL_ON": 0,
"ACCEL_NET": 0,
"CRUISE_STATE": 0,
"CANCEL_REQ": 1,
}
return packer.make_can_msg("PCM_CRUISE", 0, values)
def create_fcw_command(packer, fcw):
values = {
"FCW": fcw,
"SET_ME_X20": 0x20,
"SET_ME_X10": 0x10,
"SET_ME_X80": 0x80,
}
return packer.make_can_msg("ACC_HUD", 0, values)
def create_ui_command(packer, steer, chime, left_line, right_line, left_lane_depart, right_lane_depart):
values = {
"RIGHT_LINE": 3 if right_lane_depart else 1 if right_line else 2,
"LEFT_LINE": 3 if left_lane_depart else 1 if left_line else 2,
"BARRIERS" : 3 if left_lane_depart or right_lane_depart else 0,
"SET_ME_X0C": 0x0c,
"SET_ME_X2C": 0x2c,
"SET_ME_X38": 0x38,
"SET_ME_X02": 0x02,
"SET_ME_X01": 1,
"SET_ME_X01_2": 1,
"REPEATED_BEEPS": 0,
"TWO_BEEPS": chime,
"LDA_ALERT": steer,
}
return packer.make_can_msg("LKAS_HUD", 0, values)