mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 08:03:40 +08:00
Add optional Enhanced BSM for TSS2 Prius
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import math
|
||||
import numpy as np
|
||||
from opendbc.car import ACCEL_MAX_TAKEOFF
|
||||
from opendbc.car.toyota import enhanced_bsm
|
||||
from opendbc.car import Bus, make_tester_present_msg, rate_limit, structs, ACCELERATION_DUE_TO_GRAVITY, DT_CTRL
|
||||
from opendbc.car.lateral import apply_meas_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance
|
||||
from opendbc.car.carlog import carlog
|
||||
@@ -117,6 +118,7 @@ class CarController(CarControllerBase):
|
||||
self.secoc_lta_message_counter = 0
|
||||
self.secoc_acc_message_counter = 0
|
||||
self.secoc_prev_reset_counter = 0
|
||||
self.bsm_poller = enhanced_bsm.BsmPoller() if enhanced_bsm.configured(CP) else None
|
||||
self.brake_hold_active = False
|
||||
self._brake_hold_counter = 0
|
||||
|
||||
@@ -529,6 +531,9 @@ class CarController(CarControllerBase):
|
||||
if self.frame % 20 == 0 and self.CP.flags & ToyotaFlags.DISABLE_RADAR.value:
|
||||
can_sends.append(make_tester_present_msg(0x750, 0, 0xF))
|
||||
|
||||
if self.bsm_poller is not None:
|
||||
can_sends.extend(self.bsm_poller.update(CS.out, self.frame, factory_bsm=CS.factory_bsm))
|
||||
|
||||
door_command = self.door_locks.update(CS.out)
|
||||
if door_command is not None:
|
||||
from opendbc.car import CanData
|
||||
|
||||
@@ -6,6 +6,7 @@ from opendbc.car.toyota import (
|
||||
stock_aol, prius_longitudinal, dsu_bypass, pedal_composite, pedal, legacy_sdsu, advert_filter, legacy_advert_filter, prius_sdsu, prius_advert_filter
|
||||
)
|
||||
from opendbc.car.toyota.lexus_is import LexusIsCANParser
|
||||
from opendbc.car.toyota import enhanced_bsm
|
||||
from opendbc.car import Bus, DT_CTRL, create_button_events, structs
|
||||
from opendbc.car.common.conversions import Conversions as CV
|
||||
from opendbc.car.common.filter_simple import FirstOrderFilter
|
||||
@@ -39,6 +40,7 @@ def has_optional_prius_gap_button(CP):
|
||||
class CarState(CarStateBase):
|
||||
def __init__(self, CP):
|
||||
super().__init__(CP)
|
||||
self.factory_bsm = False
|
||||
can_define = CANDefine(DBC[CP.carFingerprint][Bus.pt])
|
||||
original_prius = prius_sdsu.configured(CP) or prius_advert_filter.configured(CP)
|
||||
self.eps_torque_scale = ((CP.safetyConfigs[0].safetyParam & 0xFF) / 100. if prius_advert_filter.configured(CP) else
|
||||
@@ -229,9 +231,13 @@ class CarState(CarStateBase):
|
||||
ret.genericToggle = bool(cp.vl["LIGHT_STALK"]["AUTO_HIGH_BEAM"])
|
||||
ret.espDisabled = cp.vl["ESP_CONTROL"]["TC_DISABLED"] != 0
|
||||
|
||||
if self.CP.flags & ToyotaFlags.HAS_BSM:
|
||||
self.factory_bsm = isinstance(cp, enhanced_bsm.BsmCANParser) and cp.factory_bsm
|
||||
if self.CP.flags & ToyotaFlags.HAS_BSM or self.factory_bsm:
|
||||
ret.leftBlindspot = (cp.vl["BSM"]["L_ADJACENT"] == 1) or (cp.vl["BSM"]["L_APPROACHING"] == 1)
|
||||
ret.rightBlindspot = (cp.vl["BSM"]["R_ADJACENT"] == 1) or (cp.vl["BSM"]["R_APPROACHING"] == 1)
|
||||
elif isinstance(cp, enhanced_bsm.BsmCANParser) and ret.vEgo > 6.0:
|
||||
ret.leftBlindspot = cp.occupied(enhanced_bsm.SIDES[0])
|
||||
ret.rightBlindspot = cp.occupied(enhanced_bsm.SIDES[1])
|
||||
|
||||
if self.CP.carFingerprint != CAR.TOYOTA_PRIUS_V:
|
||||
self.lkas_hud = copy.copy(cp_cam.vl["LKAS_HUD"])
|
||||
@@ -404,6 +410,9 @@ class CarState(CarStateBase):
|
||||
LexusIsCANParser if CP.carFingerprint == CAR.LEXUS_IS else pedal.PedalCANParser if pedal.configured(CP) else
|
||||
advert_filter.AdvertFilterCANParser if CP.flags & ToyotaFlags.FILTER_BUTTONS or advert_filter.configured(CP) else
|
||||
Rav4hCANParser if rav4h_filter_configured(CP) else CANParser)
|
||||
if enhanced_bsm.configured(CP):
|
||||
pt_parser = enhanced_bsm.BsmCANParser
|
||||
pt_messages.append(("BSM", math.nan))
|
||||
return {
|
||||
Bus.pt: pt_parser(DBC[CP.carFingerprint][Bus.pt], pt_messages, 0, **({"stock_word": CP.safetyConfigs[0].safetyParam} if stock else
|
||||
{"alternate_main": alternate_sdsu_main} if legacy_advert else {})),
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
"""Toyota blind-spot diagnostic fallback, adapted from sunnypilot/opendbc #502.
|
||||
|
||||
Copyright (c) 2021-, sunnypilot, and a number of other contributors.
|
||||
Licensed under the MIT License. See the repository license for the terms.
|
||||
"""
|
||||
|
||||
from opendbc.can import CANParser
|
||||
from opendbc.car import CanData, structs
|
||||
from opendbc.car.toyota.values import CAR, ToyotaFlags
|
||||
from opendbc.safety import ALTERNATIVE_EXPERIENCE
|
||||
|
||||
|
||||
SIDES = (0x41, 0x42)
|
||||
REPLY_MAX_AGE_NS = 500_000_000
|
||||
|
||||
|
||||
def supported(cp):
|
||||
required = ToyotaFlags.TSS2 | ToyotaFlags.NO_DSU | ToyotaFlags.RAISED_ACCEL_LIMIT | ToyotaFlags.HYBRID
|
||||
allowed = required | ToyotaFlags.AUTO_BRAKE_HOLD
|
||||
return (cp.carFingerprint == CAR.TOYOTA_PRIUS_TSS2 and cp.brand == 'toyota' and
|
||||
cp.pcmCruise and cp.openpilotLongitudinalControl and not (cp.passive or cp.dashcamOnly or cp.notCar or cp.secOcRequired) and
|
||||
cp.steerControlType == structs.CarParams.SteerControlType.torque and cp.flags & required == required and
|
||||
not cp.flags & ~int(allowed) and len(cp.safetyConfigs) == 1 and
|
||||
cp.safetyConfigs[0].safetyModel == structs.CarParams.SafetyModel.toyota and cp.safetyConfigs[0].safetyParam == 73)
|
||||
|
||||
|
||||
def configured(cp):
|
||||
return supported(cp) and bool(cp.alternativeExperience & ALTERNATIVE_EXPERIENCE.TOYOTA_ENHANCED_BSM)
|
||||
|
||||
|
||||
def prepare(cp, requested):
|
||||
permission = ALTERNATIVE_EXPERIENCE.TOYOTA_ENHANCED_BSM
|
||||
cp.alternativeExperience &= ~permission
|
||||
if requested and supported(cp):
|
||||
cp.alternativeExperience |= permission
|
||||
|
||||
|
||||
class BsmCANParser(CANParser):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.blindspots = {}
|
||||
self.factory_bsm = False
|
||||
self.bsm_stamp = 0
|
||||
self.fresh_batch = False
|
||||
|
||||
def update(self, strings, sendcan=False):
|
||||
if strings and not isinstance(strings[0], list | tuple):
|
||||
strings = [strings]
|
||||
self.fresh_batch = False
|
||||
for timestamp, frames in strings:
|
||||
self.fresh_batch = True
|
||||
if timestamp < self.bsm_stamp:
|
||||
self.blindspots.clear()
|
||||
self.bsm_stamp = timestamp
|
||||
for address, data, bus in frames:
|
||||
if bus == self.bus and address == 0x3F6 and len(data) == 8:
|
||||
self.factory_bsm = True
|
||||
self.blindspots.clear()
|
||||
if (not self.factory_bsm and bus == self.bus and address == 0x758 and len(data) == 8 and
|
||||
data[0] in SIDES and data[1:4] == b'\x06\x61\x69'):
|
||||
self.blindspots[data[0]] = (timestamp, max(data[5:7]) > 35)
|
||||
return super().update(strings, sendcan)
|
||||
|
||||
def occupied(self, side):
|
||||
timestamp, present = self.blindspots.get(side, (0, False))
|
||||
return self.fresh_batch and present and 0 < timestamp <= self.bsm_stamp <= timestamp + REPLY_MAX_AGE_NS
|
||||
|
||||
|
||||
class BsmPoller:
|
||||
def __init__(self):
|
||||
self.active = False
|
||||
self.started = 0
|
||||
|
||||
def update(self, state, frame, *, factory_bsm=False):
|
||||
ready = (not factory_bsm and frame > 200 and state.canValid and not state.canTimeout and
|
||||
state.gearShifter in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.sport) and
|
||||
state.vEgo > (6.0 if self.active else 7.0))
|
||||
if ready != self.active:
|
||||
self.active = ready
|
||||
self.started = frame
|
||||
session = 0x60 if ready else 0x01
|
||||
return [CanData(0x750, bytes((side, 2, 0x10, session, 0, 0, 0, 0)), 0) for side in SIDES]
|
||||
# Retry twice if Panda had not yet admitted the initial session request.
|
||||
# Panda ignores the repeated entry command on a side with an open session.
|
||||
if ready and frame - self.started in (100, 200):
|
||||
return [CanData(0x750, bytes((side, 2, 0x10, 0x60, 0, 0, 0, 0)), 0) for side in SIDES]
|
||||
if ready and frame % 10 == 5:
|
||||
side = SIDES[(frame // 10) % 2]
|
||||
return [CanData(0x750, bytes((side, 2, 0x21, 0x69, 0, 0, 0, 0)), 0)]
|
||||
return []
|
||||
@@ -0,0 +1,143 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from opendbc.car import Bus, gen_empty_fingerprint, structs
|
||||
from opendbc.car.toyota import enhanced_bsm
|
||||
from opendbc.car.toyota.interface import CarInterface
|
||||
from opendbc.car.toyota.values import CAR, DBC
|
||||
from opendbc.safety import ALTERNATIVE_EXPERIENCE as AE
|
||||
from opendbc.can import CANPacker
|
||||
from opendbc.safety.tests.libsafety import libsafety_py
|
||||
|
||||
|
||||
def params(car=CAR.TOYOTA_PRIUS_TSS2, *, factory=False, requested=True):
|
||||
fingerprint = gen_empty_fingerprint()
|
||||
if factory:
|
||||
fingerprint[0][0x3F6] = 8
|
||||
fw = [structs.CarParams.CarFw(ecu=structs.CarParams.Ecu.hybrid)]
|
||||
cp = CarInterface.get_params(car, fingerprint, fw, False, False, False)
|
||||
enhanced_bsm.prepare(cp, requested)
|
||||
return cp
|
||||
|
||||
|
||||
@pytest.mark.parametrize('car,factory,requested,configured', (
|
||||
(CAR.TOYOTA_PRIUS_TSS2, False, True, True),
|
||||
(CAR.TOYOTA_PRIUS_TSS2, True, True, False),
|
||||
(CAR.TOYOTA_PRIUS_TSS2, False, False, False),
|
||||
(CAR.TOYOTA_COROLLA_TSS2, False, True, False),
|
||||
))
|
||||
def test_fallback_admission(car, factory, requested, configured):
|
||||
cp = params(car, factory=factory, requested=requested)
|
||||
ci = CarInterface(cp)
|
||||
assert isinstance(ci.can_parsers[Bus.pt], enhanced_bsm.BsmCANParser) == configured
|
||||
if factory:
|
||||
packer = CANPacker(DBC[car][Bus.pt])
|
||||
bsm = packer.make_can_msg('BSM', 0, {'L_APPROACHING': 1})
|
||||
ci.update([(990_000_000, [])]) # The factory parser registers BSM on first access.
|
||||
assert ci.update([(1_000_000_000, [bsm])]).leftBlindspot
|
||||
assert (ci.CC.bsm_poller is not None) == configured
|
||||
|
||||
|
||||
def test_fresh_bsm_replies_are_independent_and_use_recorded_idle_format():
|
||||
cp = params()
|
||||
parser = CarInterface(cp).can_parsers[Bus.pt]
|
||||
left = (0x758, bytes.fromhex('4106616900320089'), 0)
|
||||
right = (0x758, bytes.fromhex('4206616900000089'), 0)
|
||||
parser.update([(1_000_000_000, [left, right])])
|
||||
assert parser.occupied(0x41)
|
||||
assert not parser.occupied(0x42)
|
||||
parser.update([(1_300_000_000, [(0x758, bytes.fromhex('4206616900310089'), 0)])])
|
||||
parser.update([(1_500_000_001, [(*left[:2], 2), (*left[:2], 128), (0x758, b'\x41\x06\x50\x69\x00\x39\x39\x89', 0)])])
|
||||
assert not parser.occupied(0x41)
|
||||
assert parser.occupied(0x42)
|
||||
parser.update([(1_450_000_000, [])])
|
||||
assert not parser.occupied(0x42)
|
||||
|
||||
|
||||
def test_late_factory_broadcast_takes_priority():
|
||||
cp = params()
|
||||
ci = CarInterface(cp)
|
||||
packer = CANPacker(DBC[CAR.TOYOTA_PRIUS_TSS2][Bus.pt])
|
||||
factory = packer.make_can_msg('BSM', 0, {'L_APPROACHING': 1})
|
||||
right = (0x758, bytes.fromhex('4206616900390089'), 0)
|
||||
state = ci.update([(1_000_000_000, [factory, right])])
|
||||
assert state.leftBlindspot and not state.rightBlindspot
|
||||
assert ci.CS.factory_bsm
|
||||
|
||||
|
||||
def test_poll_cadence_and_cleanup():
|
||||
poller = enhanced_bsm.BsmPoller()
|
||||
cs = structs.CarState(vEgo=9, canValid=True, gearShifter=structs.CarState.GearShifter.drive)
|
||||
assert not poller.update(cs, 200)
|
||||
assert [m.dat[:4] for m in poller.update(cs, 201)] == [b'A\x02\x10\x60', b'B\x02\x10\x60']
|
||||
assert [m.dat[:4] for m in poller.update(cs, 205)] == [b'A\x02\x21\x69']
|
||||
assert [m.dat[:4] for m in poller.update(cs, 215)] == [b'B\x02\x21\x69']
|
||||
cs.canTimeout = True
|
||||
assert [m.dat[:4] for m in poller.update(cs, 216)] == [b'A\x02\x10\x01', b'B\x02\x10\x01']
|
||||
assert not poller.update(cs, 217)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('release', (False, True))
|
||||
def test_native_diagnostics_are_scoped_and_require_a_paced_moving_session(tmp_path, release):
|
||||
path = Path(libsafety_py._build_libsafety(release=release, output_dir=tmp_path))
|
||||
libsafety_py.load(path)
|
||||
safety = libsafety_py.libsafety
|
||||
packer = CANPacker('toyota_nodsu_pt_generated')
|
||||
|
||||
def rx(name, values):
|
||||
a, data, b = packer.make_can_msg(name, 0, values)
|
||||
assert safety.safety_rx_hook(libsafety_py.make_CANPacket(a, b, data))
|
||||
|
||||
def wheel(speed):
|
||||
rx('WHEEL_SPEEDS', {f'WHEEL_SPEED_{wheel}': speed * 3.6 for wheel in ('FL', 'FR', 'RL', 'RR')})
|
||||
|
||||
def start(word, permission, speed=8.):
|
||||
safety.init_tests()
|
||||
safety.set_alternative_experience(permission)
|
||||
assert safety.set_safety_hooks(2, word) == 0
|
||||
safety.set_timer(1_000_000)
|
||||
wheel(speed)
|
||||
rx('STEER_TORQUE_SENSOR', {})
|
||||
rx('BRAKE_MODULE', {})
|
||||
rx('PCM_CRUISE', {'GAS_RELEASED': True})
|
||||
|
||||
def tx(data, bus=0):
|
||||
return safety.safety_tx_hook(libsafety_py.make_CANPacket(0x750, bus, data))
|
||||
|
||||
enable = bytes.fromhex('4102106000000000')
|
||||
poll = bytes.fromhex('4102216900000000')
|
||||
end = bytes.fromhex('4102100100000000')
|
||||
radar = bytes.fromhex('0f023e0000000000')
|
||||
for word, feature in ((73, 0), (585, AE.TOYOTA_ENHANCED_BSM), (0x1049, AE.TOYOTA_ENHANCED_BSM)):
|
||||
start(word, feature)
|
||||
assert not tx(enable)
|
||||
assert not tx(poll)
|
||||
assert not tx(end)
|
||||
start(73, AE.TOYOTA_ENHANCED_BSM, 0.)
|
||||
assert not tx(enable)
|
||||
wheel(8.)
|
||||
assert not tx(poll)
|
||||
assert not tx(enable, 2)
|
||||
assert not tx(enable[:-1])
|
||||
assert not tx(enable[:-1] + b'\x01')
|
||||
assert tx(radar)
|
||||
assert tx(enable)
|
||||
assert not tx(enable)
|
||||
assert not tx(poll)
|
||||
safety.set_timer(1_040_000)
|
||||
assert tx(poll)
|
||||
assert not tx(poll)
|
||||
safety.set_timer(1_101_000)
|
||||
assert not tx(poll)
|
||||
wheel(0.)
|
||||
assert not tx(poll)
|
||||
assert tx(end)
|
||||
assert not tx(end)
|
||||
wheel(8.)
|
||||
assert tx(enable)
|
||||
rx('BSM', {})
|
||||
assert not tx(poll)
|
||||
assert tx(end)
|
||||
assert not tx(enable)
|
||||
assert not safety.get_controls_allowed()
|
||||
@@ -11,3 +11,4 @@ class ALTERNATIVE_EXPERIENCE:
|
||||
GM_REMAP_CANCEL_TO_DISTANCE = 64
|
||||
TOYOTA_AUTO_HOLD = 128
|
||||
TOYOTA_AEB_HOLD = 256
|
||||
TOYOTA_ENHANCED_BSM = 512
|
||||
|
||||
@@ -357,6 +357,7 @@ extern CurvatureSteeringState curvature_state;
|
||||
#define ALT_EXP_ALLOW_AEB 16
|
||||
#define ALT_EXP_TOYOTA_AUTO_HOLD 128
|
||||
#define ALT_EXP_TOYOTA_AEB_HOLD 256
|
||||
#define ALT_EXP_TOYOTA_ENHANCED_BSM 512
|
||||
|
||||
extern int alternative_experience;
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ static bool toyota_alt_brake = false;
|
||||
static bool toyota_stock_longitudinal = false;
|
||||
static bool toyota_lta = false;
|
||||
static bool toyota_radar_diagnostics_allowed = false;
|
||||
static bool toyota_enhanced_bsm = false;
|
||||
static bool toyota_factory_bsm_seen = false;
|
||||
static uint32_t toyota_bsm_tx_ts[2] = {0U};
|
||||
static bool toyota_bsm_session[2] = {false};
|
||||
static int toyota_dbc_eps_torque_factor = 100; // conversion factor for STEER_TORQUE_EPS in %: see dbc file
|
||||
|
||||
static bool toyota_hold_main_on = false;
|
||||
@@ -219,6 +223,9 @@ static void toyota_hold_observe(const CANPacket_t *msg) {
|
||||
}
|
||||
|
||||
static void toyota_optional_rx_hook(const CANPacket_t *msg) {
|
||||
if (toyota_enhanced_bsm && msg_matches(msg, 0x3F6U, 0U) && (GET_LEN(msg) == 8U)) {
|
||||
toyota_factory_bsm_seen = true;
|
||||
}
|
||||
// Only bus0 pedal RX belongs to the required catalog. A CRC-valid camera
|
||||
// copy must neither invalidate its parent nor refresh the primary lease.
|
||||
const bool camera_copy = toyota_pedal && msg_matches(msg, 0x201U, 2U) && (GET_LEN(msg) == 6U) &&
|
||||
@@ -605,6 +612,25 @@ static bool toyota_tx_hook(const CANPacket_t *msg) {
|
||||
!vehicle_moving && !gas_pressed && !safety_rx_checks_invalid && !relay_malfunction &&
|
||||
(safety_get_ts_elapsed(now, toyota_hold_speed_ts) <= 100000U) &&
|
||||
(safety_get_ts_elapsed(now, toyota_hold_gas_ts) <= 100000U);
|
||||
} else if (toyota_enhanced_bsm && ((msg->data[0] == 0x41U) || (msg->data[0] == 0x42U))) {
|
||||
const unsigned int side = msg->data[0] - 0x41U;
|
||||
const uint64_t request = payload & ~0xFFULL;
|
||||
const bool stop_polling = request == 0x0000000001100200ULL;
|
||||
const bool start = request == 0x0000000060100200ULL;
|
||||
const bool poll = request == 0x0000000069210200ULL;
|
||||
const uint32_t now = microsecond_timer_get();
|
||||
const bool wheel_speed_current = toyota_hold_speed_seen &&
|
||||
(safety_get_ts_elapsed(now, toyota_hold_speed_ts) <= 100000U);
|
||||
const bool ready = toyota_rx_ready(now) && wheel_speed_current && !safety_rx_checks_invalid && !relay_malfunction;
|
||||
const bool session = toyota_bsm_session[side];
|
||||
const bool paced = safety_get_ts_elapsed(now, toyota_bsm_tx_ts[side]) >= 40000U;
|
||||
const bool enable = start && !session && (vehicle_speed.values[0] > (7 * VEHICLE_SPEED_FACTOR));
|
||||
const bool poll_allowed = poll && session && paced && (vehicle_speed.values[0] > (6 * VEHICLE_SPEED_FACTOR));
|
||||
tx &= (stop_polling && session) || (!toyota_factory_bsm_seen && ready && (enable || poll_allowed));
|
||||
if (tx) {
|
||||
toyota_bsm_session[side] = !stop_polling;
|
||||
toyota_bsm_tx_ts[side] = now;
|
||||
}
|
||||
} else {
|
||||
// Preserve the original radar-only tester-present allowance and configuration scope.
|
||||
tx &= toyota_radar_diagnostics_allowed && (payload == 0x00000000003E020FULL);
|
||||
@@ -619,6 +645,12 @@ static bool toyota_tx_hook(const CANPacket_t *msg) {
|
||||
}
|
||||
|
||||
static safety_config toyota_init(uint16_t param) {
|
||||
toyota_factory_bsm_seen = false;
|
||||
toyota_enhanced_bsm = (param == 73U) && ((alternative_experience & ALT_EXP_TOYOTA_ENHANCED_BSM) != 0);
|
||||
for (unsigned int i = 0U; i < 2U; i++) {
|
||||
toyota_bsm_tx_ts[i] = 0U;
|
||||
toyota_bsm_session[i] = false;
|
||||
}
|
||||
const uint16_t parent_param = toyota_pedal_parent_param(param);
|
||||
toyota_factory_stock = toyota_factory_stock_param(parent_param);
|
||||
toyota_factory_eps5 = toyota_factory_stock && (parent_param != 0x6242U) && (parent_param != 0x6249U);
|
||||
|
||||
@@ -233,7 +233,8 @@ static void toyota_aol_observe(const CANPacket_t *msg) {
|
||||
}
|
||||
|
||||
static void toyota_aol_configure(uint16_t param) {
|
||||
const bool aol_requested = (alternative_experience == 32) || (alternative_experience == 160) || (alternative_experience == 288);
|
||||
const int aol_experience = (param == 73U && current_safety_param == 73U) ? (alternative_experience & ~ALT_EXP_TOYOTA_ENHANCED_BSM) : alternative_experience;
|
||||
const bool aol_requested = (aol_experience == 32) || (aol_experience == 160) || (aol_experience == 288);
|
||||
toyota_aol_reset();
|
||||
toyota_camera_2aa_ambiguous = false;
|
||||
toyota_prius_sdsu_ambiguous = false;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -24,6 +24,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"NostalgiaMode", {PERSISTENT, BOOL, "0"}},
|
||||
{"SNGHack", {PERSISTENT, BOOL, "0"}},
|
||||
{"ToyotaAutoHold", {PERSISTENT, BOOL, "0"}},
|
||||
{"ToyotaEnhancedBsm", {PERSISTENT, BOOL, "0"}},
|
||||
{"JeepBrakeHold", {PERSISTENT, BOOL, "0"}},
|
||||
{"ToyotaRadarMode", {PERSISTENT, INT, "0"}},
|
||||
{"RemoteStartBootsComma", {PERSISTENT, BOOL, "0"}},
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -164,7 +164,12 @@ def qualified(cp, *, marked_only=False):
|
||||
allowed_experience = (32 | hold_permission,) if hold else (32,)
|
||||
if not marked_only:
|
||||
allowed_experience += (0, hold_permission) if hold else (0,)
|
||||
if (cp.alternativeExperience not in allowed_experience or
|
||||
from opendbc.car.toyota import enhanced_bsm
|
||||
from opendbc.safety import ALTERNATIVE_EXPERIENCE
|
||||
experience = cp.alternativeExperience
|
||||
if enhanced_bsm.configured(cp):
|
||||
experience &= ~ALTERNATIVE_EXPERIENCE.TOYOTA_ENHANCED_BSM
|
||||
if (experience not in allowed_experience or
|
||||
hold and not toyota_auto_hold_supported(cp)):
|
||||
return False
|
||||
required_flags = ToyotaFlags.TSS2 | ToyotaFlags.NO_DSU | ToyotaFlags.RAISED_ACCEL_LIMIT
|
||||
|
||||
@@ -5,7 +5,7 @@ from openpilot.starpilot.vehicle_selection import read_selection
|
||||
|
||||
|
||||
STARTUP_KEYS = ('SubaruAvhStartup', 'SubaruStopStartOff', 'AlphaLongitudinalEnabled', 'IsReleaseBranch', 'OpenpilotEnabledToggle', 'SafeMode',
|
||||
'DisableOpenpilotLongitudinal', 'ToyotaAutoHold', 'JeepBrakeHold',
|
||||
'DisableOpenpilotLongitudinal', 'ToyotaAutoHold', 'ToyotaEnhancedBsm', 'JeepBrakeHold',
|
||||
'VoltSNG', 'GMAutoHold', 'VoltOnePedalMode', 'TurnAssist', 'LongPitch',
|
||||
'HondaBoschARadar', 'NAPPedalEnabled', 'NAPRadarEnabled', 'NAPRadarBehindNosecone')
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ BOOL_DEFAULTS = {
|
||||
"DriveModeProfiles": False, "DriveModeAcceleration": True, "DriveModeDeceleration": True,
|
||||
"SubaruAvhStartup": False,
|
||||
"SubaruStopStartOff": False,
|
||||
"ToyotaEnhancedBsm": False,
|
||||
"SubaruSNG": False,
|
||||
"SubaruRedneckCruise": False,
|
||||
"RedneckCruise": False,
|
||||
|
||||
@@ -459,6 +459,25 @@ class FeatureSettingsOwner:
|
||||
raw=b"1" if request.value == "On" else b"0", authorized=authorized,
|
||||
temp_prefix=".toyota-sng-").verified
|
||||
|
||||
def _enhanced_bsm_capability(self) -> tuple | None:
|
||||
from opendbc.car.toyota.enhanced_bsm import supported
|
||||
cp = self.vehicle_params()
|
||||
if cp is None or not supported(cp):
|
||||
return None
|
||||
return (str(cp.carFingerprint), str(cp.carVin), int(cp.flags), int(cp.safetyConfigs[0].safetyParam))
|
||||
|
||||
def _apply_enhanced_bsm(self, request: FeatureSettingsRequest) -> bool:
|
||||
if not request.confirmation or request.value not in ("Off", "On") or request.dependencies:
|
||||
return False
|
||||
|
||||
def authorized() -> bool:
|
||||
return (bool(request.vehicle_fingerprint) and self.vehicle_fingerprint() == request.vehicle_fingerprint and
|
||||
request.capability is not None and request.capability == self._enhanced_bsm_capability() and
|
||||
self.authority("vehicle") and self.authority("parked_preferences") and request.expected in (None, b"0", b"1"))
|
||||
|
||||
return commit_exact(self.params, key="ToyotaEnhancedBsm", max_bytes=8, raw=b"1" if request.value == "On" else b"0",
|
||||
expected=request.expected, authorized=authorized, temp_prefix=".toyota-bsm-").verified
|
||||
|
||||
def _auto_hold_capability(self) -> tuple | None:
|
||||
from opendbc.car.toyota.interface import toyota_auto_hold_supported
|
||||
cp = self.vehicle_params()
|
||||
@@ -894,7 +913,8 @@ class FeatureSettingsOwner:
|
||||
page=FeaturePage.DEVELOPER_LONGITUDINAL, available=True),
|
||||
FeatureRow("", "Wheel Controls", "Assign steering-wheel buttons and cruise behavior", page=FeaturePage.WHEEL, available=True)]
|
||||
if (self._long_pitch_capability() is not None or self._bolt_disable_capability() is not None or
|
||||
self._auto_hold_capability() is not None or self._toyota_sng_capability() is not None or self._jeep_hold_capability() is not None or
|
||||
self._auto_hold_capability() is not None or self._enhanced_bsm_capability() is not None or
|
||||
self._toyota_sng_capability() is not None or self._jeep_hold_capability() is not None or
|
||||
self._mqb_cluster_takeover_capability() is not None or self._pedal_setup_capability() is not None or
|
||||
self.subaru_smoothing.capability() is not None or
|
||||
self._subaru_avh_capability() is not None or self._subaru_startup_capability() is not None or self._subaru_sng_capability() is not None or
|
||||
@@ -934,6 +954,12 @@ class FeatureSettingsOwner:
|
||||
"Hold the brake for over one second at a complete stop with cruise main on and cruise disengaged. " +
|
||||
"Holds until you press the gas; normal cruise stop-and-go is unchanged. Applies after the next startup.")
|
||||
rows.extend([replace(row, available=row.available and self._readable("ToyotaAutoHold"), capability=capability)] if capability is not None else [])
|
||||
bsm_capability = self._enhanced_bsm_capability()
|
||||
if bsm_capability is not None:
|
||||
row = self._bool_row("ToyotaEnhancedBsm", "Enhanced Blind Spot Monitoring",
|
||||
configurable and parked and self.authority("vehicle") and self.authority("parked_preferences"),
|
||||
"Read compatible Prius blind-spot sensors while driving. Applies after the next startup.")
|
||||
rows.append(replace(row, available=row.available and self._readable("ToyotaEnhancedBsm"), capability=bsm_capability))
|
||||
sng_capability = self._toyota_sng_capability()
|
||||
if sng_capability is not None:
|
||||
row = self._bool_row("SNGHack", "Stop-and-Go Hack",
|
||||
@@ -1547,6 +1573,8 @@ class FeatureSettingsOwner:
|
||||
return self._apply_alpha_long(request)
|
||||
if key == "SNGHack":
|
||||
return self._apply_toyota_sng(request)
|
||||
if key == "ToyotaEnhancedBsm":
|
||||
return self._apply_enhanced_bsm(request)
|
||||
if key == "ToyotaAutoHold":
|
||||
return self._apply_auto_hold(request)
|
||||
if key == PLANNER_SELECTION_KEY:
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
from dataclasses import replace
|
||||
from types import SimpleNamespace
|
||||
|
||||
from opendbc.car import gen_empty_fingerprint, structs
|
||||
from opendbc.car.toyota.enhanced_bsm import configured
|
||||
from opendbc.car.toyota.interface import CarInterface
|
||||
from opendbc.car.toyota.values import CAR
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner
|
||||
from openpilot.starpilot.ui.feature_settings_state import FeaturePage, row_change
|
||||
from openpilot.starpilot.ui.vehicle_bool import VEHICLE_BOOL_KEYS, confirmation_question
|
||||
from openpilot.starpilot.vehicle_preferences import VehicleStartupPreferences
|
||||
|
||||
|
||||
def test_vehicle_setting_and_startup_permission(tmp_path):
|
||||
params = Params(str(tmp_path))
|
||||
fw = [structs.CarParams.CarFw(ecu=structs.CarParams.Ecu.hybrid)]
|
||||
current = SimpleNamespace(cp=CarInterface.get_params(CAR.TOYOTA_PRIUS_TSS2, gen_empty_fingerprint(), fw, False, False, False), parked=True)
|
||||
owner = FeatureSettingsOwner(params, lambda group: current.parked and group in ('vehicle', 'parked_preferences'),
|
||||
vehicle_fingerprint=lambda: current.cp.carFingerprint, vehicle_params=lambda: current.cp)
|
||||
|
||||
def rows():
|
||||
state = owner.snapshot(FeaturePage.VEHICLE, parked=current.parked, system_long=True, lateral_context=True, metric=False)
|
||||
return [row for row in state.rows if row.key == 'ToyotaEnhancedBsm']
|
||||
|
||||
assert not configured(VehicleStartupPreferences.read(params, enabled=True).prepare(current.cp))
|
||||
row, = rows()
|
||||
assert row.available and row.value == 'Off'
|
||||
request = row_change(row)
|
||||
assert request.key in VEHICLE_BOOL_KEYS and 'next startup' in confirmation_question(request)
|
||||
assert not owner.apply(request)
|
||||
request = replace(request, confirmation=True)
|
||||
current.parked = False
|
||||
assert not owner.apply(request)
|
||||
current.parked = True
|
||||
assert owner.apply(request)
|
||||
assert not owner.apply(request)
|
||||
prefs = VehicleStartupPreferences.read(params, enabled=True)
|
||||
cp = prefs.prepare(current.cp)
|
||||
assert configured(cp)
|
||||
cp.alternativeExperience = 0 # Card resets this before finalizing startup preferences.
|
||||
prefs.finalize(cp)
|
||||
assert configured(cp)
|
||||
|
||||
params.put_bool('SafeMode', True, block=True)
|
||||
VehicleStartupPreferences.read(params, enabled=True).finalize(cp)
|
||||
assert not configured(cp)
|
||||
fp = gen_empty_fingerprint()
|
||||
fp[0][0x3F6] = 8
|
||||
current.cp = CarInterface.get_params(CAR.TOYOTA_PRIUS_TSS2, fp, fw, False, False, False)
|
||||
assert not rows()
|
||||
assert not configured(prefs.prepare(current.cp))
|
||||
@@ -3,7 +3,7 @@
|
||||
from openpilot.starpilot.car.volkswagen.preferences import MUTE_CLUSTER_TAKEOVER
|
||||
|
||||
VEHICLE_BOOL_KEYS = frozenset((MUTE_CLUSTER_TAKEOVER, "AlphaLongitudinalEnabled", "SubaruAvhStartup", "SubaruStopStartOff", "SubaruSNG",
|
||||
"SubaruRedneckCruise", "RedneckCruise",
|
||||
"SubaruRedneckCruise", "RedneckCruise", "ToyotaEnhancedBsm",
|
||||
"GMPedalLongitudinal", "DisableOpenpilotLongitudinal", "LongPitch", "VoltSNG", "SNGHack", "GMAutoHold", "VoltOnePedalMode",
|
||||
"TeslaCoopSteering", "TeslaAOLDisengageOnBrake", "TeslaSpeedSync",
|
||||
"RemoteStartBootsComma", "HKGRemoteStartBootsComma", "IgnoreIgnitionLine", "TeslaWakeOnCAN"))
|
||||
@@ -38,6 +38,8 @@ def confirmation_question(request):
|
||||
return f"{verb} Redneck Cruise after the next startup? Factory cruise keeps control of the pedals."
|
||||
if request.key == "SubaruRedneckCruise":
|
||||
return f"{verb} software cruise after the next startup? Stock ACC keeps pedal control."
|
||||
if request.key == "ToyotaEnhancedBsm":
|
||||
return f"{verb} Enhanced Blind Spot Monitoring after the next startup?"
|
||||
if request.key == "SNGHack":
|
||||
return f"{verb} Toyota stop-and-go assistance after the next startup?"
|
||||
if request.key == "VoltSNG":
|
||||
|
||||
@@ -32,6 +32,7 @@ def toyota_disable_long_supported(cp) -> bool:
|
||||
class VehicleStartupPreferences:
|
||||
controller_selection: bytes | None = field(default=None, kw_only=True)
|
||||
toyota_auto_hold: bool = False
|
||||
toyota_enhanced_bsm: bool = field(default=False, kw_only=True)
|
||||
toyota_sng: bool = field(default=False, kw_only=True)
|
||||
jeep_brake_hold: bool = field(default=False, kw_only=True)
|
||||
turn_assist: bool = False
|
||||
@@ -141,6 +142,8 @@ class VehicleStartupPreferences:
|
||||
read_saved(params, "SubaruRedneckCruise", 8) == (b"1", True)),
|
||||
ford_bluepilot=tuple(ford_bluepilot(params, enabled=enabled).items()), tesla_aol=tesla_aol, tesla_screen=screen,
|
||||
tesla_screen_brake=screen_brake, tesla_cooperative=cooperative, tesla_speed_sync=speed_sync, toyota_auto_hold=toyota,
|
||||
toyota_enhanced_bsm=bool(enabled and readable and safe in (None, b"0") and
|
||||
read_saved(params, "ToyotaEnhancedBsm", 8) == (b"1", True)),
|
||||
toyota_sng=bool(enabled and readable and safe in (None, b"0") and
|
||||
read_saved(params, "SNGHack", 8) == (b"1", True)), jeep_brake_hold=jeep_hold,
|
||||
gm_longitudinal_tune=selected_tune(params, enabled=enabled),
|
||||
@@ -255,6 +258,8 @@ class VehicleStartupPreferences:
|
||||
apply_toyota_auto_hold(cp, self.toyota_auto_hold)
|
||||
from opendbc.car.toyota.ars510_preferences import configure_radar
|
||||
configure_radar(cp)
|
||||
from opendbc.car.toyota import enhanced_bsm
|
||||
enhanced_bsm.prepare(cp, self.toyota_enhanced_bsm)
|
||||
from opendbc.bluepilot_lateral.hosts.starpilot.safety_param import init_ford_safety_param_starpilot
|
||||
init_ford_safety_param_starpilot(cp, dict(self.ford_bluepilot))
|
||||
from openpilot.starpilot.lateral.controller_selection import prepare_controller
|
||||
@@ -305,6 +310,8 @@ class VehicleStartupPreferences:
|
||||
apply_toyota_auto_hold(cp, self.toyota_auto_hold and admitted)
|
||||
from opendbc.car.toyota.ars510_preferences import configure_radar
|
||||
configure_radar(cp)
|
||||
from opendbc.car.toyota import enhanced_bsm
|
||||
enhanced_bsm.prepare(cp, self.toyota_enhanced_bsm)
|
||||
|
||||
prepare_smoothing(cp, self.subaru_smoothing)
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
extern const uint8_t gitversion[29];
|
||||
const uint8_t gitversion[29] = "DEV-6edec473-Pf38f504f-DEBUG";
|
||||
const uint8_t gitversion[29] = "DEV-e12ea3c6-Pf38f504f-DEBUG";
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
DEV-6edec473-Pf38f504f-DEBUG
|
||||
DEV-e12ea3c6-Pf38f504f-DEBUG
|
||||
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "09b3db9e9bbaa0819271a21e76d2595c9dd243b567d14f0f44fa7a958186426f", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "66fba99ed63ea12ac61aa45bcb01fbf77c25de9f730cba2c45abfc03d30c029a", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user