round rpm instead of truncating (#2023)
* round rpm instead of truncating * efiround is expensive * Revert "efiround is expensive" This reverts commit e5690f89e1b1988aacf5ced1f024d576465a7cd6. * round is better than rintf * testing * it works now?! * comment Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
e544e8150a
commit
ffae0cd335
|
@ -132,8 +132,10 @@ bool RpmCalculator::checkIfSpinning(efitick_t nowNt) const {
|
|||
|
||||
void RpmCalculator::assignRpmValue(float floatRpmValue) {
|
||||
previousRpmValue = rpmValue;
|
||||
// we still persist integer RPM! todo: figure out the next steps
|
||||
rpmValue = floatRpmValue;
|
||||
|
||||
// Round to the nearest integer RPM - some other parts of the ECU expect integer, so that's what we hand out.
|
||||
// TODO: RPM should eventually switch to floating point across the ECU
|
||||
rpmValue = efiRound(floatRpmValue, 1);
|
||||
|
||||
if (rpmValue <= 0) {
|
||||
oneDegreeUs = NAN;
|
||||
|
@ -286,10 +288,10 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
|
|||
// Replace 'normal' RPM with instant RPM for the initial spin-up period
|
||||
engine->triggerCentral.triggerState.movePreSynchTimestamps(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
int prevIndex;
|
||||
int instantRpm = engine->triggerCentral.triggerState.calculateInstantRpm(&engine->triggerCentral.triggerFormDetails,
|
||||
float instantRpm = engine->triggerCentral.triggerState.calculateInstantRpm(&engine->triggerCentral.triggerFormDetails,
|
||||
&prevIndex, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
// validate instant RPM - we shouldn't skip the cranking state
|
||||
instantRpm = minI(instantRpm, CONFIG(cranking.rpm) - 1);
|
||||
instantRpm = minF(instantRpm, CONFIG(cranking.rpm) - 1);
|
||||
rpmState->assignRpmValue(instantRpm);
|
||||
#if 0
|
||||
scheduleMsg(logger, "** RPM: idx=%d sig=%d iRPM=%d", index, ckpSignalType, instantRpm);
|
||||
|
|
|
@ -35,7 +35,7 @@ float efiFloor(float value, float precision) {
|
|||
*/
|
||||
float efiRound(float value, float precision) {
|
||||
efiAssert(CUSTOM_ERR_ASSERT, precision != 0, "zero precision", NAN);
|
||||
float a = rintf (value / precision);
|
||||
float a = round(value / precision);
|
||||
return fixNegativeZero(a * precision);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ TEST(scheduler, dwellIssue796) {
|
|||
ASSERT_EQ(CRANKING, engine->rpmCalculator.getState());
|
||||
// due to isFasterEngineSpinUp=true, we should have already detected RPM!
|
||||
ASSERT_EQ( 100, GET_RPM()) << "spinning-RPM#1";
|
||||
ASSERT_EQ(300000, ENGINE(rpmCalculator.oneDegreeUs) * 180);
|
||||
ASSERT_NEAR(300000.0f, ENGINE(rpmCalculator.oneDegreeUs) * 180, 1);
|
||||
|
||||
// with just a bit much time between events integer RPM goes down one full percent
|
||||
eth.smartFireRise(601);
|
||||
eth.smartFireFall(600);
|
||||
ASSERT_NEAR( 99, GET_RPM(), EPS3D) << "spinning-RPM#2";
|
||||
ASSERT_NEAR( 100, GET_RPM(), EPS3D) << "spinning-RPM#2";
|
||||
// while integer RPM value is 1% away from rpm=100, below oneDegreeUs is much closer to RPM=100 value
|
||||
ASSERT_EQ(300250, (int)(ENGINE(rpmCalculator.oneDegreeUs) * 180));
|
||||
ASSERT_NEAR(300250, (int)(ENGINE(rpmCalculator.oneDegreeUs) * 180), 1);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ TEST(miataNA6, realCranking) {
|
|||
// second synch
|
||||
/* 22 */ EVENT(/* timestamp*/1.45352675, /*index*/1, /*value*/true);
|
||||
ASSERT_EQ( 1, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#realCranking";
|
||||
ASSERT_EQ( 463, GET_RPM()) << "RPM at the 22";
|
||||
ASSERT_EQ( 464, GET_RPM()) << "RPM at the 22";
|
||||
/* 23 */ EVENT(/* timestamp*/1.46291525, /*index*/0, /*value*/false);
|
||||
/* 25 */ EVENT(/* timestamp*/1.49939025, /*index*/1, /*value*/false);
|
||||
/* 27 */ EVENT(/* timestamp*/1.511785, /*index*/0, /*value*/true);
|
||||
|
|
|
@ -49,11 +49,11 @@ TEST(engine, testSymmetricalCrank) {
|
|||
|
||||
mult = 0.1;
|
||||
postFourEvents(ð, mult);
|
||||
ASSERT_EQ( 1041, GET_RPM()) << "RPM#11";
|
||||
ASSERT_EQ( 1042, GET_RPM()) << "RPM#11";
|
||||
|
||||
postFourEvents(ð, mult);
|
||||
ASSERT_EQ( 1041, GET_RPM()) << "RPM#11";
|
||||
ASSERT_EQ( 1042, GET_RPM()) << "RPM#11";
|
||||
|
||||
postFourEvents(ð, mult);
|
||||
ASSERT_EQ( 1041, GET_RPM()) << "RPM#11";
|
||||
ASSERT_EQ( 1042, GET_RPM()) << "RPM#11";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue