Skip to content

Commit 18cabb5

Browse files
authored
Ford: longitudinal clean up (#28231)
clean ups old-commit-hash: c7d3b28
1 parent c5d45e7 commit 18cabb5

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

selfdrive/car/ford/carcontroller.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,14 @@ def update(self, CC, CS, now_nanos):
8282
### longitudinal control ###
8383
# send acc msg at 50Hz
8484
if self.CP.openpilotLongitudinalControl and (self.frame % CarControllerParams.ACC_CONTROL_STEP) == 0:
85+
# Both gas and accel are in m/s^2, accel is used solely for braking
8586
accel = clip(actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX)
86-
8787
gas = accel
88-
decel = accel < 0.0
89-
if accel < -0.5:
90-
gas = -5.0
88+
if not CC.longActive or gas < CarControllerParams.MIN_GAS:
89+
gas = CarControllerParams.INACTIVE_GAS
9190

9291
stopping = CC.actuators.longControlState == LongCtrlState.stopping
93-
can_sends.append(create_acc_msg(self.packer, CC.longActive, gas, accel, decel, stopping))
92+
can_sends.append(create_acc_msg(self.packer, CC.longActive, gas, accel, stopping))
9493

9594
### ui ###
9695
send_ui = (self.main_on_last != main_on) or (self.lkas_enabled_last != CC.latActive) or (self.steer_alert_last != steer_alert)

selfdrive/car/ford/fordcan.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def create_lat_ctl2_msg(packer, mode: int, path_offset: float, path_angle: float
101101
return packer.make_can_msg("LateralMotionControl2", CANBUS.main, values)
102102

103103

104-
def create_acc_msg(packer, long_active: bool, gas: float, accel: float, decel: bool, stopping: bool):
104+
def create_acc_msg(packer, long_active: bool, gas: float, accel: float, stopping: bool):
105105
"""
106106
Creates a CAN message for the Ford ACC Command.
107107
@@ -111,11 +111,13 @@ def create_acc_msg(packer, long_active: bool, gas: float, accel: float, decel: b
111111
Frequency is 50Hz.
112112
"""
113113

114+
decel = accel < 0 and long_active
114115
values = {
115116
"AccBrkTot_A_Rq": accel, # Brake total accel request: [-20|11.9449] m/s^2
116117
"Cmbb_B_Enbl": 1 if long_active else 0, # Enabled: 0=No, 1=Yes
117118
"AccPrpl_A_Rq": gas, # Acceleration request: [-5|5.23] m/s^2
118119
"AccResumEnbl_B_Rq": 1 if long_active else 0,
120+
# TODO: we may be able to improve braking response by utilizing pre-charging better
119121
"AccBrkPrchg_B_Rq": 1 if decel else 0, # Pre-charge brake request: 0=No, 1=Yes
120122
"AccBrkDecel_B_Rq": 1 if decel else 0, # Deceleration request: 0=Inactive, 1=Active
121123
"AccStopStat_B_Rq": 1 if stopping else 0,

selfdrive/car/ford/values.py

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class CarControllerParams:
3131

3232
ACCEL_MAX = 2.0 # m/s^s max acceleration
3333
ACCEL_MIN = -3.5 # m/s^s max deceleration
34+
MIN_GAS = -0.5
35+
INACTIVE_GAS = -5.0
3436

3537
def __init__(self, CP):
3638
pass

0 commit comments

Comments
 (0)