diff --git a/opendbc_repo/opendbc/car/__init__.py b/opendbc_repo/opendbc/car/__init__.py index 65a9044ebd..edddab28a2 100644 --- a/opendbc_repo/opendbc/car/__init__.py +++ b/opendbc_repo/opendbc/car/__init__.py @@ -8,6 +8,8 @@ from opendbc.car import structs, uds from opendbc.car.can_definitions import CanData from opendbc.car.docs_definitions import CarDocs, ExtraCarDocs +ACCEL_MAX_TAKEOFF = 3.5 + DT_CTRL = 0.01 # car state and control loop timestep (s) # kg of standard extra cargo to count for drive, gas, etc... diff --git a/opendbc_repo/opendbc/car/ford/carcontroller.py b/opendbc_repo/opendbc/car/ford/carcontroller.py index e7792e0676..13890bc30b 100644 --- a/opendbc_repo/opendbc/car/ford/carcontroller.py +++ b/opendbc_repo/opendbc/car/ford/carcontroller.py @@ -1,5 +1,6 @@ import math import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.can import CANPacker from opendbc.bluepilot_lateral.hosts.starpilot.lateral import BluePilotLateral, FrameInputs # BluePilot from opendbc.car import ACCELERATION_DUE_TO_GRAVITY, Bus, DT_CTRL, apply_hysteresis, structs @@ -210,8 +211,8 @@ class CarController(CarControllerBase): fcw=fcw_alert or CS.out.stockFcw or CS.out.stockAeb, ) - accel = float(np.clip(accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)) - gas = float(np.clip(gas, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)) + accel = float(np.clip(accel, CarControllerParams.ACCEL_MIN, ACCEL_MAX_TAKEOFF)) + gas = float(np.clip(gas, CarControllerParams.ACCEL_MIN, ACCEL_MAX_TAKEOFF)) # Both gas and accel are in m/s^2, accel is used solely for braking if not CC.longActive or gas < CarControllerParams.MIN_GAS: diff --git a/opendbc_repo/opendbc/car/ford/interface.py b/opendbc_repo/opendbc/car/ford/interface.py index 8256af5bdb..05ade4e48b 100644 --- a/opendbc_repo/opendbc/car/ford/interface.py +++ b/opendbc_repo/opendbc/car/ford/interface.py @@ -1,3 +1,4 @@ +from opendbc.car import ACCEL_MAX_TAKEOFF import numpy as np from opendbc.car import Bus, get_safety_config, structs from opendbc.car.carlog import carlog @@ -20,10 +21,10 @@ class CarInterface(CarInterfaceBase): DRIVABLE_GEARS = (structs.CarState.GearShifter.low, structs.CarState.GearShifter.manumatic) @staticmethod - def get_pid_accel_limits(CP, current_speed, cruise_speed): + def get_pid_accel_limits(CP, current_speed, cruise_speed, *, faster_takeoffs=False): # PCM doesn't allow acceleration near cruise_speed, # so limit limits of pid to prevent windup - ACCEL_MAX_VALS = [CarControllerParams.ACCEL_MAX, 0.2] + ACCEL_MAX_VALS = [ACCEL_MAX_TAKEOFF if faster_takeoffs else CarControllerParams.ACCEL_MAX, 0.2] ACCEL_MAX_BP = [cruise_speed - 2., cruise_speed - .4] return CarControllerParams.ACCEL_MIN, np.interp(current_speed, ACCEL_MAX_BP, ACCEL_MAX_VALS) diff --git a/opendbc_repo/opendbc/car/gm/interface.py b/opendbc_repo/opendbc/car/gm/interface.py index a2e168c667..097e0dc4f7 100644 --- a/opendbc_repo/opendbc/car/gm/interface.py +++ b/opendbc_repo/opendbc/car/gm/interface.py @@ -1,3 +1,4 @@ +from opendbc.car import ACCEL_MAX_TAKEOFF #!/usr/bin/env python3 from math import fabs, exp import numpy as np @@ -135,7 +136,10 @@ class CarInterface(CarInterfaceBase): return ret @staticmethod - def get_pid_accel_limits(CP, current_speed, cruise_speed): + def get_pid_accel_limits(CP, current_speed, cruise_speed, *, faster_takeoffs=False): + if faster_takeoffs: + lower, _ = CarInterface.get_pid_accel_limits(CP, current_speed, cruise_speed) + return lower, ACCEL_MAX_TAKEOFF if is_volt_sdgm_accepted_envelope(CP): return CarControllerParams.ACCEL_MIN, volt_sdgm_accepted_accel_max(CP, current_speed) profile = camera_acc_pedal_profile(CP) diff --git a/opendbc_repo/opendbc/car/honda/bosch_longitudinal.py b/opendbc_repo/opendbc/car/honda/bosch_longitudinal.py index 12e30e53ed..0e6c17fd16 100644 --- a/opendbc_repo/opendbc/car/honda/bosch_longitudinal.py +++ b/opendbc_repo/opendbc/car/honda/bosch_longitudinal.py @@ -1,6 +1,7 @@ import math import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.car import ACCELERATION_DUE_TO_GRAVITY, structs from opendbc.car.honda.values import CAR, HondaFlags @@ -88,7 +89,7 @@ class BoschLongitudinal: hill_brake = math.sin(self.pitch) * ACCELERATION_DUE_TO_GRAVITY wind_brake_mps2 = get_honda_bosch_wind_brake_mps2(CS.out.vEgo) min_gas = self.params.BOSCH_GAS_LOOKUP_BP[0] - self.accel = float(np.clip(accel, self.params.BOSCH_ACCEL_MIN, self.params.BOSCH_ACCEL_MAX)) + self.accel = float(np.clip(accel, self.params.BOSCH_ACCEL_MIN, ACCEL_MAX_TAKEOFF)) gas_pedal_force = self.accel + hill_brake if self.CP.carFingerprint not in HONDA_BOSCH_RADARLESS: gas_pedal_force += wind_brake_mps2 * self.bosch_wind_factor @@ -114,7 +115,7 @@ class BoschLongitudinal: self.bosch_wind_factor = max(self.bosch_wind_factor, self.bosch_wind_factor_before_brake) else: self.bosch_wind_factor_before_brake = self.bosch_wind_factor - if gas_pedal_force >= self.params.BOSCH_ACCEL_MAX: + if gas_pedal_force >= ACCEL_MAX_TAKEOFF: self.bosch_gas_factor = min(self.bosch_gas_factor, self.bosch_gas_factor_before_gasmax) self.bosch_wind_factor = min(self.bosch_wind_factor, self.bosch_wind_factor_before_gasmax) else: diff --git a/opendbc_repo/opendbc/car/honda/carcontroller.py b/opendbc_repo/opendbc/car/honda/carcontroller.py index 3c8b33d147..3dd58b86c3 100644 --- a/opendbc_repo/opendbc/car/honda/carcontroller.py +++ b/opendbc_repo/opendbc/car/honda/carcontroller.py @@ -1,4 +1,5 @@ import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.can import CANPacker from opendbc.car import Bus, DT_CTRL, rate_limit, make_tester_present_msg, structs @@ -227,7 +228,7 @@ class CarController(CarControllerBase): if self.bosch_longitudinal is not None: self.accel, self.gas, gas_force, braking = self.bosch_longitudinal.update(CC, CS, accel) else: - self.accel = float(np.clip(accel, self.params.BOSCH_ACCEL_MIN, self.params.BOSCH_ACCEL_MAX)) + self.accel = float(np.clip(accel, self.params.BOSCH_ACCEL_MIN, ACCEL_MAX_TAKEOFF)) self.gas = float(np.interp(accel, self.params.BOSCH_GAS_LOOKUP_BP, self.params.BOSCH_GAS_LOOKUP_V)) stopping = actuators.longControlState == LongCtrlState.stopping diff --git a/opendbc_repo/opendbc/car/honda/interface.py b/opendbc_repo/opendbc/car/honda/interface.py index 3485e57563..8dfe645638 100755 --- a/opendbc_repo/opendbc/car/honda/interface.py +++ b/opendbc_repo/opendbc/car/honda/interface.py @@ -1,3 +1,4 @@ +from opendbc.car import ACCEL_MAX_TAKEOFF #!/usr/bin/env python3 from opendbc.car.pedal import supported_pedal_detected import numpy as np @@ -24,15 +25,15 @@ class CarInterface(CarInterfaceBase): DRIVABLE_GEARS = (structs.CarState.GearShifter.sport,) @staticmethod - def get_pid_accel_limits(CP, current_speed, cruise_speed): + def get_pid_accel_limits(CP, current_speed, cruise_speed, *, faster_takeoffs=False): if CP.flags & HondaFlags.BOSCH: - return CarControllerParams.BOSCH_ACCEL_MIN, CarControllerParams.BOSCH_ACCEL_MAX + return CarControllerParams.BOSCH_ACCEL_MIN, ACCEL_MAX_TAKEOFF if faster_takeoffs else CarControllerParams.BOSCH_ACCEL_MAX elif CP.flags & HondaFlags.GAS_INTERCEPTOR: - return CarControllerParams.NIDEC_ACCEL_MIN, CarControllerParams.NIDEC_ACCEL_MAX + return CarControllerParams.NIDEC_ACCEL_MIN, ACCEL_MAX_TAKEOFF if faster_takeoffs else CarControllerParams.NIDEC_ACCEL_MAX else: # NIDECs don't allow acceleration near cruise_speed, # so limit limits of pid to prevent windup - ACCEL_MAX_VALS = [CarControllerParams.NIDEC_ACCEL_MAX, 0.2] + ACCEL_MAX_VALS = [ACCEL_MAX_TAKEOFF if faster_takeoffs else CarControllerParams.NIDEC_ACCEL_MAX, 0.2] ACCEL_MAX_BP = [cruise_speed - 2., cruise_speed - .2] return CarControllerParams.NIDEC_ACCEL_MIN, np.interp(current_speed, ACCEL_MAX_BP, ACCEL_MAX_VALS) diff --git a/opendbc_repo/opendbc/car/hyundai/carcontroller.py b/opendbc_repo/opendbc/car/hyundai/carcontroller.py index 3b17a6829c..48c0089dd2 100644 --- a/opendbc_repo/opendbc/car/hyundai/carcontroller.py +++ b/opendbc_repo/opendbc/car/hyundai/carcontroller.py @@ -16,6 +16,7 @@ from opendbc.car.hyundai.pe_long_aol import qualified as pe_long_aol_qualified from opendbc.car.common.filter_simple import FirstOrderFilter from opendbc.car.lateral import get_max_angle_vm, get_max_angle_delta_vm import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.can import CANPacker from opendbc.car import Bus, DT_CTRL, make_tester_present_msg, rate_limit, structs from opendbc.car.lateral import apply_driver_steer_torque_limits, apply_steer_angle_limits_vm, common_fault_avoidance @@ -229,7 +230,7 @@ class CarController(CarControllerBase): lead_data = self.g90_lead_state.update(self.g90_lead_inputs.update(), hud_control.leadVisible) # accel + longitudinal - accel = float(np.clip(actuators.accel, self.params.ACCEL_MIN, self.params.ACCEL_MAX)) + accel = float(np.clip(actuators.accel, self.params.ACCEL_MIN, ACCEL_MAX_TAKEOFF)) stopping = actuators.longControlState == LongCtrlState.stopping if self.pe_longitudinal is not None: request = self.pe_longitudinal.update(self.frame, active=CC.enabled and CC.longActive, @@ -656,7 +657,7 @@ class CarController(CarControllerBase): lead = (self.ev9_lead_inputs.update(CS.ev9_camera_lead, hud_control.leadVisible, now_nanos) if self.ev9_lead_inputs is not None else ABSENT) lead_visible, lead_distance, lead_rel_speed = lead.visible, lead.distance, lead.relative_speed - accel = float(np.clip(accel, -3.5, 2.0 if pe_long else 2.2)) + accel = float(np.clip(accel, -3.5, ACCEL_MAX_TAKEOFF)) can_sends.append(long_sender.create_ccnc_acc_control( self.packer, self.CAN, CC.enabled, accel, ccnc_longitudinal.stop.stop_request, ccnc_longitudinal.stop.cruise_standstill, CC.cruiseControl.override, set_speed_in_units, diff --git a/opendbc_repo/opendbc/car/hyundai/interface.py b/opendbc_repo/opendbc/car/hyundai/interface.py index 946da4ba64..89be14d539 100644 --- a/opendbc_repo/opendbc/car/hyundai/interface.py +++ b/opendbc_repo/opendbc/car/hyundai/interface.py @@ -1,3 +1,4 @@ +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.car.hyundai.ioniq5pe_long_profile import required as pe_long_required, candidate as pe_long_candidate from opendbc.car.pedal import supported_pedal_detected from opendbc.car.hyundai.classic_scc_aol import CLASSIC_SCC_IDS @@ -112,13 +113,13 @@ class CarInterface(CarInterfaceBase): DRIVABLE_GEARS = (structs.CarState.GearShifter.sport, structs.CarState.GearShifter.manumatic) @staticmethod - def get_pid_accel_limits(CP, current_speed, cruise_speed): + def get_pid_accel_limits(CP, current_speed, cruise_speed, *, faster_takeoffs=False): from opendbc.car.hyundai.ev9_longitudinal import qualified as ev9_long_qualified if ev9_long_qualified(CP): - return -3.5, 2.2 + return -3.5, ACCEL_MAX_TAKEOFF if faster_takeoffs else 2.2 if is_blended_alpha(CP): return -3.5, 3.5 - return CarInterfaceBase.get_pid_accel_limits(CP, current_speed, cruise_speed) + return CarInterfaceBase.get_pid_accel_limits(CP, current_speed, cruise_speed, faster_takeoffs=faster_takeoffs) @staticmethod def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, alpha_long, is_release, docs) -> structs.CarParams: diff --git a/opendbc_repo/opendbc/car/interfaces.py b/opendbc_repo/opendbc/car/interfaces.py index 22f900a4bc..33b33a0ec1 100644 --- a/opendbc_repo/opendbc/car/interfaces.py +++ b/opendbc_repo/opendbc/car/interfaces.py @@ -9,7 +9,7 @@ from collections.abc import Callable from functools import cache from opendbc.car import DT_CTRL, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, STD_CARGO_KG -from opendbc.car import structs +from opendbc.car import structs, ACCEL_MAX_TAKEOFF from opendbc.car.can_definitions import CanData, CanRecvCallable, CanSendCallable from opendbc.car.common.basedir import BASEDIR from opendbc.car.common.conversions import Conversions as CV @@ -117,8 +117,8 @@ class CarInterfaceBase(ABC): return self.CC.update(c, self.CS, now_nanos) @staticmethod - def get_pid_accel_limits(CP, current_speed, cruise_speed): - return ACCEL_MIN, ACCEL_MAX + def get_pid_accel_limits(CP, current_speed, cruise_speed, *, faster_takeoffs=False): + return ACCEL_MIN, ACCEL_MAX_TAKEOFF if faster_takeoffs else ACCEL_MAX @classmethod def get_non_essential_params(cls, candidate: str) -> structs.CarParams: diff --git a/opendbc_repo/opendbc/car/rivian/carcontroller.py b/opendbc_repo/opendbc/car/rivian/carcontroller.py index 04eaa54c86..dc8cdbb873 100644 --- a/opendbc_repo/opendbc/car/rivian/carcontroller.py +++ b/opendbc_repo/opendbc/car/rivian/carcontroller.py @@ -1,4 +1,5 @@ import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.can import CANPacker from opendbc.car import Bus, structs from opendbc.car.lateral import apply_driver_steer_torque_limits @@ -57,10 +58,10 @@ class CarController(CarControllerBase): if self.CP.openpilotLongitudinalControl: if self.base_gen1: long_active = CC.enabled and CC.longActive and CS.out.gearShifter == structs.CarState.GearShifter.drive - accel = float(np.clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)) if long_active and not CS.out.gasPressed else 0.0 + accel = float(np.clip(actuators.accel, CarControllerParams.ACCEL_MIN, ACCEL_MAX_TAKEOFF)) if long_active and not CS.out.gasPressed else 0.0 else: long_active = CC.enabled - accel = float(np.clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)) + accel = float(np.clip(actuators.accel, CarControllerParams.ACCEL_MIN, ACCEL_MAX_TAKEOFF)) can_sends.append(create_longitudinal(self.packer, self.frame, accel, long_active)) else: interface_status = None diff --git a/opendbc_repo/opendbc/car/tesla/carcontroller.py b/opendbc_repo/opendbc/car/tesla/carcontroller.py index 32ea414991..566e8a65d3 100644 --- a/opendbc_repo/opendbc/car/tesla/carcontroller.py +++ b/opendbc_repo/opendbc/car/tesla/carcontroller.py @@ -1,4 +1,5 @@ import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.can import CANPacker from opendbc.car import Bus from opendbc.car.lateral import apply_steer_angle_limits_vm @@ -79,7 +80,7 @@ class CarController(CarControllerBase): if self.CP.openpilotLongitudinalControl: if self.frame % 4 == 0: state = 13 if CC.cruiseControl.cancel else 4 # 4=ACC_ON, 13=ACC_CANCEL_GENERIC_SILENT - accel = float(np.clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)) + accel = float(np.clip(actuators.accel, CarControllerParams.ACCEL_MIN, ACCEL_MAX_TAKEOFF)) cntr = (self.frame // 4) % 8 can_sends.append(self.tesla_can.create_longitudinal_command(state, accel, cntr, CS.out.vEgo, CC.longActive)) diff --git a/opendbc_repo/opendbc/car/toyota/carcontroller.py b/opendbc_repo/opendbc/car/toyota/carcontroller.py index d8cb458735..78da0c2df8 100644 --- a/opendbc_repo/opendbc/car/toyota/carcontroller.py +++ b/opendbc_repo/opendbc/car/toyota/carcontroller.py @@ -1,5 +1,6 @@ import math import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF 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 @@ -409,6 +410,8 @@ class CarController(CarControllerBase): future_t = float(np.interp(CS.out.vEgo, [2., 5.], [0.25, 0.5])) a_ego_future = a_ego_blended + j_ego * future_t + accel_max = max(self.params.ACCEL_MAX, min(ACCEL_MAX_TAKEOFF, actuators.accel)) + self.long_pid.pos_limit = accel_max if long_active: if dom_defaults.bypass_pid(self.CP): self.long_pid.reset() @@ -450,7 +453,7 @@ class CarController(CarControllerBase): if self.prius_longitudinal: pcm_accel_cmd = prius_longitudinal.limit_prius_stopping_accel( pcm_accel_cmd, actuators.accel, stopping, CS.out.vEgo, lead) - pcm_accel_cmd = float(np.clip(pcm_accel_cmd, self.params.ACCEL_MIN, self.params.ACCEL_MAX)) + pcm_accel_cmd = float(np.clip(pcm_accel_cmd, self.params.ACCEL_MIN, accel_max)) if self.brake_hold_active and not uses_toyota_auto_hold_aeb(self.CP): pcm_accel_cmd = TOYOTA_AUTO_HOLD_ACCEL diff --git a/opendbc_repo/opendbc/car/toyota/interface.py b/opendbc_repo/opendbc/car/toyota/interface.py index 527cab3f2b..97b2c9a91c 100644 --- a/opendbc_repo/opendbc/car/toyota/interface.py +++ b/opendbc_repo/opendbc/car/toyota/interface.py @@ -1,3 +1,4 @@ +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.car import Bus, structs, get_safety_config, uds from opendbc.car.toyota.carstate import CarState from opendbc.car.toyota.carcontroller import CarController @@ -46,8 +47,8 @@ class CarInterface(CarInterfaceBase): DRIVABLE_GEARS = (structs.CarState.GearShifter.sport, structs.CarState.GearShifter.brake) @staticmethod - def get_pid_accel_limits(CP, current_speed, cruise_speed): - return CarControllerParams(CP).ACCEL_MIN, CarControllerParams(CP).ACCEL_MAX + def get_pid_accel_limits(CP, current_speed, cruise_speed, *, faster_takeoffs=False): + return CarControllerParams(CP).ACCEL_MIN, ACCEL_MAX_TAKEOFF if faster_takeoffs else CarControllerParams(CP).ACCEL_MAX @staticmethod def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, alpha_long, is_release, docs) -> structs.CarParams: diff --git a/opendbc_repo/opendbc/car/volkswagen/carcontroller.py b/opendbc_repo/opendbc/car/volkswagen/carcontroller.py index 0e7b9d2bba..14fd72dd51 100644 --- a/opendbc_repo/opendbc/car/volkswagen/carcontroller.py +++ b/opendbc_repo/opendbc/car/volkswagen/carcontroller.py @@ -1,4 +1,5 @@ import numpy as np +from opendbc.car import ACCEL_MAX_TAKEOFF from opendbc.can import CANPacker from opendbc.car import Bus, DT_CTRL, structs from opendbc.car.lateral import apply_driver_steer_torque_limits @@ -144,7 +145,7 @@ class CarController(CarControllerBase): if self.CP.openpilotLongitudinalControl: if self.frame % self.CCP.ACC_CONTROL_STEP == 0: if self.CP.flags & VolkswagenFlags.MEB: - accel = float(np.clip(actuators.accel, self.CCP.ACCEL_MIN, self.CCP.ACCEL_MAX)) + accel = float(np.clip(actuators.accel, self.CCP.ACCEL_MIN, min(ACCEL_MAX_TAKEOFF, 3.0))) accel, acc_status, acc_hold_type, braking_to_stop, leaving_standstill = self.meb_long_state.update(CS, CC, accel) acc_enabled = self.meb_long_state._long_active(CS, CC) can_sends.extend(mebcan.create_acc_accel_control(self.packer_pt, self.CAN.pt, self.CCP, CS.acc_type, acc_enabled, @@ -154,7 +155,7 @@ class CarController(CarControllerBase): else: stopping = actuators.longControlState == LongCtrlState.stopping acc_control = self.CCS.acc_control_value(CS.out.cruiseState.available, CS.out.accFaulted, CC.longActive) - accel = float(np.clip(actuators.accel, self.CCP.ACCEL_MIN, self.CCP.ACCEL_MAX) if CC.longActive else 0) + accel = float(np.clip(actuators.accel, self.CCP.ACCEL_MIN, min(ACCEL_MAX_TAKEOFF, 3.0)) if CC.longActive else 0) starting = actuators.longControlState == LongCtrlState.pid and (CS.esp_hold_confirmation or CS.out.vEgo < 0.25) can_sends.extend(self.CCS.create_acc_accel_control(self.packer_pt, self.CAN.pt, CS.acc_type, CC.longActive, accel, acc_control, stopping, starting, CS.esp_hold_confirmation)) diff --git a/opendbc_repo/opendbc/safety/modes/ford.h b/opendbc_repo/opendbc/safety/modes/ford.h index a415289742..754ac07257 100644 --- a/opendbc_repo/opendbc/safety/modes/ford.h +++ b/opendbc_repo/opendbc/safety/modes/ford.h @@ -227,13 +227,13 @@ static bool ford_tx_hook(const CANPacket_t *msg) { const LongitudinalLimits FORD_LONG_LIMITS = { // acceleration cmd limits (used for brakes) // Signal: AccBrkTot_A_Rq - .max_accel = 5641, // 1.9999 m/s^s + .max_accel = 6026, // 3.5014 m/s^2 (CAN resolution) .min_accel = 4231, // -3.4991 m/s^2 .inactive_accel = 5128, // -0.0008 m/s^2 // gas cmd limits // Signal: AccPrpl_A_Rq & AccPrpl_A_Pred - .max_gas = 700, // 2.0 m/s^2 + .max_gas = 850, // 3.5 m/s^2 .min_gas = 450, // -0.5 m/s^2 .inactive_gas = 0, // -5.0 m/s^2 }; diff --git a/opendbc_repo/opendbc/safety/modes/honda.h b/opendbc_repo/opendbc/safety/modes/honda.h index e05479189a..c75c441b33 100644 --- a/opendbc_repo/opendbc/safety/modes/honda.h +++ b/opendbc_repo/opendbc/safety/modes/honda.h @@ -218,7 +218,7 @@ static void honda_rx_hook(const CANPacket_t *msg) { static bool honda_tx_hook(const CANPacket_t *msg) { const LongitudinalLimits HONDA_BOSCH_LONG_LIMITS = { - .max_accel = 200, // accel is used for brakes + .max_accel = 350, // accel is used for brakes .min_accel = -350, .max_gas = honda_rdx_high_gas ? 2200 : 2000, diff --git a/opendbc_repo/opendbc/safety/modes/hyundai.h b/opendbc_repo/opendbc/safety/modes/hyundai.h index 431d66c025..10d45a926d 100644 --- a/opendbc_repo/opendbc/safety/modes/hyundai.h +++ b/opendbc_repo/opendbc/safety/modes/hyundai.h @@ -24,7 +24,7 @@ extern const LongitudinalLimits HYUNDAI_LONG_LIMITS; const LongitudinalLimits HYUNDAI_LONG_LIMITS = { - .max_accel = 200, // 1/100 m/s2 + .max_accel = 350, // 1/100 m/s2 .min_accel = -350, // 1/100 m/s2 }; diff --git a/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h b/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h index af8706f8d3..14ba20f430 100644 --- a/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h +++ b/opendbc_repo/opendbc/safety/modes/hyundai_canfd.h @@ -1156,7 +1156,7 @@ static bool hyundai_canfd_tx_hook_valid(const CANPacket_t *msg) { if (hyundai_longitudinal) { // Exact EV9's reached PID ceiling is 2.2 m/s2. Other vehicles retain // their existing 2.0 m/s2 maximum; this is narrower than original EV9 safety. - const LongitudinalLimits ev9_long_limits = {.max_accel = 220, .min_accel = -350}; + const LongitudinalLimits ev9_long_limits = {.max_accel = 350, .min_accel = -350}; const LongitudinalLimits limits = (hyundai_canfd_ccnc_ev_long && !hyundai_canfd_pe_long) ? ev9_long_limits : HYUNDAI_LONG_LIMITS; if (hyundai_canfd_ccnc_ev_long && ((desired_accel_raw != 0) || (desired_accel_val != 0))) { violation |= !aol_rx_healthy(); diff --git a/opendbc_repo/opendbc/safety/modes/rivian.h b/opendbc_repo/opendbc/safety/modes/rivian.h index 5ebcb32b2d..948fd09118 100644 --- a/opendbc_repo/opendbc/safety/modes/rivian.h +++ b/opendbc_repo/opendbc/safety/modes/rivian.h @@ -119,7 +119,7 @@ static bool rivian_tx_hook(const CANPacket_t *msg) { }; const LongitudinalLimits RIVIAN_LONG_LIMITS = { - .max_accel = 200, + .max_accel = 350, .min_accel = -350, .inactive_accel = 0, }; diff --git a/opendbc_repo/opendbc/safety/modes/tesla.h b/opendbc_repo/opendbc/safety/modes/tesla.h index 365e460973..fb1bc3884d 100644 --- a/opendbc_repo/opendbc/safety/modes/tesla.h +++ b/opendbc_repo/opendbc/safety/modes/tesla.h @@ -210,7 +210,7 @@ static bool tesla_tx_hook(const CANPacket_t *msg) { }; const LongitudinalLimits TESLA_LONG_LIMITS = { - .max_accel = 425, // 2 m/s^2 + .max_accel = 463, // 3.5 m/s^2 rounded to 0.04 m/s^2 CAN resolution .min_accel = 288, // -3.48 m/s^2 .inactive_accel = 375, // 0. m/s^2 }; diff --git a/opendbc_repo/opendbc/safety/modes/tesla_hw1.h b/opendbc_repo/opendbc/safety/modes/tesla_hw1.h index 35cca86538..9dd7fe188f 100644 --- a/opendbc_repo/opendbc/safety/modes/tesla_hw1.h +++ b/opendbc_repo/opendbc/safety/modes/tesla_hw1.h @@ -72,7 +72,7 @@ static void tesla_hw1_rx_hook(const CANPacket_t *msg) { static bool tesla_hw1_tx_hook(const CANPacket_t *msg) { const AngleSteeringLimits ANGLE_LIMITS = {.max_angle = 3600, .angle_deg_to_can = 10, .frequency = 50U}; const AngleSteeringParams VM = {.slip_factor = -0.0005666493436310427F, .steer_ratio = 15.0F, .wheelbase = 2.96F}; - const LongitudinalLimits LONG_LIMITS = {.max_accel = 425, .min_accel = 288, .inactive_accel = 375}; + const LongitudinalLimits LONG_LIMITS = {.max_accel = 463, .min_accel = 288, .inactive_accel = 375}; bool violation = tesla_hw1_checksum_index(msg) < 0; violation |= tesla_hw1_checksum(msg) != tesla_hw1_compute_checksum(msg); if (msg->addr == 0x488U) { diff --git a/opendbc_repo/opendbc/safety/modes/toyota.h b/opendbc_repo/opendbc/safety/modes/toyota.h index 687289ff76..a559eb1b58 100644 --- a/opendbc_repo/opendbc/safety/modes/toyota.h +++ b/opendbc_repo/opendbc/safety/modes/toyota.h @@ -424,7 +424,7 @@ static bool toyota_tx_hook(const CANPacket_t *msg) { // longitudinal limits const LongitudinalLimits TOYOTA_LONG_LIMITS = { - .max_accel = 2000, // 2.0 m/s2 + .max_accel = 3500, // 3.5 m/s2 .min_accel = -3500, // -3.5 m/s2 }; diff --git a/opendbc_repo/opendbc/safety/modes/volkswagen_meb.h b/opendbc_repo/opendbc/safety/modes/volkswagen_meb.h index f6c8a6d5e5..08bc23dd4c 100644 --- a/opendbc_repo/opendbc/safety/modes/volkswagen_meb.h +++ b/opendbc_repo/opendbc/safety/modes/volkswagen_meb.h @@ -238,7 +238,7 @@ static void volkswagen_meb_rx_hook(const CANPacket_t *msg) { static bool volkswagen_meb_tx_hook(const CANPacket_t *msg) { // acceleration in m/s2 * 1000 to avoid floating point math const LongitudinalLimits VOLKSWAGEN_MEB_LONG_LIMITS = { - .max_accel = 2000, + .max_accel = 3000, .min_accel = -3500, .inactive_accel = 3010, // VW sends one increment above the max range when inactive }; diff --git a/opendbc_repo/opendbc/safety/modes/volkswagen_mqb.h b/opendbc_repo/opendbc/safety/modes/volkswagen_mqb.h index ef4a60f9a5..80a3970940 100644 --- a/opendbc_repo/opendbc/safety/modes/volkswagen_mqb.h +++ b/opendbc_repo/opendbc/safety/modes/volkswagen_mqb.h @@ -184,7 +184,7 @@ static bool volkswagen_mqb_tx_hook(const CANPacket_t *msg) { // longitudinal limits // acceleration in m/s2 * 1000 to avoid floating point math const LongitudinalLimits VOLKSWAGEN_MQB_LONG_LIMITS = { - .max_accel = 2000, + .max_accel = 3000, .min_accel = -3500, .inactive_accel = 3010, // VW sends one increment above the max range when inactive }; diff --git a/opendbc_repo/opendbc/safety/modes/volkswagen_pq.h b/opendbc_repo/opendbc/safety/modes/volkswagen_pq.h index cdc1856836..1933ba8fcf 100644 --- a/opendbc_repo/opendbc/safety/modes/volkswagen_pq.h +++ b/opendbc_repo/opendbc/safety/modes/volkswagen_pq.h @@ -165,7 +165,7 @@ static bool volkswagen_pq_tx_hook(const CANPacket_t *msg) { // longitudinal limits // acceleration in m/s2 * 1000 to avoid floating point math const LongitudinalLimits VOLKSWAGEN_PQ_LONG_LIMITS = { - .max_accel = 2000, + .max_accel = 3000, .min_accel = -3500, .inactive_accel = 3010, // VW sends one increment above the max range when inactive }; diff --git a/opendbc_repo/opendbc/safety/tests/hyundai_common.py b/opendbc_repo/opendbc/safety/tests/hyundai_common.py index ef07bd2e9e..ceeab576a7 100644 --- a/opendbc_repo/opendbc/safety/tests/hyundai_common.py +++ b/opendbc_repo/opendbc/safety/tests/hyundai_common.py @@ -72,6 +72,7 @@ class HyundaiButtonBase: class HyundaiLongitudinalBase(common.LongitudinalAccelSafetyTest): + MAX_ACCEL = 3.5 DISABLED_ECU_UDS_MSG: tuple[int, int] DISABLED_ECU_ACTUATION_MSG: tuple[int, int] diff --git a/opendbc_repo/opendbc/safety/tests/test_ford.py b/opendbc_repo/opendbc/safety/tests/test_ford.py index 46190c06d4..379a3bd34b 100755 --- a/opendbc_repo/opendbc/safety/tests/test_ford.py +++ b/opendbc_repo/opendbc/safety/tests/test_ford.py @@ -443,11 +443,11 @@ class TestFordCANFDStockSafety(TestFordSafetyBase): class TestFordLongitudinalSafetyBase(TestFordSafetyBase): - MAX_ACCEL = 2.0 # accel is used for brakes, but openpilot can set positive values + MAX_ACCEL = 3.5 # accel is used for brakes, but openpilot can set positive values MIN_ACCEL = -3.5 INACTIVE_ACCEL = 0.0 - MAX_GAS = 2.0 + MAX_GAS = 3.5 MIN_GAS = -0.5 INACTIVE_GAS = -5.0 diff --git a/opendbc_repo/opendbc/safety/tests/test_honda.py b/opendbc_repo/opendbc/safety/tests/test_honda.py index ef568c2b9f..d3bdc02266 100755 --- a/opendbc_repo/opendbc/safety/tests/test_honda.py +++ b/opendbc_repo/opendbc/safety/tests/test_honda.py @@ -433,7 +433,7 @@ class TestHondaBoschLongSafety(HondaButtonEnableBase, TestHondaBoschSafetyBase): NO_GAS = -30000 MAX_GAS = 2000 - MAX_ACCEL = 2.0 # accel is used for brakes, but openpilot can set positive values + MAX_ACCEL = 3.5 # accel is used for brakes, but openpilot can set positive values MIN_ACCEL = -3.5 STEER_BUS = 1 @@ -516,6 +516,7 @@ class TestHondaBoschRadarlessAltBrakeSafety(HondaPcmEnableBase, TestHondaBoschRa class TestHondaBoschRadarlessLongSafety(common.LongitudinalAccelSafetyTest, HondaButtonEnableBase, TestHondaBoschRadarlessSafetyBase): + MAX_ACCEL = 3.5 """ Covers the Honda Bosch Radarless safety mode with longitudinal control """ diff --git a/opendbc_repo/opendbc/safety/tests/test_rivian.py b/opendbc_repo/opendbc/safety/tests/test_rivian.py index 8670066f8a..757880da55 100755 --- a/opendbc_repo/opendbc/safety/tests/test_rivian.py +++ b/opendbc_repo/opendbc/safety/tests/test_rivian.py @@ -9,6 +9,7 @@ from opendbc.car.rivian.values import RivianSafetyFlags class TestRivianSafetyBase(common.CarSafetyTest, common.DriverTorqueSteeringSafetyTest, common.LongitudinalAccelSafetyTest, common.VehicleSpeedSafetyTest): + MAX_ACCEL = 3.5 DBC = "rivian_primary_actuator" SAFETY_MODEL = CarParams.SafetyModel.rivian diff --git a/opendbc_repo/opendbc/safety/tests/test_tesla.py b/opendbc_repo/opendbc/safety/tests/test_tesla.py index 9085976fc4..2114d461eb 100755 --- a/opendbc_repo/opendbc/safety/tests/test_tesla.py +++ b/opendbc_repo/opendbc/safety/tests/test_tesla.py @@ -44,7 +44,7 @@ class TestTeslaSafetyBase(common.CarSafetyTest, common.AngleSteeringSafetyTest, LATERAL_FREQUENCY = 50 # Hz # Long control limits - MAX_ACCEL = 2.0 + MAX_ACCEL = 3.52 MIN_ACCEL = -3.48 INACTIVE_ACCEL = 0.0 diff --git a/opendbc_repo/opendbc/safety/tests/test_toyota.py b/opendbc_repo/opendbc/safety/tests/test_toyota.py index 0729171966..bde3ce014c 100755 --- a/opendbc_repo/opendbc/safety/tests/test_toyota.py +++ b/opendbc_repo/opendbc/safety/tests/test_toyota.py @@ -21,6 +21,7 @@ TOYOTA_COMMON_LONG_TX_MSGS = [[0x283, 0], [0x2E6, 0], [0x2E7, 0], [0x33E, 0], [0 class TestToyotaSafetyBase(common.CarSafetyTest, common.LongitudinalAccelSafetyTest): + MAX_ACCEL = 3.5 DBC = "toyota_nodsu_pt_generated" SAFETY_MODEL = CarParams.SafetyModel.toyota @@ -702,7 +703,7 @@ class TestToyotaHighlanderAol(unittest.TestCase): self.assertEqual(self.safety.aol_get_request_mask(), 1 if stock else 3) self.assertEqual(self.safety.aol_get_permission_mask(), 1 if stock else 3) for accel, cancel, allowed in ((0, 1, True), (0, 0, not stock), (0.1, 0, not stock), - (-0.1, 0, not stock), (2.1, 0, False), (-3.6, 0, False)): + (-0.1, 0, not stock), (3.6, 0, False), (-3.6, 0, False)): message = self.packer.make_can_msg_safety("ACC_CONTROL", 0, {"ACCEL_CMD": accel, "CANCEL_REQ": cancel}) self.assertEqual(bool(self.safety.safety_tx_hook(message)), allowed) for address, bus, length in ((0x750, 0, 8), (0x343, 2, 8), (0x283, 2, 7), (0x411, 2, 8)): diff --git a/opendbc_repo/opendbc/safety/tests/test_volkswagen_meb.py b/opendbc_repo/opendbc/safety/tests/test_volkswagen_meb.py index 68de2982bc..9da1818783 100644 --- a/opendbc_repo/opendbc/safety/tests/test_volkswagen_meb.py +++ b/opendbc_repo/opendbc/safety/tests/test_volkswagen_meb.py @@ -6,7 +6,7 @@ from opendbc.car.structs import CarParams from opendbc.car.volkswagen.values import VolkswagenSafetyFlags import opendbc.safety.tests.common as common -MAX_ACCEL = 2.0 +MAX_ACCEL = 3.0 MIN_ACCEL = -3.5 # ACC_18.ACC_Anforderung_HMS diff --git a/opendbc_repo/opendbc/safety/tests/test_volkswagen_mqb.py b/opendbc_repo/opendbc/safety/tests/test_volkswagen_mqb.py index 75a54f2225..81fdab58da 100755 --- a/opendbc_repo/opendbc/safety/tests/test_volkswagen_mqb.py +++ b/opendbc_repo/opendbc/safety/tests/test_volkswagen_mqb.py @@ -5,7 +5,7 @@ from opendbc.car.structs import CarParams import opendbc.safety.tests.common as common from opendbc.car.volkswagen.values import VolkswagenSafetyFlags -MAX_ACCEL = 2.0 +MAX_ACCEL = 3.0 MIN_ACCEL = -3.5 MSG_LH_EPS_03 = 0x9F # RX from EPS, for driver steering torque diff --git a/opendbc_repo/opendbc/safety/tests/test_volkswagen_pq.py b/opendbc_repo/opendbc/safety/tests/test_volkswagen_pq.py index 5a353dec6b..648e3b1439 100755 --- a/opendbc_repo/opendbc/safety/tests/test_volkswagen_pq.py +++ b/opendbc_repo/opendbc/safety/tests/test_volkswagen_pq.py @@ -101,6 +101,7 @@ class TestVolkswagenPqStockSafety(TestVolkswagenPqSafetyBase): class TestVolkswagenPqLongSafety(TestVolkswagenPqSafetyBase, common.LongitudinalAccelSafetyTest): + MAX_ACCEL = 3.0 SAFETY_MODEL = CarParams.SafetyModel.volkswagenPq SAFETY_PARAM = VolkswagenSafetyFlags.LONG_CONTROL diff --git a/openpilot/selfdrive/controls/controlsd.py b/openpilot/selfdrive/controls/controlsd.py index f80954ff8d..3718de4e34 100755 --- a/openpilot/selfdrive/controls/controlsd.py +++ b/openpilot/selfdrive/controls/controlsd.py @@ -456,12 +456,14 @@ class Controls: # accel PID loop publish_takeoff_state = getattr(self.LoC, 'takeoff_starting', False) - pid_accel_limits = self.CI.get_pid_accel_limits(self.CP, CS.vEgo, CS.vCruise * CV.KPH_TO_MS) + longitudinal_context = self.longitudinal_inputs.context(CC.longActive) + pid_accel_limits = self.CI.get_pid_accel_limits( + self.CP, CS.vEgo, CS.vCruise * CV.KPH_TO_MS, faster_takeoffs=longitudinal_context.faster_takeoffs) from opendbc.car.tesla.preap.pedal_profile import accel_limits as preap_pedal_limits pid_accel_limits = preap_pedal_limits(self.CP, CS.vEgo, getattr(self.sm['selfdriveState'].personality, 'raw', 1), pid_accel_limits) longitudinal_output = self.LoC.update( - CC.longActive, CS, long_plan.aTarget, long_plan.shouldStop, pid_accel_limits, context=self.longitudinal_inputs.context(CC.longActive) + CC.longActive, CS, long_plan.aTarget, long_plan.shouldStop, pid_accel_limits, context=longitudinal_context ) actuators.accel = final_output(longitudinal_output) if self.longitudinal_inputs.publish_state or publish_takeoff_state: diff --git a/openpilot/selfdrive/controls/lib/longcontrol.py b/openpilot/selfdrive/controls/lib/longcontrol.py index cba347988f..68c25bc1b3 100644 --- a/openpilot/selfdrive/controls/lib/longcontrol.py +++ b/openpilot/selfdrive/controls/lib/longcontrol.py @@ -2,6 +2,7 @@ import numpy as np import math from opendbc.car.structs import car from openpilot.common.realtime import DT_CTRL +from openpilot.starpilot.longitudinal.lead_takeoff_preferences import MAX_ACCEL as TAKEOFF_ACCEL_MAX from openpilot.selfdrive.controls.lib.drive_helpers import CONTROL_N from openpilot.common.pid import PIDController from openpilot.selfdrive.modeld.constants import ModelConstants @@ -60,6 +61,12 @@ class LongControl: def update(self, active, CS, a_target, should_stop, accel_limits, *, context=None): """Update longitudinal control. This updates the state machine and runs a PID loop""" context = context if context is not None else LongitudinalContext() + if context.faster_takeoffs and takeoff_eligible(self.CP): + upper = min(accel_limits[1], TAKEOFF_ACCEL_MAX) + cap = context.profile_max_accel + if type(cap) in (int, float) and math.isfinite(cap) and 0 <= cap <= TAKEOFF_ACCEL_MAX: + upper = min(upper, cap) + accel_limits = (accel_limits[0], upper) self.pid.neg_limit = accel_limits[0] self.pid.pos_limit = accel_limits[1] diff --git a/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py index 97f4d15dd5..cc8ee9d51a 100755 --- a/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py +++ b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py @@ -6,6 +6,7 @@ from dataclasses import dataclass import numpy as np from openpilot.cereal import log from opendbc.car.interfaces import ACCEL_MIN, ACCEL_MAX +from openpilot.starpilot.longitudinal.lead_takeoff_preferences import MAX_ACCEL as TAKEOFF_ACCEL_MAX from openpilot.common.realtime import DT_MDL from openpilot.common.swaglog import cloudlog # WARNING: imports outside of constants will not trigger a rebuild @@ -542,7 +543,7 @@ class LongitudinalMpc: return lead_xv def update(self, radarstate, personality=log.LongitudinalPersonality.standard, - *, follow_seconds: float | None = None, acceleration_max: float | None = None, stop_line_m: float | None = None, + *, follow_seconds: float | None = None, acceleration_max: float | None = None, stop_line_m: float | None = None, faster_takeoffs: bool = False, modelV2=None, extra_stopped_gap_m: float = 0.0): t_follow = get_T_FOLLOW(personality) if follow_seconds is not None and math.isfinite(follow_seconds) and 0.5 <= follow_seconds <= 3.0: @@ -581,9 +582,10 @@ class LongitudinalMpc: self.solver.set(N, "yref", self.yref[N][:COST_E_DIM]) self.params[:,0] = ACCEL_MIN + ceiling = TAKEOFF_ACCEL_MAX if faster_takeoffs else ACCEL_MAX bounded_accel = (acceleration_max is not None and math.isfinite(acceleration_max) and - 0.0 <= acceleration_max <= ACCEL_MAX) - self.params[:,1] = min(ACCEL_MAX, acceleration_max) if bounded_accel else ACCEL_MAX + 0.0 <= acceleration_max <= TAKEOFF_ACCEL_MAX) + self.params[:,1] = min(ceiling, acceleration_max) if bounded_accel else ceiling self.params[:,2] = np.min(x_obstacles, axis=1) self.params[:,3] = np.copy(self.a_prev) self.params[:,4] = t_follow diff --git a/openpilot/selfdrive/controls/lib/longitudinal_planner.py b/openpilot/selfdrive/controls/lib/longitudinal_planner.py index 0e362aef44..ca836f1e87 100755 --- a/openpilot/selfdrive/controls/lib/longitudinal_planner.py +++ b/openpilot/selfdrive/controls/lib/longitudinal_planner.py @@ -7,6 +7,7 @@ import numpy as np import openpilot.cereal.messaging as messaging from opendbc.car.interfaces import ACCEL_MIN, ACCEL_MAX +from openpilot.starpilot.longitudinal.lead_takeoff_preferences import MAX_ACCEL as TAKEOFF_ACCEL_MAX from openpilot.common.constants import CV from openpilot.common.filter_simple import FirstOrderFilter from openpilot.common.realtime import DT_MDL @@ -57,12 +58,12 @@ NATIVE_PLAN_INPUTS = ('carControl', 'carState', 'controlsState', 'vehicleParamet # Lookup table for turns _A_TOTAL_MAX_V = [1.7, 3.2] _A_TOTAL_MAX_BP = [20., 40.] -_TAKEOFF_TOTAL_BP = [0., 2., 5., 20., 40.] -_TAKEOFF_TOTAL_MAX = [3.5, 3.5, 1.7, 1.7, 3.2] +_TAKEOFF_TOTAL_BP = [0., 5., 10., 20., 40.] +_TAKEOFF_TOTAL_MAX = [3.5, 3.5, 3.5, 1.7, 3.2] def get_max_accel(v_ego, faster_takeoffs=False): max_accel = np.interp(v_ego, A_CRUISE_MAX_BP, A_CRUISE_MAX_VALS) - return np.interp(v_ego, [5., 10.], [ACCEL_MAX, max_accel]) if faster_takeoffs else max_accel + return np.interp(v_ego, [5., 10.], [TAKEOFF_ACCEL_MAX, max_accel]) if faster_takeoffs else max_accel def get_coast_accel(pitch): return np.sin(pitch) * -5.65 - 0.3 # fitted from data using xx/projects/allow_throttle/compute_coast_accel.py @@ -71,14 +72,15 @@ def get_cruise_accel(e2e, v_cruise, v_ego, a_cruise_prev, angle_steers, CP, dt, profile: AppliedProfile | None = None, base_brake_floor: float = A_CRUISE_MIN, selected_acceleration_max: float | None = None, faster_takeoffs: bool = False, *, a_target_prev: float | None = None): - max_accel = ACCEL_MAX if e2e else get_max_accel(v_ego, faster_takeoffs) + ceiling = TAKEOFF_ACCEL_MAX if faster_takeoffs else ACCEL_MAX + max_accel = ceiling if e2e else get_max_accel(v_ego, faster_takeoffs) if selected_acceleration_max is not None and not e2e: max_accel = selected_acceleration_max if profile is not None: - max_accel = min(max_accel, profile.acceleration_max, ACCEL_MAX) + max_accel = min(max_accel, profile.acceleration_max, ceiling) if selected_acceleration_max is not None: - max_accel = min(max_accel, selected_acceleration_max, ACCEL_MAX) + max_accel = min(max_accel, selected_acceleration_max, ceiling) if not e2e: a_total_max = np.interp(v_ego, _TAKEOFF_TOTAL_BP, _TAKEOFF_TOTAL_MAX) if faster_takeoffs else np.interp(v_ego, _A_TOTAL_MAX_BP, _A_TOTAL_MAX_V) @@ -159,6 +161,7 @@ class LongitudinalPlanner: self.model_lead_history.clear() self.plan_drive_id = drive_id faster_takeoffs = bool(faster_lead_takeoff) + accel_ceiling = TAKEOFF_ACCEL_MAX if faster_takeoffs else ACCEL_MAX sample_now_ns = self.clock_ns() if now_ns is None else now_ns if len(sm['carControl'].orientationNED) == 3: accel_coast = get_coast_accel(sm['carControl'].orientationNED[1]) @@ -271,14 +274,14 @@ class LongitudinalPlanner: preap_acceleration_cap = None if self.preap_adaptive is not None: preap_acceleration_cap = self.preap_adaptive.sample( - sm, now_ns=sample_now_ns, drive_id=drive_id, upper=ACCEL_MAX if acceleration_cap is None else acceleration_cap, + sm, now_ns=sample_now_ns, drive_id=drive_id, upper=accel_ceiling if acceleration_cap is None else min(accel_ceiling, acceleration_cap), follow_seconds=selected_follow, active=profile_eligible and not reset_state) if preap_acceleration_cap is not None: acceleration_cap = preap_acceleration_cap self.mpc.update(sm['radarState'], personality=sm['selfdriveState'].personality, follow_seconds=follow if follow is not None else (self.last_profile.follow_seconds if self.last_profile is not None else None), - acceleration_max=acceleration_cap, + acceleration_max=acceleration_cap, faster_takeoffs=faster_takeoffs, extra_stopped_gap_m=(selected_profiles.extra_stopped_gap_m if profile_eligible and selected_profiles is not None else 0.0), stop_line_m=self.force_stop_plan.obstacle_m, modelV2=qualified_model_leads(sm, sample_now_ns, self.model_lead_history)) @@ -447,7 +450,7 @@ class LongitudinalPlanner: force_stop=self.force_stop_plan.forcing, traffic_mode=traffic_mode, accel_min=ACCEL_MIN) if faster_lead_takeoff: # Dom takeoff bypasses the standstill cruise slew, never its final bounds. - takeoff_max = ACCEL_MAX if sm['selfdriveState'].experimentalMode else get_max_accel(v_ego, faster_takeoffs) + takeoff_max = accel_ceiling if sm['selfdriveState'].experimentalMode else get_max_accel(v_ego, faster_takeoffs) if selected_acceleration is not None and not sm['selfdriveState'].experimentalMode: takeoff_max = selected_acceleration if cruise_profile is not None: @@ -483,7 +486,7 @@ class LongitudinalPlanner: output_a_target, self.output_should_stop = self.ford_stop_approach.sample( sm, now_ns=sample_now_ns, drive_id=drive_id, target=float(output_a_target), stopping=self.output_should_stop, accel_min=ACCEL_MIN, active=profile_eligible and not reset_state) - self.output_a_target = np.clip(output_a_target, ACCEL_MIN, ACCEL_MAX) + self.output_a_target = np.clip(output_a_target, ACCEL_MIN, accel_ceiling) self.v_desired_filter.x = self.v_desired_filter.x + self.dt * (self.output_a_target + a_prev) / 2.0 diff --git a/openpilot/starpilot/longitudinal/lead_takeoff_preferences.py b/openpilot/starpilot/longitudinal/lead_takeoff_preferences.py index 882d522285..3eb807f4ee 100644 --- a/openpilot/starpilot/longitudinal/lead_takeoff_preferences.py +++ b/openpilot/starpilot/longitudinal/lead_takeoff_preferences.py @@ -1,7 +1,9 @@ """Persistent, default-off lead takeoff preference; invalid bytes never activate it.""" +from opendbc.car import ACCEL_MAX_TAKEOFF from openpilot.starpilot.saved_source import read_saved KEY = 'FasterLeadTakeoff' +MAX_ACCEL = ACCEL_MAX_TAKEOFF class TakeoffPreferences: diff --git a/openpilot/starpilot/longitudinal/profile_runtime.py b/openpilot/starpilot/longitudinal/profile_runtime.py index 284d6e9a4e..90e2e68a3a 100644 --- a/openpilot/starpilot/longitudinal/profile_runtime.py +++ b/openpilot/starpilot/longitudinal/profile_runtime.py @@ -7,7 +7,8 @@ from dataclasses import astuple, dataclass from openpilot.common.constants import CV from opendbc.car.structs import car -from opendbc.car.interfaces import ACCEL_MIN, ACCEL_MAX +from opendbc.car.interfaces import ACCEL_MIN +from openpilot.starpilot.longitudinal.lead_takeoff_preferences import MAX_ACCEL as ACCEL_MAX from openpilot.starpilot.longitudinal.accel_profile import A_CRUISE_MAX_VALS_TRAFFIC_ALL, interpolate_accel_profile from openpilot.starpilot.longitudinal.profile_document import ( DEFAULT_DECELERATION_PROFILE, active_personality_id, interpolate_category_curve, is_truck_fingerprint, diff --git a/openpilot/starpilot/longitudinal/tests/test_profile_runtime.py b/openpilot/starpilot/longitudinal/tests/test_profile_runtime.py index f07047588c..927139b5e0 100644 --- a/openpilot/starpilot/longitudinal/tests/test_profile_runtime.py +++ b/openpilot/starpilot/longitudinal/tests/test_profile_runtime.py @@ -199,7 +199,7 @@ class ProfileRuntimeTests(unittest.TestCase): self.assertTrue(settings.valid) tuning = resolve(settings, log.LongitudinalPersonality.standard, 12.5, self.cp, traffic_mode=True) assert tuning is not None - self.assertAlmostEqual(required_float(tuning.acceleration_max), 2.0) # Native ACCEL_MAX; keep other valid categories. + self.assertAlmostEqual(required_float(tuning.acceleration_max), 3.5) # Keep other valid categories. self.assertAlmostEqual(required_float(tuning.cruise_brake_magnitude), 0.35) self.assertAlmostEqual(tuning.follow_seconds, 2.25) ordinary = ProfileTuning('standard', 1.45, 1.0, 1.0, 1.0, 1.0, 1.0, @@ -411,7 +411,7 @@ class ProfileRuntimeTests(unittest.TestCase): settings = read_settings(self.params) tuning = resolve(settings, log.LongitudinalPersonality.standard, 0.0, self.cp) assert tuning is not None - self.assertEqual(tuning.acceleration_max, 2.0) + self.assertEqual(tuning.acceleration_max, 3.5) self.assertEqual(tuning.follow_seconds, 2.25) planner = LongitudinalPlanner(self.cp, init_v=0.0) for _ in range(40): diff --git a/openpilot/starpilot/longitudinal/tests/test_takeoffs.py b/openpilot/starpilot/longitudinal/tests/test_takeoffs.py index 57beedf2df..3b8de77375 100644 --- a/openpilot/starpilot/longitudinal/tests/test_takeoffs.py +++ b/openpilot/starpilot/longitudinal/tests/test_takeoffs.py @@ -12,7 +12,7 @@ from openpilot.common.params import Params from openpilot.cereal import messaging from openpilot.starpilot.galaxy.settings import AuthorityContext, SettingsGateway from openpilot.selfdrive.controls.lib.longcontrol import LongControl, LongCtrlState -from openpilot.selfdrive.controls.lib.longitudinal_planner import LongitudinalPlanner, get_cruise_accel +from openpilot.selfdrive.controls.lib.longitudinal_planner import LongitudinalPlanner, get_cruise_accel, get_max_accel from openpilot.starpilot.longitudinal.extension import LongitudinalContext from openpilot.starpilot.longitudinal.inputs import LongitudinalInputs from openpilot.starpilot.longitudinal.ioniq6_start import StartEvidence @@ -38,7 +38,7 @@ def test_actual_factory_longcontrol_first_start_target_bounds_and_ordinary_exit( assert eligible(cp) ctrl = LongControl(cp) cs = car_state(standstill=False) - output = ctrl.update(True, cs, 1.8, False, (np.float64(-3.), np.float64(1.5)), context=context()) + output = ctrl.update(True, cs, 1.8, False, (np.float64(-3.), np.float64(1.5)), context=replace(context(), profile_max_accel=1.5)) assert ctrl.takeoff_starting and ctrl.long_control_state == LongCtrlState.starting assert output <= 1.5 ctrl.update(True, car_state(speed=.11, standstill=False), .8, False, (-3., 2.), context=context(1)) @@ -214,3 +214,95 @@ def test_actual_inputs_qualify_current_serialized_drive_and_plan(factory, tmp_pa sm.logMonoTime['longitudinalPlan'] = NOW - 5_000_000 sm.valid['radarState'] = False assert inputs.context(True).start_evidence.lead_clear is None + + +@pytest.mark.parametrize('speed', [0., .5, 2., 4., 5.]) +def test_fast_takeoff_ceiling_is_3_point_5(speed): + assert get_max_accel(speed, True) == 3.5 + assert get_max_accel(speed, False) <= 2. + +@pytest.mark.parametrize('speed', [0., 3., 5.]) +@pytest.mark.parametrize('experimental', [False, True]) +@pytest.mark.parametrize('cap', [None, .5, 1.2, 2.4, 3.5]) +def test_user_cap_survives_without_hidden_two_clip(speed, experimental, cap): + cp = candidate()[1] + expected = 3.5 if cap is None else cap + actual = get_cruise_accel(experimental, 30., speed, expected, 0., cp, .05, 0., True, + selected_acceleration_max=cap, faster_takeoffs=True) + assert actual == expected + +@pytest.mark.parametrize('enabled', [False, True]) +def test_actual_mpc_uses_toggle_dependent_ceiling(enabled): + planner=LongitudinalPlanner(candidate()[1]) + sm=Frame() + planner.mpc.update(sm['radarState'], faster_takeoffs=enabled) + assert planner.mpc.solution_status == 0 + assert np.all(planner.mpc.params[:,1] == (3.5 if enabled else 2.)) + +@pytest.mark.parametrize('brand', ['hyundai', 'toyota', 'honda', 'ford', 'gm', 'volkswagen', 'rivian', 'tesla']) +def test_controls_ceiling_is_not_ioniq_gated(brand): + cp = candidate()[1] + cp.brand=brand + control = LongControl(cp) + control.extension=None + cs=car_state(speed=4.,standstill=False) + out=control.update(True,cs,3.5,False,(-3.5,3.5),context=LongitudinalContext(faster_takeoffs=True)) + assert out==3.5 + assert control.update(True,cs,3.5,False,(-3.5,2.),context=LongitudinalContext()) == 2. + +@pytest.mark.parametrize('cap', [0., .5, 1.2, 2.4]) +def test_controls_respects_personality_cap(cap): + cp=candidate()[1] + control=LongControl(cp) + control.extension=None + cs=car_state(speed=4.,standstill=False) + assert control.update(True,cs,3.5,False,(-3.5,3.5),context=LongitudinalContext(faster_takeoffs=True,profile_max_accel=cap)) == cap + + +def test_real_planner_reaches_three_point_five_without_losing_model_stop(): + cp=candidate()[1] + planner=LongitudinalPlanner(cp) + outputs=[] + for tick in range(100): + now=NOW+tick*50_000_000 + sm=Frame() + sm.logMonoTime=dict.fromkeys(sm,now-5_000_000) + sm.recv_time=dict.fromkeys(sm,(now-5_000_000)/1e9) + sm['carState'].vEgo=0. + sm['carState'].standstill=True + sm['carState'].vCruise=72. + sm['selfdriveState'].experimentalMode=tick<8 + sm['modelV2'].action.shouldStop=tick<8 + sm['modelV2'].action.desiredAcceleration=-.04 if tick<8 else 4. + planner.update(sm,faster_lead_takeoff=True,takeoff_drive_id=DRIVE,now_ns=now,drive_id=DRIVE) + assert planner.mpc.solution_status == 0 + assert planner.output_a_target <= 3.5 + if tick<8: + assert planner.output_should_stop + outputs.append(float(planner.output_a_target)) + assert max(outputs)==3.5 + + +@pytest.mark.parametrize('brand', ['hyundai', 'toyota', 'honda', 'ford', 'gm', 'volkswagen', 'rivian', 'tesla']) +def test_actual_interface_takeoff_ceiling_and_default_are_independent(brand): + from importlib import import_module + interface = import_module('opendbc.car.' + brand + '.interface').CarInterface + models = import_module('opendbc.car.' + brand + '.values').CAR + cp = interface.get_non_essential_params(next(iter(models))) + normal = interface.get_pid_accel_limits(cp, 0., 30.) + assert normal == interface.get_pid_accel_limits(cp, 0., 30., faster_takeoffs=False) + fast = interface.get_pid_accel_limits(cp, 0., 30., faster_takeoffs=True) + assert fast[0] == normal[0] + assert fast[1] == 3.5 + + +@pytest.mark.parametrize('brand', ['ford', 'honda']) +def test_takeoff_keeps_near_set_speed_pid_windup_limit(brand): + from importlib import import_module + interface = import_module('opendbc.car.' + brand + '.interface').CarInterface + models = import_module('opendbc.car.' + brand + '.values').CAR + cp = interface.get_non_essential_params(next(iter(models))) + if brand == 'honda': + cp = Honda.get_non_essential_params(H.HONDA_CIVIC) + upper = interface.get_pid_accel_limits(cp, 30., 30., faster_takeoffs=True)[1] + assert upper == .2