mirror of https://github.com/commaai/panda.git
safety replay: support Toyota LTA angle control (#1693)
* safety replay: support toyota lta * one line
This commit is contained in:
parent
b496de2d08
commit
549fa32fc7
|
@ -7,12 +7,12 @@ def to_signed(d, bits):
|
|||
ret = d - (1 << bits)
|
||||
return ret
|
||||
|
||||
def is_steering_msg(mode, addr):
|
||||
def is_steering_msg(mode, param, addr):
|
||||
ret = False
|
||||
if mode in (Panda.SAFETY_HONDA_NIDEC, Panda.SAFETY_HONDA_BOSCH):
|
||||
ret = (addr == 0xE4) or (addr == 0x194) or (addr == 0x33D) or (addr == 0x33DA) or (addr == 0x33DB)
|
||||
elif mode == Panda.SAFETY_TOYOTA:
|
||||
ret = addr == 0x2E4
|
||||
ret = addr == (0x191 if param & Panda.FLAG_TOYOTA_LTA else 0x2E4)
|
||||
elif mode == Panda.SAFETY_GM:
|
||||
ret = addr == 384
|
||||
elif mode == Panda.SAFETY_HYUNDAI:
|
||||
|
@ -25,14 +25,18 @@ def is_steering_msg(mode, addr):
|
|||
ret = addr == 0x3d3
|
||||
return ret
|
||||
|
||||
def get_steer_value(mode, to_send):
|
||||
def get_steer_value(mode, param, to_send):
|
||||
torque, angle = 0, 0
|
||||
if mode in (Panda.SAFETY_HONDA_NIDEC, Panda.SAFETY_HONDA_BOSCH):
|
||||
torque = (to_send.data[0] << 8) | to_send.data[1]
|
||||
torque = to_signed(torque, 16)
|
||||
elif mode == Panda.SAFETY_TOYOTA:
|
||||
torque = (to_send.data[1] << 8) | (to_send.data[2])
|
||||
torque = to_signed(torque, 16)
|
||||
if param & Panda.FLAG_TOYOTA_LTA:
|
||||
angle = (to_send.data[1] << 8) | to_send.data[2]
|
||||
angle = to_signed(angle, 16)
|
||||
else:
|
||||
torque = (to_send.data[1] << 8) | (to_send.data[2])
|
||||
torque = to_signed(torque, 16)
|
||||
elif mode == Panda.SAFETY_GM:
|
||||
torque = ((to_send.data[0] & 0x7) << 8) | to_send.data[1]
|
||||
torque = to_signed(torque, 11)
|
||||
|
@ -50,9 +54,9 @@ def get_steer_value(mode, to_send):
|
|||
def package_can_msg(msg):
|
||||
return libpanda_py.make_CANPacket(msg.address, msg.src % 4, msg.dat)
|
||||
|
||||
def init_segment(safety, lr, mode):
|
||||
def init_segment(safety, lr, mode, param):
|
||||
sendcan = (msg for msg in lr if msg.which() == 'sendcan')
|
||||
steering_msgs = (can for msg in sendcan for can in msg.sendcan if is_steering_msg(mode, can.address))
|
||||
steering_msgs = (can for msg in sendcan for can in msg.sendcan if is_steering_msg(mode, param, can.address))
|
||||
|
||||
msg = next(steering_msgs, None)
|
||||
if msg is None:
|
||||
|
@ -60,7 +64,7 @@ def init_segment(safety, lr, mode):
|
|||
return
|
||||
|
||||
to_send = package_can_msg(msg)
|
||||
torque, angle = get_steer_value(mode, to_send)
|
||||
torque, angle = get_steer_value(mode, param, to_send)
|
||||
if torque != 0:
|
||||
safety.set_controls_allowed(1)
|
||||
safety.set_desired_torque_last(torque)
|
||||
|
|
|
@ -15,7 +15,7 @@ def replay_drive(lr, safety_mode, param, alternative_experience, segment=False):
|
|||
safety.set_alternative_experience(alternative_experience)
|
||||
|
||||
if segment:
|
||||
init_segment(safety, lr, safety_mode)
|
||||
init_segment(safety, lr, safety_mode, param)
|
||||
lr.reset()
|
||||
|
||||
rx_tot, rx_invalid, tx_tot, tx_blocked, tx_controls, tx_controls_blocked = 0, 0, 0, 0, 0, 0
|
||||
|
|
Loading…
Reference in New Issue