Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toyota: the smoothest longitudinal you will ever see #15

Closed
wants to merge 169 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
96f5057
bump opendbc
Dec 7, 2023
363876f
Toyota: compensate for pcm neutral force
Dec 7, 2023
d74fb00
use self.engineRpm
cydia2020 Dec 7, 2023
f25cc69
use CS.engineRpm
cydia2020 Dec 7, 2023
f7071a6
don't account for engine rpm
Dec 7, 2023
7bdef02
Toyota: handle pcm accel explicitly
cydia2020 Dec 7, 2023
8fecf1a
try a more aggressive tune
cydia2020 Dec 7, 2023
754f8c0
Revert "try a more aggressive tune"
Dec 7, 2023
4974c6f
reinstate camry max accel
cydia2020 Dec 7, 2023
587723d
transition from driver accel to op accel
cydia2020 Dec 7, 2023
fcd878f
Update opendbc
cydia2020 Dec 7, 2023
d45968e
transition the force instead
cydia2020 Dec 7, 2023
7923b41
basic pitch compensation
cydia2020 Dec 7, 2023
de91696
progressively complicated carcontroller
cydia2020 Dec 7, 2023
cdd8780
dont know the frequency of this
cydia2020 Dec 7, 2023
e762867
should be <
cydia2020 Dec 7, 2023
ff94452
remove permit braking logic
cydia2020 Dec 7, 2023
89bb64d
remove pitch compensation
cydia2020 Dec 7, 2023
69a6297
start with 0 force
cydia2020 Dec 7, 2023
3206b55
enable stopping control
cydia2020 Dec 7, 2023
ee3bf62
remove comment
cydia2020 Dec 7, 2023
f78a4d4
Revert "remove comment"
cydia2020 Dec 7, 2023
5030d78
Revert "enable stopping control"
cydia2020 Dec 7, 2023
9ee4a76
enter stopping state sooner on toyota
cydia2020 Dec 7, 2023
10c32f6
give toyota cc stopping state
cydia2020 Dec 7, 2023
453e611
perform_force_transition -> perform_enablement_force_transition
cydia2020 Dec 7, 2023
46fe717
add a stopping force transition
cydia2020 Dec 7, 2023
47fa779
fix comment
cydia2020 Dec 7, 2023
91a784d
oops conversion
cydia2020 Dec 7, 2023
2971137
use v_ego for clearer understanding
cydia2020 Dec 7, 2023
8973d11
-0.3m/s^2*weight stopping force
cydia2020 Dec 7, 2023
2a572d6
interp pitch compensated accel from road gradient
cydia2020 Dec 7, 2023
14ed1aa
oops fix
cydia2020 Dec 7, 2023
3665c85
clip start force between 0 and max accel force
cydia2020 Dec 7, 2023
8321cd7
syntax
cydia2020 Dec 7, 2023
1cc0fb5
more responsive high speed tune
cydia2020 Dec 7, 2023
7460f2b
disable accel limit in turns
cydia2020 Dec 7, 2023
527f6c9
add some comments
cydia2020 Dec 8, 2023
79952a3
Update opendbc
cydia2020 Dec 9, 2023
52ef532
print accstbk and accstat
cydia2020 Dec 9, 2023
e336dde
match my device
cydia2020 Dec 9, 2023
fe07b2a
vEgoStopping = 0.8
cydia2020 Dec 9, 2023
bb822fd
Revert "print accstbk and accstat"
cydia2020 Dec 9, 2023
86fcae1
Update opendbc
cydia2020 Dec 9, 2023
149c6b7
Update carcontroller.py
cydia2020 Dec 9, 2023
a1dc6fd
better naming for force transition during drive
cydia2020 Dec 11, 2023
a9372fd
try a smaller neutral_stopping_decel
cydia2020 Dec 11, 2023
cf72a02
some comments
cydia2020 Dec 11, 2023
5138a75
use -2.5 ret.stopAccel
cydia2020 Dec 11, 2023
128ab0b
on-device changes
cydia2020 Dec 12, 2023
b3d58d8
higher stopping decel
cydia2020 Dec 12, 2023
22f5f21
enter stopping state earlier, and quicker decel
cydia2020 Dec 12, 2023
1441434
unify toyota long tunes
cydia2020 Dec 12, 2023
c84b815
remove force calc
cydia2020 Dec 12, 2023
1def73d
removed some useless stuff
cydia2020 Dec 12, 2023
e645cd8
Update carcontroller.py
cydia2020 Dec 12, 2023
3e0c5d6
remove empty line
cydia2020 Dec 12, 2023
a7e2deb
lower vEgo stopping, reach stopping target quicker
cydia2020 Dec 12, 2023
e5558bc
now it's responsive we don't care about lead
cydia2020 Dec 12, 2023
554f349
try this tune now
cydia2020 Dec 12, 2023
1b099f2
forgot these two
cydia2020 Dec 12, 2023
abcb7f9
don't compensate on NO_STOP_TIMER_CAR when stopped
cydia2020 Dec 12, 2023
b98aae5
Revert "try this tune now"
cydia2020 Dec 12, 2023
a6e4808
revert e85cde023710dedad7ed6f8501b70a79569093e7
cydia2020 Dec 13, 2023
45bb32c
partially revert this
cydia2020 Dec 13, 2023
6baa526
larger i
cydia2020 Dec 13, 2023
93a35a2
Update tunes.py
cydia2020 Dec 13, 2023
51472ad
Update tunes.py
cydia2020 Dec 13, 2023
503a5a5
Revert "Update tunes.py"
cydia2020 Dec 13, 2023
e5b3e1c
Revert "Update tunes.py"
cydia2020 Dec 13, 2023
0a35f9d
Revert "larger i"
cydia2020 Dec 13, 2023
6840fe3
Revert "forgot these two"
cydia2020 Dec 13, 2023
a015847
Revert "now it's responsive we don't care about lead"
cydia2020 Dec 13, 2023
9561500
Update tunes.py
cydia2020 Dec 13, 2023
81e514a
don't compensate when accelerating
cydia2020 Dec 13, 2023
409bc8b
Revert "partially revert this"
cydia2020 Dec 13, 2023
5da335b
Revert "don't compensate when accelerating"
cydia2020 Dec 13, 2023
f598bfd
add back permit braking logic
cydia2020 Dec 13, 2023
d550268
Revert "add back permit braking logic"
Dec 14, 2023
127ea94
simple permit braking
Dec 14, 2023
675e6a1
use aEgo for Accel when not engaged
cydia2020 Dec 24, 2023
a4c7592
This tune seems to work well
cydia2020 Dec 24, 2023
497faa2
request standstill command sooner
cydia2020 Dec 24, 2023
4e73840
lower vEgoStopping and vEgoStarting
cydia2020 Dec 24, 2023
a9bb2ed
higher vEgoStopping
cydia2020 Dec 24, 2023
576b5ad
rework some logic
cydia2020 Dec 24, 2023
cdef483
Revert "rework some logic"
cydia2020 Dec 24, 2023
fa0a54a
Revert "use aEgo for Accel when not engaged"
cydia2020 Dec 24, 2023
f2b75ee
Update tunes.py
cydia2020 Dec 24, 2023
7a4df00
Update interface.py
cydia2020 Dec 25, 2023
bde47dd
disable registration
cydia2020 Dec 9, 2023
4fb1452
disable unregistered alert
cydia2020 Dec 13, 2023
623ad7f
Merge branch 'pcm_compensation' of github.com:cydia2020/dodgypilot in…
cydia2020 Dec 26, 2023
2feb896
allow cost change when user is controlling gas
cydia2020 Dec 26, 2023
d20ab20
Revert "allow cost change when user is controlling gas"
cydia2020 Dec 26, 2023
e4bd039
remove unused
cydia2020 Dec 26, 2023
fc4b89f
Update tunes.py
cydia2020 Dec 26, 2023
2fadb2c
Update interface.py
cydia2020 Dec 26, 2023
4b1f673
try this?
cydia2020 Dec 26, 2023
7012727
Revert "try this?"
cydia2020 Dec 26, 2023
9ef5ea5
keep longActive when overriding on Toyotas
cydia2020 Dec 26, 2023
9f650e3
freeze integrator when gasPressed for toyota
cydia2020 Dec 26, 2023
8ec5b0b
something to test
cydia2020 Dec 26, 2023
e29419e
Revert "something to test"
cydia2020 Dec 26, 2023
3c73e81
???
cydia2020 Dec 26, 2023
38e872b
this is correct lol
cydia2020 Dec 26, 2023
5211c66
remove unused
cydia2020 Dec 26, 2023
b61b704
missing accel command?
cydia2020 Dec 26, 2023
58463f6
Update carcontroller.py
cydia2020 Dec 26, 2023
ab860b7
make long calculations always active on toyotas
cydia2020 Dec 27, 2023
fbada8c
Revert "make long calculations always active on toyotas"
Dec 28, 2023
f2ebc9a
give hudcontrol lead accel
cydia2020 Dec 28, 2023
02beaec
try this
cydia2020 Dec 28, 2023
a5421f4
bump cereal
Dec 28, 2023
674c49b
Revert "try this"
cydia2020 Dec 28, 2023
fb27d45
Revert "give hudcontrol lead accel"
cydia2020 Dec 28, 2023
b566351
try this complicated thing
cydia2020 Dec 29, 2023
ca30c6d
Revert "try this complicated thing"
cydia2020 Dec 29, 2023
e170062
try this
cydia2020 Dec 29, 2023
ec3e489
Revert "try this"
cydia2020 Dec 29, 2023
1c11e7c
Revert "this is correct lol"
cydia2020 Dec 29, 2023
4037fba
Revert "???"
cydia2020 Dec 29, 2023
13b173b
Revert "freeze integrator when gasPressed for toyota"
cydia2020 Dec 29, 2023
134865f
Revert "keep longActive when overriding on Toyotas"
cydia2020 Dec 29, 2023
ad5c88b
try this?
cydia2020 Dec 29, 2023
9608a01
low time constant
cydia2020 Dec 29, 2023
184b8ff
Revert "low time constant"
cydia2020 Dec 30, 2023
4e69836
Revert "try this?"
cydia2020 Dec 30, 2023
265df6f
remove the should compensate logic
cydia2020 Dec 30, 2023
aaf0dad
remove unused
cydia2020 Dec 30, 2023
0e6ac3b
faster time constant for smooth in vego filter
cydia2020 Dec 30, 2023
e7043ae
revert this, doesn't seem to be the issue
cydia2020 Dec 30, 2023
41fb301
also use CC.enabled
cydia2020 Dec 31, 2023
d6e0482
smaller deadzone at lower speeds to improve responsiveness
cydia2020 Dec 31, 2023
649c647
screw this
cydia2020 Jan 2, 2024
646886a
revert the stopping logic, and prohibit neg calc when engaging
cydia2020 Jan 17, 2024
f09dbc3
remove this condition
cydia2020 Jan 20, 2024
3a46d9e
send compensated accel when leadVisible
cydia2020 Jan 20, 2024
d0206ba
prevent race conditions
cydia2020 Jan 21, 2024
4859397
Revert "prevent race conditions"
cydia2020 Jan 21, 2024
45c775d
Revert "send compensated accel when leadVisible"
cydia2020 Jan 21, 2024
ae9a535
try this
cydia2020 Jan 21, 2024
d593c13
use a simpler logic
cydia2020 Jan 21, 2024
f05cd4b
rework logic
Jan 21, 2024
987358f
more comments
cydia2020 Jan 21, 2024
ab5f5da
simpler
cydia2020 Jan 21, 2024
e66a217
test if this makes any difference
cydia2020 Jan 22, 2024
d40a261
start compensating earlier
cydia2020 Jan 24, 2024
da8a42c
fix misspelling
cydia2020 Jan 25, 2024
58c0a28
0.15 is a bit too slow
cydia2020 Jan 25, 2024
a7a7148
prohibit accel when lead is stopped
cydia2020 Jan 25, 2024
f025b7c
Revert "prohibit accel when lead is stopped"
cydia2020 Jan 25, 2024
983fc8f
dont compensate when stopped
cydia2020 Jan 25, 2024
546187f
bump opendbc
cydia2020 Jan 25, 2024
acac587
is this what I think it is?
cydia2020 Jan 25, 2024
4fb7501
"starts requesting brake when aEgo is generally high"
cydia2020 Jan 25, 2024
e793f30
permit braking condition
cydia2020 Jan 26, 2024
f4df903
acceleration continuation decision?
cydia2020 Jan 26, 2024
8688ded
spam cancel?
cydia2020 Feb 21, 2024
bcf2e4d
bump submodules
cydia2020 Feb 21, 2024
f8a1a46
Revert "bump submodules"
cydia2020 Mar 12, 2024
ed4d5e8
Revert "spam cancel?"
cydia2020 Mar 12, 2024
53a92c2
Revert "acceleration continuation decision?"
cydia2020 Mar 12, 2024
c2be664
Revert "permit braking condition"
cydia2020 Mar 12, 2024
cc22e8d
Revert ""starts requesting brake when aEgo is generally high""
cydia2020 Mar 12, 2024
7ef9e74
Revert "is this what I think it is?"
cydia2020 Mar 12, 2024
2e2d857
Revert "bump opendbc"
cydia2020 Mar 12, 2024
f5f6a06
Revert "dont compensate when stopped"
cydia2020 Mar 12, 2024
444df89
dsu reroute harness
cydia2020 Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cereal
4 changes: 2 additions & 2 deletions selfdrive/athena/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def register(show_spinner=False) -> str:
IMEI = params.get("IMEI", encoding='utf8')
HardwareSerial = params.get("HardwareSerial", encoding='utf8')
dongle_id = params.get("DongleId", encoding='utf8')
needs_registration = None in (IMEI, HardwareSerial, dongle_id)
needs_registration = False

