From 6f9f6f8702862c981cf91a841dba21829a118629 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 30 Dec 2023 23:25:47 -0500 Subject: [PATCH] front to rear axle speed slip rate gauge #5842 --- firmware/console/binary/output_channels.txt | 4 +- firmware/console/status_loop.cpp | 7 ++- firmware/controllers/can/can_vss.cpp | 68 ++++++++++++++++++++- firmware/tunerstudio/rusefi.input | 1 + 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/firmware/console/binary/output_channels.txt b/firmware/console/binary/output_channels.txt index a99ec6c403..db6fe9c07a 100644 --- a/firmware/console/binary/output_channels.txt +++ b/firmware/console/binary/output_channels.txt @@ -375,5 +375,7 @@ float mapFast uint16_t autoscale afrGasolineScale;@@GAUGE_NAME_AFR_GAS_SCALE@@;"AFR",{1/@@PACK_MULT_AFR@@}, 0, 0, 0, 2 uint16_t autoscale afr2GasolineScale;@@GAUGE_NAME_AFR2_GAS_SCALE@@;"AFR",{1/@@PACK_MULT_AFR@@}, 0, 0, 0, 2 - uint8_t[120 iterate] unusedAtTheEnd;;"",1, 0, 0, 0, 0 + float wheelSlipRatio + + uint8_t[116 iterate] unusedAtTheEnd;;"",1, 0, 0, 0, 0 end_struct diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 33533e8e45..e0f9f97397 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -450,6 +450,7 @@ static void updateVvtSensors() { static void updateVehicleSpeed() { #if EFI_VEHICLE_SPEED engine->outputChannels.vehicleSpeedKph = Sensor::getOrZero(SensorType::VehicleSpeed); + engine->outputChannels.wheelSlipRatio = Sensor::getOrZero(SensorType::WheelSlipRatio); engine->outputChannels.speedToRpmRatio = engine->module()->getGearboxRatio(); engine->outputChannels.detectedGear = Sensor::getOrZero(SensorType::DetectedGear); #endif /* EFI_VEHICLE_SPEED */ @@ -733,10 +734,10 @@ void updateTunerStudioState() { tle8888PostState(); #endif /* BOARD_TLE8888_COUNT */ break; - case DBG_LOGIC_ANALYZER: -#if EFI_LOGIC_ANALYZER + case DBG_LOGIC_ANALYZER: +#if EFI_LOGIC_ANALYZER reportLogicAnalyzerToTS(); -#endif /* EFI_LOGIC_ANALYZER */ +#endif /* EFI_LOGIC_ANALYZER */ break; default: ; diff --git a/firmware/controllers/can/can_vss.cpp b/firmware/controllers/can/can_vss.cpp index f1f8756eb3..bc8790c55d 100644 --- a/firmware/controllers/can/can_vss.cpp +++ b/firmware/controllers/can/can_vss.cpp @@ -16,6 +16,7 @@ static bool isInit = false; static uint16_t filterVssCanID = 0; +static uint16_t filterSecondVssCanID = 0; static uint16_t filterRpmCanID = 0; static expected look_up_rpm_can_id(can_vss_nbc_e type) { @@ -38,9 +39,11 @@ static expected look_up_vss_can_id(can_vss_nbc_e type) { case BMW_e90: return 0x1A0; // BMW E90 ABS speed frame (not wheel speeds, vehicle speed) case NISSAN_350: - return 0x280; + // decimal 640 0x280 has cluster speed but we use wheel speeds + return /*0x284*/644; case HYUNDAI_PB: - return 1264; // decimal 1264 + // decimal 1264 0x4F0 CLU1 has cluster speed but we use wheel speeds + return /*0x1F1*/497; case HONDA_CIVIC9: return 0x309; case W202: @@ -51,12 +54,29 @@ static expected look_up_vss_can_id(can_vss_nbc_e type) { } } +static uint16_t look_up_second_vss_can_id(can_vss_nbc_e type) { + switch (type) { + case NISSAN_350: + // decimal 640 0x280 has cluster speed but we use wheel speeds + return /*0x285*/645; + default: + // it's OK not to require second packet + return 0; + } +} + static int getTwoBytesLsb(const CANRxFrame& frame, int index) { uint8_t low = frame.data8[index]; uint8_t high = frame.data8[index + 1] & 0xFF; return low | (high << 8); } +static int getTwoBytesMsb(const CANRxFrame& frame, int index) { + uint8_t low = frame.data8[index + 1]; + uint8_t high = frame.data8[index] & 0x0FF; + return low | (high << 8); +} + /* Module specific processing functions */ /* source: http://z4evconversion.blogspot.com/2016/07/completely-forgot-but-it-does-live-on.html */ float processBMW_e46(const CANRxFrame& frame) { @@ -67,6 +87,19 @@ float processBMW_e46(const CANRxFrame& frame) { return (left + right) / (16 * 2); } +// open question if that's front axle or rear axle? +static int nissanFrontAxle = 0; + +float processNissan(const CANRxFrame& frame) { + // todo: open question which one is left which one is right + int left = getTwoBytesMsb(frame, 0); + int right = getTwoBytesMsb(frame, 2); + + nissanFrontAxle = left + right; + + return nissanFrontAxle / (100 * 2); +} + float processBMW_e90(const CANRxFrame& frame) { return 0.1f * getTwoBytesLsb(frame, 0); } @@ -87,7 +120,8 @@ expected processCanRxVssImpl(const CANRxFrame& frame) { return processBMW_e90(frame); case W202: return processW202(frame); -// case NISSAN_350: + case NISSAN_350: + return processNissan(frame); default: efiPrintf("vss unsupported can option selected %x", engineConfiguration->canVssNbcType ); } @@ -96,6 +130,27 @@ expected processCanRxVssImpl(const CANRxFrame& frame) { } static StoredValueSensor canSpeed(SensorType::VehicleSpeed, MS2NT(500)); +static StoredValueSensor wheelSlipRatio(SensorType::WheelSlipRatio, MS2NT(1000)); + +static void processNissanSecondVss(const CANRxFrame& frame, efitick_t nowNt) { + // todo: open question which one is left which one is right + int left = getTwoBytesMsb(frame, 0); + int right = getTwoBytesMsb(frame, 2); + + int rearAxle = left + right; + + wheelSlipRatio.setValidValue(1.0 * nissanFrontAxle / rearAxle, nowNt); +} + +void processCanRxSecondVss(const CANRxFrame& frame, efitick_t nowNt) { + switch (engineConfiguration->canVssNbcType) { + case NISSAN_350: + processNissanSecondVss(frame, nowNt); + return; + default: + criticalError("Unexpected processCanRxSecondVss %d", (int)engineConfiguration->canVssNbcType); + } +} void processCanRxVss(const CANRxFrame& frame, efitick_t nowNt) { if ((!engineConfiguration->enableCanVss) || (!isInit)) { @@ -113,6 +168,11 @@ void processCanRxVss(const CANRxFrame& frame, efitick_t nowNt) { } } + if (CAN_SID(frame) == filterSecondVssCanID) { + processCanRxSecondVss(frame, nowNt); + } + + if (CAN_SID(frame) == filterRpmCanID) { } @@ -122,7 +182,9 @@ void initCanVssSupport() { if (engineConfiguration->enableCanVss) { if (auto canId = look_up_vss_can_id(engineConfiguration->canVssNbcType)) { filterVssCanID = canId.Value; + filterSecondVssCanID = look_up_second_vss_can_id(engineConfiguration->canVssNbcType); canSpeed.Register(); + wheelSlipRatio.Register(); isInit = true; } else { isInit = false; diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index a5aa1bd523..a755e5b706 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1437,6 +1437,7 @@ gaugeCategory = Sensors - Basic ;Name Var Title Units Lo Hi LoD LoW HiW HiD vd ld gaugeCategory = Sensors - Extra 1 VSSGauge = vehicleSpeedKph, @@GAUGE_NAME_VVS@@, "kmh", 0, 200, 0, 1, 3, 4, 1, 1 + wheelSlipRatioGauge = wheelSlipRatio, "Wheel Slip Ratio", "", 0, 200, 0, 1, 3, 4, 3, 3 turboSpeedGauge = turboSpeed, @@GAUGE_NAME_TURBO_SPEED@@, "hz", 0, 200, 0, 1, 3, 4, 1, 1 baroPressureGauge = baroPressure, @@GAUGE_NAME_BARO_PRESSURE@@, "kPa", 0, 1024, 0, 0, 0, 0, 0, 0 internalMcuTemperatureGauge = internalMcuTemperature, @@GAUGE_NAME_ECU_TEMPERATURE@@, "C", 0, 100, 0, 0, 75, 100, 0, 0