From f6e7e8871a7b0d15f4e4d4b8e33581aa5e9260d1 Mon Sep 17 00:00:00 2001 From: rusefi Date: Fri, 31 Jan 2020 01:49:10 -0500 Subject: [PATCH] VVT refactoring & assertions for VVT test --- firmware/console/status_loop.cpp | 4 ++-- firmware/controllers/actuators/aux_pid.cpp | 2 +- firmware/controllers/core/fsio_impl.cpp | 2 +- firmware/controllers/trigger/trigger_central.cpp | 4 ++++ firmware/controllers/trigger/trigger_central.h | 2 ++ firmware/svnversion.h | 6 +++--- unit_tests/tests/test_cam_vtt_input.cpp | 4 ++++ unit_tests/unit_test_framework.h | 3 +++ 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 1fbb22228e..3bc5c5d0d1 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -308,7 +308,7 @@ static void printSensors(Logging *log) { if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { reportSensorF(log, GAUGE_NAME_FUEL_VE, "%", engine->engineState.currentBaroCorrectedVE * PERCENT_MULT, 2); } - reportSensorF(log, GAUGE_NAME_VVT, "deg", engine->triggerCentral.vvtPosition, 1); + reportSensorF(log, GAUGE_NAME_VVT, "deg", engine->triggerCentral.getVVTPosition(), 1); float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE); reportSensorF(log, GAUGE_NAME_ENGINE_LOAD, "x", engineLoad, 2); @@ -782,7 +782,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ efitimesec_t timeSeconds = getTimeNowSeconds(); tsOutputChannels->timeSeconds = timeSeconds; // 248 - tsOutputChannels->vvtPosition = engine->triggerCentral.vvtPosition; + tsOutputChannels->vvtPosition = engine->triggerCentral.getVVTPosition(); // 252 tsOutputChannels->engineMode = packEngineMode(PASS_ENGINE_PARAMETER_SIGNATURE); // 120 diff --git a/firmware/controllers/actuators/aux_pid.cpp b/firmware/controllers/actuators/aux_pid.cpp index d83ad57664..7bd367d806 100644 --- a/firmware/controllers/actuators/aux_pid.cpp +++ b/firmware/controllers/actuators/aux_pid.cpp @@ -84,7 +84,7 @@ public: } - float value = engine->triggerCentral.vvtPosition; + float value = engine->triggerCentral.getVVTPosition(); float targetValue = table->getValue(rpm, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE)); percent_t pwm = auxPid.getOutput(targetValue, value); diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 94098df728..4fb636c12d 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -137,7 +137,7 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { return getMap(PASS_ENGINE_PARAMETER_SIGNATURE); case LE_METHOD_INTAKE_VVT: case LE_METHOD_EXHAUST_VVT: - return engine->triggerCentral.vvtPosition; + return engine->triggerCentral.getVVTPosition(); case LE_METHOD_TIME_SINCE_BOOT: return getTimeNowSeconds(); diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 425b7ca614..4cbd508835 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -72,6 +72,10 @@ void TriggerCentral::addEventListener(ShaftPositionListener listener, const char triggerListeneres.registerCallback((VoidInt)(void*)listener, engine); } +angle_t TriggerCentral::getVVTPosition() { + return vvtPosition; +} + /** * @brief Adds a trigger event listener * diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 5bad20e69d..c3c578bca7 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -46,6 +46,8 @@ public: TriggerNoiseFilter noiseFilter; + angle_t getVVTPosition(); + angle_t vvtPosition = 0; /** * this is similar to TriggerState#startOfCycleNt but with the crank-only sensor magic diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 96a9b53afa..8895695227 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Mon Nov 18 15:37:47 EST 2019 +// Fri Jan 31 01:23:06 EST 2020 #ifndef GIT_HASH -#define GIT_HASH "919b7393d75467a0cac9b97ed34e29192d782bfc" +#define GIT_HASH "d48a57d599dcaa48b15e95be2a9fa0c4fb9361ff" #endif #ifndef VCS_VERSION -#define VCS_VERSION "21021" +#define VCS_VERSION "21477" #endif diff --git a/unit_tests/tests/test_cam_vtt_input.cpp b/unit_tests/tests/test_cam_vtt_input.cpp index 3bdf64336e..7256a484c0 100644 --- a/unit_tests/tests/test_cam_vtt_input.cpp +++ b/unit_tests/tests/test_cam_vtt_input.cpp @@ -134,7 +134,11 @@ TEST(sensors, testNB2CamInput) { // this second important front would give us first real VVT gap duration hwHandleVvtCamSignal(TV_RISE, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); + ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition()); + eth.moveTimeForwardUs(MS2US(130)); // this third important front would give us first comparison between two real gaps hwHandleVvtCamSignal(TV_RISE, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); + + ASSERT_NEAR(-46, engine->triggerCentral.getVVTPosition(), EPS3D); } diff --git a/unit_tests/unit_test_framework.h b/unit_tests/unit_test_framework.h index a9ea863f2b..d117e194da 100644 --- a/unit_tests/unit_test_framework.h +++ b/unit_tests/unit_test_framework.h @@ -16,6 +16,9 @@ using ::testing::Return; // This lets us inspect private state from unit tests #define private public +/** + * These are usually used with ASSETR_NEAR(val1, val2, abs_error) + */ #define EPS0D 1 #define EPS1D 0.1 #define EPS2D 0.01