pubkey = Path(PERSIST+"/comma/id_rsa.pub")
if not pubkey.is_file():
Expand Down Expand Up @@ -91,7 +91,7 @@ def register(show_spinner=False) -> str:

if dongle_id:
params.put("DongleId", dongle_id)
set_offroad_alert("Offroad_UnofficialHardware", (dongle_id == UNREGISTERED_DONGLE_ID) and not PC)
set_offroad_alert("Offroad_UnofficialHardware", False)
return dongle_id


Expand Down
61 changes: 37 additions & 24 deletions selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

VisualAlert = car.CarControl.HUDControl.VisualAlert
AudibleAlert = car.CarControl.HUDControl.AudibleAlert
LongCtrlState = car.CarControl.Actuators.LongControlState

# constants for fault workaround
MAX_STEER_RATE = 100 # deg/s
MAX_STEER_RATE_FRAMES = 19

# constants for PCM available force compensation
COMPENSATORY_CALCULATION_THRESHOLD = -0.25 #m/s^2

params = Params()

class CarController:
Expand All @@ -28,9 +33,9 @@ def __init__(self, dbc_name, CP, VM):
self.standstill_req = False
self.steer_rate_limited = False
self.last_off_frame = 0
self.permit_braking = True
self.e2e_long = params.get_bool("EndToEndLong")
self.steer_rate_counter = 0
self.prohibit_neg_calculation = True

self.packer = CANPacker(dbc_name)
self.gas = 0
Expand All @@ -40,12 +45,14 @@ def update(self, CC, CS):
actuators = CC.actuators
hud_control = CC.hudControl
pcm_cancel_cmd = CC.cruiseControl.cancel or (not CC.enabled and CS.pcm_acc_status)
stopping = actuators.longControlState == LongCtrlState.stopping

# maximum position acceleration based on vehicle model
_accel_max = CarControllerParams.ACCEL_MAX_CAMRY if self.CP.carFingerprint == CAR.CAMRY else CarControllerParams.ACCEL_MAX

# gas and brake
# Default interceptor logic
if self.CP.enableGasInterceptor and CC.longActive and self.CP.openpilotLongitudinalControl and self.CP.carFingerprint not in FULL_SPEED_DRCC_CAR:
if self.CP.enableGasInterceptor and (CC.longActive and not CS.out.gasPressed) and self.CP.openpilotLongitudinalControl and self.CP.carFingerprint not in FULL_SPEED_DRCC_CAR:
MAX_INTERCEPTOR_GAS = 0.5
# RAV4 has very sensitive gas pedal
if self.CP.carFingerprint in (CAR.RAV4, CAR.RAV4H, CAR.HIGHLANDER, CAR.HIGHLANDERH):
Expand All @@ -66,8 +73,26 @@ def update(self, CC, CS):
else:
interceptor_gas_cmd = 0.

# PCM acceleration command, vehicle only responds to this when the "no accel below" speed has been reached
pcm_accel_cmd = clip(actuators.accel, CarControllerParams.ACCEL_MIN, _accel_max)
# set allow negative calculation to False when longActive is False
if not CC.longActive:
self.prohibit_neg_calculation = True
# don't reset until a reasonable compensatory value is reached
if CS.pcm_neutral_force > COMPENSATORY_CALCULATION_THRESHOLD * self.CP.mass:
self.prohibit_neg_calculation = False
# NO_STOP_TIMER_CAR will creep if compensation is applied when stopping or stopped, don't compensate when stopped or stopping
should_compensate = True
if self.CP.carFingerprint in NO_STOP_TIMER_CAR and ((CS.out.vEgo < 1e-3 and actuators.accel < 1e-3) or stopping):
should_compensate = False
# pcm neutral force
if CC.longActive and should_compensate and not self.prohibit_neg_calculation:
pcm_neutral_force = CS.pcm_neutral_force / self.CP.mass
else:
pcm_neutral_force = 0.
# calculate and clip pcm_accel_cmd
if CC.enabled:
pcm_accel_cmd = clip(actuators.accel + pcm_neutral_force, CarControllerParams.ACCEL_MIN, _accel_max)
else:
pcm_accel_cmd = 0.

