Knock count (#3240)

* knocky knocky

* check the right thing

* improve operator

* TS

* s

* bbbbb
This commit is contained in:
Matthew Kennedy 2021-09-20 11:27:26 -07:00 committed by GitHub
parent dc945ab2ee
commit 0e2af73e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 5 deletions

View File

@ -281,7 +281,9 @@ struct TunerStudioOutputChannels {
scaled_voltage rawTps2Primary; // 302
scaled_voltage rawTps2Secondary; // 304
uint8_t unusedAtTheEnd[32]; // we have some unused bytes to allow compatible TS changes
scaled_channel<uint16_t> knockCount;
uint8_t unusedAtTheEnd[30]; // we have some unused bytes to allow compatible TS changes
// Temporary - will remove soon
TsDebugChannels* getDebugChannels() {

View File

@ -138,7 +138,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
cltTimingCorrection = getCltTimingCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);
engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins,
knockThreshold = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins,
engineConfiguration->knockNoise);
baroCorrection = getBaroCorrection(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -32,7 +32,7 @@ public:
*/
float airFlow = 0;
float engineNoiseHipLevel = 0;
float knockThreshold = 0;
float auxValveStart = 0;
float auxValveEnd = 0;

View File

@ -232,6 +232,11 @@ void processLastKnockEvent() {
tsOutputChannels.knockLevels[currentCylinderIndex] = roundf(cylPeak);
tsOutputChannels.knockLevel = allCylinderPeakDetector.detect(db, lastKnockTime);
// If this was a knock, count it!
bool isKnock = db > ENGINE(engineState).knockThreshold;
if (isKnock) {
tsOutputChannels.knockCount++;
}
}
void KnockThread::ThreadTask() {

View File

@ -294,6 +294,7 @@ enable2ndByteCanID = false
; Knock
knockLevel = scalar, F32, 108, "Volts", 1, 0
knockCount = scalar, U16, 306, "count", 1, 0
; Mode, firmware, protocol, run time
; TS requires 'seconds' name since it has special internal meaning
@ -979,6 +980,7 @@ gaugeCategory = Sensors - Extra 2
egt8Gauge = egt8, "EGT#8", "C", 0, 2000
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
knockCountGauge = knockCount, "Knock count", "count", 0, 10000, 0, 0, 10000, 10000, 0, 0
fuelTankLevelGauge = fuelTankLevel,"Fuel level", "%", 0, 100, 10, 20, 100, 100, 1, 1
speedToRpmRatioGauge = speedToRpmRatio, "speed2rpm", "", 0, 100, 0, 0, 100, 100, 4, 4
wastegatePosGauge = wastegatePositionSensor, @@GAUGE_NAME_WG_POSITION@@, "%", 0, 100, 0, 0, 100, 100, 1, 1

View File

@ -12,6 +12,7 @@
#pragma once
#include <cstdint>
#include <type_traits>
#include "rusefi_generated.h"
@ -22,6 +23,8 @@
// float x = myVar; // converts back to float, returns 2.4f
template <typename T, int mult = 1>
class scaled_channel {
using TSelf = scaled_channel<T, mult>;
public:
constexpr scaled_channel() : m_value(static_cast<T>(0)) { }
constexpr scaled_channel(float val)
@ -35,8 +38,14 @@ public:
}
// Postfix increment operator
T operator ++(int) {
return (m_value / (float)mult) + 1;
// only enable if:
// - base type T is an integral type (integer)
// - multiplier is equal to 1
void operator++(int) {
static_assert(mult == 1, "Increment operator only supported for non-scaled integer types");
static_assert(std::is_integral_v<T>, "Increment operator only supported for non-scaled integer types");
m_value++;
}
constexpr const char* getFirstByteAddr() const {