rpm rate of change (#2159)

* compute rpm rate of change

* fix units on gauge

* oops

* correct order

* scaling and limits

* correct for engine cycle length

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-01-03 06:55:44 -08:00 committed by GitHub
parent 07f6a0f7fd
commit eecb7ce97f
4 changed files with 19 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -209,7 +209,7 @@ enable2ndByteCanID = false
; RPM, vss
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
vehicleSpeedKph = scalar, U08, 10, "kph", 1, 0.0
@ -937,7 +937,7 @@ gaugeCategory = Sensors - Extra 2
egt6Gauge = egt6, "EGT#6", "C", 0, 2000
egt7Gauge = egt7, "EGT#7", "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
fuelTankLevelGauge = fuelTankLevel,"Fuel level", "x", 0, 7, 10, 10, 100, 100, 1, 2
speedToRpmRatioGauge = speedToRpmRatio, "speed2rpm", "", 0, 100, 0, 0, 100, 100, 4, 4
@ -1203,7 +1203,7 @@ gaugeCategory = DynoView
entry = knockLevel, @@GAUGE_NAME_KNOCK_LEVEL@@, float, "%.2f"
entry = vehicleSpeedKph, @@GAUGE_NAME_VVS@@, float, "%.2f"
entry = speedToRpmRatio, "s2rpm", float, "%.3f"
entry = rpmAcceleration, "dRPM", float, "%.3f"
entry = rpmAcceleration, "dRPM", int, "%d"
entry = massAirFlowValue,@@GAUGE_NAME_AIR_FLOW@@, float, "%.3f"
entry = chargeAirMass, @@GAUGE_NAME_AIR_MASS@@, float, "%.3f"
entry = throttlePedalPosition, @@GAUGE_NAME_THROTTLE_PEDAL@@, float, "%.3f"