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

Feature to alert user of faster adjacent lanes #116

Merged
merged 109 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
9e84727
rename dynamic_lane_speed to lane_speed
sshane Jun 18, 2020
e162b24
add function to group tracks based on lane width
sshane Jun 18, 2020
34df805
add updates
sshane Jun 18, 2020
4ce3196
add checking for how long lane has been fastest. min 1 second before …
sshane Jun 19, 2020
4610748
add alert, should be feature complete!
sshane Jun 19, 2020
9deb525
reset fastest once we show alert
sshane Jun 19, 2020
f49e71e
disable debugging
sshane Jun 19, 2020
1c0bc78
fix
sshane Jun 19, 2020
0518de4
log data
sshane Jun 19, 2020
396c91c
Fix, right is negative
sshane Jun 19, 2020
a965684
Update alerts.py
sshane Jun 19, 2020
4b18960
Tune some values
sshane Jun 19, 2020
cc839a0
All capz
sshane Jun 19, 2020
a919044
all 100mb of data was just vRel lol rip
sshane Jun 19, 2020
afbc3c7
add file to plot gathered data
sshane Jun 19, 2020
cba71e6
preprocess data
sshane Jun 19, 2020
edfdf11
offset lane center based on dPoly and tracks' distance from car
sshane Jun 19, 2020
cf1b3b4
wow, that was crazy accurate. just an update
sshane Jun 19, 2020
9cd38a2
only show auto alert if time since last lane speed alert is greater t…
sshane Jun 19, 2020
bd591b9
speed up track grouping! from 7200 Hz to 10600 Hz
sshane Jun 19, 2020
3b78840
specify not to be changed
sshane Jun 19, 2020
0fb8c92
Revert tuning
sshane Jun 19, 2020
54fd327
Increase cost as a test
sshane Jun 19, 2020
b2fe7bc
change alert time to 10s, don't show alert until last alert has finished
sshane Jun 20, 2020
2d843cc
Merge remote-tracking branch 'origin/stock_additions-lane-speed' into…
sshane Jun 20, 2020
60e5694
make auto alert and lanespeed alert smaller
sshane Jun 20, 2020
a13923e
make alert easier to read
sshane Jun 20, 2020
6889d27
wait up to 5 seconds after last alert finishes before next alert is a…
sshane Jun 20, 2020
861ef11
restrict to above 35 mph
sshane Jun 20, 2020
c88c98c
change the minimum fastest time based on how many tracks are in that …
sshane Jun 20, 2020
a14734c
lane_speed is its own process now (lanespeedd) to avoid lagging contr…
sshane Jun 20, 2020
3bc1cf5
run all test
sshane Jun 21, 2020
5365932
debug
sshane Jun 21, 2020
25a8414
fake lag
sshane Jun 21, 2020
3e98beb
fix
sshane Jun 21, 2020
bff3eba
more lag
sshane Jun 21, 2020
5a33bcd
revert
sshane Jun 21, 2020
b48ca3c
allow down to 0 for testing
sshane Jun 21, 2020
a33f7ff
Comment out, need to add message in laneSpeed service
sshane Jun 21, 2020
de2721c
Revert to medium alert
sshane Jun 21, 2020
c24fd83
show alert for as long as faster lane is faster, need to test
sshane Jun 21, 2020
3ebea0e
no need to have a variable
sshane Jun 21, 2020
6f79d81
don't beep when alert disapears lol
sshane Jun 22, 2020
d25bb8b
debug what controlsd is receiving
sshane Jun 22, 2020
99230f0
first test of transforming dPoly
sshane Jun 22, 2020
bce4359
test
sshane Jun 22, 2020
1daa60e
wait 5 seconds before next alert is allowed to be shown
sshane Jun 22, 2020
233423a
rename
sshane Jun 22, 2020
5973b17
fix
sshane Jun 22, 2020
1c7a879
some lane_speed refactorization
sshane Jun 23, 2020
abce43e
remove old
sshane Jun 23, 2020
4cf06c8
change min fastest time and tuning
sshane Jun 23, 2020
d70cb73
tune auto alert
sshane Jun 23, 2020
00174c1
add effective_profile
sshane Jun 23, 2020
541c6ac
increase cost when effective profile changes to get to new profile qu…
sshane Jun 23, 2020
718a549
decrease base cost
sshane Jun 23, 2020
71d91d4
10 might be too much lol
sshane Jun 23, 2020
3802fc6
Fix
sshane Jun 23, 2020
2cda473
Is this even working?
sshane Jun 23, 2020
a733db9
cost tuning
sshane Jun 23, 2020
8411c50
use lane width seen by openpilot in lane_speed.py
sshane Jun 24, 2020
f0dff04
use lane width seen by openpilot in lane_speed.py
sshane Jun 24, 2020
cba3e43
add lane_speed_alerts param
sshane Jun 24, 2020
2344bc6
unneeded
sshane Jun 24, 2020
c557fc3
better
sshane Jun 24, 2020
efd2fc7
remove old
sshane Jun 24, 2020
5946e09
add doc
sshane Jun 24, 2020
8393e96
add left mid and right avg speed messages
sshane Jun 24, 2020
e9607e6
debug
sshane Jun 24, 2020
c8eb0fb
debug
sshane Jun 24, 2020
aade16a
debug
sshane Jun 24, 2020
2be3d4c
debug
sshane Jun 24, 2020
0080643
debug
sshane Jun 24, 2020
a974e32
debug
sshane Jun 24, 2020
f896ca9
add speed and distance list messages for each lane to gather data for…
sshane Jun 24, 2020
3847db0
remove log data
sshane Jun 24, 2020
8412fb4
debug
sshane Jun 24, 2020
a6a23ff
debug
sshane Jun 24, 2020
b4d007e
debug
sshane Jun 24, 2020
c0aa924
fix
sshane Jun 24, 2020
02eddd8
debug
sshane Jun 24, 2020
14e5226
debug
sshane Jun 24, 2020
7bc60b5
debug
sshane Jun 24, 2020
41bb840
revert tests
sshane Jun 24, 2020
224f393
make lists
sshane Jun 24, 2020
9572be0
run all test
sshane Jun 24, 2020
581459e
debug
sshane Jun 24, 2020
033ea45
revert tests, working!
sshane Jun 24, 2020
16b6356
relaxed: slight farther above 30 mph
sshane Jun 24, 2020
9cd45d0
farther roadtrip profile
sshane Jun 24, 2020
aea92ec
tune profile mods for new relaxed and roadtrip
sshane Jun 24, 2020
1dc4cc8
tune traffic mods
sshane Jun 24, 2020
8273684
don't stop lanespeedd if disabled, just stop picking a fastest lane
sshane Jun 26, 2020
33706c2
debug lane speed button
sshane Jun 27, 2020
295c437
stop run all test
sshane Jun 27, 2020
ce554d6
guess the button bounds, not sure if this is right
sshane Jun 27, 2020
86fd4ae
debug
sshane Jun 27, 2020
1c763aa
Update paint.cc
sshane Jun 27, 2020
bc6bd59
receive lsButton messages for alert and change LaneSpeed state
sshane Jun 28, 2020
249692b
tune cost change times
sshane Jun 29, 2020
8405827
forgot to add the button to service_list
sshane Jun 29, 2020
36fbe49
less cost mod
sshane Jun 29, 2020
a30fe22
general improvements, make ls alert smaller
sshane Jun 29, 2020
333e17b
final updates, remove old files
sshane Jun 30, 2020
2cf18c4
restrict under 35 mph
sshane Jun 30, 2020
95e27fb
raise roadtrip profile distance and reduce negative mods
sshane Jul 1, 2020
9c3e85a
tune change time for cost
sshane Jul 1, 2020
d06f87d
slightly reduce
sshane Jul 1, 2020
79c35c6
use TR for dynamic gas again!
sshane Jul 1, 2020
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
20 changes: 20 additions & 0 deletions cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,24 @@ struct DynamicFollowButton {
status @0 :UInt16;
}

