Compare commits

...

13 Commits

Author SHA1 Message Date
Jason Wen 6263d353ca stopping behind lead is actually consistent now! 2024-07-27 01:32:07 -04:00
Jason Wen 40a001a9f8 handle stopAccel = 0 2024-07-27 00:26:21 -04:00
Jason Wen da2b9eade2 different jerk limits 2024-07-26 16:48:10 -04:00
Jason Wen 7308a27831 move it 2024-07-26 11:40:38 -04:00
Jason Wen 39383f6d23 add comments and TODO 2024-07-26 11:36:33 -04:00
Jason Wen 546201438c totally did not forget to push this :) 2024-07-26 11:30:32 -04:00
Jason Wen 8d656b5115 unused 2024-07-26 09:55:26 -04:00
Jason Wen 4fb4858ab6 match factory's rate of change 2024-07-26 09:53:43 -04:00
Jason Wen 2d870b27b5 less aggressive 2024-07-26 09:53:02 -04:00
Jason Wen 544c7e4a9c Merge remote-tracking branch 'commaai/openpilot/master' into hkg-can-long-tuning 2024-07-26 09:52:42 -04:00
Jason Wen 0efb5b3310 higher startAccel 2024-07-23 11:11:45 -04:00
Jason Wen 91422154fc clean slate to get sample routes 2024-07-20 08:54:39 -04:00
Jason Wen 8a2e0e6002 Hyundai CAN Longitudinal: New tuning with new API 2024-07-20 08:45:55 -04:00
5 changed files with 30 additions and 9 deletions
+18 -3
View File
@@ -55,6 +55,8 @@ class CarController(CarControllerBase):
self.apply_steer_last = 0
self.car_fingerprint = CP.carFingerprint
self.last_button_frame = 0
self.accel_raw = 0
self.accel_val = 0
def update(self, CC, CS, now_nanos):
actuators = CC.actuators
@@ -144,10 +146,11 @@ class CarController(CarControllerBase):
if self.frame % 2 == 0 and self.CP.openpilotLongitudinalControl:
# TODO: unclear if this is needed
jerk = 3.0 if actuators.longControlState == LongCtrlState.pid else 1.0
jerk = 2.0 if actuators.longControlState == LongCtrlState.pid else 1.0
use_fca = self.CP.flags & HyundaiFlags.USE_FCA.value
can_sends.extend(hyundaican.create_acc_commands(self.packer, CC.enabled, accel, jerk, int(self.frame / 2),
hud_control, set_speed_in_units, stopping,
self.create_accel_value(CC, accel)
can_sends.extend(hyundaican.create_acc_commands(self.packer, CC.enabled, self.accel_raw, self.accel_val, jerk,
int(self.frame / 2), hud_control, set_speed_in_units, stopping,
CC.cruiseControl.override, use_fca))
# 20 Hz LFA MFA message
@@ -205,3 +208,15 @@ class CarController(CarControllerBase):
self.last_button_frame = self.frame
return can_sends
# We currently use static jerk limits for all accel commands, the PCM is very sensitive to how accels are being
# sent from the SCC source of truth. Dynamic jerk upper/lower limits are required to make PCM accept controls
# more smoothly
def create_accel_value(self, CC, accel):
rate = 0.1 # TODO: Dynamic jerk upper/lower limits should change this for more accurate and smoother controls
if not CC.enabled:
self.accel_raw, self.accel_val = 0, 0
else:
self.accel_raw = accel
self.accel_val = clip(self.accel_raw, self.accel_last - rate, self.accel_last + rate)
self.accel_last = self.accel_val
+5 -4
View File
@@ -126,7 +126,8 @@ def create_lfahda_mfc(packer, enabled, hda_set_speed=0):
}
return packer.make_can_msg("LFAHDA_MFC", 0, values)
def create_acc_commands(packer, enabled, accel, upper_jerk, idx, hud_control, set_speed, stopping, long_override, use_fca):
def create_acc_commands(packer, enabled, accel_raw, accel_val, upper_jerk, idx, hud_control, set_speed, stopping,
long_override, use_fca):
commands = []
scc11_values = {
@@ -145,8 +146,8 @@ def create_acc_commands(packer, enabled, accel, upper_jerk, idx, hud_control, se
scc12_values = {
"ACCMode": 2 if enabled and long_override else 1 if enabled else 0,
"StopReq": 1 if stopping else 0,
"aReqRaw": accel,
"aReqValue": accel, # stock ramps up and down respecting jerk limit until it reaches aReqRaw
"aReqRaw": accel_raw,
"aReqValue": accel_val, # stock ramps up and down respecting jerk limit until it reaches aReqRaw
"CR_VSM_Alive": idx % 0xF,
}
@@ -165,7 +166,7 @@ def create_acc_commands(packer, enabled, accel, upper_jerk, idx, hud_control, se
"ComfortBandUpper": 0.0, # stock usually is 0 but sometimes uses higher values
"ComfortBandLower": 0.0, # stock usually is 0 but sometimes uses higher values
"JerkUpperLimit": upper_jerk, # stock usually is 1.0 but sometimes uses higher values
"JerkLowerLimit": 5.0, # stock usually is 0.5 but sometimes uses higher values
"JerkLowerLimit": 3.0, # stock usually is 0.5 but sometimes uses higher values
"ACCMode": 2 if enabled and long_override else 1 if enabled else 4, # stock will always be 4 instead of 0 after first disengage
"ObjGap": 2 if hud_control.leadVisible else 0, # 5: >30, m, 4: 25-30 m, 3: 20-25 m, 2: < 20 m, 0: no lead
}
+3 -1
View File
@@ -89,7 +89,9 @@ class CarInterface(CarInterfaceBase):
ret.stoppingControl = True
ret.startingState = True
ret.vEgoStarting = 0.1
ret.startAccel = 1.0
ret.startAccel = 1.8
ret.stopAccel = 0.0
ret.stoppingDecelRate = 10
ret.longitudinalActuatorDelay = 0.5
# *** feature detection ***
+3
View File
@@ -73,6 +73,9 @@ class LongControl:
if output_accel > self.CP.stopAccel:
output_accel = min(output_accel, 0.0)
output_accel -= self.CP.stoppingDecelRate * DT_CTRL
elif output_accel < self.CP.stopAccel:
output_accel = min(output_accel, 0.0)
output_accel += self.CP.stoppingDecelRate * DT_CTRL
self.reset()
elif self.long_control_state == LongCtrlState.starting:
@@ -55,7 +55,7 @@ T_IDXS = np.array(T_IDXS_LST)
FCW_IDXS = T_IDXS < 5.0
T_DIFFS = np.diff(T_IDXS, prepend=[0.])
COMFORT_BRAKE = 2.5
STOP_DISTANCE = 6.0
STOP_DISTANCE = 8.0
def get_jerk_factor(personality=log.LongitudinalPersonality.standard):
if personality==log.LongitudinalPersonality.relaxed: