Skip to content

Commit

Permalink
Add e2e long toggle (commaai#25638)
Browse files Browse the repository at this point in the history
* Add toggle

* Misc fixes

* Update translations

* pre alpha not great
  • Loading branch information
haraschax authored and rjsmith1999 committed Sep 16, 2022
1 parent 938d54c commit 32c4af5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions selfdrive/common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"ControlsReady", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_ON},
{"CurrentRoute", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_ON},
{"DisablePowerDown", PERSISTENT},
{"EndToEndLong", PERSISTENT},
{"DisableRadar_Allow", PERSISTENT},
{"DisableRadar", PERSISTENT}, // WARNING: THIS DISABLES AEB
{"DisableUpdates", PERSISTENT},
Expand Down
10 changes: 4 additions & 6 deletions selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ def set_weights(self, prev_accel_constraint=True):
cost_weights = [X_EGO_OBSTACLE_COST, X_EGO_COST, V_EGO_COST, A_EGO_COST, a_change_cost, J_EGO_COST]
constraint_cost_weights = [LIMIT_COST, LIMIT_COST, LIMIT_COST, DANGER_ZONE_COST]
elif self.mode == 'blended':
cost_weights = [0., 1.0, 0.0, 0.0, 0.0, 1.0]
constraint_cost_weights = [LIMIT_COST, LIMIT_COST, LIMIT_COST, 0.0]
cost_weights = [0., 0.2, 0.25, 1.0, 0.0, 1.0]
constraint_cost_weights = [LIMIT_COST, LIMIT_COST, LIMIT_COST, 5.0]
elif self.mode == 'e2e':
cost_weights = [0., 0.2, 0.25, 1., 0.0, .1]
constraint_cost_weights = [LIMIT_COST, LIMIT_COST, LIMIT_COST, 0.0]
else:
raise NotImplementedError(f'Planner mode {self.mode} not recognized')
raise NotImplementedError(f'Planner mode {self.mode} not recognized in planner cost set')
self.set_cost_weights(cost_weights, constraint_cost_weights)

def set_cur_state(self, v, a):
Expand Down Expand Up @@ -347,7 +347,7 @@ def update(self, carstate, radarstate, v_cruise, x, v, a, j):
self.source = 'e2e'

else:
raise NotImplementedError(f'Planner mode {self.mode} not recognized')
raise NotImplementedError(f'Planner mode {self.mode} not recognized in planner update')

self.yref[:,1] = x
self.yref[:,2] = v
Expand All @@ -357,8 +357,6 @@ def update(self, carstate, radarstate, v_cruise, x, v, a, j):
self.solver.set(i, "yref", self.yref[i])
self.solver.set(N, "yref", self.yref[N][:COST_E_DIM])

x_obstacles = np.column_stack([lead_0_obstacle, lead_1_obstacle, cruise_obstacle])
self.source = SOURCES[np.argmin(x_obstacles[0])]
self.params[:,2] = np.min(x_obstacles, axis=1)
self.params[:,3] = np.copy(self.prev_a)

Expand Down
9 changes: 7 additions & 2 deletions selfdrive/controls/lib/longitudinal_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cereal.messaging as messaging
from common.conversions import Conversions as CV
from common.filter_simple import FirstOrderFilter
from common.params import Params
from common.realtime import DT_MDL
from selfdrive.modeld.constants import T_IDXS
from selfdrive.controls.lib.longcontrol import LongCtrlState
Expand Down Expand Up @@ -47,7 +48,10 @@ def limit_accel_in_turns(v_ego, angle_steers, a_target, CP):
class Planner:
def __init__(self, CP, init_v=0.0, init_a=0.0):
self.CP = CP
self.mpc = LongitudinalMpc()
params = Params()
# TODO read param in the loop for live toggling
mode = 'blended' if params.get_bool('EndToEndLong') else 'acc'
self.mpc = LongitudinalMpc(mode=mode)

self.fcw = False

Expand Down Expand Up @@ -122,7 +126,8 @@ def update(self, sm):
self.j_desired_trajectory = np.interp(T_IDXS[:CONTROL_N], T_IDXS_MPC[:-1], self.mpc.j_solution)

# TODO counter is only needed because radar is glitchy, remove once radar is gone
self.fcw = self.mpc.crash_cnt > 5
# TODO write fcw in e2e_long mode
self.fcw = self.mpc.mode == 'acc' and self.mpc.crash_cnt > 5
if self.fcw:
cloudlog.info("FCW triggered")

Expand Down
6 changes: 6 additions & 0 deletions selfdrive/ui/qt/offroad/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
"Upload data from the driver facing camera and help improve the driver monitoring algorithm.",
"../assets/offroad/icon_monitoring.png",
},
{
"EndToEndLong",
tr("🌮 End-to-end longitudinal (extremely alpha) 🌮"),
tr("Let the driving model control the gas and brakes, openpilot will drive as it thinks a human would. Super experimental."),
"../assets/offroad/icon_road.png",
},
{
"DisengageOnAccelerator",
"Disengage On Accelerator Pedal",
Expand Down

0 comments on commit 32c4af5

Please sign in to comment.