Skip to content

Commit 288f954

Browse files
committed
Refine torque ramp-down logic for user overrides.
Introduced an adaptive ramp-down rate based on the torque difference and defined a fixed number of override cycles. This ensures a smoother and more controlled reduction to minimum torque when overriding steering torque.
1 parent ccb9ef0 commit 288f954

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

opendbc/car/hyundai/carcontroller.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ def update(self, CC, CC_SP, CS, now_nanos):
9595
# but this is a single threshold for simplicity. It also matches the stock system behavior.
9696
USER_OVERRIDING = abs(CS.out.steeringTorque) > self.params.STEER_THRESHOLD
9797
NEAR_CENTER_ANGLE = 3.0 # Threshold in degrees to consider "near center"
98+
OVERRIDE_CYCLES = 20 # Number of cycles to ramp down to minimum
9899

99100
if USER_OVERRIDING:
100-
# When the user is overriding, ramp down to the absolute minimum torque.
101-
self.lkas_max_torque = max(self.lkas_max_torque - self.params.ANGLE_TORQUE_DOWN_RATE, self.params.ANGLE_MIN_TORQUE)
101+
# When the user is overriding, calculate a ramp-down rate that will reach minimum torque in OVERRIDE_CYCLES
102+
torque_delta = self.lkas_max_torque - self.params.ANGLE_MIN_TORQUE
103+
adaptive_ramp_rate = max(torque_delta / OVERRIDE_CYCLES, 1) # Ensure we move at least 1 unit per cycle
104+
self.lkas_max_torque = max(self.lkas_max_torque - adaptive_ramp_rate, self.params.ANGLE_MIN_TORQUE)
102105
else:
103106
# Calculate target torque based on current speed
104107
speed_range = [0, 5.5] # Speed threshold for reduced torque effect

0 commit comments

Comments
 (0)