extract engine phase function (#3456)
* extract getCurrentEnginePhase * inject engine ref * never invalid RPM, use 0 instead Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
4b1a641e11
commit
cadaf2a801
|
@ -461,6 +461,7 @@ void Engine::OnTriggerSyncronization(bool wasSynchronized) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Engine::injectEngineReferences() {
|
void Engine::injectEngineReferences() {
|
||||||
|
INJECT_ENGINE_REFERENCE(&triggerCentral);
|
||||||
INJECT_ENGINE_REFERENCE(&primaryTriggerConfiguration);
|
INJECT_ENGINE_REFERENCE(&primaryTriggerConfiguration);
|
||||||
for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
|
for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
|
||||||
INJECT_ENGINE_REFERENCE(&vvtTriggerConfiguration[camIndex]);
|
INJECT_ENGINE_REFERENCE(&vvtTriggerConfiguration[camIndex]);
|
||||||
|
|
|
@ -85,6 +85,7 @@ RpmCalculator::RpmCalculator() :
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
// todo: reuse assignRpmValue() method which needs PASS_ENGINE_PARAMETER_SUFFIX
|
// todo: reuse assignRpmValue() method which needs PASS_ENGINE_PARAMETER_SUFFIX
|
||||||
// which we cannot provide inside this parameter-less constructor. need a solution for this minor mess
|
// which we cannot provide inside this parameter-less constructor. need a solution for this minor mess
|
||||||
|
setValidValue(0, 0); // 0 for current time since RPM sensor never times out
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +128,7 @@ void RpmCalculator::assignRpmValue(float floatRpmValue) {
|
||||||
|
|
||||||
if (rpmValue <= 0) {
|
if (rpmValue <= 0) {
|
||||||
oneDegreeUs = NAN;
|
oneDegreeUs = NAN;
|
||||||
invalidate();
|
setValidValue(0, 0); // 0 for current time since RPM sensor never times out
|
||||||
} else {
|
} else {
|
||||||
setValidValue(floatRpmValue, 0); // 0 for current time since RPM sensor never times out
|
setValidValue(floatRpmValue, 0); // 0 for current time since RPM sensor never times out
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,16 @@ angle_t TriggerCentral::getVVTPosition(uint8_t bankIndex, uint8_t camIndex) {
|
||||||
return vvtPosition[bankIndex][camIndex];
|
return vvtPosition[bankIndex][camIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expected<float> TriggerCentral::getCurrentEnginePhase(efitick_t nowNt) const {
|
||||||
|
floatus_t oneDegreeUs = engine->rpmCalculator.oneDegreeUs;
|
||||||
|
|
||||||
|
if (cisnan(oneDegreeUs)) {
|
||||||
|
return unexpected;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_virtualZeroTimer.getElapsedUs(nowNt) / oneDegreeUs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo: why is this method NOT reciprocal to getRpmMultiplier?!
|
* todo: why is this method NOT reciprocal to getRpmMultiplier?!
|
||||||
*/
|
*/
|
||||||
|
@ -259,8 +269,8 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index DECL
|
||||||
logFront(isImportantFront, nowNt, index PASS_ENGINE_PARAMETER_SUFFIX);
|
logFront(isImportantFront, nowNt, index PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
|
|
||||||
floatus_t oneDegreeUs = engine->rpmCalculator.oneDegreeUs;
|
auto currentPhase = tc->getCurrentEnginePhase(nowNt);
|
||||||
if (cisnan(oneDegreeUs)) {
|
if (!currentPhase) {
|
||||||
// todo: this code branch is slowing NB2 cranking since we require RPM sync for VVT sync!
|
// todo: this code branch is slowing NB2 cranking since we require RPM sync for VVT sync!
|
||||||
// todo: smarter code
|
// todo: smarter code
|
||||||
//
|
//
|
||||||
|
@ -278,11 +288,9 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index DECL
|
||||||
front == TV_RISE ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING, nowNt);
|
front == TV_RISE ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING, nowNt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tc->vvtCamCounter++;
|
tc->vvtCamCounter++;
|
||||||
|
|
||||||
float offsetUs = tc->virtualZeroTimer.getElapsedUs(nowNt);
|
angle_t currentPosition = currentPhase.Value;
|
||||||
angle_t currentPosition = offsetUs / oneDegreeUs;
|
|
||||||
// convert engine cycle angle into trigger cycle angle
|
// convert engine cycle angle into trigger cycle angle
|
||||||
currentPosition -= tdcPosition();
|
currentPosition -= tdcPosition();
|
||||||
// https://github.com/rusefi/rusefi/issues/1713 currentPosition could be negative that's expected
|
// https://github.com/rusefi/rusefi/issues/1713 currentPosition could be negative that's expected
|
||||||
|
@ -619,7 +627,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
||||||
int crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider;
|
int crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider;
|
||||||
int triggerIndexForListeners = triggerState.getCurrentIndex() + (crankInternalIndex * getTriggerSize());
|
int triggerIndexForListeners = triggerState.getCurrentIndex() + (crankInternalIndex * getTriggerSize());
|
||||||
if (triggerIndexForListeners == 0) {
|
if (triggerIndexForListeners == 0) {
|
||||||
virtualZeroTimer.reset(timestamp);
|
m_virtualZeroTimer.reset(timestamp);
|
||||||
}
|
}
|
||||||
reportEventToWaveChart(signal, triggerIndexForListeners PASS_ENGINE_PARAMETER_SUFFIX);
|
reportEventToWaveChart(signal, triggerIndexForListeners PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
*/
|
*/
|
||||||
class TriggerCentral final : public trigger_central_s {
|
class TriggerCentral final : public trigger_central_s {
|
||||||
public:
|
public:
|
||||||
|
DECLARE_ENGINE_PTR;
|
||||||
|
|
||||||
TriggerCentral();
|
TriggerCentral();
|
||||||
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
void handleShaftSignal(trigger_event_e signal, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void handleShaftSignal(trigger_event_e signal, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
@ -45,6 +47,8 @@ public:
|
||||||
void resetCounters();
|
void resetCounters();
|
||||||
void validateCamVvtCounters();
|
void validateCamVvtCounters();
|
||||||
|
|
||||||
|
expected<float> getCurrentEnginePhase(efitick_t nowNt) const;
|
||||||
|
|
||||||
float getTimeSinceTriggerEvent(efitick_t nowNt) const {
|
float getTimeSinceTriggerEvent(efitick_t nowNt) const {
|
||||||
return m_lastEventTimer.getElapsedSeconds(nowNt);
|
return m_lastEventTimer.getElapsedSeconds(nowNt);
|
||||||
}
|
}
|
||||||
|
@ -72,8 +76,6 @@ public:
|
||||||
// synchronization event position
|
// synchronization event position
|
||||||
angle_t vvtPosition[BANKS_COUNT][CAMS_PER_BANK];
|
angle_t vvtPosition[BANKS_COUNT][CAMS_PER_BANK];
|
||||||
|
|
||||||
Timer virtualZeroTimer;
|
|
||||||
|
|
||||||
efitick_t vvtSyncTimeNt[BANKS_COUNT][CAMS_PER_BANK];
|
efitick_t vvtSyncTimeNt[BANKS_COUNT][CAMS_PER_BANK];
|
||||||
|
|
||||||
TriggerStateWithRunningStatistics triggerState;
|
TriggerStateWithRunningStatistics triggerState;
|
||||||
|
@ -84,8 +86,12 @@ public:
|
||||||
|
|
||||||
TriggerFormDetails triggerFormDetails;
|
TriggerFormDetails triggerFormDetails;
|
||||||
|
|
||||||
|
private:
|
||||||
// Keep track of the last time we got a valid trigger event
|
// Keep track of the last time we got a valid trigger event
|
||||||
Timer m_lastEventTimer;
|
Timer m_lastEventTimer;
|
||||||
|
|
||||||
|
// Keep track of the last time we saw the sync tooth go by (trigger index 0)
|
||||||
|
Timer m_virtualZeroTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
void triggerInfo(void);
|
void triggerInfo(void);
|
||||||
|
|
Loading…
Reference in New Issue