2021-07-02 11:56:12 -07:00
|
|
|
/*
|
|
|
|
* @file test_nissan_vq_vvt.cpp
|
|
|
|
*
|
|
|
|
* Created on: Jul 2, 2021
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2021
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engine_test_helper.h"
|
2021-07-02 14:32:29 -07:00
|
|
|
#include "trigger_nissan.h"
|
|
|
|
|
|
|
|
class TriggerCallback {
|
|
|
|
public:
|
|
|
|
Engine *engine;
|
2021-07-02 16:23:37 -07:00
|
|
|
int toothIndex;
|
2021-07-02 14:32:29 -07:00
|
|
|
TriggerWaveform *form;
|
2021-07-02 16:23:37 -07:00
|
|
|
bool isVvt;
|
2021-07-02 17:28:15 -07:00
|
|
|
int vvtIndex;
|
2021-07-02 14:32:29 -07:00
|
|
|
};
|
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
static void func(TriggerCallback *callback) {
|
2021-07-02 16:23:37 -07:00
|
|
|
int formIndex = callback->toothIndex % callback->form->getSize();
|
2021-07-02 14:32:29 -07:00
|
|
|
Engine *engine = callback->engine;
|
|
|
|
EXPAND_Engine;
|
|
|
|
|
|
|
|
int value = callback->form->wave.channels[0].getState(formIndex);
|
2021-07-02 16:23:37 -07:00
|
|
|
efitick_t nowNt = getTimeNowNt();
|
|
|
|
if (callback->isVvt) {
|
|
|
|
trigger_value_e v = value ? TV_RISE : TV_FALL;
|
2021-07-02 17:28:15 -07:00
|
|
|
hwHandleVvtCamSignal(v, nowNt, callback->vvtIndex PASS_ENGINE_PARAMETER_SUFFIX);
|
2021-07-02 14:32:29 -07:00
|
|
|
} else {
|
2021-07-02 16:23:37 -07:00
|
|
|
handleShaftSignal(0, value, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
2021-07-02 14:32:29 -07:00
|
|
|
}
|
2021-07-02 16:23:37 -07:00
|
|
|
}
|
|
|
|
|
2021-07-02 14:32:29 -07:00
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
static void scheduleTriggerEvents(TriggerWaveform *shape,
|
|
|
|
float timeScale,
|
|
|
|
int count,
|
|
|
|
bool isVvt,
|
2021-07-02 17:28:15 -07:00
|
|
|
int vvtIndex,
|
|
|
|
int vvtOffset
|
|
|
|
DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2021-07-02 16:23:37 -07:00
|
|
|
int totalIndex = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* yet another approach to trigger testing: let's schedule a huge list of events from heap
|
|
|
|
* and then execute those one
|
|
|
|
*/
|
2021-07-02 16:57:26 -07:00
|
|
|
for (int r = 0; r < count; r++) {
|
2021-07-02 16:23:37 -07:00
|
|
|
for (int i = 0; i < shape->getSize(); i++) {
|
2021-07-02 17:28:15 -07:00
|
|
|
float angle = vvtOffset + shape->getAngle(totalIndex);
|
2021-07-02 16:23:37 -07:00
|
|
|
TriggerCallback *param = new TriggerCallback();
|
|
|
|
param->engine = engine;
|
|
|
|
param->toothIndex = totalIndex;
|
|
|
|
param->form = shape;
|
|
|
|
param->isVvt = isVvt;
|
2021-07-02 17:28:15 -07:00
|
|
|
param->vvtIndex = vvtIndex;
|
2021-07-02 16:23:37 -07:00
|
|
|
|
|
|
|
scheduling_s *sch = new scheduling_s();
|
2021-07-03 07:15:41 -07:00
|
|
|
engine->executor.scheduleByTimestamp(sch, timeScale * 1000 * angle, { func, param });
|
2021-07-02 16:23:37 -07:00
|
|
|
totalIndex++;
|
|
|
|
}
|
|
|
|
}
|
2021-07-02 14:32:29 -07:00
|
|
|
}
|
2021-07-02 11:56:12 -07:00
|
|
|
|
2021-07-02 16:23:37 -07:00
|
|
|
|
2021-07-02 11:56:12 -07:00
|
|
|
TEST(nissan, vq_vvt) {
|
2021-07-02 14:32:29 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER (HELLEN_121_NISSAN);
|
2021-07-02 15:33:32 -07:00
|
|
|
engineConfiguration->isIgnitionEnabled = false;
|
|
|
|
engineConfiguration->isInjectionEnabled = false;
|
2021-07-02 14:32:29 -07:00
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
int cyclesCount = 36;
|
2021-07-02 16:57:26 -07:00
|
|
|
|
2021-07-03 06:43:54 -07:00
|
|
|
angle_t offsetBetweenCams = 360;
|
|
|
|
|
2021-07-02 14:32:29 -07:00
|
|
|
{
|
2021-07-02 15:33:32 -07:00
|
|
|
static TriggerWaveform crank;
|
2021-07-02 14:32:29 -07:00
|
|
|
initializeNissanVQcrank(&crank);
|
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
scheduleTriggerEvents(&crank,
|
|
|
|
/* timeScale */ 1,
|
|
|
|
cyclesCount, false, -1, 0 PASS_ENGINE_PARAMETER_SUFFIX);
|
2021-07-02 14:32:29 -07:00
|
|
|
}
|
2021-07-03 07:15:41 -07:00
|
|
|
// crank being FOUR_STROKE_THREE_TIMES_CRANK_SENSOR means 120 degrees cycle duration which does not match cam shaft cycle duration
|
|
|
|
float vvtTimeScale = 1 / 1.5;
|
2021-07-02 14:32:29 -07:00
|
|
|
|
2021-07-02 16:23:37 -07:00
|
|
|
{
|
|
|
|
static TriggerWaveform vvt;
|
|
|
|
initializeNissanVQvvt(&vvt);
|
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
scheduleTriggerEvents(&vvt,
|
|
|
|
/* timeScale */ vvtTimeScale,
|
|
|
|
cyclesCount / 6, true,
|
2021-07-02 17:28:15 -07:00
|
|
|
/* vvtIndex */ 0,
|
|
|
|
/* vvtOffset */ 0
|
|
|
|
PASS_ENGINE_PARAMETER_SUFFIX);
|
2021-07-02 16:23:37 -07:00
|
|
|
}
|
|
|
|
|
2021-07-02 17:28:15 -07:00
|
|
|
{
|
|
|
|
static TriggerWaveform vvt;
|
|
|
|
initializeNissanVQvvt(&vvt);
|
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
scheduleTriggerEvents(&vvt,
|
|
|
|
/* timeScale */ vvtTimeScale,
|
|
|
|
cyclesCount / 6, true,
|
2021-07-02 17:28:15 -07:00
|
|
|
/* vvtIndex */1,
|
2021-07-03 06:43:54 -07:00
|
|
|
/* vvtOffset */ offsetBetweenCams
|
2021-07-02 17:28:15 -07:00
|
|
|
PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
2021-07-02 16:23:37 -07:00
|
|
|
|
2021-07-02 15:33:32 -07:00
|
|
|
scheduling_s *head;
|
|
|
|
while ((head = engine->executor.getHead()) != nullptr) {
|
|
|
|
eth.setTimeAndInvokeEventsUs(head->momentX);
|
2021-07-02 14:32:29 -07:00
|
|
|
}
|
2021-07-02 11:56:12 -07:00
|
|
|
|
2021-07-02 15:33:32 -07:00
|
|
|
ASSERT_EQ(250, GET_RPM());
|
2021-07-03 07:15:41 -07:00
|
|
|
|
|
|
|
TriggerCentral *tc = &engine->triggerCentral;
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(tc->vvtState[0][0].shaft_is_synchronized);
|
|
|
|
//huh? ASSERT_TRUE(tc->vvtState[0][1].shaft_is_synchronized);
|
|
|
|
|
|
|
|
angle_t firstVVTangle = 27.5;
|
|
|
|
ASSERT_NEAR(firstVVTangle, tc->vvtPosition[0][0], EPS2D);
|
|
|
|
// hmm, why 340 not 360?
|
|
|
|
ASSERT_EQ(firstVVTangle + 360 - 20, tc->vvtPosition[0][1]);
|
2021-07-02 11:56:12 -07:00
|
|
|
}
|