# steer torque
new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX))
Expand Down Expand Up @@ -102,7 +127,7 @@ def update(self, CC, CS):
else:
# cydia2020 - mimic stock behaviour, send standstill if the lead vehicle is stopped, else release
# Don't go into standstill when using e2e long
if CS.out.standstill and lead_vehicle_stopped and self.CP.carFingerprint not in NO_STOP_TIMER_CAR:
if CS.out.vEgo < self.CP.vEgoStopping and lead_vehicle_stopped and self.CP.carFingerprint not in NO_STOP_TIMER_CAR:
self.standstill_req = True
else:
self.standstill_req = False
Expand Down Expand Up @@ -132,36 +157,24 @@ def update(self, CC, CS):
alert_prompt_repeat = hud_control.audibleAlert in (AudibleAlert.promptRepeat, AudibleAlert.warningSoft)
alert_immediate = hud_control.audibleAlert == AudibleAlert.warningImmediate

# record frames
if not CC.enabled:
self.last_off_frame = self.frame

# cydia2020 - PERMIT_BRAKING commands the PCM to allow openpilot to engage the friction brakes
# and engine brake on your vehicle, it does not affect regen braking as far as I can tell
# setting PERMIT_BRAKING to 1 prevents the vehicle from coasting at low speed with low accel
# allow the vehicle to coast when the speed is below 6m/s for improved SnG smoothness
permit_braking_accel = interp(CS.out.vEgo, [0.0, 6., 10.], [0., 0.0, 0.35])
# Handle permit braking logic
if (actuators.accel > permit_braking_accel) or not CC.enabled:
self.permit_braking = False
else:
self.permit_braking = True

# we can spam can to cancel the system even if we are using lat only control
if (self.frame % 3 == 0 and self.CP.openpilotLongitudinalControl) or pcm_cancel_cmd:
lead = hud_control.leadVisible or CS.out.vEgo < 12. # at low speed we always assume the lead is present so ACC can be engaged
adjust_distance = CS.distance_btn == 1

# Send ACC_CONTROL_SAFE if RADAR Interceptor is detected, else send 0x343
acc_msg = 'ACC_CONTROL_SAFE' if self.CP.carFingerprint in RADAR_ACC_CAR_TSS1 else 'ACC_CONTROL'
# Handle raw acceleration, prevent vehicle creeping when coming to a stop
# send compensated when lead visible, send -2.5 when stopping, else send actuators.accel
at_raw = -2.5 if stopping or (CS.out.vEgo < 0.5 and lead_vehicle_stopped) else pcm_accel_cmd if hud_control.leadVisible else actuators.accel
# Lexus IS uses a different cancellation message
if pcm_cancel_cmd and self.CP.carFingerprint in (CAR.LEXUS_IS, CAR.LEXUS_RC):
can_sends.append(create_acc_cancel_command(self.packer))
elif self.CP.openpilotLongitudinalControl:
can_sends.append(create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type, adjust_distance, fcw_alert, self.permit_braking, lead_vehicle_stopped, acc_msg))
can_sends.append(create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type, adjust_distance, fcw_alert, lead_vehicle_stopped, at_raw, acc_msg))
self.accel = pcm_accel_cmd
else:
can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type, adjust_distance, False, False, False, acc_msg))
can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type, adjust_distance, False, False, 0, acc_msg))

if self.frame % 2 == 0 and self.CP.enableGasInterceptor:
# send exactly zero if gas cmd is zero. Interceptor will send the max between read value and gas cmd.
Expand All @@ -172,10 +185,10 @@ def update(self, CC, CS):
if self.CP.carFingerprint != CAR.PRIUS_V:
if self.frame % 10 == 0:
can_sends.append(create_ui_command(self.packer, alert_prompt, alert_prompt_repeat, alert_immediate, hud_control.leftLaneVisible,
hud_control.rightLaneVisible, CS.sws_toggle, CS.sws_sensitivity, CS.sws_buzzer, CS.sws_fld,
hud_control.rightLaneVisible, CS.sws_toggle, CS.sws_sensitivity, CS.sws_buzzer, CS.sws_fld,
CS.sws_warning, CS.lda_left_lane, CS.lda_right_lane, CS.lda_sa_toggle, CS.lkas_status,
CS.lda_speed_too_low, CS.lda_on_message, CS.lda_sensitivity, CS.ldw_exist, CC.enabled, CS.sws_beeps,
CS.lda_take_control, CS.lda_adjusting_camera, CS.lda_unavailable_quiet, CS.lda_unavailable,
CS.lda_take_control, CS.lda_adjusting_camera, CS.lda_unavailable_quiet, CS.lda_unavailable,
CS.lda_malfunction, CS.lda_fcb))

