@@ -54,6 +54,12 @@ class Controls:
54
54
def __init__ (self , sm = None , pm = None , can_sock = None ):
55
55
config_realtime_process (4 if TICI else 3 , Priority .CTRL_HIGH )
56
56
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
+
57
63
# Setup sockets
58
64
self .pm = pm
59
65
if self .pm is None :
@@ -140,6 +146,7 @@ def __init__(self, sm=None, pm=None, can_sock=None):
140
146
self .soft_disable_timer = 0
141
147
self .v_cruise_kph = 255
142
148
self .v_cruise_kph_last = 0
149
+ self .cruiseState_enabled_last = False
143
150
self .mismatch_counter = 0
144
151
self .can_error_counter = 0
145
152
self .last_blinker_frame = 0
@@ -365,9 +372,34 @@ def state_transition(self, CS):
365
372
366
373
self .v_cruise_kph_last = self .v_cruise_kph
367
374
375
+ cur_time = self .sm .frame * DT_CTRL
376
+
368
377
# if stock cruise is completely disabled, then we can use our own set speed logic
369
378
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
371
403
elif self .CP .pcmCruise and CS .cruiseState .enabled :
372
404
self .v_cruise_kph = CS .cruiseState .speed * CV .MS_TO_KPH
373
405
@@ -427,7 +459,17 @@ def state_transition(self, CS):
427
459
else :
428
460
self .state = State .enabled
429
461
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
431
473
432
474
# Check if actuators are enabled
433
475
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):
541
583
CC .cruiseControl .accelOverride = float (self .CI .calc_accel_override (CS .aEgo , self .a_target ,
542
584
CS .vEgo , self .v_target ))
543
585
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
545
587
CC .hudControl .speedVisible = self .enabled
546
588
CC .hudControl .lanesVisible = self .enabled
547
589
CC .hudControl .leadVisible = self .sm ['longitudinalPlan' ].hasLead
0 commit comments