struct LaneSpeed {
fastestLane @0 :Text;
state @1 :Text;
new @2 :Bool;

leftLaneSpeeds @3 :List(Float32);
middleLaneSpeeds @4 :List(Float32);
rightLaneSpeeds @5 :List(Float32);

leftLaneDistances @6 :List(Float32);
middleLaneDistances @7 :List(Float32);
rightLaneDistances @8 :List(Float32);
}

struct LaneSpeedButton {
status @0 :UInt16;
}

struct Event {
# in nanoseconds?
logMonoTime @0 :UInt64;
Expand Down Expand Up @@ -2059,5 +2077,7 @@ struct Event {

dynamicFollowData @74 :DynamicFollowData;
dynamicFollowButton @75 :DynamicFollowButton;
laneSpeed @76 :LaneSpeed;
laneSpeedButton @77 :LaneSpeedButton;
}
}
2 changes: 2 additions & 0 deletions cereal/service_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ offroadLayout: [8074, false, 0.]

dynamicFollowData: [8075, false, 20.]
dynamicFollowButton: [8076, false, 0.]
laneSpeed: [8077, false, 0.]
laneSpeedButton: [8078, false, 0.]

testModel: [8040, false, 0.]
testLiveLocation: [8045, false, 0.]
Expand Down
3 changes: 1 addition & 2 deletions common/op_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def __init__(self):
'alca_min_speed': {'default': 25.0, 'allowed_types': [float, int], 'description': 'The minimum speed allowed for an automatic lane change (in MPH)'},
'steer_ratio': {'default': None, 'allowed_types': [type(None), float, int], 'description': '(Can be: None, or a float) If you enter None, openpilot will use the learned sR.\n'
'If you use a float/int, openpilot will use that steer ratio instead', 'live': True},
'use_dynamic_lane_speed': {'default': True, 'allowed_types': [bool], 'description': 'Whether you want openpilot to adjust your speed based on surrounding vehicles', 'hide': True},
'min_dynamic_lane_speed': {'default': 20.0, 'allowed_types': [float, int], 'description': 'The minimum speed to allow dynamic lane speed to operate (in MPH)', 'hide': True},
'lane_speed_alerts': {'default': True, 'allowed_types': [str], 'description': 'Can be: (\'off\', \'silent\', \'audible\'): Whether you want openpilot to alert you of faster-traveling adjacent lanes'},
'upload_on_hotspot': {'default': False, 'allowed_types': [bool], 'description': 'If False, openpilot will not upload driving data while connected to your phone\'s hotspot'},
'enable_long_derivative': {'default': False, 'allowed_types': [bool], 'description': 'If you have longitudinal overshooting, enable this! This enables derivative-based\n'
'integral wind-down to help reduce overshooting within the long PID loop'},
Expand Down
49 changes: 34 additions & 15 deletions helper_scripts/df-test-tuner-profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,45 @@
import numpy as np
from selfdrive.config import Conversions as CV

