instant rpm uses full engine cycle (#3077)

* instant rpm uses full engine cycle

* turn off fast spinup for this test
This commit is contained in:
Matthew Kennedy 2021-07-30 05:18:24 -07:00 committed by GitHub
parent 2347858d70
commit e3e5e57eac
4 changed files with 17 additions and 15 deletions

View File

@ -291,7 +291,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
#endif /* EFI_SENSOR_CHART */
// Always update instant RPM even when not spinning up
engine->triggerCentral.triggerState.updateInstantRpm(&engine->triggerCentral.triggerFormDetails, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
engine->triggerCentral.triggerState.updateInstantRpm(&engine->triggerCentral.triggerFormDetails, index, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
if (rpmState->isSpinningUp()) {
float instantRpm = engine->triggerCentral.triggerState.getInstantRpm();

View File

@ -242,21 +242,21 @@ void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PA
memcpy(timeOfLastEvent + firstDst, spinningEvents + firstSrc, eventsToCopy * sizeof(timeOfLastEvent[0]));
}
float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
int current_index = currentCycle.current_index; // local copy so that noone changes the value on us
assertIsInBoundsWithResult(current_index, timeOfLastEvent, "calc timeOfLastEvent", 0);
float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails *triggerFormDetails, uint32_t current_index, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
assertIsInBoundsWithResult((int)current_index, timeOfLastEvent, "calc timeOfLastEvent", 0);
// Record the time of this event so we can calculate RPM from it later
timeOfLastEvent[current_index] = nowNt;
/**
* Here we calculate RPM based on last 90 degrees
*/
// Determine where we currently are in the revolution
angle_t currentAngle = triggerFormDetails->eventAngles[current_index];
// todo: make this '90' depend on cylinder count or trigger shape?
if (cisnan(currentAngle)) {
return NOISY_RPM;
}
// Hunt for a tooth ~90 degrees ago to compare to the current time
angle_t previousAngle = currentAngle - 90;
fixAngle(previousAngle, "prevAngle", CUSTOM_ERR_TRIGGER_ANGLE_RANGE);
// todo: prevIndex should be pre-calculated
int prevIndex = triggerFormDetails->triggerIndexByAngle[(int)previousAngle];
// now let's get precise angle for that event
@ -269,7 +269,8 @@ float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails
// OK for small time differences like this one
uint32_t time = nowNt - time90ago;
angle_t angleDiff = currentAngle - prevIndexAngle;
// todo: angle diff should be pre-calculated
// Wrap the angle in to the correct range (ie, could be -630 when we want +90)
fixAngle(angleDiff, "angleDiff", CUSTOM_ERR_6561);
// just for safety
@ -277,7 +278,7 @@ float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails
return prevInstantRpmValue;
float instantRpm = (60000000.0 / 360 * US_TO_NT_MULTIPLIER) * angleDiff / time;
assertIsInBoundsWithResult(current_index, instantRpmValue, "instantRpmValue", 0);
assertIsInBoundsWithResult((int)current_index, instantRpmValue, "instantRpmValue", 0);
instantRpmValue[current_index] = instantRpm;
// This fixes early RPM instability based on incomplete data
@ -306,8 +307,8 @@ void TriggerStateWithRunningStatistics::setLastEventTimeForInstantRpm(efitick_t
spinningEvents[spinningEventIndex++] = nowNt;
}
void TriggerStateWithRunningStatistics::updateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
m_instantRpm = calculateInstantRpm(triggerFormDetails, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
void TriggerStateWithRunningStatistics::updateInstantRpm(TriggerFormDetails *triggerFormDetails, uint32_t index, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
m_instantRpm = calculateInstantRpm(triggerFormDetails, index, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
#if EFI_SENSOR_CHART

View File

@ -202,7 +202,7 @@ public:
void movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
void updateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
void updateInstantRpm(TriggerFormDetails *triggerFormDetails, uint32_t index, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
#endif
/**
* Update timeOfLastEvent[] on every trigger event - even without synchronization
@ -211,7 +211,7 @@ public:
void setLastEventTimeForInstantRpm(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
private:
float calculateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
float calculateInstantRpm(TriggerFormDetails *triggerFormDetails, uint32_t index, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
float m_instantRpm = 0;
float m_instantRpmRatio = 0;

View File

@ -125,6 +125,7 @@ TEST(trigger, testNB2CamInput) {
// this crank trigger would be easier to test, crank shape is less important for this test
eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX);
engineConfiguration->isFasterEngineSpinUpEnabled = false;
engineConfiguration->useOnlyRisingEdgeForTrigger = true;