diff --git a/opendbc/car/ford/carcontroller.py b/opendbc/car/ford/carcontroller.py index 91466825..df3b6111 100644 --- a/opendbc/car/ford/carcontroller.py +++ b/opendbc/car/ford/carcontroller.py @@ -2,7 +2,7 @@ import math import numpy as np from opendbc.can import CANPacker from opendbc.car import ACCELERATION_DUE_TO_GRAVITY, Bus, DT_CTRL, apply_hysteresis, structs -from opendbc.car.lateral import ISO_LATERAL_ACCEL, apply_std_steer_angle_limits +from opendbc.car.lateral import AVERAGE_ROAD_ROLL, ISO_LATERAL_ACCEL, apply_std_steer_angle_limits from opendbc.car.ford import fordcan from opendbc.car.ford.values import CarControllerParams, FordFlags, CAR from opendbc.car.interfaces import CarControllerBase, V_CRUISE_MAX @@ -11,8 +11,7 @@ LongCtrlState = structs.CarControl.Actuators.LongControlState VisualAlert = structs.CarControl.HUDControl.VisualAlert # CAN FD limits: -# Limit to average banked road since safety doesn't have the roll -AVERAGE_ROAD_ROLL = 0.06 # ~3.4 degrees, 6% superelevation. higher actual roll raises lateral acceleration +# Limit to average banked road since safety doesn't have the roll, higher actual roll lowers lateral acceleration MAX_LATERAL_ACCEL = ISO_LATERAL_ACCEL - (ACCELERATION_DUE_TO_GRAVITY * AVERAGE_ROAD_ROLL) # ~2.4 m/s^2 diff --git a/opendbc/car/lateral.py b/opendbc/car/lateral.py index 5cc5f86c..46b521ab 100644 --- a/opendbc/car/lateral.py +++ b/opendbc/car/lateral.py @@ -1,26 +1,39 @@ import math import numpy as np from dataclasses import dataclass -from opendbc.car import structs, rate_limit, DT_CTRL +from opendbc.car import structs, rate_limit, DT_CTRL, ACCELERATION_DUE_TO_GRAVITY from opendbc.car.vehicle_model import VehicleModel FRICTION_THRESHOLD = 0.2 -# ISO 11270 +# - ISO 11270 ISO_LATERAL_ACCEL = 3.0 # m/s^2 ISO_LATERAL_JERK = 5.0 # m/s^3 +# - Common angle safety limits +AVERAGE_ROAD_ROLL = 0.06 # ~3.4 degrees, 6% superelevation. higher actual roll lowers lateral acceleration + +# TODO: deprecate in favor of vehicle-model-based limiting +# (need to solve cars having different steering ratios, etc.) @dataclass class AngleSteeringLimits: - # v1 limits (using apply_std_steer_angle_limits) + # uses apply_std_steer_angle_limits STEER_ANGLE_MAX: float ANGLE_RATE_LIMIT_UP: tuple[list[float], list[float]] ANGLE_RATE_LIMIT_DOWN: tuple[list[float], list[float]] - # v2 vehicle model limits (using apply_steer_angle_limits_vm) - MAX_LATERAL_ACCEL: float = 0 - MAX_LATERAL_JERK: float = 0 + +@dataclass +class AngleSteeringLimitsVM: + # uses apply_steer_angle_limits_vm + # Max accepted by the EPS + STEER_ANGLE_MAX: float + # Add extra tolerance for average banked road since safety doesn't have the roll + MAX_LATERAL_ACCEL: float = ISO_LATERAL_ACCEL + (ACCELERATION_DUE_TO_GRAVITY * AVERAGE_ROAD_ROLL) # ~3.6 m/s^2 + # Lower than ISO 11270 lateral jerk limit (5.0 m/s^3) with bank tolerance, matches safety MAX_LATERAL_JERK + MAX_LATERAL_JERK: float = 3.0 + (ACCELERATION_DUE_TO_GRAVITY * AVERAGE_ROAD_ROLL) # ~3.6 m/s^3 + # Used for comfort or to prevent faults at low speed MAX_ANGLE_RATE: float = math.inf diff --git a/opendbc/car/tesla/values.py b/opendbc/car/tesla/values.py index fb018006..0acd3912 100644 --- a/opendbc/car/tesla/values.py +++ b/opendbc/car/tesla/values.py @@ -1,7 +1,7 @@ from dataclasses import dataclass, field from enum import Enum, IntFlag -from opendbc.car import ACCELERATION_DUE_TO_GRAVITY, Bus, CarSpecs, DbcDict, PlatformConfig, Platforms -from opendbc.car.lateral import AngleSteeringLimits, ISO_LATERAL_ACCEL +from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms +from opendbc.car.lateral import AngleSteeringLimitsVM from opendbc.car.structs import CarParams, CarState from opendbc.car.docs_definitions import CarDocs, CarFootnote, CarHarness, CarParts, Column from opendbc.car.fw_query_definitions import FwQueryConfig, Request, StdQueries @@ -106,23 +106,10 @@ GEAR_MAP = { } -# Add extra tolerance for average banked road since safety doesn't have the roll -AVERAGE_ROAD_ROLL = 0.06 # ~3.4 degrees, 6% superelevation. higher actual roll lowers lateral acceleration - - class CarControllerParams: - ANGLE_LIMITS: AngleSteeringLimits = AngleSteeringLimits( + ANGLE_LIMITS: AngleSteeringLimitsVM = AngleSteeringLimitsVM( # EPAS faults above this angle 360, # deg - # Tesla uses a vehicle model instead, check carcontroller.py for details - ([], []), - ([], []), - - # Vehicle model angle limits - # Add extra tolerance for average banked road since safety doesn't have the roll - MAX_LATERAL_ACCEL=ISO_LATERAL_ACCEL + (ACCELERATION_DUE_TO_GRAVITY * AVERAGE_ROAD_ROLL), # ~3.6 m/s^2 - MAX_LATERAL_JERK=3.0 + (ACCELERATION_DUE_TO_GRAVITY * AVERAGE_ROAD_ROLL), # ~3.6 m/s^3 - # limit angle rate to both prevent a fault and for low speed comfort (~12 mph rate down to 0 mph) MAX_ANGLE_RATE=5, # deg/20ms frame, EPS faults at 12 at a standstill )