x_vel = [0.0, 4.166741231209736, 8.333258768790266, 12.500000000000002, 16.666741231209738, 20.833258768790266, 25.85853614889048, 30.52299570508232, 50.00000000000001, 70.0, 75.0, 80.0, 90.00000000000001]
y_dist_old = [1.3978, 1.4071, 1.4194, 1.4348, 1.4596, 1.4904, 1.5362, 1.5565, 1.5845, 1.6205, 1.6565, 1.6905, 1.7435] # TRs
plt.plot(np.array(x_vel), y_dist_old, label='old roadtrip')
x_vel_relaxed = [0.0, 1.8627, 3.7253, 5.588, 7.4507, 9.3133, 11.5598, 13.645, 22.352, 31.2928, 33.528, 35.7632, 40.2336]
y_dist_relaxed = [1.385, 1.394, 1.406, 1.421, 1.444, 1.474, 1.521, 1.544, 1.568, 1.588, 1.599, 1.613, 1.634]
plt.plot(np.array(x_vel_relaxed) * CV.MS_TO_MPH, y_dist_relaxed, label='relaxed')


x = [0, 23.9, 55, 70, 91]
y = [1.0, 1.025, 1.1, 1.125, 1.06]
y_dist_new = [np.interp(x_, x, y) * y_ for x_, y_ in zip(x_vel, y_dist_old)]
# x_vel_traffic = [0.0, 1.892, 3.7432, 5.8632, 8.0727, 10.7301, 14.343, 17.6275, 22.4049, 28.6752, 34.8858, 40.35]
# y_dist_traffic = [1.3781, 1.3791, 1.3457, 1.3134, 1.3145, 1.318, 1.3485, 1.257, 1.144, 0.979, 0.9461, 0.9156]
# plt.plot(np.array(x_vel_traffic) * CV.MS_TO_MPH, y_dist_traffic, label='traffic')


