Skip to content

Commit 279b50d

Browse files
committed
work for AP1 cars with AP disabled
1 parent 7f0d85b commit 279b50d

File tree

8 files changed

+66
-41
lines changed

8 files changed

+66
-41
lines changed

panda

selfdrive/car/modules/qt/tsettings.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ TeslaTogglesPanel::TeslaTogglesPanel(SettingsWindow *parent) : ListWidget(parent
397397
"",
398398
0.0,0.0,0.0,0.0,TINKLA_STRING
399399
},
400-
{"TinklaUseAEBevent",
401-
"Use AEB Events (Experimental)",
402-
"Use AEB Events to control speed on cars with AP disabled. This is an EXPERIMENTAL feature.",
400+
{"TinklaAutopilotDisabled",
401+
"Autopilot feature disabled",
402+
"Use when car has the autopilot feature disabled.",
403403
"../assets/offroad/icon_settings.png",
404404
"","","",0.0,0.0,0.0,0.0, TINKLA_TOGGLE
405405
},

selfdrive/car/tesla/HUD_module.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def update(self, controls_state, enabled, CS, frame, actuators, cruise_cancel, h
232232

233233
# send DAS_status and DAS_status2 at 2Hz
234234
if (self.IC_integration_counter %20 == 0) or (self.IC_previous_enabled and not enabled ):
235-
should_send = enabled or (self.IC_previous_enabled and not enabled )#not(self.prev_autopilot_enabled and CS.autopilot_enabled)
235+
should_send = enabled or (self.IC_previous_enabled and not enabled ) or CS.autopilot_disabled_det
236236
self.prev_autopilot_enabled = CS.autopilot_enabled
237237
if CS.enableICIntegration and should_send:
238238
messages.append(self.tesla_can.create_das_status(DAS_op_status, DAS_collision_warning,
@@ -242,7 +242,7 @@ def update(self, controls_state, enabled, CS, frame, actuators, cruise_cancel, h
242242
messages.append(self.tesla_can.create_das_status2(DAS_csaState, cruise_speed,
243243
DAS_collision_warning, CAN_CHASSIS[self.CP.carFingerprint], 1))
244244

245-
if (enabled or CS.autopilot_enabled or self.IC_previous_enabled or self.CP.carFingerprint == CAR.PREAP_MODELS) and (self.IC_integration_counter % 10 == 0):
245+
if (enabled or CS.autopilot_disabled_det or self.IC_previous_enabled or self.CP.carFingerprint == CAR.PREAP_MODELS) and (self.IC_integration_counter % 10 == 0):
246246

247247
# send DAS_bodyControls
248248
if (self.IC_integration_counter in [20,70]) or (self.IC_previous_enabled and not enabled):
@@ -282,9 +282,9 @@ def update(self, controls_state, enabled, CS, frame, actuators, cruise_cancel, h
282282
CS.DAS_219_lcTempUnavailableSpeed, CS.DAS_220_lcTempUnavailableRoad, CS.DAS_221_lcAborting, CS.DAS_222_accCameraBlind,
283283
CS.DAS_208_rackDetected, CS.DAS_216_driverOverriding, CS.stopSignWarning, CS.stopLightWarning, CAN_CHASSIS[self.CP.carFingerprint]))
284284

285-
#send message for TB/Panda if preAP
286-
if self.CP.carFingerprint == CAR.PREAP_MODELS:
287-
if CS.enableICIntegration:
285+
#send message for TB/Panda if preAP or AP disabled
286+
if self.CP.carFingerprint == CAR.PREAP_MODELS or CS.autopilot_disabled:
287+
if CS.enableICIntegration and self.CP.carFingerprint == CAR.PREAP_MODELS:
288288
messages.append(
289289
self.tesla_can.create_ap1_long_control(
290290
not CS.carNotInDrive,
@@ -314,10 +314,11 @@ def update(self, controls_state, enabled, CS, frame, actuators, cruise_cancel, h
314314
1 if CS.pcc_available else 0,
315315
DAS_alca_state,
316316
v_cruise_pcm,
317-
CS.DAS_fusedSpeedLimit,
317+
int(CS.DAS_fusedSpeedLimit),
318318
apply_angle,
319319
1 if enabled else 0,
320320
1 if CS.enablePedal else 0, #is pedal enabled
321+
1 if CS.autopilot_disabled else 0, #autopilot feature disabled
321322
CAN_CHASSIS[self.CP.carFingerprint],
322323
)
323324
)

selfdrive/car/tesla/LONG_module.py

+37-19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self,CP,packer, tesla_can, pedalcan):
4848
self.adjustSpeedWithSpeedLimit = load_bool_param("TinklaAdjustAccWithSpeedLimit",True)
4949
self.adjustSpeedRelative = load_bool_param("TinklaSpeedLimitUseRelative",False)
5050
self.useLongControlData = load_bool_param("TinklaUseLongControlData",False)
51+
self.autopilot_disabled = load_bool_param("TinklaAutopilotDisabled",False)
5152
average_speed_over_x_suggestions = 5 # 1 second @ 5Hz
5253
self.speed_limit_uom = 0.
5354
self.prev_speed_limit_uom = 0.
@@ -60,7 +61,8 @@ def __init__(self,CP,packer, tesla_can, pedalcan):
6061
self.ap1_adjusting_speed = False
6162
self.ap1_speed_target = 0.
6263
self.set_speed_limit_active = False
63-
if (CP.carFingerprint == CAR.PREAP_MODELS):
64+
self.longPlan = None
65+
if (CP.carFingerprint == CAR.PREAP_MODELS) or self.autopilot_disabled:
6466
self.ACC = ACCController(self)
6567
self.PCC = PCCController(self,tesla_can,pedalcan,CP )
6668

@@ -74,6 +76,19 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
7476
if my_accel < 0:
7577
my_accel = my_accel * BRAKE_FACTOR
7678
#update options
79+
80+
target_accel = clip(my_accel, TESLA_MIN_ACCEL,TESLA_MAX_ACCEL)
81+
if self.CP.carFingerprint == CAR.PREAP_MODELS or CS.autopilot_disabled:
82+
target_accel = clip(my_accel * interp(CS.out.vEgo, BRAKE_FACTOR_BP, BRAKE_FACTOR_V ), TESLA_MIN_ACCEL,TESLA_MAX_ACCEL)
83+
84+
max_accel = 0 if target_accel < 0 else target_accel
85+
min_accel = 0 if target_accel > 0 else target_accel
86+
87+
max_jerk = CarControllerParams.JERK_LIMIT_MAX
88+
min_jerk = CarControllerParams.JERK_LIMIT_MIN
89+
90+
tesla_jerk_limits = [min_jerk,max_jerk]
91+
tesla_accel_limits = [min_accel,max_accel]
7792

7893
if enabled and not self.prev_enabled:
7994
self.fleet_speed.reset_averager()
@@ -103,7 +118,7 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
103118
if not self.CP.openpilotLongitudinalControl:
104119
return messages
105120
#preAP ModelS
106-
if self.CP.carFingerprint == CAR.PREAP_MODELS:
121+
if self.CP.carFingerprint == CAR.PREAP_MODELS or CS.autopilot_disabled:
107122
# update PCC module info
108123
pedal_can_sends = self.PCC.update_stat(CS, frame)
109124
if len(pedal_can_sends) > 0:
@@ -183,14 +198,12 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
183198
if self.PCC.pcc_available and frame % 1 == 0: # pedal processed at 100Hz, we get speed at 50Hz from ESP_B
184199
#following = False
185200
#TODO: see what works best for these
186-
self.v_target = self.longPlan.speeds[0]
187-
if long_plan and long_plan.longitudinalPlan:
188-
self.v_target = long_plan.longitudinalPlan.speeds[0]
189-
self.a_target = long_plan.longitudinalPlan.accels[0]
201+
if self.longPlan:
202+
self.v_target = self.longPlan.speeds[0]
203+
self.a_target = self.longPlan.accels[0]
190204

191205
if self.v_target is None:
192206
self.v_target = CS.out.vEgo
193-
target_accel = clip(my_accel * interp(CS.out.vEgo, BRAKE_FACTOR_BP, BRAKE_FACTOR_V ), TESLA_MIN_ACCEL,TESLA_MAX_ACCEL)
194207
target_speed = max(self.v_target, 0)
195208

196209
apply_accel, self.apply_brake, accel_needed, accel_idx = self.PCC.update_pdl(
@@ -225,6 +238,23 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
225238
)
226239
self.ibooster_idx = (self.ibooster_idx + 1) % 16
227240

241+
if self.autopilot_disabled:
242+
target_speed = target_speed * CV.MS_TO_KPH
243+
if enabled:
244+
if self.CP.carFingerprint == CAR.AP1_MODELS:
245+
messages.append(self.tesla_can.create_ap1_long_control(not CS.carNotInDrive, False, CS.pcc_enabled ,target_speed, tesla_accel_limits, tesla_jerk_limits, CAN_POWERTRAIN[self.CP.carFingerprint], self.long_control_counter))
246+
else:
247+
if CS.carNotInDrive:
248+
CS.cc_state = 0
249+
else:
250+
CS.cc_state = 1
251+
#send this values so we can enable at 0 km/h
252+
tesla_accel_limits = [-1.4000000000000004,1.8000000000000007]
253+
tesla_jerk_limits = [-0.46000000000000085,0.47600000000000003]
254+
if self.CP.carFingerprint == CAR.AP1_MODELS:
255+
messages.append(self.tesla_can.create_ap1_long_control(not CS.carNotInDrive, False, False , 0, tesla_accel_limits, tesla_jerk_limits, CAN_POWERTRAIN[self.CP.carFingerprint], self.long_control_counter))
256+
257+
228258
#AP ModelS with OP Long and enabled
229259
elif enabled and self.CP.openpilotLongitudinalControl and (frame %1 == 0) and (self.CP.carFingerprint in [CAR.AP1_MODELS,CAR.AP2_MODELS]):
230260
#we use the same logic from planner here to get the speed
@@ -299,9 +329,6 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
299329
self.j_target = 8
300330

301331
#following = False
302-
#TODO: see what works best for these
303-
target_accel = clip(my_accel, TESLA_MIN_ACCEL,TESLA_MAX_ACCEL)
304-
#target_jerk = 0.
305332
target_speed = max(CS.out.vEgo + (target_accel * CarControllerParams.ACCEL_TO_SPEED_MULTIPLIER), 0)
306333

307334
#if accel pedal pressed send 0 for target_accel
@@ -316,15 +343,6 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
316343
if self.fleet_speed_ms < target_speed and self.fleet_speed_ms > 0:
317344
target_accel = min(target_accel,FLEET_SPEED_ACCEL)
318345
target_speed = min(target_speed,self.fleet_speed_ms,CS.out.cruiseState.speed)
319-
320-
max_accel = 0 if target_accel < 0 else target_accel
321-
min_accel = 0 if target_accel > 0 else target_accel
322-
323-
max_jerk = CarControllerParams.JERK_LIMIT_MAX
324-
min_jerk = CarControllerParams.JERK_LIMIT_MIN
325-
326-
tesla_jerk_limits = [min_jerk,max_jerk]
327-
tesla_accel_limits = [min_accel,max_accel]
328346

329347
target_speed = target_speed * CV.MS_TO_KPH
330348

selfdrive/car/tesla/PCC_module.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,5 @@ def _update_pedal_state(self, CS, frame):
387387
frame < self.pedal_timeout_frame and CS.pedal_interceptor_state == 0
388388
)
389389
# Mark pedal unavailable while traditional cruise is on.
390-
self.pcc_available = pedal_ready and CS.enablePedal
390+
self.pcc_available = (pedal_ready and CS.enablePedal) or (CS.autopilot_disabled)
391391

selfdrive/car/tesla/carcontroller.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def update(self, c, enabled, CS, frame, actuators, cruise_cancel, pcm_speed, pcm
4848
CS.autoresumeAcc = load_bool_param("TinklaAutoResumeACC",False)
4949
can_sends = []
5050
#add 1 second delay logic to wait for AP which has a status at 2Hz
51-
if self.CP.carFingerprint != CAR.PREAP_MODELS:
51+
if self.CP.carFingerprint != CAR.PREAP_MODELS and not CS.autopilot_disabled:
5252
if CS.cruiseEnabled:
5353
if not self.prevCruiseEnabled:
5454
self.cruiseDelayFrame = frame

selfdrive/car/tesla/carstate.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def __init__(self, CP):
2525
# Needed by carcontroller
2626
self.msg_stw_actn_req = None
2727

28-
self.autopilot_disabled = False
28+
self.autopilot_disabled = load_bool_param("TinklaAutopilotDisabled",False)
29+
self.autopilot_disabled_det = False
2930

3031
self.das_steeringControl_counter = -1
3132
self.das_status_counter = -1
@@ -108,7 +109,7 @@ def __init__(self, CP):
108109
self.pcc_enabled = False
109110
self.torqueLevel = 0.0
110111
self.cruise_state = None
111-
self.enableHumanLongControl = load_bool_param("TinklaForceTeslaPreAP", False)
112+
self.enableHumanLongControl = load_bool_param("TinklaForceTeslaPreAP", False) or self.autopilot_disabled
112113
self.enableICIntegration = load_bool_param("TinklaHasIcIntegration", False)
113114
self.pedalcanzero = load_bool_param("TinklaPedalCanZero",False)
114115
self.has_ibooster_ecu = load_bool_param("TinklaHasIBooster",False)
@@ -231,7 +232,6 @@ def update(self, cp, cp_cam):
231232

232233
self.esp_long_acceleration = cp.vl["ESP_ACC"]["Long_Acceleration"]
233234
self.esp_lat_acceleration = cp.vl["ESP_ACC"]["Lat_Acceleration"]
234-
self.autopilot_disabled = (cp.vl["GTW_carConfig"]["GTW_autopilot"] == 0)
235235

236236
#Detect car model - Needs more work when we do 3/Y
237237
#can look like S/SD/SP/SPD XD/XPD
@@ -244,6 +244,7 @@ def update(self, cp, cp_cam):
244244
if (self.teslaModelDetected == 0) or (prev_teslaModel != self.teslaModel):
245245
self.teslaModelDetected = 1
246246

247+
self.autopilot_disabled_det = (cp.vl["GTW_carConfig"]["GTW_autopilot"] == 0)
247248

248249
# Cruise state
249250
#cruise_state = self.can_define.dv["DI_state"]["DI_cruiseState"].get(int(cp.vl["DI_state"]["DI_cruiseState"]), None)
@@ -287,7 +288,7 @@ def update(self, cp, cp_cam):
287288
else:
288289
ret.followDistanceS = 255
289290

290-
if (self.CP.carFingerprint != CAR.PREAP_MODELS):
291+
if (self.CP.carFingerprint != CAR.PREAP_MODELS) and (not self.autopilot_disabled):
291292
acc_enabled = (cruise_state in ["ENABLED", "STANDSTILL", "OVERRIDE", "PRE_FAULT", "PRE_CANCEL"])
292293
self.autopilot_enabled = (autopilot_status in ["ACTIVE_1", "ACTIVE_2"]) #, "ACTIVE_NAVIGATE_ON_AUTOPILOT"])
293294
cruiseEnabled = acc_enabled and not self.autopilot_enabled and not summon_or_autopark_enabled
@@ -436,6 +437,7 @@ def update(self, cp, cp_cam):
436437
if gtw_esp1 is not None:
437438
self.gtw_esp1 = gtw_esp1
438439
self.gtw_esp1_last_sent_id = self.gtw_esp1["GTW_ESP1Counter"]
440+
if self.CP.carFingerprint in [CAR.PREAP_MODELS] or self.autopilot_disabled:
439441
#Pedal Interceptor
440442
self.prev_pedal_interceptor_state = self.pedal_interceptor_state
441443
self.prev_pedal_idx = self.pedal_idx
@@ -451,7 +453,8 @@ def update(self, cp, cp_cam):
451453
self.pedal_interceptor_value2 = transform_pedal_to_di(cp_cam.vl["GAS_SENSOR"]["INTERCEPTOR_GAS2"])
452454
self.pedal_idx = cp_cam.vl["GAS_SENSOR"]["IDX"]
453455
ret.gas = self.pedal_interceptor_value/100.
454-
ret.gasPressed = (self.pedal_interceptor_value > PEDAL_DI_PRESSED)
456+
ret.gasPressed = (self.pedal_interceptor_value > PEDAL_DI_PRESSED)
457+
if self.enablePedal:
455458
if self.enableHAO and self.pcc_enabled:
456459
self.DAS_216_driverOverriding = 1 if ret.gasPressed else 0
457460
ret.gas = 0

selfdrive/car/tesla/teslacan.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from selfdrive.car.tesla.values import CarControllerParams, CAN_CHASSIS, CAN_POWERTRAIN
1010
from selfdrive.car.modules.CFG_module import load_bool_param
1111

12-
USE_AEB_EVENT = load_bool_param("TinklaUseAEBevent",False)
12+
AUTOPILOT_DISABLED = load_bool_param("TinklaAutopilotDisabled",False)
13+
ENABLE_AEB_EVENTS = False
1314

1415
class TeslaCAN:
1516
def __init__(self, dbc_name, packer, pt_packer):
@@ -137,16 +138,17 @@ def create_steering_control(self, angle, enabled, ldw, bus, counter):
137138
def create_ap1_long_control(self, in_drive, static_cruise, cruise_enabled, speed, accel_limits, jerk_limits, bus, counter):
138139
accState = 0
139140
aeb_event = 0
140-
if USE_AEB_EVENT:
141-
aeb_event = 1 #AEB ACTIVE
142141
if in_drive:
143142
accState = 4
144143
if static_cruise and cruise_enabled:
145144
accState = 3
145+
if cruise_enabled and AUTOPILOT_DISABLED and ENABLE_AEB_EVENTS:
146+
aeb_event = 1 #AEB ACTIVE
147+
#accState = 0 #ACC DISABLED
146148
values = {
147149
"DAS_setSpeed" : clip(speed,0,200), #kph
148150
"DAS_accState" : accState, # 4-ACC ON, 3-HOLD, 0-CANCEL
149-
"DAS_aebEvent" : aeb_event, # 0 - AEB NOT ACTIVE
151+
"DAS_aebEvent" : aeb_event, # 1 - AEB ACTIVE, 0 - AEB NOT ACTIVE
150152
"DAS_jerkMin" : clip(jerk_limits[0],-8.,8.), #m/s^3 -8.67,0
151153
"DAS_jerkMax" : clip(jerk_limits[1],-8.,8.), #m/s^3 0,8.67
152154
"DAS_accelMin" : clip(accel_limits[0],-12.,3.44), #m/s^2 -15,5.44
@@ -305,6 +307,7 @@ def create_fake_DAS_msg(
305307
apply_angle,
306308
enable_steer_control,
307309
pedalEnabled,
310+
autopilot_disabled,
308311
bus,
309312
):
310313
units_included = 1
@@ -332,7 +335,7 @@ def create_fake_DAS_msg(
332335
acc_speed_limit + 0.5
333336
), # IC rounds current speed, so we need to round cruise speed the same way
334337
int(
335-
(legal_speed_limit & 0x1F) + ((pedalEnabled << 5) & 0x20)
338+
(legal_speed_limit & 0x1F) + ((pedalEnabled << 5) & 0x20) + ((autopilot_disabled << 7) & 0x80)
336339
), # positions 7 not used yet, 6 determines extended or not CC_state
337340
int(c_apply_steer & 0xFF),
338341
int((c_apply_steer >> 8) & 0xFF)

0 commit comments

Comments
 (0)