if self.frame % 10 == 0 and self.CP.enableDsu:
Expand Down
6 changes: 4 additions & 2 deletions selfdrive/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def update(self, cp, cp_cam):
ret.meterDimmed = cp.vl["BODY_CONTROL_STATE"]['METER_DIMMED'] == 1
ret.meterLowBrightness = cp.vl["BODY_CONTROL_STATE_2"]["METER_SLIDER_LOW_BRIGHTNESS"] == 1
ret.brakeLights = bool(cp.vl["ESP_CONTROL"]['BRAKE_LIGHTS_ACC'] or cp.vl["BRAKE_MODULE"]["BRAKE_PRESSED"] != 0)
self.pcm_neutral_force = cp.vl["PCM_CRUISE"]["NEUTRAL_FORCE"]

if self.CP.carFingerprint in (CAR.LEXUS_IS, CAR.LEXUS_RC):
ret.cruiseState.available = cp.vl["DSU_CRUISE"]["MAIN_ON"] != 0
Expand All @@ -119,7 +120,7 @@ def update(self, cp, cp_cam):
else:
ret.pcmFollowDistance = cp.vl["PCM_CRUISE_2"]["PCM_FOLLOW_DISTANCE"]

if self.CP.carFingerprint in TSS2_CAR:
if self.CP.carFingerprint in TSS2_CAR or self.CP.flags & ToyotaFlags.DSU_BYPASS:
self.acc_type = cp_cam.vl["ACC_CONTROL"]["ACC_TYPE"]
self.distance_btn = 2 if (cp_cam.vl["ACC_CONTROL"]["DISTANCE"] == 1 and not self.allow_distance_adjustment) else 1 if (cp_cam.vl["ACC_CONTROL"]["DISTANCE"] == 1 and self.allow_distance_adjustment) else 0
elif self.CP.smartDsu:
Expand Down Expand Up @@ -242,6 +243,7 @@ def get_can_parser(CP):
("ACCEL_Y", "KINEMATICS"),
("ACCEL_X", "KINEMATICS"),
("YAW_RATE", "KINEMATICS"),
("NEUTRAL_FORCE", "PCM_CRUISE"),
]

checks = [
Expand Down Expand Up @@ -354,7 +356,7 @@ def get_cam_can_parser(CP):
("LKAS_HUD", 1),
]

if CP.carFingerprint in TSS2_CAR:
if CP.carFingerprint in TSS2_CAR or CP.flags & ToyotaFlags.DSU_BYPASS:
signals.append(("ACC_TYPE", "ACC_CONTROL"))
signals.append(("DISTANCE", "ACC_CONTROL"))
checks.append(("ACC_CONTROL", 33))
Expand Down
42 changes: 16 additions & 26 deletions selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[], disabl
steering_angle_deadzone_deg = 0.0
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning, steering_angle_deadzone_deg)

# we can't use the fingerprint to detect this reliably, since
# the EV gas pedal signal can take a couple seconds to appear
if candidate in EV_HYBRID_CAR:
ret.flags |= ToyotaFlags.HYBRID.value

if params.get_bool("chrBsm"):
ret.flags |= ToyotaFlags.CHR_BSM.value

if 0x343 in fingerprint[2] and candidate not in TSS2_CAR:
ret.flags |= ToyotaFlags.DSU_BYPASS.value

if candidate == CAR.PRIUS:
stop_and_go = True
ret.wheelbase = 2.70
Expand All @@ -62,13 +73,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[], disabl
ret.steerRatio = 17.4
tire_stiffness_factor = 0.5533
ret.mass = 4387. * CV.LB_TO_KG + STD_CARGO_KG
if enableTorqueController:
# TODO override until there is enough data
ret.maxLateralAccel = 1.8
torque_params = CarInterfaceBase.get_torque_params(CAR.PRIUS)
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning, steering_angle_deadzone_deg)
else:
set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4)
set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4)


elif candidate in (CAR.RAV4, CAR.RAV4H):
Expand Down Expand Up @@ -299,36 +304,21 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[], disabl
ret.enableDsu = (len(found_ecus) > 0) and (Ecu.dsu not in found_ecus) and (candidate not in NO_DSU_CAR) and (not ret.smartDsu)
ret.enableGasInterceptor = 0x201 in fingerprint[0]
# if the smartDSU is detected, openpilot can send ACC_CMD (and the smartDSU will block it from the DSU) or not (the DSU is "connected")
ret.openpilotLongitudinalControl = (ret.smartDsu or ret.enableDsu or candidate in TSS2_CAR or ret.radarInterceptor) and not params.get_bool("SmartDSULongToggle")
ret.openpilotLongitudinalControl = bool(ret.flags & ToyotaFlags.DSU_BYPASS.value) or (ret.smartDsu or ret.enableDsu or candidate in TSS2_CAR or ret.radarInterceptor) and not params.get_bool("SmartDSULongToggle")
if ret.radarInterceptor:
if Params().get_bool("ToyotaRadarACCTSS1_ObjectMode"):
ret.radarTimeStep = 1.0 / 15.0
else:
ret.radarTimeStep = 1.0 / 10.0

