From 701f7fd7aa782b61b9b84c96e22d3343b2934f3d Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sun, 22 Mar 2020 14:09:46 -0700 Subject: [PATCH] Accelerator pedal with new sensors (#1208) * add pedal sensor * update status loop * add bit to ts * fix math * divide at config time * this used a little bit of ram --- .../binary/tunerstudio_configuration.h | 2 +- firmware/console/status_loop.cpp | 31 +++++++++---------- firmware/controllers/engine_controller.cpp | 2 +- .../sensors/converters/linear_func.cpp | 3 ++ .../sensors/converters/linear_func.h | 5 ++- firmware/controllers/sensors/sensor_type.h | 5 +++ firmware/init/sensor/init_tps.cpp | 17 ++++++---- firmware/tunerstudio/rusefi.input | 2 ++ 8 files changed, 41 insertions(+), 26 deletions(-) diff --git a/firmware/console/binary/tunerstudio_configuration.h b/firmware/console/binary/tunerstudio_configuration.h index 829bd7be5b..55a5751c3b 100644 --- a/firmware/console/binary/tunerstudio_configuration.h +++ b/firmware/console/binary/tunerstudio_configuration.h @@ -59,7 +59,7 @@ typedef struct { unsigned int isTriggerError : 1; // bit 23 unsigned int hasFatalError : 1; // bit 24 unsigned int isWarnNow : 1; // bit 25 - unsigned int unused80b8 : 1; // bit 26 + unsigned int isPedalError : 1; // bit 26 unsigned int isKnockChipOk : 1; // bit 27 // RPM, vss diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 9eb6d8fd19..c8b9f8b1dd 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -323,24 +323,20 @@ static void printSensors(Logging *log) { reportSensorF(log, GAUGE_NAME_TIMING_ADVANCE, "deg", engine->engineState.timingAdvance, 2); - if (hasPedalPositionSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - // 136 - reportSensorF(log, GAUGE_NAME_THROTTLE_PEDAL, "%", getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE), 2); - } + reportSensorF(log, GAUGE_NAME_THROTTLE_PEDAL, "%", Sensor::get(SensorType::AcceleratorPedal).value_or(0), 2); + floatms_t fuelBase = getBaseFuel(rpm PASS_ENGINE_PARAMETER_SUFFIX); + reportSensorF(log, GAUGE_NAME_FUEL_BASE, "ms", fuelBase, 2); + reportSensorF(log, GAUGE_NAME_FUEL_LAST_INJECTION, "ms", ENGINE(actualLastInjection), 2); + reportSensorF(log, GAUGE_NAME_INJECTOR_LAG, "ms", engine->engineState.running.injectorLag, 2); + reportSensorF(log, GAUGE_NAME_FUEL_RUNNING, "ms", ENGINE(engineState.running.fuel), 2); + // 268 + reportSensorF(log, GAUGE_NAME_FUEL_PID_CORR, "ms", ENGINE(engineState.running.pidCorrection), 2); - floatms_t fuelBase = getBaseFuel(rpm PASS_ENGINE_PARAMETER_SUFFIX); - reportSensorF(log, GAUGE_NAME_FUEL_BASE, "ms", fuelBase, 2); - reportSensorF(log, GAUGE_NAME_FUEL_LAST_INJECTION, "ms", ENGINE(actualLastInjection), 2); - reportSensorF(log, GAUGE_NAME_INJECTOR_LAG, "ms", engine->engineState.running.injectorLag, 2); - reportSensorF(log, GAUGE_NAME_FUEL_RUNNING, "ms", ENGINE(engineState.running.fuel), 2); - // 268 - reportSensorF(log, GAUGE_NAME_FUEL_PID_CORR, "ms", ENGINE(engineState.running.pidCorrection), 2); + reportSensorF(log, GAUGE_NAME_FUEL_WALL_AMOUNT, "v", ENGINE(wallFuel[0]).getWallFuel(), 2); + reportSensorF(log, GAUGE_NAME_FUEL_WALL_CORRECTION, "v", ENGINE(wallFuel[0]).wallFuelCorrection, 2); - reportSensorF(log, GAUGE_NAME_FUEL_WALL_AMOUNT, "v", ENGINE(wallFuel[0]).getWallFuel(), 2); - reportSensorF(log, GAUGE_NAME_FUEL_WALL_CORRECTION, "v", ENGINE(wallFuel[0]).wallFuelCorrection, 2); - - reportSensorI(log, GAUGE_NAME_VERSION, "#", getRusEfiVersion()); + reportSensorI(log, GAUGE_NAME_VERSION, "#", getRusEfiVersion()); #if EFI_VEHICLE_SPEED if (hasVehicleSpeedSensor()) { @@ -732,6 +728,9 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ SensorResult tps2 = Sensor::get(SensorType::Tps2); tsOutputChannels->throttle2Position = tps2.Value; + SensorResult pedal = Sensor::get(SensorType::AcceleratorPedal); + tsOutputChannels->pedalPosition = pedal.Value; + tsOutputChannels->isPedalError = !pedal.Valid; // offset 16 tsOutputChannels->massAirFlowVoltage = hasMafSensor() ? getMafVoltage(PASS_ENGINE_PARAMETER_SIGNATURE) : 0; @@ -771,8 +770,6 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->orderingErrorCounter = engine->triggerCentral.triggerState.orderingErrorCounter; // 68 tsOutputChannels->baroCorrection = engine->engineState.baroCorrection; - // 136 - tsOutputChannels->pedalPosition = hasPedalPositionSensor(PASS_ENGINE_PARAMETER_SIGNATURE) ? getPedalPosition(PASS_ENGINE_PARAMETER_SIGNATURE) : 0; // 140 #if EFI_ENGINE_CONTROL tsOutputChannels->injectorDutyCycle = getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index e8986a6cf6..10f1359640 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -828,7 +828,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) // help to notice when RAM usage goes up - if a code change adds to RAM usage these variables would fail // linking process which is the way to raise the alarm #ifndef RAM_UNUSED_SIZE -#define RAM_UNUSED_SIZE 14300 +#define RAM_UNUSED_SIZE 14200 #endif #ifndef CCM_UNUSED_SIZE #define CCM_UNUSED_SIZE 4100 diff --git a/firmware/controllers/sensors/converters/linear_func.cpp b/firmware/controllers/sensors/converters/linear_func.cpp index 8664805642..19f4f7c074 100644 --- a/firmware/controllers/sensors/converters/linear_func.cpp +++ b/firmware/controllers/sensors/converters/linear_func.cpp @@ -6,6 +6,9 @@ void LinearFunc::configure(float in1, float out1, float in2, float out2, float m m_minOutput = minOutput; m_maxOutput = maxOutput; + in1 = in1 / m_divideInput; + in2 = in2 / m_divideInput; + m_a = INTERPOLATION_A(in1, out1, in2, out2); m_b = out1 - m_a * in1; } diff --git a/firmware/controllers/sensors/converters/linear_func.h b/firmware/controllers/sensors/converters/linear_func.h index 3cb3a44161..2350ea9db0 100644 --- a/firmware/controllers/sensors/converters/linear_func.h +++ b/firmware/controllers/sensors/converters/linear_func.h @@ -4,7 +4,7 @@ class LinearFunc final : public SensorConverter { public: - LinearFunc() = default; + LinearFunc(float divideInput = 1.0f) : m_divideInput(divideInput) {} void configure(float in1, float out1, float in2, float out2, float minOutput, float maxOutput); @@ -18,4 +18,7 @@ private: float m_minOutput = 0; float m_maxOutput = 0; + + // Divisor for the input values - some configurations use a ratio'd value for compat + const float m_divideInput; }; diff --git a/firmware/controllers/sensors/sensor_type.h b/firmware/controllers/sensors/sensor_type.h index 8b44077e89..bc1d6eaeed 100644 --- a/firmware/controllers/sensors/sensor_type.h +++ b/firmware/controllers/sensors/sensor_type.h @@ -32,6 +32,11 @@ enum class SensorType : unsigned char { Tps2Primary, Tps2Secondary, + // Redundant and combined sensors for acc pedal + AcceleratorPedal, + AcceleratorPedalPrimary, + AcceleratorPedalSecondary, + // Leave me at the end! PlaceholderLast }; diff --git a/firmware/init/sensor/init_tps.cpp b/firmware/init/sensor/init_tps.cpp index d8e57a95ca..9fbe007412 100644 --- a/firmware/init/sensor/init_tps.cpp +++ b/firmware/init/sensor/init_tps.cpp @@ -8,20 +8,23 @@ EXTERN_ENGINE; -LinearFunc tpsFunc1p; -//LinearFunc tpsFunc1s; -LinearFunc tpsFunc2p; -//LinearFunc tpsFunc2s; +LinearFunc tpsFunc1p(TPS_TS_CONVERSION); +//LinearFunc tpsFunc1s(TPS_TS_CONVERSION); +LinearFunc tpsFunc2p(TPS_TS_CONVERSION); +//LinearFunc tpsFunc2s(TPS_TS_CONVERSION); FunctionalSensor tpsSens1p(SensorType::Tps1, MS2NT(10)); //FunctionalSensor tpsSens1s(SensorType::Tps1Secondary, MS2NT(10)); FunctionalSensor tpsSens2p(SensorType::Tps2, MS2NT(10)); //FunctionalSensor tpsSens2s(SensorType::Tps2Secondary, MS2NT(10)); +LinearFunc pedalFunc; +FunctionalSensor pedalSensor(SensorType::AcceleratorPedal, MS2NT(10)); + static void configureTps(LinearFunc& func, float closed, float open) { func.configure( - closed / TPS_TS_CONVERSION, 0, - open / TPS_TS_CONVERSION, 100, + closed, 0, + open, 100, CONFIG(tpsErrorDetectionTooLow), CONFIG(tpsErrorDetectionTooHigh) ); @@ -47,9 +50,11 @@ static void initTpsFunc(LinearFunc& func, FunctionalSensor& sensor, adc_channel_ void initTps() { initTpsFunc(tpsFunc1p, tpsSens1p, CONFIG(tps1_1AdcChannel), CONFIG(tpsMin), CONFIG(tpsMax)); initTpsFunc(tpsFunc2p, tpsSens2p, CONFIG(tps2_1AdcChannel), CONFIG(tps2Min), CONFIG(tps2Max)); + initTpsFunc(pedalFunc, pedalSensor, CONFIG(throttlePedalPositionAdcChannel), CONFIG(throttlePedalUpVoltage), CONFIG(throttlePedalWOTVoltage)); } void reconfigureTps() { configureTps(tpsFunc1p, CONFIG(tpsMin), CONFIG(tpsMax)); configureTps(tpsFunc2p, CONFIG(tps2Min), CONFIG(tps2Max)); + configureTps(pedalFunc, CONFIG(throttlePedalUpVoltage), CONFIG(throttlePedalWOTVoltage)); } diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index eb38a5bdb4..a320f2dd9f 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -193,6 +193,7 @@ fileVersion = { @@TS_FILE_VERSION@@ } ind_isTriggerError = bits, U32, 0, [23:23], "true", "false"; ind_hasFatalError=bits, U32, 0, [24:24], "true", "false"; ind_isWarnNow =bits, U32, 0, [25:25], "true", "false"; + ind_pedal_error =bits, U32, 0, [26:26], "true", "false"; ; RPM, vss RPMValue = scalar, U16, 4, "RPM", 1, 0.00000 @@ -1005,6 +1006,7 @@ gaugeCategory = Throttle Body (incl. ETB) indicator = { ind_clt_error}, "clt", "clt error", white, black, red, black indicator = { ind_iat_error}, "iat", "iat error", white, black, red, black indicator = { ind_map_error}, "map", "map error", white, black, red, black + indicator = { ind_pedal_error}, "map", "map error", white, black, red, black indicator = { knockEverIndicator }, "", "Knock recently", white, black, red, black indicator = { knockNowIndicator }, "no knock", "Knock NOW", white, black, red, black