From f5b28ad2d267adae0d6e6fd7816389d3f8d32200 Mon Sep 17 00:00:00 2001 From: HaraldSchafer Date: Wed, 15 Apr 2020 21:19:25 -0700 Subject: [PATCH] add traffic convention (#1372) * I think this works * clean up --- selfdrive/modeld/modeld.cc | 2 +- selfdrive/modeld/models/driving.cc | 22 ++++++++++++++-------- selfdrive/modeld/models/driving.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/selfdrive/modeld/modeld.cc b/selfdrive/modeld/modeld.cc index 7a2a85d52a..1f5da4ac6b 100644 --- a/selfdrive/modeld/modeld.cc +++ b/selfdrive/modeld/modeld.cc @@ -219,7 +219,7 @@ int main(int argc, char **argv) { ModelDataRaw model_buf = model_eval_frame(&model, q, yuv_cl, buf_info.width, buf_info.height, - model_transform, NULL, vec_desire, NULL); + model_transform, NULL, vec_desire); mt2 = millis_since_boot(); model_publish(model_sock, extra.frame_id, model_buf, extra.timestamp_eof); diff --git a/selfdrive/modeld/models/driving.cc b/selfdrive/modeld/models/driving.cc index df84e4fc56..3cae9657a3 100644 --- a/selfdrive/modeld/models/driving.cc +++ b/selfdrive/modeld/models/driving.cc @@ -3,6 +3,7 @@ #include #include #include "common/timing.h" +#include "common/params.h" #include "driving.h" @@ -53,6 +54,18 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t s->traffic_convention = (float*)malloc(TRAFFIC_CONVENTION_LEN * sizeof(float)); for (int i = 0; i < TRAFFIC_CONVENTION_LEN; i++) s->traffic_convention[i] = 0.0; s->m->addTrafficConvention(s->traffic_convention, TRAFFIC_CONVENTION_LEN); + + char *string; + const int result = read_db_value(NULL, "IsRHD", &string, NULL); + if (result == 0) { + bool is_rhd = string[0] == '1'; + free(string); + if (is_rhd) { + s->traffic_convention[1] = 1.0; + } else { + s->traffic_convention[0] = 1.0; + } + } #endif // Build Vandermonde matrix @@ -68,7 +81,7 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q, cl_mem yuv_cl, int width, int height, mat3 transform, void* sock, - float *desire_in, float *traffic_convention_in) { + float *desire_in) { #ifdef DESIRE if (desire_in != NULL) { for (int i = 0; i < DESIRE_LEN; i++) { @@ -84,13 +97,6 @@ ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q, } #endif -#ifdef TRAFFIC_CONVENTION - if (traffic_convention_in != NULL) { - for (int i = 0; i < TRAFFIC_CONVENTION_LEN; i++) { - s->traffic_convention[i] = traffic_convention_in[i]; - } - } -#endif //for (int i = 0; i < OUTPUT_SIZE + TEMPORAL_SIZE; i++) { printf("%f ", s->output[i]); } printf("\n"); diff --git a/selfdrive/modeld/models/driving.h b/selfdrive/modeld/models/driving.h index 45d5396e7c..1366960833 100644 --- a/selfdrive/modeld/models/driving.h +++ b/selfdrive/modeld/models/driving.h @@ -74,7 +74,7 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int temporal); ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q, cl_mem yuv_cl, int width, int height, - mat3 transform, void* sock, float *desire_in, float *traffic_convention_in); + mat3 transform, void* sock, float *desire_in); void model_free(ModelState* s); void poly_fit(float *in_pts, float *in_stds, float *out);