Skip to content

Commit 1dcaf9f

Browse files
authored
ML tune
1 parent 11fc3b8 commit 1dcaf9f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

opendbc/car/honda/carcontroller.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import numpy as np
22
from collections import namedtuple
33

4-
from opendbc.car.common.conversions import Conversions as CV
54
from opendbc.can.packer import CANPacker
6-
from opendbc.car import Bus, DT_CTRL, rate_limit, make_tester_present_msg, structs
5+
from opendbc.car import Bus, DT_CTRL, rate_limit, make_tester_present_msg, structs, apply_driver_steer_torque_limits
76
from opendbc.car.honda import hondacan
8-
from opendbc.car.honda.values import CruiseButtons, VISUAL_HUD, HONDA_BOSCH, HONDA_BOSCH_RADARLESS, HONDA_NIDEC_ALT_PCM_ACCEL, CarControllerParams
7+
from opendbc.car.common.conversions import Conversions as CV
8+
from opendbc.car.honda.values import CruiseButtons, VISUAL_HUD, HONDA_BOSCH, HONDA_BOSCH_RADARLESS, HONDA_NIDEC_ALT_PCM_ACCEL, HONDA_BOSCH_1000, \
9+
CarControllerParams, SERIAL_STEERING, LKAS_LIMITS
910
from opendbc.car.interfaces import CarControllerBase
1011

1112
VisualAlert = structs.CarControl.HUDControl.VisualAlert
@@ -18,7 +19,7 @@ def compute_gb_honda_bosch(accel, speed):
1819

1920

2021
def compute_gb_honda_nidec(accel, speed):
21-
newaccel = np.interp ( accel, [-3.5, 0, 2], [-14, 0, 8 ] )
22+
newaccel = interp ( accel, [-3.5, 0, 2 ] , [-14, 0, 8 ] )
2223
creep_brake = 0.0
2324
creep_speed = 2.3
2425
creep_brake_value = 0.15
@@ -121,8 +122,7 @@ def __init__(self, dbc_names, CP):
121122
def update(self, CC, CS, now_nanos):
122123
actuators = CC.actuators
123124
hud_control = CC.hudControl
124-
conversion = CV.KPH_TO_MS # MVL
125-
# hondacan.get_cruise_speed_conversion(self.CP.carFingerprint, CS.is_metric)
125+
conversion = CV.KPH_TO_MS if CS.is_metric_cruise else CV.MPH_TO_MS
126126
hud_v_cruise = hud_control.setSpeed / conversion if hud_control.speedVisible else 255
127127
pcm_cancel_cmd = CC.cruiseControl.cancel
128128

@@ -150,6 +150,11 @@ def update(self, CC, CS, now_nanos):
150150

151151
# **** process the car messages ****
152152

153+
if (CS.CP.carFingerprint in SERIAL_STEERING):
154+
limited_torque = apply_driver_steer_torque_limits(limited_torque, self.last_torque, CS.out.steeringTorque, LKAS_LIMITS)
155+
self.last_torque = limited_torque
156+
self.apply_steer_over_max_counter = 0
157+
153158
# steer torque is converted back to CAN reference (positive when steering right)
154159
apply_torque = int(np.interp(-limited_torque * self.params.STEER_MAX,
155160
self.params.STEER_LOOKUP_BP, self.params.STEER_LOOKUP_V))
@@ -163,7 +168,7 @@ def update(self, CC, CS, now_nanos):
163168
can_sends.append(make_tester_present_msg(0x18DAB0F1, 1, suppress_response=True))
164169

165170
# Send steering command.
166-
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_torque, CC.latActive, self.CP.carfingerprint))
171+
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_torque, CC.latActive, self.CP.carFingerprint))
167172

168173
# wind brake from air resistance decel at high speed
169174
wind_brake = np.interp(CS.out.vEgo, [0.0, 2.3, 35.0], [0.001, 0.002, 0.15])
@@ -196,7 +201,7 @@ def update(self, CC, CS, now_nanos):
196201

197202
if not self.CP.openpilotLongitudinalControl:
198203
if self.frame % 2 == 0 and self.CP.carFingerprint not in HONDA_BOSCH_RADARLESS: # radarless cars don't have supplemental message
199-
can_sends.append(hondacan.create_bosch_supplemental_1(self.packer, self.CAN))
204+
can_sends.append(hondacan.create_bosch_supplemental_1(self.packer, self.CAN, self.CP.carFingerprint))
200205
# If using stock ACC, spam cancel command to kill gas when OP disengages.
201206
if pcm_cancel_cmd:
202207
can_sends.append(hondacan.spam_buttons_command(self.packer, self.CAN, CruiseButtons.CANCEL, self.CP.carFingerprint))
@@ -210,7 +215,10 @@ def update(self, CC, CS, now_nanos):
210215

211216
if self.CP.carFingerprint in HONDA_BOSCH:
212217
self.accel = float(np.clip(accel, self.params.BOSCH_ACCEL_MIN, self.params.BOSCH_ACCEL_MAX))
213-
self.gas = float(np.interp(accel, self.params.BOSCH_GAS_LOOKUP_BP, self.params.BOSCH_GAS_LOOKUP_V))
218+
if self.CP.carFingerprint in HONDA_BOSCH_1000:
219+
self.gas = float(np.interp(accel, self.params.BOSCH_GAS_LOOKUP_BP, self.params.BOSCH_1000_GAS_LOOKUP_V))
220+
else:
221+
self.gas = float(np.interp(accel, self.params.BOSCH_GAS_LOOKUP_BP, self.params.BOSCH_GAS_LOOKUP_V))
214222

215223
stopping = actuators.longControlState == LongCtrlState.stopping
216224
self.stopping_counter = self.stopping_counter + 1 if stopping else 0

0 commit comments

Comments
 (0)