Madlad stuff

This commit is contained in:
firestar5683
2026-06-27 13:51:16 -05:00
parent 562c5eb58d
commit b75b21681d
6 changed files with 70 additions and 17 deletions
+5 -7
View File
@@ -420,7 +420,7 @@ class CarController(CarControllerBase):
self.last_button_frame = 0
self.cancel_counter = 0
self.lka_steering_cmd_counter = 0
self.lka_steering_cmd_counter = -1
self.lka_icon_status_last = (False, False)
self.params = CarControllerParams(self.CP)
@@ -836,20 +836,17 @@ class CarController(CarControllerBase):
# - on startup, first few msgs are blocked
# - until we're in sync with camera so counters align when relay closes, preventing a fault.
# openpilot can subtly drift, so this is activated throughout a drive to stay synced
out_of_sync = self.lka_steering_cmd_counter % 4 != (CS.cam_lka_steering_cmd_counter + 1) % 4
next_lka_steering_cmd_counter = get_lka_steering_cmd_counter(self.lka_steering_cmd_counter, CS)
out_of_sync = next_lka_steering_cmd_counter % 4 != (CS.cam_lka_steering_cmd_counter + 1) % 4
if CS.loopback_lka_steering_cmd_ts_nanos == 0 or out_of_sync:
steer_step = self.params.STEER_STEP
self.lka_steering_cmd_counter += 1 if CS.loopback_lka_steering_cmd_updated else 0
self.lka_steering_cmd_counter = get_lka_steering_cmd_counter(self.lka_steering_cmd_counter, CS)
# Avoid GM EPS faults when transmitting messages too close together: skip this transmit if we
# received the ASCMLKASteeringCmd loopback confirmation too recently
last_lka_steer_msg_ms = (now_nanos - CS.loopback_lka_steering_cmd_ts_nanos) * 1e-6
if (self.frame - self.last_steer_frame) >= steer_step and last_lka_steer_msg_ms > MIN_STEER_MSG_INTERVAL_MS:
# Initialize ASCMLKASteeringCmd counter using the camera until we get a msg on the bus
if CS.loopback_lka_steering_cmd_ts_nanos == 0:
self.lka_steering_cmd_counter = CS.pt_lka_steering_cmd_counter + 1
if CC.latActive:
new_torque = int(round(actuators.torque * self.params.STEER_MAX))
apply_torque = apply_driver_steer_torque_limits(new_torque, self.apply_torque_last, CS.out.steeringTorque, self.params)
@@ -864,6 +861,7 @@ class CarController(CarControllerBase):
self.apply_torque_last = apply_torque
idx = self.lka_steering_cmd_counter % 4
can_sends.append(gmcan.create_steering_control(self.packer_pt, CanBus.POWERTRAIN, apply_torque, idx, CC.latActive))
self.lka_steering_cmd_counter = (idx + 1) % 4
if should_spoof_ecm_cruise_status(self.CP) and self.frame % 4 == 0:
can_sends.append(gmcan.create_ecm_cruise_control_command(
+11
View File
@@ -680,6 +680,17 @@ class CarInterface(CarInterfaceBase):
# Reuse the no-camera safety bit as an ASCM Volt selector for the alternate EBCM brake path.
ret.safetyConfigs[0].safetyParam |= GMSafetyFlags.FLAG_GM_NO_CAMERA.value
volt_ascm_sascm_stock_acc = (
candidate == CAR.CHEVROLET_VOLT_ASCM and
has_sascm and
not alpha_long and
ret.pcmCruise and
not ret.openpilotLongitudinalControl and
not ret.enableGasInterceptorDEPRECATED
)
if volt_ascm_sascm_stock_acc:
ret.safetyConfigs[0].safetyParam |= GMSafetyFlags.FLAG_GM_VOLT_ASCM_STOCK_ACC.value
try:
remote_start_boots_comma = params.get_bool("RemoteStartBootsComma")
except UnknownKeyName:
@@ -138,6 +138,28 @@ class TestGMInterface:
assert not car_params.startingState
assert car_params.startAccel == pytest.approx(0.0)
def test_volt_ascm_sascm_stock_long_sets_marker_only_with_alpha_long_off(self):
CarInterface = interfaces[CAR.CHEVROLET_VOLT_ASCM]
fingerprint = _empty_fingerprint()
fingerprint[0][0x2FF] = 8 # SASCM detected
stock_params = CarInterface.get_params(CAR.CHEVROLET_VOLT_ASCM, fingerprint, [], alpha_long=False,
is_release=False, docs=False, starpilot_toggles=_test_starpilot_toggles())
alpha_params = CarInterface.get_params(CAR.CHEVROLET_VOLT_ASCM, fingerprint, [], alpha_long=True,
is_release=False, docs=False, starpilot_toggles=_test_starpilot_toggles())
assert not stock_params.openpilotLongitudinalControl
assert stock_params.safetyConfigs[0].safetyParam & GMSafetyFlags.FLAG_GM_VOLT_ASCM_STOCK_ACC.value
assert alpha_params.openpilotLongitudinalControl
assert not alpha_params.safetyConfigs[0].safetyParam & GMSafetyFlags.FLAG_GM_VOLT_ASCM_STOCK_ACC.value
def test_volt_ascm_stock_long_marker_requires_sascm(self):
CarInterface = interfaces[CAR.CHEVROLET_VOLT_ASCM]
car_params = CarInterface.get_params(CAR.CHEVROLET_VOLT_ASCM, _empty_fingerprint(), [], alpha_long=False,
is_release=False, docs=False, starpilot_toggles=_test_starpilot_toggles())
assert not car_params.safetyConfigs[0].safetyParam & GMSafetyFlags.FLAG_GM_VOLT_ASCM_STOCK_ACC.value
def test_volt_cc_sparse_fingerprint_without_camera_sets_no_camera(self):
CarInterface = interfaces[CAR.CHEVROLET_VOLT_CC]
fingerprint = {
+3
View File
@@ -172,6 +172,9 @@ class GMSafetyFlags(IntFlag):
HW_SDGM = 1024
FLAG_GM_BOLT_2017 = 2048
FLAG_GM_BOLT_2022_PEDAL = 4096
# Context-specific alias for Volt ASCM + SASCM stock ACC. The Bolt pedal
# meaning remains active only on pedal/no-ACC paths in panda safety.
FLAG_GM_VOLT_ASCM_STOCK_ACC = 4096
FLAG_GM_REMOTE_START_BOOTS_COMMA = 8192
FLAG_GM_PANDA_3D1_SCHED = 16384
FLAG_GM_PANDA_PADDLE_SCHED = 32768
+15 -10
View File
@@ -62,6 +62,7 @@ static bool gm_bolt_2022_pedal = false;
static bool gm_alt_brake = false;
static bool gm_volt_auto_hold = false;
static bool gm_volt_one_pedal = false;
static bool gm_volt_ascm_stock_acc = false;
static bool gm_cc_long = false;
static bool gm_has_acc = true;
@@ -519,7 +520,7 @@ static bool gm_fwd_hook(int bus_num, int addr) {
bool is_acc_actuation_msg = (addr == 0x315U) || (addr == 0x2CBU);
block_msg = is_lkas_msg;
if (gm_cam_long || gm_pedal_long) {
if (gm_cam_long || gm_pedal_long || gm_volt_ascm_stock_acc) {
block_msg |= is_acc_status_msg;
}
if (gm_cam_long) {
@@ -706,16 +707,8 @@ static safety_config gm_init(uint16_t param) {
enable_gas_interceptor = GET_FLAG(param, GM_PARAM_PEDAL_INTERCEPTOR);
gm_force_ascm = GET_FLAG(param, GM_PARAM_HW_ASCM_LONG);
gm_force_brake_c9 = GET_FLAG(param, GM_PARAM_FORCE_BRAKE_C9);
gm_bolt_2022_pedal = GET_FLAG(param, GM_PARAM_BOLT_2022_PEDAL);
const bool gm_bolt_2022_pedal_param = GET_FLAG(param, GM_PARAM_BOLT_2022_PEDAL);
gm_remote_start_boots_comma = GET_FLAG(param, GM_PARAM_REMOTE_START_BOOTS_COMMA);
gm_panda_3d1_sched = GET_FLAG(param, GM_PARAM_PANDA_3D1_SCHED) && gm_pedal_long && !gm_has_acc && !gm_bolt_2022_pedal;
gm_panda_paddle_sched = GET_FLAG(param, GM_PARAM_PANDA_PADDLE_SCHED) && gm_pedal_long && enable_gas_interceptor;
// Reuse the paddle-scheduler bit as a stock-Volt auto-hold marker on non-pedal ACC paths.
gm_volt_auto_hold = GET_FLAG(param, GM_PARAM_PANDA_PADDLE_SCHED) && !gm_pedal_long && !gm_cc_long && gm_has_acc;
// Reuse the 3D1 scheduler bit as a stock-Volt one-pedal marker on non-pedal
// ACC paths. The actual 3D1 scheduler still requires pedal-long and no-ACC,
// so this stays isolated from the Bolt pedal path.
gm_volt_one_pedal = GET_FLAG(param, GM_PARAM_PANDA_3D1_SCHED) && !gm_pedal_long && !gm_cc_long && gm_has_acc;
gm_alt_brake = GET_FLAG(param, GM_PARAM_NO_CAMERA) && (gm_hw == GM_ASCM) && !gm_sdgm && !gm_ascm_int;
gm_3d1_spoof_valid = false;
@@ -746,6 +739,18 @@ static safety_config gm_init(uint16_t param) {
gm_cam_long = GET_FLAG(param, GM_PARAM_HW_CAM_LONG) && !gm_cc_long;
gm_pcm_cruise = (gm_hw == GM_CAM || gm_sdgm) && !gm_cam_long && !gm_force_ascm && !gm_pedal_long;
const bool gm_ascm_int_stock_cam = gm_ascm_int && (gm_hw == GM_CAM) && gm_pcm_cruise && !gm_cam_long && !gm_pedal_long && !gm_cc_long;
// On the stock-ASCM_INT camera path, reuse the Bolt pedal bit as a Volt
// ASCM + SASCM stock-ACC marker and strip its pedal-long meaning.
gm_volt_ascm_stock_acc = gm_ascm_int_stock_cam && gm_bolt_2022_pedal_param;
gm_bolt_2022_pedal = gm_bolt_2022_pedal_param && !gm_volt_ascm_stock_acc;
gm_panda_3d1_sched = GET_FLAG(param, GM_PARAM_PANDA_3D1_SCHED) && gm_pedal_long && !gm_has_acc && !gm_bolt_2022_pedal;
gm_panda_paddle_sched = GET_FLAG(param, GM_PARAM_PANDA_PADDLE_SCHED) && gm_pedal_long && enable_gas_interceptor;
// Reuse the paddle-scheduler bit as a stock-Volt auto-hold marker on non-pedal ACC paths.
gm_volt_auto_hold = GET_FLAG(param, GM_PARAM_PANDA_PADDLE_SCHED) && !gm_pedal_long && !gm_cc_long && gm_has_acc;
// Reuse the 3D1 scheduler bit as a stock-Volt one-pedal marker on non-pedal
// ACC paths. The actual 3D1 scheduler still requires pedal-long and no-ACC,
// so this stays isolated from the Bolt pedal path.
gm_volt_one_pedal = GET_FLAG(param, GM_PARAM_PANDA_3D1_SCHED) && !gm_pedal_long && !gm_cc_long && gm_has_acc;
const bool gm_ascm_int_no_accel_pos = gm_ascm_int && (gm_hw == GM_CAM) && gm_force_brake_c9;
// FLAG_GM_BOLT_2022_PEDAL is shared with Malibu Hybrid pedal-long. Requiring
// the paddle scheduler bit narrows this whitelist to the Gen2 Bolt pedal-long
@@ -297,6 +297,20 @@ def test_gm_ascm_int_stock_cam_f1_rx_pinning():
assert not safety.safety_config_valid()
def test_gm_volt_ascm_stock_acc_marker_blocks_camera_acc_status_forwarding():
safety = libsafety_py.libsafety
stock_ascm_int = GMSafetyFlags.HW_CAM | GMSafetyFlags.HW_ASCM_INT
marked_volt_ascm = stock_ascm_int | GMSafetyFlags.FLAG_GM_VOLT_ASCM_STOCK_ACC
safety.set_safety_hooks(CarParams.SafetyModel.gm, stock_ascm_int)
safety.init_tests()
assert safety.safety_fwd_hook(2, 0x370) == 0
safety.set_safety_hooks(CarParams.SafetyModel.gm, marked_volt_ascm)
safety.init_tests()
assert safety.safety_fwd_hook(2, 0x370) == -1
def test_gm_ascm_int_long_no_accel_pos_uses_stock_cam_rx_checks():
safety = libsafety_py.libsafety
safety.set_safety_hooks(CarParams.SafetyModel.gm, GMSafetyFlags.HW_CAM | GMSafetyFlags.HW_CAM_LONG |