Skip to content

Commit 3532ed5

Browse files
committed
Fix: Pedal unit logic and honda behaviour
1 parent bfb3d98 commit 3532ed5

File tree

4 files changed

+69
-15
lines changed

4 files changed

+69
-15
lines changed

selfdrive/car/honda/carcontroller.py

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def update(self, enabled, CS, frame, actuators,
129129
# send pcm acc cancel cmd if drive is disabled but pcm is still on, or if the system can't be activated
130130
pcm_cancel_cmd = True
131131

132+
# Never send cancel command if we never enter cruise state (no cruise if pedal)
133+
# Cancel cmd causes brakes to release at a standstill causing grinding
134+
pcm_cancel_cmd = pcm_cancel_cmd and CS.CP.pcmCruise
135+
132136
# *** rate limit after the enable check ***
133137
self.brake_last = rate_limit(pre_limit_brake, self.brake_last, -2., DT_CTRL)
134138

selfdrive/car/honda/interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]): # py
8787
ret.enableGasInterceptor = 0x201 in fingerprint[0]
8888
ret.openpilotLongitudinalControl = True
8989

90-
ret.pcmCruise = True
90+
ret.pcmCruise = not ret.enableGasInterceptor
9191
ret.communityFeature = ret.enableGasInterceptor
9292

9393
if candidate == CAR.CRV_5G:

selfdrive/controls/controlsd.py

+45-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class Controls:
5454
def __init__(self, sm=None, pm=None, can_sock=None):
5555
config_realtime_process(4 if TICI else 3, Priority.CTRL_HIGH)
5656

57+
self.accel_pressed = False
58+
self.decel_pressed = False
59+
self.accel_pressed_last = 0.
60+
self.decel_pressed_last = 0.
61+
self.fastMode = False
62+
5763
# Setup sockets
5864
self.pm = pm
5965
if self.pm is None:
@@ -140,6 +146,7 @@ def __init__(self, sm=None, pm=None, can_sock=None):
140146
self.soft_disable_timer = 0
141147
self.v_cruise_kph = 255
142148
self.v_cruise_kph_last = 0
149+
self.cruiseState_enabled_last = False
143150
self.mismatch_counter = 0
144151
self.can_error_counter = 0
145152
self.last_blinker_frame = 0
@@ -365,9 +372,34 @@ def state_transition(self, CS):
365372

366373
self.v_cruise_kph_last = self.v_cruise_kph
367374

375+
cur_time = self.sm.frame * DT_CTRL
376+
368377
# if stock cruise is completely disabled, then we can use our own set speed logic
369378
if not self.CP.pcmCruise:
370-
self.v_cruise_kph = update_v_cruise(self.v_cruise_kph, CS.buttonEvents, self.enabled)
379+
for b in CS.buttonEvents:
380+
if b.pressed:
381+
if b.type == car.CarState.ButtonEvent.Type.accelCruise:
382+
self.accel_pressed = True
383+
self.accel_pressed_last = cur_time
384+
elif b.type == car.CarState.ButtonEvent.Type.decelCruise:
385+
self.decel_pressed = True
386+
self.decel_pressed_last = cur_time
387+
else:
388+
if b.type == car.CarState.ButtonEvent.Type.accelCruise:
389+
self.accel_pressed = False
390+
elif b.type == car.CarState.ButtonEvent.Type.decelCruise:
391+
self.decel_pressed = False
392+
393+
self.v_cruise_kph = update_v_cruise(self.v_cruise_kph if self.is_metric else int(round((float(self.v_cruise_kph) * 0.6233 + 0.0995))), CS.buttonEvents, self.enabled and CS.cruiseState.enabled, cur_time, self.accel_pressed,self.decel_pressed, self.accel_pressed_last,self.decel_pressed_last,self.fastMode)
394+
self.v_cruise_kph = self.v_cruise_kph if self.is_metric else int(round((float(round(self.v_cruise_kph))-0.0995)/0.6233))
395+
396+
if(self.accel_pressed or self.decel_pressed):
397+
if self.v_cruise_kph_last != self.v_cruise_kph:
398+
self.accel_pressed_last = cur_time
399+
self.decel_pressed_last = cur_time
400+
self.fastMode = True
401+
else:
402+
self.fastMode = False
371403
elif self.CP.pcmCruise and CS.cruiseState.enabled:
372404
self.v_cruise_kph = CS.cruiseState.speed * CV.MS_TO_KPH
373405

