Revert "Revert "rpm rate of change (#2159)""

This reverts commit 538b3ac6
This commit is contained in:
rusefillc 2021-01-09 20:06:19 -05:00
parent 750d80bf83
commit 1cbb0c5680
4 changed files with 19 additions and 6 deletions

View File

@ -83,7 +83,7 @@ typedef struct {
// RPM, vss // RPM, vss
scaled_channel<uint16_t> rpm; // 4 scaled_channel<uint16_t> rpm; // 4
scaled_percent rpmAcceleration; // 6 int16_t rpmAcceleration; // 6
scaled_percent speedToRpmRatio; // 8 scaled_percent speedToRpmRatio; // 8
scaled_channel<uint8_t> vehicleSpeedKph; // 10 scaled_channel<uint8_t> vehicleSpeedKph; // 10

View File

@ -45,7 +45,7 @@ extern WaveChart waveChart;
#endif /* NO_RPM_EVENTS_TIMEOUT_SECS */ #endif /* NO_RPM_EVENTS_TIMEOUT_SECS */
float RpmCalculator::getRpmAcceleration() const { float RpmCalculator::getRpmAcceleration() const {
return 1.0 * previousRpmValue / rpmValue; return rpmRate;
} }
bool RpmCalculator::isStopped() const { bool RpmCalculator::isStopped() const {
@ -201,6 +201,9 @@ uint32_t RpmCalculator::getRevolutionCounterM(void) const {
void RpmCalculator::setStopped() { void RpmCalculator::setStopped() {
revolutionCounterSinceStart = 0; revolutionCounterSinceStart = 0;
rpmRate = 0;
if (rpmValue != 0) { if (rpmValue != 0) {
assignRpmValue(0); assignRpmValue(0);
// needed by 'useNoiselessTriggerDecoder' // needed by 'useNoiselessTriggerDecoder'
@ -250,7 +253,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
bool hadRpmRecently = rpmState->checkIfSpinning(nowNt); bool hadRpmRecently = rpmState->checkIfSpinning(nowNt);
if (hadRpmRecently) { if (hadRpmRecently) {
efitick_t diffNt = nowNt - rpmState->lastRpmEventTimeNt; int32_t diffNt = (int32_t)(nowNt - rpmState->lastRpmEventTimeNt);
/** /**
* Four stroke cycle is two crankshaft revolutions * Four stroke cycle is two crankshaft revolutions
* *
@ -260,10 +263,16 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType,
*/ */
if (diffNt == 0) { if (diffNt == 0) {
rpmState->setRpmValue(NOISY_RPM); rpmState->setRpmValue(NOISY_RPM);
rpmState->rpmRate = 0;
} else { } else {
int mult = (int)getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) / 360; int mult = (int)getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) / 360;
float rpm = 60.0 * NT_PER_SECOND * mult / diffNt; float rpm = 60.0 * NT_PER_SECOND * mult / diffNt;
auto rpmDelta = rpm - rpmState->previousRpmValue;
rpmState->rpmRate = rpmDelta / (mult * 1e-6 * NT2US(diffNt));
rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm); rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm);
} }
} }
rpmState->onNewEngineCycle(); rpmState->onNewEngineCycle();

View File

@ -115,6 +115,9 @@ public:
volatile floatus_t oneDegreeUs = NAN; volatile floatus_t oneDegreeUs = NAN;
volatile efitick_t lastRpmEventTimeNt = 0; volatile efitick_t lastRpmEventTimeNt = 0;
// RPM rate of change, in RPM per second
float rpmRate = 0;
protected: protected:
// Print sensor info - current RPM state // Print sensor info - current RPM state
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(Logging* logger, const char* sensorName) const override;
@ -125,6 +128,7 @@ private:
* Zero if engine is not running * Zero if engine is not running
*/ */
int rpmValue = 0; int rpmValue = 0;
/** /**
* Should be called once we've realized engine is not spinning any more. * Should be called once we've realized engine is not spinning any more.
*/ */

View File

@ -209,7 +209,7 @@ enable2ndByteCanID = false
; RPM, vss ; RPM, vss
RPMValue = scalar, U16, 4, "RPM", 1, 0.00000 RPMValue = scalar, U16, 4, "RPM", 1, 0.00000
rpmAcceleration = scalar, S16, 6, "dRpm",{1/@@PACK_MULT_PERCENT@@}, 0 rpmAcceleration = scalar, S16, 6, "RPM/s", 1, 0
speedToRpmRatio = scalar, S16, 8, "value",{1/@@PACK_MULT_PERCENT@@}, 0 speedToRpmRatio = scalar, S16, 8, "value",{1/@@PACK_MULT_PERCENT@@}, 0
vehicleSpeedKph = scalar, U08, 10, "kph", 1, 0.0 vehicleSpeedKph = scalar, U08, 10, "kph", 1, 0.0
@ -939,7 +939,7 @@ gaugeCategory = Sensors - Extra 2
egt6Gauge = egt6, "EGT#6", "C", 0, 2000 egt6Gauge = egt6, "EGT#6", "C", 0, 2000
egt7Gauge = egt7, "EGT#7", "C", 0, 2000 egt7Gauge = egt7, "EGT#7", "C", 0, 2000
egt8Gauge = egt8, "EGT#8", "C", 0, 2000 egt8Gauge = egt8, "EGT#8", "C", 0, 2000
rpmAccelerationGa = rpmAcceleration, "rpm delta", "dRpm", 0, 3, 0, 1, 3, 4, 1, 1 rpmAccelerationGa = rpmAcceleration, "rpm delta", "RPM/s", -2000, 2000, -2000, 2000, -2000, 2000, 0, 0
knockLevelGauge = knockLevel,"Knock level", "volts", 0, 7, 10, 10, 100, 100, 1, 2 knockLevelGauge = knockLevel,"Knock level", "volts", 0, 7, 10, 10, 100, 100, 1, 2
fuelTankLevelGauge = fuelTankLevel,"Fuel level", "x", 0, 7, 10, 10, 100, 100, 1, 2 fuelTankLevelGauge = fuelTankLevel,"Fuel level", "x", 0, 7, 10, 10, 100, 100, 1, 2
speedToRpmRatioGauge = speedToRpmRatio, "speed2rpm", "", 0, 100, 0, 0, 100, 100, 4, 4 speedToRpmRatioGauge = speedToRpmRatio, "speed2rpm", "", 0, 100, 0, 0, 100, 100, 4, 4
@ -1206,7 +1206,7 @@ gaugeCategory = DynoView
entry = knockLevel, @@GAUGE_NAME_KNOCK_LEVEL@@, float, "%.2f" entry = knockLevel, @@GAUGE_NAME_KNOCK_LEVEL@@, float, "%.2f"
entry = vehicleSpeedKph, @@GAUGE_NAME_VVS@@, float, "%.2f" entry = vehicleSpeedKph, @@GAUGE_NAME_VVS@@, float, "%.2f"
entry = speedToRpmRatio, "s2rpm", float, "%.3f" entry = speedToRpmRatio, "s2rpm", float, "%.3f"
entry = rpmAcceleration, "dRPM", float, "%.3f" entry = rpmAcceleration, "dRPM", int, "%d"
entry = massAirFlowValue,@@GAUGE_NAME_AIR_FLOW@@, float, "%.3f" entry = massAirFlowValue,@@GAUGE_NAME_AIR_FLOW@@, float, "%.3f"
entry = chargeAirMass, @@GAUGE_NAME_AIR_MASS@@, float, "%.3f" entry = chargeAirMass, @@GAUGE_NAME_AIR_MASS@@, float, "%.3f"
entry = throttlePedalPosition, @@GAUGE_NAME_THROTTLE_PEDAL@@, float, "%.3f" entry = throttlePedalPosition, @@GAUGE_NAME_THROTTLE_PEDAL@@, float, "%.3f"