Skip to content

Commit

Permalink
Auto Lane Change Timer: cleaner method (commaai#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin authored Jun 28, 2023
1 parent 30c5781 commit 938a646
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 4 additions & 3 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def __init__(self, sm=None, pm=None, can_sock=None, CI=None):
self.v_cruise_helper = VCruiseHelper(self.CP)
self.recalibrating_seen = False

self.lane_change_set_timer = int(self.params.get("AutoLaneChangeTimer", encoding="utf8"))
self.reverse_acc_change = False

self.live_torque = self.params.get_bool("LiveTorque")
Expand Down Expand Up @@ -317,7 +318,6 @@ def update_events(self, CS):
self.events.add(EventName.calibrationInvalid)

# Handle lane change
lane_change_set_timer = int(self.params.get("AutoLaneChangeTimer", encoding="utf8"))
if self.sm['lateralPlan'].laneChangeEdgeBlock:
self.events.add(EventName.laneChangeRoadEdge)
elif self.sm['lateralPlan'].laneChangeState == LaneChangeState.preLaneChange:
Expand All @@ -328,10 +328,10 @@ def update_events(self, CS):
self.events.add(EventName.laneChangeBlocked)
else:
if direction == LaneChangeDirection.left:
self.events.add(EventName.preLaneChangeLeft) if lane_change_set_timer == 0 or lc_prev else \
self.events.add(EventName.preLaneChangeLeft) if self.lane_change_set_timer == 0 or lc_prev else \
self.events.add(EventName.laneChange)
else:
self.events.add(EventName.preLaneChangeRight) if lane_change_set_timer == 0 or lc_prev else \
self.events.add(EventName.preLaneChangeRight) if self.lane_change_set_timer == 0 or lc_prev else \
self.events.add(EventName.laneChange)
elif self.sm['lateralPlan'].laneChangeState in (LaneChangeState.laneChangeStarting,
LaneChangeState.laneChangeFinishing):
Expand Down Expand Up @@ -900,6 +900,7 @@ def step(self):
self.is_metric = self.params.get_bool("IsMetric")
self.experimental_mode = self.params.get_bool("ExperimentalMode") and self.CP.openpilotLongitudinalControl

self.lane_change_set_timer = int(self.params.get("AutoLaneChangeTimer", encoding="utf8"))
self.reverse_acc_change = self.params.get_bool("ReverseAccChange")

# Sample data from sockets and get a carState
Expand Down
15 changes: 11 additions & 4 deletions selfdrive/controls/lib/desire_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
},
}

AUTO_LANE_CHANGE_TIMER = {
0: 0.0,
1: 0.1,
2: 0.5,
3: 1.0,
4: 1.5,
}


class DesireHelper:
def __init__(self):
Expand All @@ -48,13 +56,12 @@ def __init__(self):
self.road_edge = False
self.count = 0
self.edge_toggle = self.param_s.get("RoadEdge")
self.lane_change_set_timer = int(self.param_s.get("AutoLaneChangeTimer", encoding="utf8"))
self.lane_change_bsm_delay = self.param_s.get_bool("AutoLaneChangeBsmDelay")

def update(self, carstate, lateral_active, lane_change_prob, model_data):
lane_change_set_timer = int(self.param_s.get("AutoLaneChangeTimer", encoding="utf8"))
lane_change_auto_timer = 0.0 if lane_change_set_timer == 0 else 0.1 if lane_change_set_timer == 1 else \
0.5 if lane_change_set_timer == 2 else 1.0 if lane_change_set_timer == 3 else \
1.5 if lane_change_set_timer == 4 else 2.0
self.lane_change_set_timer = int(self.param_s.get("AutoLaneChangeTimer", encoding="utf8"))
lane_change_auto_timer = AUTO_LANE_CHANGE_TIMER.get(self.lane_change_set_timer, 2.0)
v_ego = carstate.vEgo
one_blinker = carstate.leftBlinker != carstate.rightBlinker
below_lane_change_speed = v_ego < LANE_CHANGE_SPEED_MIN
Expand Down

0 comments on commit 938a646

Please sign in to comment.