# we can't use the fingerprint to detect this reliably, since
# the EV gas pedal signal can take a couple seconds to appear
if candidate in EV_HYBRID_CAR:
ret.flags |= ToyotaFlags.HYBRID.value

if params.get_bool("chrBsm"):
ret.flags |= ToyotaFlags.CHR_BSM.value

# min speed to enable ACC. if car can do stop and go, then set enabling speed
# to a negative value, so it won't matter.
ret.minEnableSpeed = -1. if (stop_and_go or ret.enableGasInterceptor) else MIN_ACC_SPEED

# Longitudinal Tunes
ret.stoppingDecelRate = 0.3 # reach stopping target smoothly

if candidate == CAR.PRIUS:
set_long_tune(ret.longitudinalTuning, LongTunes.TSSPPrius) # TSS-P Toyota Prius has a special tune
elif candidate in (CAR.CAMRY, CAR.CAMRYH):
set_long_tune(ret.longitudinalTuning, LongTunes.TSSPCamry) # TSS-P Toyota Camry / Camry H have a special tune
elif (candidate in TSS2_CAR) or (ret.enableGasInterceptor and not candidate in FULL_SPEED_DRCC_CAR):
set_long_tune(ret.longitudinalTuning, LongTunes.TSS2) # Use TSS 2.0 tune for both pedal and TSS 2.0 cars
else:
set_long_tune(ret.longitudinalTuning, LongTunes.TSSStock) # Use stock TSS-P tune for all other cars
ret.stoppingDecelRate = 0.3
ret.stopAccel = -2.5 # stock Toyota has this value
set_long_tune(ret.longitudinalTuning, LongTunes.Toyota)

return ret

Expand Down
8 changes: 4 additions & 4 deletions selfdrive/car/toyota/toyotacan.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ def create_lta_steer_command(packer, steer, steer_req, raw_cnt):
return packer.make_can_msg("STEERING_LTA", 0, values)


def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_type, distance_button, fcw_alert, permit_braking, lead_vehicle_stopped, msg='ACC_CONTROL'):
def create_accel_command(packer, accel, pcm_cancel, standstill_req, lead, acc_type, distance_button, fcw_alert, lead_vehicle_stopped, at_raw, msg='ACC_CONTROL'):
# TODO: find the exact canceling bit that does not create a chime
values = {
"ACCEL_CMD": accel,
"ACC_TYPE": acc_type,
"DISTANCE": distance_button,
"MINI_CAR": lead,
"PERMIT_BRAKING": permit_braking,
"PERMIT_BRAKING": 1 if accel < 0.3 else 0,
"RELEASE_STANDSTILL": not standstill_req,
"CANCEL_REQ": pcm_cancel,
"ALLOW_LONG_PRESS": 1,
"ACC_CUT_IN": fcw_alert,
"ACCEL_CMD_ALT": accel,
"ACCEL_CMD_ALT": at_raw,
"LEAD_STANDSTILL": lead_vehicle_stopped,
}
return packer.make_can_msg(msg, 0, values)
Expand Down Expand Up @@ -70,7 +70,7 @@ def create_fcw_command(packer, fcw):
return packer.make_can_msg("ACC_HUD", 0, values)


