Skip to content

Commit 588464d

Browse files
authored
car: common update_steering_pressed (#1774)
* common update_steering_pressed * simplify * clean up
1 parent 3ac03cb commit 588464d

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

opendbc/car/interfaces.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ def update_blinker_from_lamp(self, blinker_time: int, left_blinker_lamp: bool, r
321321

322322
def update_steering_pressed(self, steering_pressed, steering_pressed_min_count):
323323
"""Applies filtering on steering pressed for noisy driver torque signals."""
324-
self.steering_pressed_cnt += 1 if steering_pressed else -1
325-
self.steering_pressed_cnt = float(np.clip(self.steering_pressed_cnt, 0, steering_pressed_min_count * 2))
324+
self.steering_pressed_cnt = self.steering_pressed_cnt + 1 if steering_pressed else 0
325+
self.steering_pressed_cnt = min(self.steering_pressed_cnt, steering_pressed_min_count + 1)
326326
return self.steering_pressed_cnt > steering_pressed_min_count
327327

328328
def update_blinker_from_stalk(self, blinker_time: int, left_blinker_stalk: bool, right_blinker_stalk: bool):

opendbc/car/tesla/carstate.py

-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import copy
2-
import numpy as np
32
from opendbc.can.can_define import CANDefine
43
from opendbc.can.parser import CANParser
54
from opendbc.car import Bus, structs
@@ -19,13 +18,6 @@ def __init__(self, CP):
1918
self.hands_on_level = 0
2019
self.das_control = None
2120

22-
def update_steering_pressed(self, steering_pressed, steering_pressed_min_count):
23-
"""Applies filtering on steering pressed for noisy driver torque signals."""
24-
# TODO: this differs from the base implementation by resetting the counter to 0 immediately, unify this
25-
self.steering_pressed_cnt = self.steering_pressed_cnt + 1 if steering_pressed else 0
26-
self.steering_pressed_cnt = float(np.clip(self.steering_pressed_cnt, 0, steering_pressed_min_count * 2))
27-
return self.steering_pressed_cnt > steering_pressed_min_count
28-
2921
def update(self, can_parsers) -> structs.CarState:
3022
cp_party = can_parsers[Bus.party]
3123
cp_ap_party = can_parsers[Bus.ap_party]

0 commit comments

Comments
 (0)