gear detection in to the sensor model
This commit is contained in:
parent
cb7c3e72ba
commit
82794403f8
|
@ -433,7 +433,7 @@ static void updateVehicleSpeed() {
|
|||
#if EFI_VEHICLE_SPEED
|
||||
engine->outputChannels.vehicleSpeedKph = Sensor::getOrZero(SensorType::VehicleSpeed);
|
||||
engine->outputChannels.speedToRpmRatio = engine->module<GearDetector>()->getGearboxRatio();
|
||||
engine->outputChannels.detectedGear = engine->module<GearDetector>()->getCurrentGear();
|
||||
engine->outputChannels.detectedGear = Sensor::getOrZero(SensorType::DetectedGear);
|
||||
#endif /* EFI_VEHICLE_SPEED */
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ expected<float> readGppwmChannel(gppwm_channel_e channel) {
|
|||
case GPPWM_GppwmOutput4:
|
||||
return (float)engine->outputChannels.gppwmOutput[3];
|
||||
case GPPWM_DetectedGear:
|
||||
return engine->module<GearDetector>()->getCurrentGear();
|
||||
return Sensor::get(SensorType::DetectedGear);
|
||||
}
|
||||
|
||||
return unexpected;
|
||||
|
|
|
@ -4,6 +4,11 @@ static constexpr float geometricMean(float x, float y) {
|
|||
return sqrtf(x * y);
|
||||
}
|
||||
|
||||
GearDetector::GearDetector()
|
||||
: StoredValueSensor(SensorType::DetectedGear, MS2NT(100))
|
||||
{
|
||||
}
|
||||
|
||||
void GearDetector::onConfigurationChange(engine_configuration_s const * /*previousConfig*/) {
|
||||
// Compute gear thresholds between gears
|
||||
|
||||
|
@ -44,7 +49,8 @@ void GearDetector::onSlowCallback() {
|
|||
float ratio = computeGearboxRatio();
|
||||
m_gearboxRatio = ratio;
|
||||
|
||||
m_currentGear = determineGearFromRatio(ratio);
|
||||
auto gear = determineGearFromRatio(ratio);
|
||||
setValidValue(gear, getTimeNowNt());
|
||||
}
|
||||
|
||||
size_t GearDetector::determineGearFromRatio(float ratio) const {
|
||||
|
@ -124,7 +130,3 @@ float GearDetector::getRpmInGear(size_t gear) const {
|
|||
float GearDetector::getGearboxRatio() const {
|
||||
return m_gearboxRatio;
|
||||
}
|
||||
|
||||
size_t GearDetector::getCurrentGear() const {
|
||||
return m_currentGear;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
class GearDetector : public EngineModule {
|
||||
class GearDetector : public EngineModule, public StoredValueSensor {
|
||||
public:
|
||||
GearDetector();
|
||||
|
||||
void onSlowCallback() override;
|
||||
void onConfigurationChange(engine_configuration_s const * /*previousConfig*/) override;
|
||||
|
||||
float getGearboxRatio() const;
|
||||
|
||||
// Returns 0 for neutral, 1 for 1st, 5 for 5th, etc.
|
||||
size_t getCurrentGear() const;
|
||||
|
||||
size_t determineGearFromRatio(float ratio) const;
|
||||
|
||||
float getRpmInGear(size_t gear) const;
|
||||
|
|
|
@ -861,7 +861,7 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
|
||||
#if EFI_VEHICLE_SPEED
|
||||
lua_register(l, "getCurrentGear", [](lua_State* l) {
|
||||
lua_pushinteger(l, engine->module<GearDetector>()->getCurrentGear());
|
||||
lua_pushinteger(l, Sensor::getOrZero(SensorType::DetectedGear));
|
||||
return 1;
|
||||
});
|
||||
|
||||
|
|
|
@ -89,6 +89,8 @@ enum class SensorType : unsigned char {
|
|||
MapSlow2,
|
||||
MapFast2,
|
||||
|
||||
DetectedGear,
|
||||
|
||||
// analog voltage inputs for Lua
|
||||
AuxAnalog1,
|
||||
AuxAnalog2,
|
||||
|
|
|
@ -41,7 +41,7 @@ void TransmissionControllerBase::measureShiftTime(gear_e gear) {
|
|||
}
|
||||
|
||||
float TransmissionControllerBase::isShiftCompleted() {
|
||||
if (m_shiftTime && m_shiftTimeGear == engine->module<GearDetector>()->getCurrentGear()) {
|
||||
if (m_shiftTime && m_shiftTimeGear == Sensor::getOrZero(SensorType::DetectedGear)) {
|
||||
m_shiftTime = false;
|
||||
return m_shiftTimer.getElapsedSeconds();
|
||||
} else {
|
||||
|
|
|
@ -12,7 +12,7 @@ float GetGearRatioFor(float revPerKm, float axle, float kph, float rpm) {
|
|||
GearDetector dut;
|
||||
dut.onSlowCallback();
|
||||
|
||||
return dut.getGearboxRatio();
|
||||
return dut.get().value_or(0);
|
||||
}
|
||||
|
||||
TEST(GearDetector, ComputeGearRatio) {
|
||||
|
|
Loading…
Reference in New Issue