mirror of https://github.com/rusefi/rusefi-1.git
fix instant rpm (#2180)
* consumers * impl * instant rpm in idle timing
This commit is contained in:
parent
b16704c9f9
commit
bdacda558c
|
@ -851,7 +851,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
|
||||||
break;
|
break;
|
||||||
case DBG_INSTANT_RPM:
|
case DBG_INSTANT_RPM:
|
||||||
{
|
{
|
||||||
float instantRpm = engine->triggerCentral.triggerState.instantRpm;
|
float instantRpm = engine->triggerCentral.triggerState.getInstantRpm();
|
||||||
tsOutputChannels->debugFloatField1 = instantRpm;
|
tsOutputChannels->debugFloatField1 = instantRpm;
|
||||||
tsOutputChannels->debugFloatField2 = instantRpm / GET_RPM();
|
tsOutputChannels->debugFloatField2 = instantRpm / GET_RPM();
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,6 +289,10 @@ float IdleController::getIdleTimingAdjustment(int rpm, int targetRpm, Phase phas
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CONFIG(useInstantRpmForIdle)) {
|
||||||
|
rpm = engine->triggerCentral.triggerState.getInstantRpm();
|
||||||
|
}
|
||||||
|
|
||||||
// If inside the deadzone, do nothing
|
// If inside the deadzone, do nothing
|
||||||
if (absI(rpm - targetRpm) < CONFIG(idleTimingPidDeadZone)) {
|
if (absI(rpm - targetRpm) < CONFIG(idleTimingPidDeadZone)) {
|
||||||
m_timingPid.reset();
|
m_timingPid.reset();
|
||||||
|
@ -454,8 +458,7 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm,
|
||||||
|
|
||||||
float rpm;
|
float rpm;
|
||||||
if (CONFIG(useInstantRpmForIdle)) {
|
if (CONFIG(useInstantRpmForIdle)) {
|
||||||
efitick_t nowNt = getTimeNowNt();
|
rpm = engine->triggerCentral.triggerState.getInstantRpm();
|
||||||
rpm = engine->triggerCentral.triggerState.calculateInstantRpm(&engine->triggerCentral.triggerFormDetails, NULL, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
|
||||||
} else {
|
} else {
|
||||||
rpm = GET_RPM();
|
rpm = GET_RPM();
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,10 +397,6 @@ void Engine::OnTriggerStateProperState(efitick_t nowNt) {
|
||||||
Engine *engine = this;
|
Engine *engine = this;
|
||||||
EXPAND_Engine;
|
EXPAND_Engine;
|
||||||
|
|
||||||
#if EFI_SHAFT_POSITION_INPUT
|
|
||||||
triggerCentral.triggerState.runtimeStatistics(&triggerCentral.triggerFormDetails, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
|
||||||
#endif /* EFI_SHAFT_POSITION_INPUT */
|
|
||||||
|
|
||||||
rpmCalculator.setSpinningUp(nowNt);
|
rpmCalculator.setSpinningUp(nowNt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,9 +295,14 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
|
||||||
// while transitioning from 'spinning' to 'running'
|
// while transitioning from 'spinning' to 'running'
|
||||||
// Replace 'normal' RPM with instant RPM for the initial spin-up period
|
// Replace 'normal' RPM with instant RPM for the initial spin-up period
|
||||||
engine->triggerCentral.triggerState.movePreSynchTimestamps(PASS_ENGINE_PARAMETER_SIGNATURE);
|
engine->triggerCentral.triggerState.movePreSynchTimestamps(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||||
int prevIndex;
|
}
|
||||||
float instantRpm = engine->triggerCentral.triggerState.calculateInstantRpm(&engine->triggerCentral.triggerFormDetails,
|
|
||||||
&prevIndex, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
// Always update instant RPM even when not spinning up
|
||||||
|
engine->triggerCentral.triggerState.updateInstantRpm(&engine->triggerCentral.triggerFormDetails, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
|
if (rpmState->isSpinningUp()) {
|
||||||
|
float instantRpm = engine->triggerCentral.triggerState.getInstantRpm();
|
||||||
|
|
||||||
// validate instant RPM - we shouldn't skip the cranking state
|
// validate instant RPM - we shouldn't skip the cranking state
|
||||||
instantRpm = minF(instantRpm, CONFIG(cranking.rpm) - 1);
|
instantRpm = minF(instantRpm, CONFIG(cranking.rpm) - 1);
|
||||||
rpmState->assignRpmValue(instantRpm);
|
rpmState->assignRpmValue(instantRpm);
|
||||||
|
|
|
@ -211,8 +211,7 @@ void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails *triggerFormDetails,
|
float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
int *prevIndexOut, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
||||||
int current_index = currentCycle.current_index; // local copy so that noone changes the value on us
|
int current_index = currentCycle.current_index; // local copy so that noone changes the value on us
|
||||||
assertIsInBoundsWithResult(current_index, timeOfLastEvent, "calc timeOfLastEvent", 0);
|
assertIsInBoundsWithResult(current_index, timeOfLastEvent, "calc timeOfLastEvent", 0);
|
||||||
timeOfLastEvent[current_index] = nowNt;
|
timeOfLastEvent[current_index] = nowNt;
|
||||||
|
@ -229,10 +228,6 @@ float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails
|
||||||
// todo: prevIndex should be pre-calculated
|
// todo: prevIndex should be pre-calculated
|
||||||
int prevIndex = triggerFormDetails->triggerIndexByAngle[(int)previousAngle];
|
int prevIndex = triggerFormDetails->triggerIndexByAngle[(int)previousAngle];
|
||||||
|
|
||||||
if (prevIndexOut) {
|
|
||||||
*prevIndexOut = prevIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now let's get precise angle for that event
|
// now let's get precise angle for that event
|
||||||
angle_t prevIndexAngle = triggerFormDetails->eventAngles[prevIndex];
|
angle_t prevIndexAngle = triggerFormDetails->eventAngles[prevIndex];
|
||||||
efitick_t time90ago = timeOfLastEvent[prevIndex];
|
efitick_t time90ago = timeOfLastEvent[prevIndex];
|
||||||
|
@ -255,10 +250,14 @@ float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails
|
||||||
instantRpmValue[current_index] = instantRpm;
|
instantRpmValue[current_index] = instantRpm;
|
||||||
|
|
||||||
// This fixes early RPM instability based on incomplete data
|
// This fixes early RPM instability based on incomplete data
|
||||||
if (instantRpm < RPM_LOW_THRESHOLD)
|
if (instantRpm < RPM_LOW_THRESHOLD) {
|
||||||
return prevInstantRpmValue;
|
return prevInstantRpmValue;
|
||||||
|
}
|
||||||
|
|
||||||
prevInstantRpmValue = instantRpm;
|
prevInstantRpmValue = instantRpm;
|
||||||
|
|
||||||
|
m_instantRpmRatio = instantRpm / instantRpmValue[prevIndex];
|
||||||
|
|
||||||
return instantRpm;
|
return instantRpm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,23 +275,20 @@ void TriggerStateWithRunningStatistics::setLastEventTimeForInstantRpm(efitick_t
|
||||||
spinningEvents[spinningEventIndex++] = nowNt;
|
spinningEvents[spinningEventIndex++] = nowNt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerStateWithRunningStatistics::runtimeStatistics(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
void TriggerStateWithRunningStatistics::updateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
if (engineConfiguration->debugMode == DBG_INSTANT_RPM) {
|
m_instantRpm = calculateInstantRpm(triggerFormDetails, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
instantRpm = calculateInstantRpm(triggerFormDetails, NULL, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
|
||||||
}
|
|
||||||
if (ENGINE(sensorChartMode) == SC_RPM_ACCEL || ENGINE(sensorChartMode) == SC_DETAILED_RPM) {
|
|
||||||
int prevIndex;
|
|
||||||
instantRpm = calculateInstantRpm(triggerFormDetails, &prevIndex, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
|
||||||
|
|
||||||
#if EFI_SENSOR_CHART
|
#if EFI_SENSOR_CHART
|
||||||
|
if (ENGINE(sensorChartMode) == SC_RPM_ACCEL || ENGINE(sensorChartMode) == SC_DETAILED_RPM) {
|
||||||
angle_t currentAngle = triggerFormDetails->eventAngles[currentCycle.current_index];
|
angle_t currentAngle = triggerFormDetails->eventAngles[currentCycle.current_index];
|
||||||
if (CONFIG(sensorChartMode) == SC_DETAILED_RPM) {
|
if (CONFIG(sensorChartMode) == SC_DETAILED_RPM) {
|
||||||
scAddData(currentAngle, instantRpm);
|
scAddData(currentAngle, m_instantRpm);
|
||||||
} else {
|
} else {
|
||||||
scAddData(currentAngle, instantRpm / instantRpmValue[prevIndex]);
|
scAddData(currentAngle, m_instantRpmRatio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* EFI_SENSOR_CHART */
|
#endif /* EFI_SENSOR_CHART */
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TriggerState::isValidIndex(const TriggerWaveform& triggerShape) const {
|
bool TriggerState::isValidIndex(const TriggerWaveform& triggerShape) const {
|
||||||
|
|
|
@ -169,7 +169,11 @@ private:
|
||||||
class TriggerStateWithRunningStatistics : public TriggerState {
|
class TriggerStateWithRunningStatistics : public TriggerState {
|
||||||
public:
|
public:
|
||||||
TriggerStateWithRunningStatistics();
|
TriggerStateWithRunningStatistics();
|
||||||
float instantRpm = 0;
|
|
||||||
|
float getInstantRpm() const {
|
||||||
|
return m_instantRpm;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* timestamp of each trigger wheel tooth
|
* timestamp of each trigger wheel tooth
|
||||||
*/
|
*/
|
||||||
|
@ -187,15 +191,22 @@ public:
|
||||||
*/
|
*/
|
||||||
float prevInstantRpmValue = 0;
|
float prevInstantRpmValue = 0;
|
||||||
void movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
float calculateInstantRpm(TriggerFormDetails *triggerFormDetails, int *prevIndex, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|
||||||
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
|
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
|
||||||
void runtimeStatistics(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void updateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* Update timeOfLastEvent[] on every trigger event - even without synchronization
|
* Update timeOfLastEvent[] on every trigger event - even without synchronization
|
||||||
* Needed for early spin-up RPM detection.
|
* Needed for early spin-up RPM detection.
|
||||||
*/
|
*/
|
||||||
void setLastEventTimeForInstantRpm(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void setLastEventTimeForInstantRpm(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
|
private:
|
||||||
|
float calculateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
|
float m_instantRpm = 0;
|
||||||
|
float m_instantRpmRatio = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
angle_t getEngineCycle(operation_mode_e operationMode);
|
angle_t getEngineCycle(operation_mode_e operationMode);
|
||||||
|
|
Loading…
Reference in New Issue