Revert "Deadband lateral jerk before friction compensation"

This reverts commit 9e68801db0.
This commit is contained in:
rav4kumar
2026-07-21 15:13:31 -07:00
parent 2c162b1a14
commit 8aa23cfed5
7 changed files with 11 additions and 127 deletions
-1
View File
@@ -283,7 +283,6 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
// Torque lateral control custom params
{"CustomTorqueParams", {PERSISTENT | BACKUP , BOOL}},
{"EnforceTorqueControl", {PERSISTENT | BACKUP, BOOL}},
{"FrictionJerkDeadzoneEnabled", {PERSISTENT | BACKUP, BOOL, "0"}},
{"LiveTorqueParamsToggle", {PERSISTENT | BACKUP , BOOL}},
{"LiveTorqueParamsRelaxedToggle", {PERSISTENT | BACKUP , BOOL}},
{"TorqueControlTune", {PERSISTENT | BACKUP, FLOAT, "0.0"}},
+1 -2
View File
@@ -84,12 +84,11 @@ class LatControlTorque(LatControl):
lookahead_idx = int(np.clip(-delay_frames + self.lookahead_frames, -self.lat_accel_request_buffer_len+1, -2))
raw_lateral_jerk = (self.lat_accel_request_buffer[lookahead_idx+1] - self.lat_accel_request_buffer[lookahead_idx-1]) / (2 * self.dt)
desired_lateral_jerk = self.jerk_filter.update(raw_lateral_jerk)
friction_jerk = self.extension.get_friction_jerk(desired_lateral_jerk)
gravity_adjusted_future_lateral_accel = future_desired_lateral_accel - roll_compensation
ff = gravity_adjusted_future_lateral_accel
# latAccelOffset corrects roll compensation bias from device roll misalignment relative to car roll
ff -= self.torque_params.latAccelOffset
ff += get_friction(error + JERK_GAIN * friction_jerk, lateral_accel_deadzone, FRICTION_THRESHOLD, self.torque_params)
ff += get_friction(error + JERK_GAIN * desired_lateral_jerk, lateral_accel_deadzone, FRICTION_THRESHOLD, self.torque_params)
if not active:
output_torque = 0.0
@@ -5,19 +5,8 @@ This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
import math
from openpilot.common.params import Params
# Planner-replan jitter shows up as small nonzero desired_lateral_jerk even on a straight
# road with a near-zero lateral accel error. Fed into get_friction() that noise still
# clears the (much smaller, sensor-deadzone-sized) lateral_accel_deadzone and comes out
# as a real friction-compensation torque command, i.e. chatter with no steering need
# behind it. Deadbanding the jerk itself (not the combined error) kills that noise floor
# while leaving real jerk (an actual curve entry or lane change, an order of magnitude
# larger) essentially unaffected.
FRICTION_JERK_DEADZONE = 0.3 # m/s^3
class LatControlTorqueExtOverride:
def __init__(self, CP):
@@ -25,15 +14,8 @@ class LatControlTorqueExtOverride:
self.params = Params()
self.enforce_torque_control_toggle = self.params.get_bool("EnforceTorqueControl") # only during init
self.torque_override_enabled = self.params.get_bool("TorqueParamsOverrideEnabled")
self.friction_jerk_deadzone_enabled = self.params.get_bool("FrictionJerkDeadzoneEnabled")
self.frame = -1
def get_friction_jerk(self, desired_lateral_jerk: float) -> float:
if not self.friction_jerk_deadzone_enabled:
return desired_lateral_jerk
return math.copysign(max(abs(desired_lateral_jerk) - FRICTION_JERK_DEADZONE, 0.0), desired_lateral_jerk)
def update_override_torque_params(self, torque_params) -> bool:
if not self.enforce_torque_control_toggle:
return False
@@ -1,42 +0,0 @@
"""
Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
from openpilot.sunnypilot.selfdrive.controls.lib.latcontrol_torque_ext_override import (
FRICTION_JERK_DEADZONE, LatControlTorqueExtOverride,
)
class TestLatControlTorqueExtOverrideFrictionJerkDeadzone:
def setup_method(self):
self.override = LatControlTorqueExtOverride(None)
def test_disabled_by_default(self):
assert self.override.friction_jerk_deadzone_enabled is False
def test_disabled_is_passthrough(self):
self.override.friction_jerk_deadzone_enabled = False
for jerk in (0.0, 0.05, -0.05, FRICTION_JERK_DEADZONE, -FRICTION_JERK_DEADZONE, 2.0, -2.0):
assert self.override.get_friction_jerk(jerk) == jerk
def test_enabled_kills_jerk_below_deadzone(self):
self.override.friction_jerk_deadzone_enabled = True
for jerk in (0.0, 0.05, -0.05, 0.29, -0.29):
assert self.override.get_friction_jerk(jerk) == 0.0
def test_enabled_boundary_at_deadzone(self):
self.override.friction_jerk_deadzone_enabled = True
assert self.override.get_friction_jerk(FRICTION_JERK_DEADZONE) == 0.0
assert self.override.get_friction_jerk(-FRICTION_JERK_DEADZONE) == 0.0
def test_enabled_shifts_jerk_above_deadzone_preserving_sign(self):
self.override.friction_jerk_deadzone_enabled = True
assert self.override.get_friction_jerk(2.0) == 2.0 - FRICTION_JERK_DEADZONE
assert self.override.get_friction_jerk(-2.0) == -(2.0 - FRICTION_JERK_DEADZONE)
+10 -14
View File
@@ -332,10 +332,6 @@
"title": "Force Power Down",
"description": ""
},
"FrictionJerkDeadzoneEnabled": {
"title": "Reduce Friction Torque Chatter",
"description": "Ignores small, short-lived steering jerk from planner noise when computing friction compensation, reducing steering chatter on straight roads. Does not change torque during real turns or lane changes."
},
"GitBranch": {
"title": "Git Branch",
"description": ""
@@ -1354,11 +1350,19 @@
"step": 0.1,
"unit": "m/s\u00b2"
},
"ToyotaAutoHold": {
"ToyotaAutoHold": {
"title": "Toyota: Auto Brake Hold FOR TSS2 HYBRID CARS",
"description": ""
},
"ToyotaDriveMode": {
"ToyotaEnhancedBsm": {
"title": "Toyota: Prius TSS2 BSM and some tssp",
"description": ""
},
"ToyotaTSS2Long": {
"title": "Toyota: custom longitudinal for TSS2",
"description": ""
},
"ToyotaDriveMode": {
"title": "Enable drive mode btn link",
"description": ""
},
@@ -1366,18 +1370,10 @@
"title": "Toyota: Enforce Factory Longitudinal Control",
"description": "When enabled, sunnypilot will not take over control of gas and brakes. Factory Toyota longitudinal control will be used."
},
"ToyotaEnhancedBsm": {
"title": "Toyota: Prius TSS2 BSM and some tssp",
"description": ""
},
"ToyotaStopAndGoHack": {
"title": "Toyota: Stop and Go Hack (Alpha)",
"description": "sunnypilot will allow some Toyota/Lexus cars to auto resume during stop and go traffic. This feature is only applicable to certain models that are able to use longitudinal control. This is an alpha feature. Use at your own risk."
},
"ToyotaTSS2Long": {
"title": "Toyota: custom longitudinal for TSS2",
"description": ""
},
"TrainingVersion": {
"title": "Training Version",
"description": ""
-31
View File
@@ -310,37 +310,6 @@
"equals": false
}
]
},
{
"key": "FrictionJerkDeadzoneEnabled",
"widget": "toggle",
"title": "Reduce Friction Torque Chatter",
"description": "Ignores small, short-lived steering jerk from planner noise when computing friction compensation, reducing steering chatter on straight roads. Does not change torque during real turns or lane changes.",
"visibility": [
{
"type": "not",
"condition": {
"type": "capability",
"field": "steer_control_type",
"equals": "angle"
}
}
],
"enablement": [
{
"type": "offroad_only"
},
{
"type": "capability",
"field": "torque_allowed",
"equals": true
},
{
"type": "param",
"key": "NeuralNetworkLateralControl",
"equals": false
}
]
}
],
"sub_panels": [
@@ -118,25 +118,6 @@ sections:
- type: param
key: NeuralNetworkLateralControl
equals: false
- key: FrictionJerkDeadzoneEnabled
widget: toggle
title: Reduce Friction Torque Chatter
description: Ignores small, short-lived steering jerk from planner noise when computing friction compensation, reducing
steering chatter on straight roads. Does not change torque during real turns or lane changes.
visibility:
- type: not
condition:
type: capability
field: steer_control_type
equals: angle
enablement:
- $ref: '#/macros/offroad'
- type: capability
field: torque_allowed
equals: true
- type: param
key: NeuralNetworkLateralControl
equals: false
sub_panels:
- id: torque_settings
label: Torque Settings