# y_dist_new = [1.3978, 1.4071, 1.4194, 1.4348, 1.4596, 1.4904, 1.5362, 1.5565, 1.5845, 1.6205, 1.6565, 1.6905, 1.7435]
plt.plot(np.array(x_vel), y_dist_new, label='new roadtrip')
x_vel_roadtrip = [0.0, 1.8627, 3.7253, 5.588, 7.4507, 9.3133, 11.5598, 13.645, 22.352, 31.2928, 33.528, 35.7632, 40.2336]
y_dist_roadtrip = [1.3978, 1.4132, 1.4318, 1.4536, 1.4862, 1.5321, 1.6058, 1.6589, 1.7798, 1.8748, 1.8953, 1.9127, 1.9276]
plt.plot(np.array(x_vel_roadtrip) * CV.MS_TO_MPH, y_dist_roadtrip, label='roadtrip')

x_vel_stock = [0.0, 1.8627, 3.7253, 5.588, 7.4507, 9.3133, 11.5598, 13.645, 22.352, 31.2928, 33.528, 35.7632, 40.2336]
y_dist_stock = [1.8 for _ in range(len(x_vel_stock))]
plt.plot(np.array(x_vel_stock) * CV.MS_TO_MPH, y_dist_stock, label='stock')

y_dist_roadtrip_new = []
for (x_vel, y_dist), y_stock in zip(zip(x_vel_roadtrip, y_dist_roadtrip), y_dist_stock):
print(x_vel)
x = [0, 55, 90]
y_roadtrip_mod = [0.625, 0.8, 0.2]
roadtrip_mod = np.interp(x_vel, x, y_roadtrip_mod)
stock_mod = 1 - roadtrip_mod
y_dist_roadtrip_new.append((y_dist * roadtrip_mod) + (y_stock * stock_mod))

plt.plot(np.array(x_vel_roadtrip) * CV.MS_TO_MPH, y_dist_roadtrip_new, label='new roadtrip')


# y_dist_roadtrip_new = []
# for x_vel, y_dist in zip(x_vel_roadtrip, y_dist_roadtrip):
# x = [16, 22, 30, 45, 60, 90]
# y = [1., 1.015, 1.046666, 1.075, 1.045, 1.08]
# y_dist *= ((np.interp(x_vel, x, y) - 1) / 2) + 1
# y_dist_roadtrip_new.append(y_dist)
#
# plt.plot(np.array(x_vel_roadtrip), np.round(y_dist_roadtrip_new, 3), label='new roadtrip')

# y_dist = np.mean(np.array([y_dist_old, y_dist_new]).T, axis=1)
# plt.plot(np.array(x_vel) * CV.MS_TO_MPH, y_dist, label='avg. traffic')
# print(y_dist.tolist())
# ft = np.array(traffic_x_vel) * np.array(traffic_y_dist) * 3.28084
# print(ft.tolist())
# plt.plot(np.array(traffic_x_vel) * CV.MS_TO_MPH, ft, 'o-', label='traffic profile')
# plt.plot(np.array(x_vel) * CV.MS_TO_MPH, np.array(x_vel) * np.array(y_dist), 'o-', label='relaxed profile')


# plt.plot([min(x), max(x)], [0, 0], 'r--')
Expand Down
38 changes: 19 additions & 19 deletions helper_scripts/df_profile_mod_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ def to_ms(x):
for v_ego in p_mod_x:
if v_ego != 80.:
continue
# roadtrip
x_vel = [0.0, 1.8627, 3.7253, 5.588, 7.4507, 9.3133, 11.5598, 13.645, 22.352, 31.2928, 33.528, 35.7632, 40.2336]
x_vel = to_mph(x_vel)
y_dist = [1.3978, 1.4132, 1.4318, 1.4536, 1.485, 1.5229, 1.5819, 1.6203, 1.7238, 1.8231, 1.8379, 1.8495, 1.8535] # avg. 7.3 ft closer from 18 to 90 mph
# profile to tune mods for
x_vel_tuning = [0.0, 1.8627, 3.7253, 5.588, 7.4507, 9.3133, 11.5598, 13.645, 22.352, 31.2928, 33.528, 35.7632, 40.2336]
x_vel_tuning = to_mph(x_vel_tuning)
y_dist_tuning = [1.5486, 1.556, 1.5655, 1.5773, 1.5964, 1.6246, 1.6715, 1.7057, 1.7859, 1.8542, 1.8697, 1.8833, 1.8961]