@@ -427,7 +459,17 @@ def state_transition(self, CS):
427459
else:
428460
self.state = State.enabled
429461
self.current_alert_types.append(ET.ENABLE)
430-
self.v_cruise_kph = initialize_v_cruise(CS.vEgo, CS.buttonEvents, self.v_cruise_kph_last)
462+
if not self.CP.pcmCruise:
463+
if CS.cruiseState.enabled:
464+
self.v_cruise_kph = initialize_v_cruise(CS.vEgo, CS.buttonEvents, self.v_cruise_kph_last)
465+
else:
466+
self.v_cruise_kph = initialize_v_cruise(CS.vEgo, CS.buttonEvents, self.v_cruise_kph_last)
467+
468+
if not self.CP.pcmCruise:
469+
if CS.cruiseState.enabled and not self.cruiseState_enabled_last:
470+
self.v_cruise_kph = initialize_v_cruise(CS.vEgo, CS.buttonEvents, self.v_cruise_kph_last)
471+
472+
self.cruiseState_enabled_last = CS.cruiseState.enabled
431473

432474
# Check if actuators are enabled
433475
self.active = self.state == State.enabled or self.state == State.softDisabling
@@ -541,7 +583,7 @@ def publish_logs(self, CS, start_time, actuators, lac_log):
541583
CC.cruiseControl.accelOverride = float(self.CI.calc_accel_override(CS.aEgo, self.a_target,
542584
CS.vEgo, self.v_target))
543585

544-
CC.hudControl.setSpeed = float(self.v_cruise_kph * CV.KPH_TO_MS)
586+
CC.hudControl.setSpeed = float(self.v_cruise_kph) * CV.KPH_TO_MS
545587
CC.hudControl.speedVisible = self.enabled
546588
CC.hudControl.lanesVisible = self.enabled
547589
CC.hudControl.leadVisible = self.sm['longitudinalPlan'].hasLead

selfdrive/controls/lib/drive_helpers.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
# kph
99
V_CRUISE_MAX = 135
10-
V_CRUISE_MIN = 8
11-
V_CRUISE_DELTA = 8
10+
V_CRUISE_MIN = 5
11+
V_CRUISE_DELTA = 5
1212
V_CRUISE_ENABLE_MIN = 40
1313
LAT_MPC_N = 16
1414
LON_MPC_N = 32
@@ -39,17 +39,25 @@ def rate_limit(new_value, last_value, dw_step, up_step):
3939
def get_steer_max(CP, v_ego):
4040
return interp(v_ego, CP.steerMaxBP, CP.steerMaxV)
4141

42-
43-
def update_v_cruise(v_cruise_kph, buttonEvents, enabled):
44-
# handle button presses. TODO: this should be in state_control, but a decelCruise press
45-
# would have the effect of both enabling and changing speed is checked after the state transition
46-
for b in buttonEvents:
47-
if enabled and not b.pressed:
48-
if b.type == car.CarState.ButtonEvent.Type.accelCruise:
42+
def update_v_cruise(v_cruise_kph, buttonEvents, enabled, cur_time, accel_pressed,decel_pressed,accel_pressed_last,decel_pressed_last, fastMode):
43+
44+
if enabled:
45+
if accel_pressed:
46+
if ((cur_time-accel_pressed_last) >= 1 or (fastMode and (cur_time-accel_pressed_last) >= 0.5)):
4947
v_cruise_kph += V_CRUISE_DELTA - (v_cruise_kph % V_CRUISE_DELTA)
50-
elif b.type == car.CarState.ButtonEvent.Type.decelCruise:
48+
elif decel_pressed:
49+
if ((cur_time-decel_pressed_last) >= 1 or (fastMode and (cur_time-decel_pressed_last) >= 0.5)):
5150
v_cruise_kph -= V_CRUISE_DELTA - ((V_CRUISE_DELTA - v_cruise_kph) % V_CRUISE_DELTA)
52-
v_cruise_kph = clip(v_cruise_kph, V_CRUISE_MIN, V_CRUISE_MAX)
51+
else:
52+
for b in buttonEvents:
53+
if not b.pressed:
54+
if b.type == car.CarState.ButtonEvent.Type.accelCruise:
55+
if (not fastMode):
56+
v_cruise_kph += 1
57+
elif b.type == car.CarState.ButtonEvent.Type.decelCruise:
58+
if (not fastMode):
59+
v_cruise_kph -= 1
60+
v_cruise_kph = clip(v_cruise_kph, V_CRUISE_MIN, V_CRUISE_MAX)
5361

5462
return v_cruise_kph
5563

0 commit comments

Comments
 (0)