Skip to content

Commit cebf71c

Browse files
committed
longcontrol: remove starting state
1 parent d1e143a commit cebf71c

2 files changed

Lines changed: 15 additions & 42 deletions

File tree

openpilot/selfdrive/controls/lib/longcontrol.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
LongCtrlState = car.CarControl.Actuators.LongControlState
1111

1212

13-
def long_control_state_trans(CP, active, long_control_state, v_ego,
14-
should_stop, brake_pressed, cruise_standstill):
13+
def long_control_state_trans(active, long_control_state, should_stop, brake_pressed, cruise_standstill):
1514
starting_condition = (not should_stop and
1615
not cruise_standstill and
1716
not brake_pressed)
@@ -23,22 +22,17 @@ def long_control_state_trans(CP, active, long_control_state, v_ego,
2322
if long_control_state == LongCtrlState.off:
2423
if not starting_condition:
2524
long_control_state = LongCtrlState.stopping
26-
elif CP.startingState:
27-
long_control_state = LongCtrlState.starting
2825
else:
2926
long_control_state = LongCtrlState.pid
3027

3128
elif long_control_state == LongCtrlState.stopping:
32-
if starting_condition and CP.startingState:
33-
long_control_state = LongCtrlState.starting
34-
elif starting_condition:
29+
if starting_condition:
3530
long_control_state = LongCtrlState.pid
3631

37-
elif long_control_state in [LongCtrlState.starting, LongCtrlState.pid]:
32+
elif long_control_state == LongCtrlState.pid:
3833
if should_stop:
3934
long_control_state = LongCtrlState.stopping
40-
elif v_ego > CP.vEgoStarting:
41-
long_control_state = LongCtrlState.pid
35+
4236
return long_control_state
4337

4438
class LongControl:
@@ -58,9 +52,8 @@ def update(self, active, CS, a_target, should_stop, accel_limits):
5852
self.pid.neg_limit = accel_limits[0]
5953
self.pid.pos_limit = accel_limits[1]
6054

61-
self.long_control_state = long_control_state_trans(self.CP, active, self.long_control_state, CS.vEgo,
62-
should_stop, CS.brakePressed,
63-
CS.cruiseState.standstill)
55+
self.long_control_state = long_control_state_trans(active, self.long_control_state, should_stop,
56+
CS.brakePressed, CS.cruiseState.standstill)
6457
if self.long_control_state == LongCtrlState.off:
6558
self.reset()
6659
output_accel = 0.
@@ -72,10 +65,6 @@ def update(self, active, CS, a_target, should_stop, accel_limits):
7265
output_accel -= self.CP.stoppingDecelRate * DT_CTRL
7366
self.reset()
7467

75-
elif self.long_control_state == LongCtrlState.starting:
76-
output_accel = self.CP.startAccel
77-
self.reset()
78-
7968
else: # LongCtrlState.pid
8069
error = a_target - CS.aEgo
8170
output_accel = self.pid.update(error, speed=CS.vEgo,
Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,40 @@
1-
from opendbc.car.structs import car
21
from openpilot.selfdrive.controls.lib.longcontrol import LongCtrlState, long_control_state_trans
32

43

5-
6-
74
class TestLongControlStateTransition:
85

96
def test_stay_stopped(self):
10-
CP = car.CarParams.new_message()
117
active = True
128
current_state = LongCtrlState.stopping
13-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
9+
next_state = long_control_state_trans(active, current_state,
1410
should_stop=True, brake_pressed=False, cruise_standstill=False)
1511
assert next_state == LongCtrlState.stopping
16-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
12+
next_state = long_control_state_trans(active, current_state,
1713
should_stop=False, brake_pressed=True, cruise_standstill=False)
1814
assert next_state == LongCtrlState.stopping
19-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
15+
next_state = long_control_state_trans(active, current_state,
2016
should_stop=False, brake_pressed=False, cruise_standstill=True)
2117
assert next_state == LongCtrlState.stopping
22-
next_state = long_control_state_trans(CP, active, current_state, v_ego=1.0,
18+
next_state = long_control_state_trans(active, current_state,
2319
should_stop=False, brake_pressed=False, cruise_standstill=False)
2420
assert next_state == LongCtrlState.pid
2521
active = False
26-
next_state = long_control_state_trans(CP, active, current_state, v_ego=1.0,
22+
next_state = long_control_state_trans(active, current_state,
2723
should_stop=False, brake_pressed=False, cruise_standstill=False)
2824
assert next_state == LongCtrlState.off
2925

3026
def test_engage():
31-
CP = car.CarParams.new_message()
3227
active = True
3328
current_state = LongCtrlState.off
34-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
29+
next_state = long_control_state_trans(active, current_state,
3530
should_stop=True, brake_pressed=False, cruise_standstill=False)
3631
assert next_state == LongCtrlState.stopping
37-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
32+
next_state = long_control_state_trans(active, current_state,
3833
should_stop=False, brake_pressed=True, cruise_standstill=False)
3934
assert next_state == LongCtrlState.stopping
40-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
35+
next_state = long_control_state_trans(active, current_state,
4136
should_stop=False, brake_pressed=False, cruise_standstill=True)
4237
assert next_state == LongCtrlState.stopping
43-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
44-
should_stop=False, brake_pressed=False, cruise_standstill=False)
45-
assert next_state == LongCtrlState.pid
46-
47-
def test_starting():
48-
CP = car.CarParams.new_message(startingState=True, vEgoStarting=0.5)
49-
active = True
50-
current_state = LongCtrlState.starting
51-
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1,
52-
should_stop=False, brake_pressed=False, cruise_standstill=False)
53-
assert next_state == LongCtrlState.starting
54-
next_state = long_control_state_trans(CP, active, current_state, v_ego=1.0,
38+
next_state = long_control_state_trans(active, current_state,
5539
should_stop=False, brake_pressed=False, cruise_standstill=False)
5640
assert next_state == LongCtrlState.pid

0 commit comments

Comments
 (0)