def create_ui_command(packer, alert_prompt, alert_prompt_repeat, alert_immediate, left_line, right_line, sws_toggle,
def create_ui_command(packer, alert_prompt, alert_prompt_repeat, alert_immediate, left_line, right_line, sws_toggle,
sws_sensitivity, sws_buzzer, sws_fld, sws_warning, lda_left_lane, lda_right_lane, lda_sa_toggle,
lkas_status, lda_speed_too_low, lda_on_message, lda_sensitivity, ldw_exist, enabled, sws_beeps,
lda_take_control, lda_adjusting_camera, lda_unavailable_quiet, lda_unavailable, lda_malfunction,
Expand Down
41 changes: 8 additions & 33 deletions selfdrive/car/toyota/tunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from enum import Enum

class LongTunes(Enum):
TSS2 = 0
TSSPPrius = 1
TSSStock = 2
TSSPCamry = 3
Toyota = 0

class LatTunes(Enum):
INDI_PRIUS = 0
Expand All @@ -28,35 +25,13 @@ class LatTunes(Enum):

###### LONG ######
def set_long_tune(tune, name):
# Improved longitudinal tune
if name == LongTunes.TSS2 or name == LongTunes.TSSPPrius:
tune.deadzoneBP = [0., 8.05]
tune.deadzoneV = [.0, .14]
tune.kpBP = [0., 5., 20., 30.]
tune.kpV = [1.3, 1.0, 0.7, 0.1]
#really smooth (make it toggleable)
#tune.kiBP = [0., 0.07, 5, 8, 11., 18., 20., 24., 33.]
#tune.kiV = [.001, .01, .1, .18, .21, .22, .23, .22, .001]
#okay ish
#tune.kiBP = [0., 11., 17., 20., 24., 30., 33., 40.]
#tune.kiV = [.001, .21, .22, .23, .22, .1, .001, .0001]
tune.kiBP = [0., 6., 8., 11., 30., 33., 40.]
tune.kiV = [.001, .07, .15, .2, .2, .01, .0001]
# Default longitudinal tune
elif name == LongTunes.TSSStock:
tune.deadzoneBP = [0., 9.]
tune.deadzoneV = [.0, .15]
tune.kpBP = [0., 5., 35.]
tune.kiBP = [0., 35.]
tune.kpV = [3.6, 2.4, 1.5]
tune.kiV = [0.54, 0.36]
elif name == LongTunes.TSSPCamry:
tune.deadzoneBP = [0., 9.]
tune.deadzoneV = [.0, .15]
tune.kpBP = [0., 9., 35.]
tune.kiBP = [0., 9., 35.]
tune.kpV = [2.0, 1.2, 1.0]
tune.kiV = [0.60, 0.54, 0.35]
if name == LongTunes.Toyota:
tune.deadzoneBP = [0., 16., 20., 30.]
tune.deadzoneV = [0., .03, .06, .15]
tune.kpBP = [0.]
tune.kpV = [1.]
tune.kiBP = [0.]
tune.kiV = [1.]
else:
raise NotImplementedError('This longitudinal tune does not exist')

Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/toyota/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, CP):
class ToyotaFlags(IntFlag):
HYBRID = 1
CHR_BSM = 2
DSU_BYPASS = 4


class CAR:
Expand Down
10 changes: 3 additions & 7 deletions selfdrive/controls/lib/longitudinal_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
from selfdrive.controls.lib.drive_helpers import V_CRUISE_MAX, CONTROL_N
from selfdrive.swaglog import cloudlog

LON_MPC_STEP = 0.2 # first step is 0.2s
AWARENESS_DECEL = -0.2 # car smoothly decel at .2m/s^2 when user is distracted
A_CRUISE_MIN = -1.2
A_CRUISE_MAX_VALS = [2.0, 1.5, 0.8, 0.6]
A_CRUISE_MAX_BP = [0., 15., 25., 40.]
A_CRUISE_MIN_VALS = [-0.5, -0.5, -0.2, -0.3, -0.4, -1.2] # mimick stock, slightly release brakes when stopping
A_CRUISE_MIN_BP = [0., 0.3, 0.35, 3., 6., 20.]

# Lookup table for turns
_A_TOTAL_MAX_V = [1.7, 3.2]
Expand All @@ -30,8 +28,6 @@
def get_max_accel(v_ego):
return interp(v_ego, A_CRUISE_MAX_BP, A_CRUISE_MAX_VALS)

def get_min_accel(v_ego):
return interp(v_ego, A_CRUISE_MIN_BP, A_CRUISE_MIN_VALS)

def limit_accel_in_turns(v_ego, angle_steers, a_target, CP):
"""
Expand Down Expand Up @@ -108,8 +104,8 @@ def update(self, sm):
# Prevent divergence, smooth in current v_ego
self.v_desired_filter.x = max(0.0, self.v_desired_filter.update(v_ego))

accel_limits = [get_min_accel(v_ego), get_max_accel(v_ego)]
accel_limits_turns = limit_accel_in_turns(v_ego, sm['carState'].steeringAngleDeg, accel_limits, self.CP)
accel_limits = [A_CRUISE_MIN, get_max_accel(v_ego)]
accel_limits_turns = limit_accel_in_turns(v_ego, 0, accel_limits, self.CP)
if force_slow_decel:
# if required so, force a smooth deceleration
accel_limits_turns[1] = min(accel_limits_turns[1], AWARENESS_DECEL)
Expand Down
Loading
Loading