TR_traffic = interp(v_ego, x_vel, y_dist)
TR_tuning = interp(v_ego, x_vel_tuning, y_dist_tuning)

traffic_mod_pos = [0.92, 0.7, 0.25, 0.15]
traffic_mod_neg = [1.1, 1.3, 2.0, 2.3]
traffic_mod_pos = [0.5, 0.35, 0.1, 0.03]
traffic_mod_neg = [1.3, 1.4, 1.8, 2.0]

traffic_mod_pos = interp(v_ego, p_mod_x, traffic_mod_pos)
traffic_mod_neg = interp(v_ego, p_mod_x, traffic_mod_neg)

# relaxed
x_vel = [0.0, 1.8627, 3.7253, 5.588, 7.4507, 9.3133, 11.5598, 13.645, 22.352, 31.2928, 33.528, 35.7632, 40.2336]
x_vel = to_mph(x_vel)
y_dist = [1.385, 1.394, 1.406, 1.421, 1.444, 1.474, 1.516, 1.534, 1.546, 1.568, 1.579, 1.593, 1.614]
TR_relaxed = interp(v_ego, x_vel, y_dist)
# base profile to compare to (relaxed)
x_vel_base = [0.0, 1.8627, 3.7253, 5.588, 7.4507, 9.3133, 11.5598, 13.645, 22.352, 31.2928, 33.528, 35.7632, 40.2336]
x_vel_base = to_mph(x_vel_base)
y_dist_base = [1.385, 1.394, 1.406, 1.421, 1.444, 1.474, 1.516, 1.534, 1.546, 1.568, 1.579, 1.593, 1.614]
TR_base = interp(v_ego, x_vel_base, y_dist_base)
relaxed_mod_pos = [1.0, 1.0, 1.0, 1.0]
relaxed_mod_neg = [1.0, 1.0, 1.0, 1.0]
relaxed_mod_pos = interp(v_ego, p_mod_x, relaxed_mod_pos)
Expand All @@ -44,15 +44,15 @@ def to_ms(x):
TR_mod_pos = interp(-10, x_rel, y_rel)
TR_mod_neg = interp(3.6, x_rel, y_rel)
print('v_ego: {}'.format(v_ego))
print('traffic: {}'.format(TR_traffic))
pos_traffic = TR_traffic + TR_mod_pos * traffic_mod_pos
neg_traffic = TR_traffic + TR_mod_neg * traffic_mod_neg
print('TUNING TR: {}'.format(TR_tuning))
pos_traffic = TR_tuning + TR_mod_pos * traffic_mod_pos
neg_traffic = TR_tuning + TR_mod_neg * traffic_mod_neg
print('pos: {}, neg: {}'.format(pos_traffic, neg_traffic))
print()
print('relaxed: {}'.format(TR_relaxed))
pos_relaxed = TR_relaxed + TR_mod_pos * relaxed_mod_pos
neg_relaxed = TR_relaxed + TR_mod_neg * relaxed_mod_neg
print('BASE TR: {}'.format(TR_base))
pos_relaxed = TR_base + TR_mod_pos * relaxed_mod_pos
neg_relaxed = TR_base + TR_mod_neg * relaxed_mod_neg
print('pos: {}, neg: {}'.format(pos_relaxed, neg_relaxed))
print('pos difference: {}%'.format(100*(1 - (pos_traffic / pos_relaxed))))
print('\npos difference: {}%'.format(100*(1 - (pos_traffic / pos_relaxed))))
print('neg difference: {}%'.format(100*(1 - (neg_traffic / neg_relaxed))))
print('------')
6 changes: 3 additions & 3 deletions selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
tire_stiffness_factor = 0.444 # not optimized yet
ret.mass = 2860. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid

if ret.enableGasInterceptor:
ret.longitudinalTuning.kpV = [(_n * 0.5 + _o * 0.5) for _n, _o in zip([0.333, 0.364, 0.15], [1.2, 0.8, 0.5])]
ret.longitudinalTuning.kiV = [(_n * 0.5 + _o * 0.5) for _n, _o in zip([0.07, 0.05], [0.18, 0.12])]
# if ret.enableGasInterceptor:
# ret.longitudinalTuning.kpV = [(_n * 0.5 + _o * 0.5) for _n, _o in zip([0.333, 0.364, 0.15], [1.2, 0.8, 0.5])]
# ret.longitudinalTuning.kiV = [(_n * 0.5 + _o * 0.5) for _n, _o in zip([0.07, 0.05], [0.18, 0.12])]

ret.lateralTuning.init('lqr')
ret.lateralTuning.lqr.scale = 1500.0
Expand Down
26 changes: 20 additions & 6 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def data_sample(CI, CC, sm, can_sock, state, mismatch_counter, can_error_counter
return CS, events, cal_perc, mismatch_counter, can_error_counter


def state_transition(frame, CS, CP, state, events, soft_disable_timer, v_cruise_kph, AM):
def state_transition(frame, CS, CP, state, events, soft_disable_timer, v_cruise_kph, AM, sm_smiskol):
"""Compute conditional state transitions and execute actions on state transitions"""
enabled = isEnabled(state)

Expand All @@ -156,13 +156,27 @@ def state_transition(frame, CS, CP, state, events, soft_disable_timer, v_cruise_
# entrance in SOFT_DISABLING state
soft_disable_timer = max(0, soft_disable_timer - 1)

ls_state = sm_smiskol['laneSpeed'].state
if ls_state != '':
AM.add(frame, 'lsButtonAlert', enabled, extra_text_1=ls_state)

faster_lane = sm_smiskol['laneSpeed'].fastestLane
ls_alert_shown = False
if faster_lane in ['left', 'right']:
ls_alert = 'laneSpeedAlert'
if not sm_smiskol['laneSpeed'].new:
ls_alert += 'Silent'
AM.add(frame, ls_alert, enabled, extra_text_1='{} lane faster'.format(faster_lane).upper(), extra_text_2='Change lanes to faster {} lane'.format(faster_lane))
ls_alert_shown = True

df_out = df_manager.update()
if df_out.changed:
df_alert = 'dfButtonAlert'
if df_out.is_auto and df_out.last_is_auto:
if CS.cruiseState.enabled and not hide_auto_df_alerts:
df_alert += 'NoSound'
AM.add(frame, df_alert, enabled, extra_text_1=df_out.model_profile_text + ' (auto)', extra_text_2='Dynamic follow: {} profile active'.format(df_out.model_profile_text))
# only show auto alert if engaged, not hiding auto, and time since lane speed alert not showing
if CS.cruiseState.enabled and not hide_auto_df_alerts and not ls_alert_shown:
df_alert += 'Silent'
AM.add(frame, df_alert, enabled, extra_text_1=df_out.model_profile_text + ' (auto)')
else:
AM.add(frame, df_alert, enabled, extra_text_1=df_out.user_profile_text, extra_text_2='Dynamic follow: {} profile active'.format(df_out.user_profile_text))

Expand Down Expand Up @@ -486,7 +500,7 @@ def controlsd_thread(sm=None, pm=None, can_sock=None, sm_smiskol=None):
'model'])

if sm_smiskol is None:
sm_smiskol = messaging.SubMaster(['radarState', 'dynamicFollowData', 'liveTracks', 'dynamicFollowButton'])
sm_smiskol = messaging.SubMaster(['radarState', 'dynamicFollowData', 'liveTracks', 'dynamicFollowButton', 'laneSpeed'])

if can_sock is None:
can_timeout = None if os.environ.get('NO_CAN_TIMEOUT', False) else 100
Expand Down Expand Up @@ -604,7 +618,7 @@ def controlsd_thread(sm=None, pm=None, can_sock=None, sm_smiskol=None):
if not read_only:
# update control state
state, soft_disable_timer, v_cruise_kph, v_cruise_kph_last = \
state_transition(sm.frame, CS, CP, state, events, soft_disable_timer, v_cruise_kph, AM)
state_transition(sm.frame, CS, CP, state, events, soft_disable_timer, v_cruise_kph, AM, sm_smiskol)
prof.checkpoint("State transition")

