Skip to content

Commit bd2b09c

Browse files
Deprecate controlsState state fields (#33437)
* Deprecate controlsState state fields * sim works * update refs * one more * these too * update sim old-commit-hash: 3924ac5
1 parent 53288d4 commit bd2b09c

File tree

18 files changed

+60
-74
lines changed

18 files changed

+60
-74
lines changed

cereal/log.capnp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -739,21 +739,7 @@ struct ControlsState @0x97ff69c53601abf1 {
739739
aTarget @35 :Float32;
740740
curvature @37 :Float32; # path curvature from vehicle model
741741
desiredCurvature @61 :Float32; # lag adjusted curvatures used by lateral controllers
742-
743-
# TODO: remove these, they're now in selfdriveState
744-
alertText1 @24 :Text;
745-
alertText2 @25 :Text;
746-
alertStatus @38 :SelfdriveState.AlertStatus;
747-
alertSize @39 :SelfdriveState.AlertSize;
748-
alertType @44 :Text;
749-
alertSound @56 :Car.CarControl.HUDControl.AudibleAlert;
750-
engageable @41 :Bool; # can OP be engaged?
751742
forceDecel @51 :Bool;
752-
state @31 :SelfdriveState.OpenpilotState;
753-
enabled @19 :Bool;
754-
active @36 :Bool;
755-
experimentalMode @64 :Bool;
756-
personality @66 :LongitudinalPersonality;
757743

758744
lateralControlState :union {
759745
indiState @52 :LateralINDIState;
@@ -880,6 +866,18 @@ struct ControlsState @0x97ff69c53601abf1 {
880866
canErrorCounterDEPRECATED @57 :UInt32;
881867
vPidDEPRECATED @2 :Float32;
882868
alertBlinkingRateDEPRECATED @42 :Float32;
869+
alertText1DEPRECATED @24 :Text;
870+
alertText2DEPRECATED @25 :Text;
871+
alertStatusDEPRECATED @38 :SelfdriveState.AlertStatus;
872+
alertSizeDEPRECATED @39 :SelfdriveState.AlertSize;
873+
alertTypeDEPRECATED @44 :Text;
874+
alertSound2DEPRECATED @56 :Car.CarControl.HUDControl.AudibleAlert;
875+
engageableDEPRECATED @41 :Bool; # can OP be engaged?
876+
stateDEPRECATED @31 :SelfdriveState.OpenpilotState;
877+
enabledDEPRECATED @19 :Bool;
878+
activeDEPRECATED @36 :Bool;
879+
experimentalModeDEPRECATED @64 :Bool;
880+
personalityDEPRECATED @66 :LongitudinalPersonality;
883881
vCruiseDEPRECATED @22 :Float32; # actual set speed
884882
vCruiseClusterDEPRECATED @63 :Float32; # set speed to display in the UI
885883
}

selfdrive/controls/controlsd.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -733,31 +733,17 @@ def publish_logs(self, CS, start_time, CC, lac_log):
733733
dat = messaging.new_message('controlsState')
734734
dat.valid = CS.canValid
735735
controlsState = dat.controlsState
736-
if current_alert:
737-
controlsState.alertText1 = current_alert.alert_text_1
738-
controlsState.alertText2 = current_alert.alert_text_2
739-
controlsState.alertSize = current_alert.alert_size
740-
controlsState.alertStatus = current_alert.alert_status
741-
controlsState.alertType = current_alert.alert_type
742-
controlsState.alertSound = current_alert.audible_alert
743-
744736
controlsState.longitudinalPlanMonoTime = self.sm.logMonoTime['longitudinalPlan']
745737
controlsState.lateralPlanMonoTime = self.sm.logMonoTime['modelV2']
746-
controlsState.enabled = self.enabled
747-
controlsState.active = self.active
748738
controlsState.curvature = curvature
749739
controlsState.desiredCurvature = self.desired_curvature
750-
controlsState.state = self.state
751-
controlsState.engageable = not self.events.contains(ET.NO_ENTRY)
752740
controlsState.longControlState = self.LoC.long_control_state
753741
controlsState.upAccelCmd = float(self.LoC.pid.p)
754742
controlsState.uiAccelCmd = float(self.LoC.pid.i)
755743
controlsState.ufAccelCmd = float(self.LoC.pid.f)
756744
controlsState.cumLagMs = -self.rk.remaining * 1000.
757745
controlsState.startMonoTime = int(start_time * 1e9)
758746
controlsState.forceDecel = bool(force_decel)
759-
controlsState.experimentalMode = self.experimental_mode
760-
controlsState.personality = self.personality
761747

762748
lat_tuning = self.CP.lateralTuning.which()
763749
if self.joystick_mode:

selfdrive/controls/lib/longitudinal_planner.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def parse_model(model_msg, model_error):
9696
return x, v, a, j
9797

9898
def update(self, sm):
99-
self.mpc.mode = 'blended' if sm['controlsState'].experimentalMode else 'acc'
99+
self.mpc.mode = 'blended' if sm['selfdriveState'].experimentalMode else 'acc'
100100

101101
v_ego = sm['carState'].vEgo
102102
v_cruise_kph = min(sm['carState'].vCruise, V_CRUISE_MAX)
@@ -106,7 +106,7 @@ def update(self, sm):
106106
force_slow_decel = sm['controlsState'].forceDecel
107107

108108
# Reset current state when not engaged, or user is controlling the speed
109-
reset_state = long_control_off if self.CP.openpilotLongitudinalControl else not sm['controlsState'].enabled
109+
reset_state = long_control_off if self.CP.openpilotLongitudinalControl else not sm['selfdriveState'].enabled
110110

111111
# No change cost when user is controlling the speed, or when standstill
112112
prev_accel_constraint = not (reset_state or sm['carState'].standstill)
@@ -134,11 +134,11 @@ def update(self, sm):
134134
accel_limits_turns[0] = min(accel_limits_turns[0], self.a_desired + 0.05)
135135
accel_limits_turns[1] = max(accel_limits_turns[1], self.a_desired - 0.05)
136136

137-
self.mpc.set_weights(prev_accel_constraint, personality=sm['controlsState'].personality)
137+
self.mpc.set_weights(prev_accel_constraint, personality=sm['selfdriveState'].personality)
138138
self.mpc.set_accel_limits(accel_limits_turns[0], accel_limits_turns[1])
139139
self.mpc.set_cur_state(self.v_desired_filter.x, self.a_desired)
140140
x, v, a, j = self.parse_model(sm['modelV2'], self.v_model_error)
141-
self.mpc.update(sm['radarState'], v_cruise, x, v, a, j, personality=sm['controlsState'].personality)
141+
self.mpc.update(sm['radarState'], v_cruise, x, v, a, j, personality=sm['selfdriveState'].personality)
142142

143143
self.v_desired_trajectory = np.interp(CONTROL_N_T_IDX, T_IDXS_MPC, self.mpc.v_solution)
144144
self.a_desired_trajectory = np.interp(CONTROL_N_T_IDX, T_IDXS_MPC, self.mpc.a_solution)
@@ -157,7 +157,7 @@ def update(self, sm):
157157
def publish(self, sm, pm):
158158
plan_send = messaging.new_message('longitudinalPlan')
159159

160-
plan_send.valid = sm.all_checks(service_list=['carState', 'controlsState'])
160+
plan_send.valid = sm.all_checks(service_list=['carState', 'controlsState', 'selfdriveState'])
161161

162162
longitudinalPlan = plan_send.longitudinalPlan
163163
longitudinalPlan.modelMonoTime = sm.logMonoTime['modelV2']

selfdrive/controls/plannerd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def plannerd_thread():
1717

1818
longitudinal_planner = LongitudinalPlanner(CP)
1919
pm = messaging.PubMaster(['longitudinalPlan'])
20-
sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2'],
20+
sm = messaging.SubMaster(['carControl', 'carState', 'controlsState', 'radarState', 'modelV2', 'selfdriveState'],
2121
poll='modelV2', ignore_avg_freq=['radarState'])
2222

2323
while True:

selfdrive/monitoring/dmonitoringd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def dmonitoringd_thread():
1313

1414
params = Params()
1515
pm = messaging.PubMaster(['driverMonitoringState'])
16-
sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'controlsState', 'modelV2'], poll='driverStateV2')
16+
sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'selfdriveState', 'modelV2'], poll='driverStateV2')
1717

