From 4bd08f0355b6b2cf3c027202d5ad301b4e182953 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期五, 31 三月 2023 17:16:22 +0800 Subject: [PATCH] 科目二修改 --- lib/src/main/cpp/test_common/odo_graph.cpp | 41 +++++++++++++++++++++++------------------ 1 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/src/main/cpp/test_common/odo_graph.cpp b/lib/src/main/cpp/test_common/odo_graph.cpp index 87381a9..555b177 100644 --- a/lib/src/main/cpp/test_common/odo_graph.cpp +++ b/lib/src/main/cpp/test_common/odo_graph.cpp @@ -3,18 +3,18 @@ // #include "odo_graph.h" -#include "../test_items2/road_exam.h" #include "../common/apptimer.h" #include "../utils/xconvert.h" +#include "../driver_test.h" static double odoGraph; -static struct RtkTime odoTimer; -static double odoPrevSpeed; -static int odoCnt; +static int64_t prevTimestamp; +static double prevSpeed; +static bool isstop; void ResetOdo(void) { - odoCnt = 0; + isstop = true; odoGraph = 0; } @@ -23,22 +23,27 @@ return odoGraph; } -void UpdataOdo(double speed, int moveDirect, const struct RtkTime *rtkTime) { +void UpdataOdo(motion_t &motion) { // 琛岄┒璺濈锛屽惈鍊掕溅 - if (odoCnt == 0 && moveDirect != 0) { - odoPrevSpeed = speed; - odoCnt = 1; - odoTimer = *rtkTime; - } else if (odoCnt == 1) { - if (moveDirect != 0) { - uint32_t tm = TimeGetDiff(rtkTime, &odoTimer); - if (tm >= D_SEC(1)) { - odoGraph += ((double) tm) * (odoPrevSpeed + speed) / 2.0 / 1000.0; - odoTimer = *rtkTime; - odoPrevSpeed = speed; + if (isstop && motion.move != STOP) { + prevSpeed = motion.speed; + isstop = false; + prevTimestamp = motion.timestamp; + } else if (!isstop) { + if (motion.move != STOP) { + uint32_t elapsed = motion.timestamp - prevTimestamp; + if (elapsed >= D_SEC(5)) { // 涓�旈暱鏃堕棿鏈畾浣嶏紝閲嶆柊寮�濮嬫祴閲� + prevSpeed = motion.speed; + prevTimestamp = motion.timestamp; + return; + } + if (elapsed >= D_SEC(1)) { + odoGraph += ((double) elapsed) * (prevSpeed + motion.speed) / 2.0 / 1000.0; + prevTimestamp = motion.timestamp; + prevSpeed = motion.speed; } } else { - odoCnt = 0; + isstop = true; } } } \ No newline at end of file -- Gitblit v1.8.0