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
d6d0200b14
commit
59e9d05fc7
|
@ -461,6 +461,7 @@ void Engine::OnTriggerSyncronization(bool wasSynchronized) {
|
|||
#endif
|
||||
|
||||
void Engine::injectEngineReferences() {
|
||||
INJECT_ENGINE_REFERENCE(&triggerCentral);
|
||||
INJECT_ENGINE_REFERENCE(&primaryTriggerConfiguration);
|
||||
for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
|
||||
INJECT_ENGINE_REFERENCE(&vvtTriggerConfiguration[camIndex]);
|
||||
|
|
|
@ -85,6 +85,7 @@ RpmCalculator::RpmCalculator() :
|
|||
#endif /* EFI_PROD_CODE */
|
||||
// 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
|
||||
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) {
|
||||
oneDegreeUs = NAN;
|
||||
invalidate();
|
||||
setValidValue(0, 0); // 0 for current time since RPM sensor never times out
|
||||
} else {
|
||||
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];
|
||||
}
|
||||
|
||||
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?!
|
||||
*/
|
||||
|
@ -259,8 +269,8 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index DECL
|
|||
logFront(isImportantFront, nowNt, index PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
|
||||
floatus_t oneDegreeUs = engine->rpmCalculator.oneDegreeUs;
|
||||
if (cisnan(oneDegreeUs)) {
|
||||
auto currentPhase = tc->getCurrentEnginePhase(nowNt);
|
||||
if (!currentPhase) {
|
||||
// todo: this code branch is slowing NB2 cranking since we require RPM sync for VVT sync!
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
tc->vvtCamCounter++;
|
||||
|
||||
float offsetUs = tc->virtualZeroTimer.getElapsedUs(nowNt);
|
||||
angle_t currentPosition = offsetUs / oneDegreeUs;
|
||||
angle_t currentPosition = currentPhase.Value;
|
||||
// convert engine cycle angle into trigger cycle angle
|
||||
currentPosition -= tdcPosition();
|
||||
// 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 triggerIndexForListeners = triggerState.getCurrentIndex() + (crankInternalIndex * getTriggerSize());
|
||||
if (triggerIndexForListeners == 0) {
|
||||
virtualZeroTimer.reset(timestamp);
|
||||
m_virtualZeroTimer.reset(timestamp);
|
||||
}
|
||||
reportEventToWaveChart(signal, triggerIndexForListeners PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ public:
|
|||
*/
|
||||
class TriggerCentral final : public trigger_central_s {
|
||||
public:
|
||||
DECLARE_ENGINE_PTR;
|
||||
|
||||
TriggerCentral();
|
||||
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void handleShaftSignal(trigger_event_e signal, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
@ -45,6 +47,8 @@ public:
|
|||
void resetCounters();
|
||||
void validateCamVvtCounters();
|
||||
|
||||
expected<float> getCurrentEnginePhase(efitick_t nowNt) const;
|
||||
|
||||
float getTimeSinceTriggerEvent(efitick_t nowNt) const {
|
||||
return m_lastEventTimer.getElapsedSeconds(nowNt);
|
||||
}
|
||||
|
@ -72,8 +76,6 @@ public:
|
|||
// synchronization event position
|
||||
angle_t vvtPosition[BANKS_COUNT][CAMS_PER_BANK];
|
||||
|
||||
Timer virtualZeroTimer;
|
||||
|
||||
efitick_t vvtSyncTimeNt[BANKS_COUNT][CAMS_PER_BANK];
|
||||
|
||||
TriggerStateWithRunningStatistics triggerState;
|
||||
|
@ -84,8 +86,12 @@ public:
|
|||
|
||||
TriggerFormDetails triggerFormDetails;
|
||||
|
||||
private:
|
||||
// Keep track of the last time we got a valid trigger event
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue