diff --git a/cereal b/cereal index 78b8887198..1538183eaa 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 78b8887198a4d4c86d1e7e251dcb38b6e6672710 +Subproject commit 1538183eaa3c9a22a3e675182d6e1cc8e23ad574 diff --git a/selfdrive/camerad/main.cc b/selfdrive/camerad/main.cc index 658204a751..bbd850d04e 100644 --- a/selfdrive/camerad/main.cc +++ b/selfdrive/camerad/main.cc @@ -1,6 +1,7 @@ #include #include #include +#include #if defined(QCOM) && !defined(QCOM_REPLAY) #include "cameras/camera_qcom.h" @@ -13,6 +14,7 @@ #endif #include "common/util.h" +#include "common/params.h" #include "common/swaglog.h" #include "common/ipc.h" @@ -145,8 +147,8 @@ struct VisionState { int rgb_front_width, rgb_front_height, rgb_front_stride; VisionBuf rgb_front_bufs[UI_BUF_COUNT]; cl_mem rgb_front_bufs_cl[UI_BUF_COUNT]; + bool rhd_front; - bool rhd_front_checked; int front_meteringbox_xmin, front_meteringbox_xmax; int front_meteringbox_ymin, front_meteringbox_ymax; @@ -181,11 +183,12 @@ struct VisionState { void* frontview_thread(void *arg) { int err; VisionState *s = (VisionState*)arg; + s->rhd_front = read_db_bool("IsRHD"); set_thread_name("frontview"); // we subscribe to this for placement of the AE metering box // TODO: the loop is bad, ideally models shouldn't affect sensors - SubMaster sm({"driverState", "dMonitoringState"}); + SubMaster sm({"driverState"}); cl_command_queue q = clCreateCommandQueue(s->context, s->device_id, 0, &err); assert(err == 0); @@ -236,12 +239,6 @@ void* frontview_thread(void *arg) { visionbuf_sync(&s->rgb_front_bufs[ui_idx], VISIONBUF_SYNC_FROM_DEVICE); sm.update(0); - // no more check after gps check - if (!s->rhd_front_checked && sm.updated("dMonitoringState")) { - auto state = sm["dMonitoringState"].getDMonitoringState(); - s->rhd_front = state.getIsRHD(); - s->rhd_front_checked = state.getRhdChecked(); - } #ifdef NOSCREEN if (frame_data.frame_id % 4 == 2) { diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index 4d9c214d37..3da9079552 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -366,3 +366,8 @@ std::vector read_db_bytes(const char* param_name, bool persistent_param) { } return bytes; } + +bool read_db_bool(const char* param_name, bool persistent_param) { + std::vector bytes = read_db_bytes(param_name, persistent_param); + return bytes.size() > 0 and bytes[0] == '1'; +} diff --git a/selfdrive/common/params.h b/selfdrive/common/params.h index 49af04b4fd..394c9b6ed7 100644 --- a/selfdrive/common/params.h +++ b/selfdrive/common/params.h @@ -40,4 +40,5 @@ void read_db_value_blocking(const char* key, char** value, size_t* value_sz, boo #include int read_db_all(std::map *params, bool persistent_param = false); std::vector read_db_bytes(const char* param_name, bool persistent_param = false); +bool read_db_bool(const char* param_name, bool persistent_param = false); #endif diff --git a/selfdrive/modeld/dmonitoringmodeld.cc b/selfdrive/modeld/dmonitoringmodeld.cc index 28776f94ee..4f3c3053d8 100644 --- a/selfdrive/modeld/dmonitoringmodeld.cc +++ b/selfdrive/modeld/dmonitoringmodeld.cc @@ -49,7 +49,6 @@ int main(int argc, char **argv) { LOGW("connected with buffer size: %d", buf_info.buf_len); double last = 0; - int chk_counter = 0; while (!do_exit) { VIPCBuf *buf; VIPCBufExtra extra; @@ -58,23 +57,9 @@ int main(int argc, char **argv) { printf("visionstream get failed\n"); break; } - //printf("frame_id: %d %dx%d\n", extra.frame_id, buf_info.width, buf_info.height); - if (!dmonitoringmodel.is_rhd_checked) { - if (chk_counter >= RHD_CHECK_INTERVAL) { - if (sm.update(0) > 0) { - auto state = sm["dMonitoringState"].getDMonitoringState(); - dmonitoringmodel.is_rhd = state.getIsRHD(); - dmonitoringmodel.is_rhd_checked = state.getRhdChecked(); - } - chk_counter = 0; - } - chk_counter += 1; - } double t1 = millis_since_boot(); - DMonitoringResult res = dmonitoring_eval_frame(&dmonitoringmodel, buf->addr, buf_info.width, buf_info.height); - double t2 = millis_since_boot(); // send dm packet diff --git a/selfdrive/modeld/models/dmonitoring.cc b/selfdrive/modeld/models/dmonitoring.cc index 4f4203a38a..163ff3bee8 100644 --- a/selfdrive/modeld/models/dmonitoring.cc +++ b/selfdrive/modeld/models/dmonitoring.cc @@ -2,6 +2,7 @@ #include "dmonitoring.h" #include "common/mat.h" #include "common/timing.h" +#include "common/params.h" #include @@ -22,8 +23,7 @@ void dmonitoring_init(DMonitoringModelState* s) { const char* model_path = "../../models/dmonitoring_model.dlc"; #endif s->m = new DefaultRunModel(model_path, (float*)&s->output, OUTPUT_SIZE, USE_DSP_RUNTIME); - s->is_rhd = false; - s->is_rhd_checked = false; + s->is_rhd = read_db_bool("IsRHD"); } template diff --git a/selfdrive/modeld/models/dmonitoring.h b/selfdrive/modeld/models/dmonitoring.h index 439b9c0051..b1b6819d57 100644 --- a/selfdrive/modeld/models/dmonitoring.h +++ b/selfdrive/modeld/models/dmonitoring.h @@ -10,7 +10,6 @@ extern "C" { #endif #define OUTPUT_SIZE 34 -#define RHD_CHECK_INTERVAL 10 typedef struct DMonitoringResult { float face_orientation[3]; @@ -28,7 +27,6 @@ typedef struct DMonitoringResult { typedef struct DMonitoringModelState { RunModel *m; bool is_rhd; - bool is_rhd_checked; float output[OUTPUT_SIZE]; std::vector resized_buf; std::vector cropped_buf; diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index 71e4fcae3a..f15aa13f3b 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -54,14 +54,11 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t s->traffic_convention = std::make_unique(TRAFFIC_CONVENTION_LEN); s->m->addTrafficConvention(s->traffic_convention.get(), TRAFFIC_CONVENTION_LEN); - std::vector result = read_db_bytes("IsRHD"); - if (result.size() > 0) { - bool is_rhd = result[0] == '1'; - if (is_rhd) { - s->traffic_convention[1] = 1.0; - } else { - s->traffic_convention[0] = 1.0; - } + bool is_rhd = read_db_bool("IsRHD"); + if (is_rhd) { + s->traffic_convention[1] = 1.0; + } else { + s->traffic_convention[0] = 1.0; } #endif diff --git a/selfdrive/monitoring/dmonitoringd.py b/selfdrive/monitoring/dmonitoringd.py index 6b0d184bfe..e93964a3a5 100755 --- a/selfdrive/monitoring/dmonitoringd.py +++ b/selfdrive/monitoring/dmonitoringd.py @@ -20,12 +20,10 @@ def dmonitoringd_thread(sm=None, pm=None): if sm is None: sm = messaging.SubMaster(['driverState', 'liveCalibration', 'carState', 'model']) - is_rhd = Params().get("IsRHD") - offroad = Params().get("IsOffroad") == b"1" - driver_status = DriverStatus() - driver_status.is_rhd_region = is_rhd == b"1" - driver_status.is_rhd_region_checked = is_rhd is not None + driver_status.is_rhd_region = Params().get("IsRHD") == b"1" + + offroad = Params().get("IsOffroad") == b"1" sm['liveCalibration'].calStatus = Calibration.INVALID sm['liveCalibration'].rpyCalib = [0, 0, 0] @@ -78,7 +76,6 @@ def dmonitoringd_thread(sm=None, pm=None): "isDistracted": driver_status.driver_distracted, "awarenessStatus": driver_status.awareness, "isRHD": driver_status.is_rhd_region, - "rhdChecked": driver_status.is_rhd_region_checked, "posePitchOffset": driver_status.pose.pitch_offseter.filtered_stat.mean(), "posePitchValidCount": driver_status.pose.pitch_offseter.filtered_stat.n, "poseYawOffset": driver_status.pose.yaw_offseter.filtered_stat.mean(), diff --git a/selfdrive/test/process_replay/model_replay_ref_commit b/selfdrive/test/process_replay/model_replay_ref_commit index 40e490daf6..57015b7459 100644 --- a/selfdrive/test/process_replay/model_replay_ref_commit +++ b/selfdrive/test/process_replay/model_replay_ref_commit @@ -1 +1 @@ -55aee68ca0f3c5ba9fa5b100d21149cad79b732b \ No newline at end of file +734ee7118a5bcab4accdd73ae8fdc03df104157a \ No newline at end of file