Gear detection improvements (#4047)
* gear detect improvements * ui * ui for gear ratios * ui
This commit is contained in:
parent
a9fcfa15d3
commit
ad368b2031
|
@ -548,11 +548,8 @@ static void updateVvtSensors() {
|
|||
|
||||
static void updateVehicleSpeed(int rpm) {
|
||||
#if EFI_VEHICLE_SPEED
|
||||
float vehicleSpeedKph = Sensor::getOrZero(SensorType::VehicleSpeed);
|
||||
float wheelRPM = vehicleSpeedKph * 1000 / 60 / (2 * CONST_PI * engineConfiguration->wheelDiameter);
|
||||
float driveshaftRpm = wheelRPM * engineConfiguration->finalGearRatio;
|
||||
engine->outputChannels.vehicleSpeedKph = vehicleSpeedKph;
|
||||
engine->outputChannels.speedToRpmRatio = rpm / driveshaftRpm;
|
||||
engine->outputChannels.vehicleSpeedKph = Sensor::getOrZero(SensorType::VehicleSpeed);
|
||||
engine->outputChannels.speedToRpmRatio = engine->module<GearDetector>()->getGearboxRatio();
|
||||
#endif /* EFI_VEHICLE_SPEED */
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ CONTROLLERS_ALGO_SRC_CPP = $(PROJECT_DIR)/controllers/algo/advance_map.cpp \
|
|||
$(PROJECT_DIR)/controllers/algo/engine_configuration.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/engine.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/engine2.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/gear_detector.cpp \
|
||||
$(PROJECT_DIR)/controllers/gauges/lcd_menu_tree.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/event_registry.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/airmass/airmass.cpp \
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "ignition_controller.h"
|
||||
#include "alternator_controller.h"
|
||||
#include "dfco.h"
|
||||
#include "gear_detector.h"
|
||||
|
||||
#ifndef EFI_UNIT_TEST
|
||||
#error EFI_UNIT_TEST must be defined!
|
||||
|
@ -185,6 +186,9 @@ public:
|
|||
PrimeController,
|
||||
DfcoController,
|
||||
Mockable<WallFuelController>,
|
||||
#if EFI_VEHICLE_SPEED
|
||||
GearDetector,
|
||||
#endif // EFI_VEHICLE_SPEED
|
||||
EngineModule // dummy placeholder so the previous entries can all have commas
|
||||
> engineModules;
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#include "pch.h"
|
||||
|
||||
void GearDetector::onSlowCallback() {
|
||||
m_gearboxRatio = computeGearboxRatio();
|
||||
|
||||
// TODO: solve for which gear this is
|
||||
}
|
||||
|
||||
float GearDetector::computeGearboxRatio() const {
|
||||
auto vssKph = Sensor::getOrZero(SensorType::VehicleSpeed);
|
||||
|
||||
if (vssKph < 5) {
|
||||
// Vehicle too slow to determine gearbox ratio, avoid div/0
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto engineRpm = Sensor::getOrZero(SensorType::Rpm);
|
||||
|
||||
// Convert to wheel RPM
|
||||
// km rev 1 hr
|
||||
// ------ * ------------ * __________
|
||||
// hr km 60 min
|
||||
float wheelRpm = vssKph * engineConfiguration->driveWheelRevPerKm * (1 / 60.0f);
|
||||
|
||||
// Convert to driveshaft RPM
|
||||
auto driveshaftRpm = wheelRpm * engineConfiguration->finalGearRatio;
|
||||
|
||||
return engineRpm / driveshaftRpm;
|
||||
}
|
||||
|
||||
float GearDetector::getGearboxRatio() const {
|
||||
return m_gearboxRatio;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
class GearDetector : public EngineModule {
|
||||
public:
|
||||
void onSlowCallback() override;
|
||||
|
||||
float getGearboxRatio() const;
|
||||
|
||||
private:
|
||||
float computeGearboxRatio() const;
|
||||
|
||||
float m_gearboxRatio = 0;
|
||||
};
|
|
@ -724,8 +724,8 @@ custom adc_channel_mode_e 4 bits, U32, @OFFSET@, [0:1], "Off", "Slow", "Fast"
|
|||
pin_input_mode_e throttlePedalUpPinMode;
|
||||
uint8_t acIdleExtraOffset;+Additional idle % while A/C is active;"%", 1, 0, 0, 100, 0
|
||||
|
||||
uint16_t autoscale finalGearRatio;;"ratio", 0.1, 0, 0, 100, 2
|
||||
uint16_t autoscale wheelDiameter;;"m", 0.001, 0, 0, 20, 2
|
||||
uint16_t autoscale finalGearRatio;Ratio between the wheels and your transmission output. ;"ratio", 0.01, 0, 0, 10, 2
|
||||
uint16_t autoscale unused722;;"", 1, 0, 0, 0, 0
|
||||
uint16_t wastegatePositionMin;+Voltage when the wastegate is closed.\nYou probably don't have one of these!;"mv", 1, 0, 0, 5000, 0
|
||||
uint16_t wastegatePositionMax;+Voltage when the wastegate is fully open.\nYou probably don't have one of these!\n1 volt = 1000 units;"mv", 1, 0, 0, 5000, 0
|
||||
uint16_t idlePositionMin;+Voltage when the idle valve is closed.\nYou probably don't have one of these!;"mv", 1, 0, 0, 5000, 0
|
||||
|
@ -1177,7 +1177,7 @@ int16_t tps2Max;Full throttle#2. tpsMax value as 10 bit ADC value. Not Voltage!\
|
|||
float tpsAccelEnrichmentThreshold;+Maximum change delta of TPS percentage over the 'length'. Actual TPS change has to be above this value in order for TPS/TPS acceleration to kick in.;"roc", 1, 0, 0, 200, 1
|
||||
|
||||
brain_input_pin_e[2 iterate] auxSpeedSensorInputPin;
|
||||
uint8_t totalGearsCount;;"", 1, 0, 0, 1, 0
|
||||
uint8_t totalGearsCount;;"", 1, 0, 1, @@GEARS_COUNT@@, 0
|
||||
uint8_t unused16962;;"", 1, 0, 0, 1, 0
|
||||
|
||||
uint32_t uartConsoleSerialSpeed;Band rate for primary TTL;"BPs", 1, 0, 0, 1000000, 0
|
||||
|
@ -1500,7 +1500,7 @@ int8_t[MAX_CYLINDER_COUNT iterate] fuelTrim;;"Percent", @@PERCENT_TRIM_BYTE_PACK
|
|||
|
||||
output_pin_e[4 iterate] stepper_raw_output;
|
||||
|
||||
uint16_t[GEARS_COUNT iterate] autoscale gearRatio;;"ratio", 0.01, 0, 0, 650, 0
|
||||
uint16_t[GEARS_COUNT iterate] autoscale gearRatio;;"ratio", 0.01, 0, 0, 10, 2
|
||||
|
||||
uint16_t vvtActivationDelayMs;We need to give engine time to build oil pressure without diverting it to VVT;"ms", 1, 0, 0, 65000, 0
|
||||
uint16_t unusedShort;;"RPM", 1, 0, 0, 65000, 0
|
||||
|
|
|
@ -1463,6 +1463,7 @@ menuDialog = main
|
|||
|
||||
menu = "&Advanced"
|
||||
subMenu = ignitionCylExtra, "Cylinder offsets", 0
|
||||
subMenu = gearDetection, "Gear detection", 0
|
||||
|
||||
subMenu = std_separator
|
||||
subMenu = boostDialog, "Boost Control"
|
||||
|
@ -3102,30 +3103,41 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
|
|||
panel = alternator
|
||||
panel = startStopDialog
|
||||
|
||||
dialog = speedSensorAnalog
|
||||
dialog = speedSensorAnalog, "Speed sensor"
|
||||
field = "Input pin", vehicleSpeedSensorInputPin
|
||||
field = "Wheel revolutions per kilometer", driveWheelRevPerKm
|
||||
field = "Filter Reciprocal", vssFilterReciprocal, { vehicleSpeedSensorInputPin != @@ADC_CHANNEL_NONE@@ }
|
||||
|
||||
;
|
||||
; We prefer quantities that users can actually measure or inspect without math, so we have
|
||||
; two separate natural settings here without one 'sensor tooth to wheel revolution' ratio
|
||||
;
|
||||
field = "Speed sensor gear ratio", vssGearRatio
|
||||
field = "Speed sensor tooth count", vssToothCount
|
||||
field = "Wheel revolutions per kilometer", driveWheelRevPerKm
|
||||
field = "Speed sensor gear ratio", vssGearRatio, { vehicleSpeedSensorInputPin != @@ADC_CHANNEL_NONE@@ }
|
||||
field = "Speed sensor tooth count", vssToothCount, { vehicleSpeedSensorInputPin != @@ADC_CHANNEL_NONE@@ }
|
||||
|
||||
dialog = speedSensorCan
|
||||
field = "Vss Car Type", canVssNbcType, { enableCanVss }
|
||||
dialog = speedSensorCan, "CAN Vehicle Speed"
|
||||
field = "Enable CAN VSS", enableCanVss, { canReadEnabled }
|
||||
field = "VSS CAN message type", canVssNbcType, { enableCanVss }
|
||||
|
||||
dialog = vssFilter
|
||||
field = "Filter Reciprocal", vssFilterReciprocal
|
||||
|
||||
dialog = speedSensorLeft, "Speed sensor config", yAxis
|
||||
panel = speedSensorCan, { enableCanVss }
|
||||
dialog = speedSensorLeft, "", yAxis
|
||||
panel = speedSensorAnalog, { enableCanVss == 0 }
|
||||
field = "Enable CANbus VSS values", enableCanVss, { canReadEnabled }
|
||||
panel = speedSensorCan
|
||||
panel = vssFilter
|
||||
field = "finalGearRatio", finalGearRatio
|
||||
field = "wheelDiameter", wheelDiameter
|
||||
|
||||
dialog = gearDetection, "Gear Detection"
|
||||
field = "Wheel revolutions per kilometer", driveWheelRevPerKm
|
||||
field = "Final drive ratio", finalGearRatio
|
||||
field = ""
|
||||
field = "Forward gear count", totalGearsCount
|
||||
field = ""
|
||||
field = "1st gear", gearRatio1, { totalGearsCount >= 1 }
|
||||
field = "2nd gear", gearRatio2, { totalGearsCount >= 2 }
|
||||
field = "3rd gear", gearRatio3, { totalGearsCount >= 3 }
|
||||
field = "4th gear", gearRatio4, { totalGearsCount >= 4 }
|
||||
field = "5th gear", gearRatio5, { totalGearsCount >= 5 }
|
||||
field = "6th gear", gearRatio6, { totalGearsCount >= 6 }
|
||||
field = "7th gear", gearRatio6, { totalGearsCount >= 7 }
|
||||
field = "8th gear", gearRatio6, { totalGearsCount >= 8 }
|
||||
|
||||
dialog = speedSensor, "Speed sensor", xAxis
|
||||
panel = speedSensorLeft
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include "pch.h"
|
||||
|
||||
float GetGearRatioFor(float revPerKm, float axle, float kph, float rpm) {
|
||||
EngineTestHelper eth(TEST_ENGINE);
|
||||
|
||||
engineConfiguration->driveWheelRevPerKm = revPerKm;
|
||||
engineConfiguration->finalGearRatio = axle;
|
||||
|
||||
Sensor::setMockValue(SensorType::VehicleSpeed, kph);
|
||||
Sensor::setMockValue(SensorType::Rpm, rpm);
|
||||
|
||||
GearDetector dut;
|
||||
dut.onSlowCallback();
|
||||
|
||||
return dut.getGearboxRatio();
|
||||
}
|
||||
|
||||
TEST(GearDetector, ComputeGearRatio) {
|
||||
// real gears from Volvo racecar
|
||||
EXPECT_NEAR_M3(3.35f, GetGearRatioFor(507, 4.1, 29.45f / 0.6214f, 5500));
|
||||
EXPECT_NEAR_M3(1.99f, GetGearRatioFor(507, 4.1, 49.57f / 0.6214f, 5500));
|
||||
EXPECT_NEAR_M3(1.33f, GetGearRatioFor(507, 4.1, 74.18f / 0.6214f, 5500));
|
||||
EXPECT_NEAR_M3(1.00f, GetGearRatioFor(507, 4.1, 98.65f / 0.6214f, 5500));
|
||||
EXPECT_NEAR_M3(0.72f, GetGearRatioFor(507, 4.1, 137.02f / 0.6214f, 5500));
|
||||
|
||||
// Idling, car stopped, check no div/0
|
||||
EXPECT_EQ(0, GetGearRatioFor(507, 4.1, 0, 800));
|
||||
}
|
|
@ -49,6 +49,7 @@ TESTS_SRC_CPP = \
|
|||
tests/test_scattered_outputs.cpp \
|
||||
tests/test_launch.cpp \
|
||||
tests/test_fuel_map.cpp \
|
||||
tests/test_gear_detector.cpp \
|
||||
tests/ignition_injection/test_fuel_wall_wetting.cpp \
|
||||
tests/test_one_cylinder_logic.cpp \
|
||||
tests/test_tunerstudio.cpp \
|
||||
|
|
Loading…
Reference in New Issue