@@ -48,6 +48,7 @@ def __init__(self,CP,packer, tesla_can, pedalcan):
48
48
self .adjustSpeedWithSpeedLimit = load_bool_param ("TinklaAdjustAccWithSpeedLimit" ,True )
49
49
self .adjustSpeedRelative = load_bool_param ("TinklaSpeedLimitUseRelative" ,False )
50
50
self .useLongControlData = load_bool_param ("TinklaUseLongControlData" ,False )
51
+ self .autopilot_disabled = load_bool_param ("TinklaAutopilotDisabled" ,False )
51
52
average_speed_over_x_suggestions = 5 # 1 second @ 5Hz
52
53
self .speed_limit_uom = 0.
53
54
self .prev_speed_limit_uom = 0.
@@ -60,7 +61,8 @@ def __init__(self,CP,packer, tesla_can, pedalcan):
60
61
self .ap1_adjusting_speed = False
61
62
self .ap1_speed_target = 0.
62
63
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 :
64
66
self .ACC = ACCController (self )
65
67
self .PCC = PCCController (self ,tesla_can ,pedalcan ,CP )
66
68
@@ -74,6 +76,19 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
74
76
if my_accel < 0 :
75
77
my_accel = my_accel * BRAKE_FACTOR
76
78
#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 ]
77
92
78
93
if enabled and not self .prev_enabled :
79
94
self .fleet_speed .reset_averager ()
@@ -103,7 +118,7 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
103
118
if not self .CP .openpilotLongitudinalControl :
104
119
return messages
105
120
#preAP ModelS
106
- if self .CP .carFingerprint == CAR .PREAP_MODELS :
121
+ if self .CP .carFingerprint == CAR .PREAP_MODELS or CS . autopilot_disabled :
107
122
# update PCC module info
108
123
pedal_can_sends = self .PCC .update_stat (CS , frame )
109
124
if len (pedal_can_sends ) > 0 :
@@ -183,14 +198,12 @@ def update(self, enabled, CS, frame, actuators, cruise_cancel,pcm_speed,pcm_over
183
198
if self .PCC .pcc_available and frame % 1 == 0 : # pedal processed at 100Hz, we get speed at 50Hz from ESP_B
184
199
#following = False
185
200
#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 ]
190
204
191
205
if self .v_target is None :
192
206
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 )
194
207
target_speed = max (self .v_target , 0 )
195
208
196
209
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
225
238
)
226
239
self .ibooster_idx = (self .ibooster_idx + 1 ) % 16
227
240
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
+
228
258
#AP ModelS with OP Long and enabled
229
259
elif enabled and self .CP .openpilotLongitudinalControl and (frame % 1 == 0 ) and (self .CP .carFingerprint in [CAR .AP1_MODELS ,CAR .AP2_MODELS ]):
230
260
#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
299
329
self .j_target = 8
300
330
301
331
#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.
305
332
target_speed = max (CS .out .vEgo + (target_accel * CarControllerParams .ACCEL_TO_SPEED_MULTIPLIER ), 0 )
306
333
307
334
#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
316
343
if self .fleet_speed_ms < target_speed and self .fleet_speed_ms > 0 :
317
344
target_accel = min (target_accel ,FLEET_SPEED_ACCEL )
318
345
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 ]
328
346
329
347
target_speed = target_speed * CV .MS_TO_KPH
330
348
0 commit comments