mirror of https://github.com/rusefi/rusefi.git
only: setTimeNowUs(): replace global fiddling with a function call
This commit is contained in:
parent
a42092826a
commit
3f45fd63c5
|
@ -586,9 +586,8 @@ struct LuaIndustrialPid final {
|
||||||
|
|
||||||
float get(float target, float input) {
|
float get(float target, float input) {
|
||||||
#if EFI_UNIT_TEST
|
#if EFI_UNIT_TEST
|
||||||
extern int timeNowUs;
|
|
||||||
// this is how we avoid zero dt
|
// this is how we avoid zero dt
|
||||||
timeNowUs += 1000;
|
advanceTimeUs(1000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float dt = m_lastUpdate.getElapsedSecondsAndReset(getTimeNowNt());
|
float dt = m_lastUpdate.getElapsedSecondsAndReset(getTimeNowNt());
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
extern WaveChart waveChart;
|
extern WaveChart waveChart;
|
||||||
#endif /* EFI_ENGINE_SNIFFER */
|
#endif /* EFI_ENGINE_SNIFFER */
|
||||||
|
|
||||||
|
|
||||||
extern int timeNowUs;
|
|
||||||
extern WarningCodeState unitTestWarningCodeState;
|
extern WarningCodeState unitTestWarningCodeState;
|
||||||
extern engine_configuration_s & activeConfiguration;
|
extern engine_configuration_s & activeConfiguration;
|
||||||
extern bool printTriggerDebug;
|
extern bool printTriggerDebug;
|
||||||
|
@ -256,10 +254,10 @@ void EngineTestHelper::moveTimeForwardAndInvokeEventsUs(int deltaTimeUs) {
|
||||||
if (printTriggerDebug || printFuelDebug) {
|
if (printTriggerDebug || printFuelDebug) {
|
||||||
printf("moveTimeForwardAndInvokeEventsUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
printf("moveTimeForwardAndInvokeEventsUs %.1fms\r\n", deltaTimeUs / 1000.0);
|
||||||
}
|
}
|
||||||
setTimeAndInvokeEventsUs(timeNowUs + deltaTimeUs);
|
setTimeAndInvokeEventsUs(getTimeNowUs() + deltaTimeUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineTestHelper::setTimeAndInvokeEventsUs(int targetTime) {
|
void EngineTestHelper::setTimeAndInvokeEventsUs(int targetTimeUs) {
|
||||||
while (true) {
|
while (true) {
|
||||||
scheduling_s* nextScheduledEvent = engine.executor.getHead();
|
scheduling_s* nextScheduledEvent = engine.executor.getHead();
|
||||||
if (nextScheduledEvent == nullptr) {
|
if (nextScheduledEvent == nullptr) {
|
||||||
|
@ -267,15 +265,15 @@ void EngineTestHelper::setTimeAndInvokeEventsUs(int targetTime) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int nextEventTime = nextScheduledEvent->momentX;
|
int nextEventTime = nextScheduledEvent->momentX;
|
||||||
if (nextEventTime > targetTime) {
|
if (nextEventTime > targetTimeUs) {
|
||||||
// next event is too far in the future
|
// next event is too far in the future
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
timeNowUs = nextEventTime;
|
setTimeNowUs(nextEventTime);
|
||||||
engine.executor.executeAll(timeNowUs);
|
engine.executor.executeAll(getTimeNowUs());
|
||||||
}
|
}
|
||||||
|
|
||||||
timeNowUs = targetTime;
|
setTimeNowUs(targetTimeUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineTestHelper::fireTriggerEvents(int count) {
|
void EngineTestHelper::fireTriggerEvents(int count) {
|
||||||
|
|
|
@ -48,7 +48,6 @@ TEST(etb, integrated) {
|
||||||
ASSERT_NEAR(destination, 130.2554, EPS3D);
|
ASSERT_NEAR(destination, 130.2554, EPS3D);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int timeNowUs;
|
|
||||||
extern WarningCodeState unitTestWarningCodeState;
|
extern WarningCodeState unitTestWarningCodeState;
|
||||||
|
|
||||||
TEST(etb, intermittentTps) {
|
TEST(etb, intermittentTps) {
|
||||||
|
@ -60,7 +59,7 @@ TEST(etb, intermittentTps) {
|
||||||
// Tell the sensor checker that the ignition is on
|
// Tell the sensor checker that the ignition is on
|
||||||
engine->module<SensorChecker>()->onIgnitionStateChanged(true);
|
engine->module<SensorChecker>()->onIgnitionStateChanged(true);
|
||||||
engine->module<SensorChecker>()->onSlowCallback();
|
engine->module<SensorChecker>()->onSlowCallback();
|
||||||
timeNowUs += MS2US(1000);
|
advanceTimeUs(MS2US(1000));
|
||||||
engine->module<SensorChecker>()->onSlowCallback();
|
engine->module<SensorChecker>()->onSlowCallback();
|
||||||
// todo: fix me https://github.com/rusefi/rusefi/issues/5233
|
// todo: fix me https://github.com/rusefi/rusefi/issues/5233
|
||||||
// EXPECT_EQ( 3, recentWarnings.getCount()) << "intermittentTps";
|
// EXPECT_EQ( 3, recentWarnings.getCount()) << "intermittentTps";
|
||||||
|
@ -117,7 +116,7 @@ TEST(etb, intermittentPps) {
|
||||||
// Tell the sensor checker that the ignition is on
|
// Tell the sensor checker that the ignition is on
|
||||||
engine->module<SensorChecker>()->onIgnitionStateChanged(true);
|
engine->module<SensorChecker>()->onIgnitionStateChanged(true);
|
||||||
engine->module<SensorChecker>()->onSlowCallback();
|
engine->module<SensorChecker>()->onSlowCallback();
|
||||||
timeNowUs += 10e6;
|
advanceTimeUs(10e6);
|
||||||
engine->module<SensorChecker>()->onSlowCallback();
|
engine->module<SensorChecker>()->onSlowCallback();
|
||||||
|
|
||||||
ASSERT_TRUE(engine->module<SensorChecker>()->analogSensorsShouldWork());
|
ASSERT_TRUE(engine->module<SensorChecker>()->analogSensorsShouldWork());
|
||||||
|
|
|
@ -208,8 +208,6 @@ TEST(idle_v2, runningOpenLoopTpsTaper) {
|
||||||
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 0, 20));
|
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(IIdleController::Phase::Cranking, 0, 0, 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int timeNowUs;
|
|
||||||
|
|
||||||
TEST(idle_v2, runningOpenLoopTpsTaperWithDashpot) {
|
TEST(idle_v2, runningOpenLoopTpsTaperWithDashpot) {
|
||||||
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
|
||||||
IdleController dut;
|
IdleController dut;
|
||||||
|
@ -227,21 +225,21 @@ TEST(idle_v2, runningOpenLoopTpsTaperWithDashpot) {
|
||||||
engineConfiguration->iacByTpsDecayTime = 10; // 10 secs
|
engineConfiguration->iacByTpsDecayTime = 10; // 10 secs
|
||||||
|
|
||||||
// save the lastTimeRunningUs time - let it be the start of the hold phase
|
// save the lastTimeRunningUs time - let it be the start of the hold phase
|
||||||
timeNowUs += 5'000'000;
|
advanceTimeUs(5'000'000);
|
||||||
// full throttle = max.iac
|
// full throttle = max.iac
|
||||||
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(ICP::Running, 0, 0, 100));
|
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(ICP::Running, 0, 0, 100));
|
||||||
|
|
||||||
// jump to the end of the 'hold' phase of dashpot
|
// jump to the end of the 'hold' phase of dashpot
|
||||||
timeNowUs += 10'000'000;
|
advanceTimeUs(10'000'000);
|
||||||
|
|
||||||
// change the state to idle (release the pedal) - but still 100% max.iac!
|
// change the state to idle (release the pedal) - but still 100% max.iac!
|
||||||
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
|
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
|
||||||
// now we're in the middle of decay
|
// now we're in the middle of decay
|
||||||
timeNowUs += 5'000'000;
|
advanceTimeUs(5'000'000);
|
||||||
// 50% decay (50% of 50 is 25)
|
// 50% decay (50% of 50 is 25)
|
||||||
EXPECT_FLOAT_EQ(25, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
|
EXPECT_FLOAT_EQ(25, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
|
||||||
// now the decay is finished
|
// now the decay is finished
|
||||||
timeNowUs += 5'000'000;
|
advanceTimeUs(5'000'000);
|
||||||
// no correction
|
// no correction
|
||||||
EXPECT_FLOAT_EQ(0, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
|
EXPECT_FLOAT_EQ(0, dut.getRunningOpenLoop(ICP::Idling, 0, 0, 0));
|
||||||
// still react to the pedal
|
// still react to the pedal
|
||||||
|
|
Loading…
Reference in New Issue