mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-08-22 00:33:48 +08:00
Toyota Long Enhancement: Allow 5 km/h (5 mph) speed increments
This commit is contained in:
@@ -128,6 +128,7 @@ BO_ 742 LEAD_INFO: 8 DSU
|
||||
|
||||
BO_ 835 ACC_CONTROL: 8 DSU
|
||||
SG_ ACCEL_CMD : 7|16@0- (0.001,0) [-20|20] "m/s2" HCU
|
||||
SG_ ALLOW_LONG_PRESS : 17|2@0+ (1,0) [0|2] "" XXX
|
||||
SG_ ACC_TYPE : 23|2@0+ (1,0) [0|3] "" HCU
|
||||
SG_ DISTANCE : 20|1@0+ (1,0) [0|1] "" XXX
|
||||
SG_ MINI_CAR : 21|1@0+ (1,0) [0|1] "" XXX
|
||||
@@ -317,6 +318,7 @@ CM_ SG_ 643 COUNTER "only used on cars that use this msg for cruise control";
|
||||
CM_ SG_ 643 BRAKE_STATUS "only used on cars that use this msg for cruise control";
|
||||
CM_ SG_ 643 PRECOLLISION_ACTIVE "set 0.5s before any braking";
|
||||
CM_ SG_ 835 ACC_TYPE "if 2, car is likely to have a permanent low speed lockout. 1 is ok";
|
||||
CM_ SG_ 835 ALLOW_LONG_PRESS "Enable Toyota's factory set speed increment behaviour, available on both metrics cars and imperial unit cars";
|
||||
CM_ SG_ 835 PERMIT_BRAKING "Original ACC has this going high when a car in front is detected. In openpilot and before the PERMIT_BRAKING name, this was 'SET_ME_1' and is hardcoded to be high. Unsure if only informational or has an effect though existing usage in openpilot is to always set it to 1. Originally 'PMTBRKG' in the leaked toyota_2017_ref_pt.dbc file and name expansion speculated to be PerMiT BRaKinG.";
|
||||
CM_ SG_ 835 ACCEL_CMD_ALT "Copy of main ACCEL_CMD, but across 8 bits instead of 16 bits like ACCEL_CMD. Unsure if only informational or has an effect. Likely informational as existing openpilot sets this to 0 and no loss of functionality observed. Originally 'AT_RAW' in leaked toyota_2017_ref_pt.dbc file.";
|
||||
CM_ SG_ 921 UI_SET_SPEED "set speed shown in UI with user set unit";
|
||||
@@ -345,6 +347,7 @@ VAL_ 614 STATE 3 "enabled" 1 "disabled";
|
||||
VAL_ 614 DIRECTION_CMD 3 "right" 2 "center" 1 "left";
|
||||
VAL_ 643 STATE 0 "normal" 1 "adaptive_cruise_control" 3 "emergency_braking";
|
||||
VAL_ 835 ACC_TYPE 2 "permanent low speed lockout" 1 "ok";
|
||||
VAL_ 835 ALLOW_LONG_PRESS 2 "set speed increase by 5 speed units regardless" 1 "set speed increase by 1 speed unit on short press, 5 speed units on long press";
|
||||
VAL_ 921 CRUISE_CONTROL_STATE 2 "disabled" 11 "hold" 10 "hold_waiting_user_cmd" 6 "enabled" 5 "faulted";
|
||||
VAL_ 956 SPORT_ON 0 "off" 1 "on";
|
||||
VAL_ 956 ECON_ON 0 "off" 1 "on";
|
||||
|
||||
@@ -35,10 +35,11 @@ def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_ty
|
||||
"ACC_TYPE": acc_type,
|
||||
"DISTANCE": distance,
|
||||
"MINI_CAR": lead,
|
||||
"SET_ME_X3": 3,
|
||||
#"SET_ME_X3": 3,
|
||||
"PERMIT_BRAKING": 1,
|
||||
"RELEASE_STANDSTILL": not standstill_req,
|
||||
"CANCEL_REQ": pcm_cancel,
|
||||
"ALLOW_LONG_PRESS": 1,
|
||||
}
|
||||
return packer.make_can_msg("ACC_CONTROL", 0, values)
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ Desire = log.LateralPlan.Desire
|
||||
LaneChangeState = log.LateralPlan.LaneChangeState
|
||||
LaneChangeDirection = log.LateralPlan.LaneChangeDirection
|
||||
EventName = car.CarEvent.EventName
|
||||
|
||||
ButtonEvent = car.CarState.ButtonEvent
|
||||
|
||||
class Controls:
|
||||
def __init__(self, sm=None, pm=None, can_sock=None):
|
||||
@@ -158,6 +158,7 @@ class Controls:
|
||||
self.logged_comm_issue = False
|
||||
self.v_target = 0.0
|
||||
self.a_target = 0.0
|
||||
self.button_timers = {ButtonEvent.Type.decelCruise: 0, ButtonEvent.Type.accelCruise: 0}
|
||||
|
||||
self.led_state = False
|
||||
self.led_state_prev = False
|
||||
@@ -386,7 +387,7 @@ class Controls:
|
||||
|
||||
# if stock cruise is completely disabled, then we can use our own set speed logic
|
||||
if not self.CP.pcmCruise:
|
||||
self.v_cruise_kph = update_v_cruise(self.v_cruise_kph, CS.buttonEvents, self.enabled)
|
||||
self.v_cruise_kph = update_v_cruise(self.v_cruise_kph, CS.buttonEvents, self.button_timers, self.enabled, self.is_metric)
|
||||
elif self.CP.pcmCruise and CS.cruiseState.enabled:
|
||||
self.v_cruise_kph = CS.cruiseState.speed * CV.MS_TO_KPH
|
||||
|
||||
@@ -544,6 +545,16 @@ class Controls:
|
||||
|
||||
return actuators, lac_log
|
||||
|
||||
def update_button_timers(self, buttonEvents):
|
||||
# increment timer for buttons still pressed
|
||||
for k in self.button_timers.keys():
|
||||
if self.button_timers[k] > 0:
|
||||
self.button_timers[k] += 1
|
||||
|
||||
for b in buttonEvents:
|
||||
if b.type.raw in self.button_timers:
|
||||
self.button_timers[b.type.raw] = 1 if b.pressed else 0
|
||||
|
||||
def publish_logs(self, CS, start_time, actuators, lac_log):
|
||||
"""Send actuators and hud commands to the car, send controlsstate and MPC logging"""
|
||||
|
||||
@@ -717,6 +728,8 @@ class Controls:
|
||||
self.publish_logs(CS, start_time, actuators, lac_log)
|
||||
self.prof.checkpoint("Sent")
|
||||
|
||||
self.update_button_timers(CS.buttonEvents)
|
||||
|
||||
def controlsd_thread(self):
|
||||
while True:
|
||||
self.step()
|
||||
|
||||
@@ -3,7 +3,7 @@ from common.numpy_fast import clip, interp
|
||||
from common.realtime import DT_MDL
|
||||
from selfdrive.config import Conversions as CV
|
||||
from selfdrive.modeld.constants import T_IDXS
|
||||
|
||||
import math
|
||||
|
||||
# kph
|
||||
V_CRUISE_MAX = 135
|
||||
@@ -19,6 +19,18 @@ CAR_ROTATION_RADIUS = 0.0
|
||||
MAX_CURVATURE_RATES = [0.03762194918267951, 0.003441203371932992]
|
||||
MAX_CURVATURE_RATE_SPEEDS = [0, 35]
|
||||
|
||||
CRUISE_LONG_PRESS = 50
|
||||
CRUISE_NEAREST_FUNC = {
|
||||
car.CarState.ButtonEvent.Type.accelCruise: math.ceil,
|
||||
car.CarState.ButtonEvent.Type.decelCruise: math.floor,
|
||||
}
|
||||
CRUISE_INTERVAL_SIGN = {
|
||||
car.CarState.ButtonEvent.Type.accelCruise: +1,
|
||||
car.CarState.ButtonEvent.Type.decelCruise: -1,
|
||||
}
|
||||
|
||||
CRUISE_CONFORT_DECEL = -1. # Confortable deceleration for cruise.
|
||||
|
||||
# Constants for Limit controllers.
|
||||
LIMIT_ADAPT_ACC = -0.6 # (closer to zero ealier it decel) m/s^2 Ideal acceleration for the adapting (braking) phase when approaching speed limits.
|
||||
LIMIT_MIN_ACC = -1.0 # m/s^2 Maximum deceleration allowed for limit controllers to provide.
|
||||
@@ -48,17 +60,37 @@ def rate_limit(new_value, last_value, dw_step, up_step):
|
||||
def get_steer_max(CP, v_ego):
|
||||
return interp(v_ego, CP.steerMaxBP, CP.steerMaxV)
|
||||
|
||||
|
||||
def update_v_cruise(v_cruise_kph, buttonEvents, enabled):
|
||||
def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric):
|
||||
# handle button presses. TODO: this should be in state_control, but a decelCruise press
|
||||
# would have the effect of both enabling and changing speed is checked after the state transition
|
||||
if not enabled:
|
||||
return v_cruise_kph
|
||||
|
||||
long_press = False
|
||||
button_type = None
|
||||
|
||||
v_cruise_delta = 1 if metric else 1.6
|
||||
|
||||
for b in buttonEvents:
|
||||
if enabled and not b.pressed:
|
||||
if b.type == car.CarState.ButtonEvent.Type.accelCruise:
|
||||
v_cruise_kph += V_CRUISE_DELTA - (v_cruise_kph % V_CRUISE_DELTA)
|
||||
elif b.type == car.CarState.ButtonEvent.Type.decelCruise:
|
||||
v_cruise_kph -= V_CRUISE_DELTA - ((V_CRUISE_DELTA - v_cruise_kph) % V_CRUISE_DELTA)
|
||||
v_cruise_kph = clip(v_cruise_kph, V_CRUISE_MIN, V_CRUISE_MAX)
|
||||
if b.type.raw in button_timers and not b.pressed:
|
||||
if button_timers[b.type.raw] > CRUISE_LONG_PRESS:
|
||||
return v_cruise_kph # end long press
|
||||
button_type = b.type.raw
|
||||
break
|
||||
else:
|
||||
for k in button_timers.keys():
|
||||
if button_timers[k] and button_timers[k] % CRUISE_LONG_PRESS == 0:
|
||||
button_type = k
|
||||
long_press = True
|
||||
break
|
||||
|
||||
if button_type:
|
||||
v_cruise_delta = v_cruise_delta * (5 if long_press else 1)
|
||||
if long_press and v_cruise_kph % v_cruise_delta != 0: # partial interval
|
||||
v_cruise_kph = CRUISE_NEAREST_FUNC[button_type](v_cruise_kph / v_cruise_delta) * v_cruise_delta
|
||||
else:
|
||||
v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type]
|
||||
v_cruise_kph = clip(round(v_cruise_kph, 1), V_CRUISE_MIN, V_CRUISE_MAX)
|
||||
|
||||
return v_cruise_kph
|
||||
|
||||
|
||||
Reference in New Issue
Block a user