1818
DM = DriverMonitoring(rhd_saved=params.get_bool("IsRhdDetected"), always_on=params.get_bool("AlwaysOnDM"))
1919

selfdrive/monitoring/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,13 @@ def run_step(self, sm):
403403
driver_state=sm['driverStateV2'],
404404
cal_rpy=sm['liveCalibration'].rpyCalib,
405405
car_speed=sm['carState'].vEgo,
406-
op_engaged=sm['controlsState'].enabled
406+
op_engaged=sm['selfdriveState'].enabled
407407
)
408408

409409
# Update distraction events
410410
self._update_events(
411411
driver_engaged=sm['carState'].steeringPressed or sm['carState'].gasPressed,
412-
op_engaged=sm['controlsState'].enabled,
412+
op_engaged=sm['selfdriveState'].enabled,
413413
standstill=sm['carState'].standstill,
414414
wrong_gear=sm['carState'].gearShifter in [car.CarState.GearShifter.reverse, car.CarState.GearShifter.park],
415415
car_speed=sm['carState'].vEgo

selfdrive/pandad/pandad.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void send_peripheral_state(Panda *panda, PubMaster *pm) {
313313
}
314314

315315
void process_panda_state(std::vector<Panda *> &pandas, PubMaster *pm, bool spoofing_started) {
316-
static SubMaster sm({"controlsState"});
316+
static SubMaster sm({"selfdriveState"});
317317

318318
std::vector<std::string> connected_serials;
319319
for (Panda *p : pandas) {
@@ -351,7 +351,7 @@ void process_panda_state(std::vector<Panda *> &pandas, PubMaster *pm, bool spoof
351351
}
352352

353353
sm.update(0);
354-
const bool engaged = sm.allAliveAndValid({"controlsState"}) && sm["controlsState"].getControlsState().getEnabled();
354+
const bool engaged = sm.allAliveAndValid({"selfdriveState"}) && sm["selfdriveState"].getSelfdriveState().getEnabled();
355355
for (const auto &panda : pandas) {
356356
panda->send_heartbeat(engaged);
357357
}

selfdrive/test/longitudinal_maneuvers/plant.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self, lead_relevancy=False, speed=0.0, distance_lead=2.0,
2121
if not Plant.messaging_initialized:
2222
Plant.radar = messaging.pub_sock('radarState')
2323
Plant.controls_state = messaging.pub_sock('controlsState')
24+
Plant.selfdrive_state = messaging.pub_sock('selfdriveState')
2425
Plant.car_state = messaging.pub_sock('carState')
2526
Plant.plan = messaging.sub_sock('longitudinalPlan')
2627
Plant.messaging_initialized = True
@@ -61,6 +62,7 @@ def step(self, v_lead=0.0, prob=1.0, v_cruise=50.):
6162
# note that this is worst case for MPC, since model will delay long mpc by one time step
6263
radar = messaging.new_message('radarState')
6364
control = messaging.new_message('controlsState')
65+
ss = messaging.new_message('selfdriveState')
6466
car_state = messaging.new_message('carState')
6567
model = messaging.new_message('modelV2')
6668
a_lead = (v_lead - self.v_lead_prev)/self.ts
@@ -111,8 +113,8 @@ def step(self, v_lead=0.0, prob=1.0, v_cruise=50.):
111113
model.modelV2.acceleration = acceleration
112114

113115
control.controlsState.longControlState = LongCtrlState.pid if self.enabled else LongCtrlState.off
114-
control.controlsState.experimentalMode = self.e2e
115-
control.controlsState.personality = self.personality
116+
ss.selfdriveState.experimentalMode = self.e2e
117+
ss.selfdriveState.personality = self.personality
116118
control.controlsState.forceDecel = self.force_decel
117119
car_state.carState.vEgo = float(self.speed)
118120
car_state.carState.standstill = self.speed < 0.01
@@ -122,6 +124,7 @@ def step(self, v_lead=0.0, prob=1.0, v_cruise=50.):
122124
sm = {'radarState': radar.radarState,
123125
'carState': car_state.carState,
124126
'controlsState': control.controlsState,
127+
'selfdriveState': ss.selfdriveState,
125128
'modelV2': model.modelV2}
126129
self.planner.update(sm)
127130
self.speed = self.planner.v_desired_filter.x

selfdrive/test/process_replay/migration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def migrate_controlsState(lr):
3939
m.logMonoTime = msg.logMonoTime
4040
ss = m.selfdriveState
4141
for field in ("enabled", "active", "state", "engageable", "alertText1", "alertText2",
42-
"alertStatus", "alertSize", "alertType", "alertSound", "experimentalMode",
42+
"alertStatus", "alertSize", "alertType", "experimentalMode",
4343
"personality"):
44-
setattr(ss, field, getattr(msg.controlsState, field))
44+
setattr(ss, field, getattr(msg.controlsState, field+"DEPRECATED"))
4545
ret.append(m.as_reader())
4646
elif msg.which() == 'carState' and last_cs is not None:
4747
if last_cs.controlsState.vCruiseDEPRECATED - msg.carState.vCruise > 0.1:

selfdrive/test/process_replay/process_replay.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def locationd_config_pubsub_callback(params, cfg, lr):
506506
),
507507
ProcessConfig(
508508
proc_name="plannerd",
509-
pubs=["modelV2", "carControl", "carState", "controlsState", "radarState"],
509+
pubs=["modelV2", "carControl", "carState", "controlsState", "radarState", "selfdriveState"],
510510
subs=["longitudinalPlan"],
511511
ignore=["logMonoTime", "longitudinalPlan.processingDelay", "longitudinalPlan.solverExecutionTime"],
512512
init_callback=get_car_params_callback,
@@ -522,7 +522,7 @@ def locationd_config_pubsub_callback(params, cfg, lr):
522522
),
523523
ProcessConfig(
524524
proc_name="dmonitoringd",
525-
pubs=["driverStateV2", "liveCalibration", "carState", "modelV2", "controlsState"],
525+
pubs=["driverStateV2", "liveCalibration", "carState", "modelV2", "selfdriveState"],
526526
subs=["driverMonitoringState"],
527527
ignore=["logMonoTime"],
528528
should_recv_callback=FrequencyBasedRcvCallback("driverStateV2"),
@@ -810,8 +810,8 @@ def check_openpilot_enabled(msgs: LogIterable) -> bool:
810810
if msg.which() == "carParams":
811811
if msg.carParams.notCar:
812812
return True
813-
elif msg.which() == "controlsState":
814-
if msg.controlsState.active:
813+
elif msg.which() == "selfdriveState":
814+
if msg.selfdriveState.active:
815815
cur_enabled_count += 1
816816
else:
817817
cur_enabled_count = 0

0 commit comments

Comments
 (0)