# Compute actuators (runs PID loops and lateral MPC)
Expand Down
26 changes: 22 additions & 4 deletions selfdrive/controls/lib/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,32 @@ def __gt__(self, alert2):
"Using profile: ",
"",
AlertStatus.normal, AlertSize.mid,
Priority.LOWER, VisualAlert.none, AudibleAlert.chimeWarning1, 0.2, 0., 2.),
Priority.LOW, VisualAlert.none, AudibleAlert.chimeWarning1, 0.2, 0., 2.),

Alert("dfButtonAlertNoSound",
"Using profile: ",
Alert("lsButtonAlert",
"Lane Speed set to: ",
"",
AlertStatus.normal, AlertSize.mid,
AlertStatus.normal, AlertSize.small,
Priority.LOW, VisualAlert.none, AudibleAlert.chimeWarning1, 0.2, 0., 2.),

Alert("dfButtonAlertSilent",
"Dynamic follow: ",
"",
AlertStatus.normal, AlertSize.small,
Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0.2, 0., 2.),

Alert("laneSpeedAlert",
"",
"",
AlertStatus.normal, AlertSize.mid,
Priority.LOW, VisualAlert.none, AudibleAlert.chimeWarning1, 0.2, 0., 0.1),

Alert("laneSpeedAlertSilent",
"",
"",
AlertStatus.normal, AlertSize.mid,
Priority.LOW, VisualAlert.none, AudibleAlert.none, 0.2, 0., 0.1),

Alert(
"ethicalDilemma",
"TAKE CONTROL IMMEDIATELY",
Expand Down
48 changes: 34 additions & 14 deletions selfdrive/controls/lib/dynamic_follow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ def __init__(self, mpc_id):
self._setup_changing_variables()

def _setup_collector(self):
self.sm_collector = SubMaster(['liveTracks'])
self.sm_collector = SubMaster(['liveTracks', 'laneSpeed'])
self.log_auto_df = self.op_params.get('log_auto_df', False)
if not isinstance(self.log_auto_df, bool):
self.log_auto_df = False
self.data_collector = DataCollector(file_path='/data/df_data', keys=['v_ego', 'a_ego', 'a_lead', 'v_lead', 'x_lead', 'live_tracks', 'profile', 'time'], log_data=self.log_auto_df)
self.data_collector = DataCollector(file_path='/data/df_data', keys=['v_ego', 'a_ego', 'a_lead', 'v_lead', 'x_lead', 'left_lane_speeds', 'middle_lane_speeds', 'right_lane_speeds', 'left_lane_distances', 'middle_lane_distances', 'right_lane_distances', 'profile', 'time'], log_data=self.log_auto_df)

def _setup_changing_variables(self):
self.TR = self.default_TR
self.user_profile = self.df_profiles.relaxed # just a starting point
self.model_profile = self.df_profiles.relaxed

self.last_effective_profile = self.user_profile
self.profile_change_time = 0

self.sng = False
self.car_data = CarData()
self.lead_data = LeadData()
Expand Down Expand Up @@ -98,14 +101,20 @@ def _get_profiles(self):

def _gather_data(self):
self.sm_collector.update(0)
live_tracks = [[i.dRel, i.vRel, i.aRel, i.yRel] for i in self.sm_collector['liveTracks']]
# live_tracks = [[i.dRel, i.vRel, i.aRel, i.yRel] for i in self.sm_collector['liveTracks']]
if self.car_data.cruise_enabled:
self.data_collector.update([self.car_data.v_ego,
self.car_data.a_ego,
self.lead_data.a_lead,
self.lead_data.v_lead,
self.lead_data.x_lead,
live_tracks,
list(self.sm_collector['laneSpeed'].leftLaneSpeeds),
list(self.sm_collector['laneSpeed'].middleLaneSpeeds),
list(self.sm_collector['laneSpeed'].rightLaneSpeeds),

list(self.sm_collector['laneSpeed'].leftLaneDistances),
list(self.sm_collector['laneSpeed'].middleLaneDistances),
list(self.sm_collector['laneSpeed'].rightLaneDistances),
self.user_profile,
sec_since_boot()])

Expand All @@ -117,14 +126,21 @@ def _send_cur_state(self):
if self.mpc_id == 1 and self.pm is not None:
dat = messaging.new_message()
dat.init('dynamicFollowData')
dat.dynamicFollowData.mpcTR = 1.8 # self.TR # FIX THIS! sometimes nonetype
dat.dynamicFollowData.mpcTR = self.TR
dat.dynamicFollowData.profilePred = self.model_profile
self.pm.send('dynamicFollowData', dat)

def _change_cost(self, libmpc):
TRs = [0.9, 1.8, 2.7]
costs = [1.0, 0.115, 0.05]
costs = [1.25, 0.2, 0.075]
cost = interp(self.TR, TRs, costs)

change_time = sec_since_boot() - self.profile_change_time
change_time_x = [0, 0.5, 4] # for three seconds after effective profile has changed
change_mod_y = [2, 8, 1] # multiply cost by multiplier to quickly change distance
if change_time < change_time_x[-1]: # if profile changed in last 3 seconds
cost *= interp(change_time, change_time_x, change_mod_y)

if self.last_cost != cost:
libmpc.change_tr(MPC_COST_LONG.TTC, cost, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)
self.last_cost = cost
Expand Down Expand Up @@ -263,21 +279,25 @@ def _get_TR(self):
else:
df_profile = self.user_profile

if df_profile != self.last_effective_profile:
self.profile_change_time = sec_since_boot()
self.last_effective_profile = df_profile

if df_profile == self.df_profiles.roadtrip:
y_dist = [1.3978, 1.4132, 1.4318, 1.4536, 1.485, 1.5229, 1.5819, 1.6203, 1.7238, 1.8231, 1.8379, 1.8495, 1.8535] # TRs
profile_mod_pos = [0.92, 0.7, 0.25, 0.15]
profile_mod_neg = [1.1, 1.3, 2.0, 2.3]
y_dist = [1.5486, 1.556, 1.5655, 1.5773, 1.5964, 1.6246, 1.6715, 1.7057, 1.7859, 1.8542, 1.8697, 1.8833, 1.8961] # TRs
profile_mod_pos = [0.5, 0.35, 0.1, 0.03]
profile_mod_neg = [1.3, 1.4, 1.8, 2.0]
elif df_profile == self.df_profiles.traffic: # for in congested traffic
x_vel = [0.0, 1.892, 3.7432, 5.8632, 8.0727, 10.7301, 14.343, 17.6275, 22.4049, 28.6752, 34.8858, 40.35]
# y_dist = [1.3781, 1.3791, 1.3802, 1.3825, 1.3984, 1.4249, 1.4194, 1.3162, 1.1916, 1.0145, 0.9855, 0.9562] # original
# y_dist = [1.3781, 1.3791, 1.3112, 1.2442, 1.2306, 1.2112, 1.2775, 1.1977, 1.0963, 0.9435, 0.9067, 0.8749] # avg. 7.3 ft closer from 18 to 90 mph
y_dist = [1.3781, 1.3791, 1.3457, 1.3134, 1.3145, 1.318, 1.3485, 1.257, 1.144, 0.979, 0.9461, 0.9156]
profile_mod_pos = [1.05, 1.55, 2.6, 3.75]
profile_mod_neg = [0.84, .275, 0.1, 0.05]
profile_mod_pos = [1.075, 1.55, 2.6, 3.75]
profile_mod_neg = [0.95, .275, 0.1, 0.05]
elif df_profile == self.df_profiles.relaxed: # default to relaxed/stock
y_dist = [1.385, 1.394, 1.406, 1.421, 1.444, 1.474, 1.516, 1.534, 1.546, 1.568, 1.579, 1.593, 1.614]
profile_mod_pos = [1.0] * 4
profile_mod_neg = [1.0] * 4
y_dist = [1.385, 1.394, 1.406, 1.421, 1.444, 1.474, 1.521, 1.544, 1.568, 1.588, 1.599, 1.613, 1.634]
profile_mod_pos = [1.0, 0.955, 0.898, 0.905]
profile_mod_neg = [1.0, 1.0825, 1.1877, 1.174]
else:
raise Exception('Unknown profile type: {}'.format(df_profile))

Expand Down
Loading