driver monitoring cleanup (#2101)

* read rhd from param

* don't need that anymore

* fix build

* bump cereal

* read param from camerad too

* add read_db_bool helper

* bump model replay ref commit, IsRHD wasn't set
pull/2104/head
Adeeb Shihadeh 2020-08-29 17:16:00 -07:00 committed by GitHub
parent 284938cd43
commit 349040d958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 23 additions and 43 deletions

2
cereal

@ -1 +1 @@
Subproject commit 78b8887198a4d4c86d1e7e251dcb38b6e6672710
Subproject commit 1538183eaa3c9a22a3e675182d6e1cc8e23ad574

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <signal.h>
#include <cassert>
#include <vector>
#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) {

View File

@ -366,3 +366,8 @@ std::vector<char> 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<char> bytes = read_db_bytes(param_name, persistent_param);
return bytes.size() > 0 and bytes[0] == '1';
}

View File

@ -40,4 +40,5 @@ void read_db_value_blocking(const char* key, char** value, size_t* value_sz, boo
#include <vector>
int read_db_all(std::map<std::string, std::string> *params, bool persistent_param = false);
std::vector<char> read_db_bytes(const char* param_name, bool persistent_param = false);
bool read_db_bool(const char* param_name, bool persistent_param = false);
#endif

View File

@ -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

View File

@ -2,6 +2,7 @@
#include "dmonitoring.h"
#include "common/mat.h"
#include "common/timing.h"
#include "common/params.h"
#include <libyuv.h>
@ -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 <class T>

View File

@ -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<uint8_t> resized_buf;
std::vector<uint8_t> cropped_buf;

View File

@ -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<float[]>(TRAFFIC_CONVENTION_LEN);
s->m->addTrafficConvention(s->traffic_convention.get(), TRAFFIC_CONVENTION_LEN);
std::vector<char> 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

View File

@ -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(),

View File

@ -1 +1 @@
55aee68ca0f3c5ba9fa5b100d21149cad79b732b
734ee7118a5bcab4accdd73ae8fdc03df104157a