mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-23 17:23:44 +08:00
UI: remove duplicate capnp readers (#20855)
* refactor submaster * rebase master * CAPNP best pratice * zero initialize * vwp_w has not been initialized before UIState() * no static * rebase master * Minimize refactoring * cleanup * remove gpsOk Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 533bc30c2e4ecac5e022f2ba4f3919842dfa0a1a
This commit is contained in:
+9
-27
@@ -72,7 +72,6 @@ static void update_leads(UIState *s, const cereal::RadarState::Reader &radar_sta
|
||||
// negative because radarState uses left positive convention
|
||||
calib_frame_to_full_frame(s, lead_data.getDRel(), -lead_data.getYRel(), z + 1.22, &s->scene.lead_vertices[i]);
|
||||
}
|
||||
s->scene.lead_data[i] = lead_data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +113,9 @@ static void update_model(UIState *s, const cereal::ModelDataV2::Reader &model) {
|
||||
}
|
||||
|
||||
// update path
|
||||
if (scene.lead_data[0].getStatus()) {
|
||||
const float lead_d = scene.lead_data[0].getDRel() * 2.;
|
||||
auto lead_one = (*s->sm)["radarState"].getRadarState().getLeadOne();
|
||||
if (lead_one.getStatus()) {
|
||||
const float lead_d = lead_one.getDRel() * 2.;
|
||||
max_distance = std::clamp((float)(lead_d - fmin(lead_d * 0.35, 10.)), 0.0f, max_distance);
|
||||
}
|
||||
max_idx = get_path_length_idx(model_position, max_distance);
|
||||
@@ -123,20 +123,13 @@ static void update_model(UIState *s, const cereal::ModelDataV2::Reader &model) {
|
||||
}
|
||||
|
||||
static void update_sockets(UIState *s){
|
||||
SubMaster &sm = *(s->sm);
|
||||
sm.update(0);
|
||||
s->sm->update(0);
|
||||
}
|
||||
|
||||
static void update_state(UIState *s) {
|
||||
SubMaster &sm = *(s->sm);
|
||||
|
||||
UIScene &scene = s->scene;
|
||||
if (scene.started && sm.updated("controlsState")) {
|
||||
scene.controls_state = sm["controlsState"].getControlsState();
|
||||
}
|
||||
if (sm.updated("carState")) {
|
||||
scene.car_state = sm["carState"].getCarState();
|
||||
}
|
||||
|
||||
if (sm.updated("radarState")) {
|
||||
std::optional<cereal::ModelDataV2::XYZTData::Reader> line;
|
||||
if (sm.rcv_frame("modelV2") > 0) {
|
||||
@@ -164,9 +157,6 @@ static void update_state(UIState *s) {
|
||||
if (sm.updated("modelV2")) {
|
||||
update_model(s, sm["modelV2"].getModelV2());
|
||||
}
|
||||
if (sm.updated("deviceState")) {
|
||||
scene.deviceState = sm["deviceState"].getDeviceState();
|
||||
}
|
||||
if (sm.updated("pandaState")) {
|
||||
auto pandaState = sm["pandaState"].getPandaState();
|
||||
scene.pandaType = pandaState.getPandaType();
|
||||
@@ -180,18 +170,9 @@ static void update_state(UIState *s) {
|
||||
scene.satelliteCount = data.getMeasurementReport().getNumMeas();
|
||||
}
|
||||
}
|
||||
if (sm.updated("liveLocationKalman")) {
|
||||
scene.gpsOK = sm["liveLocationKalman"].getLiveLocationKalman().getGpsOK();
|
||||
}
|
||||
if (sm.updated("carParams")) {
|
||||
scene.longitudinal_control = sm["carParams"].getCarParams().getOpenpilotLongitudinalControl();
|
||||
}
|
||||
if (sm.updated("driverState")) {
|
||||
scene.driver_state = sm["driverState"].getDriverState();
|
||||
}
|
||||
if (sm.updated("driverMonitoringState")) {
|
||||
scene.dmonitoring_state = sm["driverMonitoringState"].getDriverMonitoringState();
|
||||
}
|
||||
if (sm.updated("sensorEvents")) {
|
||||
for (auto sensor : sm["sensorEvents"].getSensorEvents()) {
|
||||
if (!Hardware::TICI() && sensor.which() == cereal::SensorEventData::LIGHT) {
|
||||
@@ -215,7 +196,7 @@ static void update_state(UIState *s) {
|
||||
float gain = camera_state.getGainFrac() * (camera_state.getGlobalGain() > 100 ? 2.5 : 1.0) / 10.0;
|
||||
scene.light_sensor = std::clamp<float>((1023.0 / 1757.0) * (1757.0 - camera_state.getIntegLines()) * (1.0 - gain), 0.0, 1023.0);
|
||||
}
|
||||
scene.started = scene.deviceState.getStarted() || scene.driver_view;
|
||||
scene.started = sm["deviceState"].getDeviceState().getStarted() || scene.driver_view;
|
||||
}
|
||||
|
||||
static void update_params(UIState *s) {
|
||||
@@ -245,13 +226,14 @@ static void update_vision(UIState *s) {
|
||||
|
||||
static void update_status(UIState *s) {
|
||||
if (s->scene.started && s->sm->updated("controlsState")) {
|
||||
auto alert_status = s->scene.controls_state.getAlertStatus();
|
||||
auto controls_state = (*s->sm)["controlsState"].getControlsState();
|
||||
auto alert_status = controls_state.getAlertStatus();
|
||||
if (alert_status == cereal::ControlsState::AlertStatus::USER_PROMPT) {
|
||||
s->status = STATUS_WARNING;
|
||||
} else if (alert_status == cereal::ControlsState::AlertStatus::CRITICAL) {
|
||||
s->status = STATUS_ALERT;
|
||||
} else {
|
||||
s->status = s->scene.controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED;
|
||||
s->status = controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user