start fuel pump as soon as trigger events happen (#2038)

* switch pump fsio logic

* value collision

* fuel pump in tests

* mock time since trigger

* test fp

* init pin in test

* fix gpio outputs in tests

* comment

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-12-10 00:23:24 -06:00 committed by GitHub
parent 5f69d23976
commit f2426677db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 4 deletions

View File

@ -93,6 +93,7 @@ public:
float mockRpm = 0;
float mockCrankingRpm = 0;
float mockTimeSinceBoot = 0;
float mockTimeSinceTrigger = 0;
int mockAcToggle = 0;
#endif

View File

@ -56,7 +56,7 @@ typedef enum {
LE_METHOD_FSIO_DIGITAL_INPUT = 123,
LE_METHOD_FSIO_SETTING = 124,
LE_METHOD_PPS = 125,
LE_METHOD_TIME_SINCE_TRIGGER_EVENT = 126,
LE_METHOD_TIME_SINCE_TRIGGER_EVENT = 127,
#include "fsio_enums_generated.def"

View File

@ -537,11 +537,15 @@ void OutputPin::initPin(const char *msg, brain_pin_e brainPin, const pin_output_
this->currentLogicValue = 0;
#endif // briefly leave the include guard because we need to set default state in tests
// The order of the next two calls may look strange, which is a good observation.
// We call them in this order so that the pin is set to a known state BEFORE
// it's enabled. Enabling the pin then setting it could result in a (brief)
// mystery state being driven on the pin (potentially dangerous).
setDefaultPinState(outputMode);
#if EFI_GPIO_HARDWARE && EFI_PROD_CODE
efiSetPadMode(msg, brainPin, mode);
if (brain_pin_is_onchip(brainPin)) {
int actualValue = palReadPad(port, pin);

View File

@ -18,8 +18,8 @@
// Human-readable: (fan and (coolant > cfg_fanOffTemperature)) | (coolant > cfg_fanOnTemperature) | is_clt_broken
#define FAN_CONTROL_LOGIC "fan coolant cfg_fanofftemperature > and coolant cfg_fanontemperature > | is_clt_broken |"
// Human-readable: ((time_since_boot >= 0) & (time_since_boot < startup_fuel_pump_duration)) | (rpm > 0)
#define FUEL_PUMP_LOGIC "time_since_boot 0 >= time_since_boot startup_fuel_pump_duration < & rpm 0 > |"
// Human-readable: ((time_since_boot >= 0) & (time_since_boot < startup_fuel_pump_duration)) | (time_since_trigger > 0)
#define FUEL_PUMP_LOGIC "time_since_boot 0 >= time_since_boot startup_fuel_pump_duration < & time_since_trigger 1 < |"
// Human-readable: vbatt < 14.5
#define ALTERNATOR_LOGIC "vbatt 14.5 <"

View File

@ -18,7 +18,7 @@ FAN_CONTROL_LOGIC=(fan and (coolant > cfg_fanOffTemperature)) | (coolant > cfg_f
# todo: 'time_since_boot' means 'getTimeIgnitionSeconds' in case of EFI_MAIN_RELAY_CONTROL like Proteus
# and it's negative if ignition is off? does Proteus not get fuel pump start-up priming pulse?!
#
FUEL_PUMP_LOGIC=((time_since_boot >= 0) & (time_since_boot < startup_fuel_pump_duration)) | (rpm > 0)
FUEL_PUMP_LOGIC=((time_since_boot >= 0) & (time_since_boot < startup_fuel_pump_duration)) | (time_since_trigger < 1)
ALTERNATOR_LOGIC=vbatt < 14.5

View File

@ -71,3 +71,5 @@
#define EFI_JOYSTICK FALSE
#define EFI_MAP_AVERAGING TRUE
#define EFI_FUEL_PUMP TRUE

View File

@ -27,6 +27,10 @@ FsioValue getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
return engine->fsioState.mockCrankingRpm;
case LE_METHOD_TIME_SINCE_BOOT:
return engine->fsioState.mockTimeSinceBoot;
case LE_METHOD_STARTUP_FUEL_PUMP_DURATION:
return 2.0f;
case LE_METHOD_TIME_SINCE_TRIGGER_EVENT:
return engine->fsioState.mockTimeSinceTrigger;
case LE_METHOD_VBATT:
return 12;
case LE_METHOD_AC_TOGGLE:
@ -299,3 +303,41 @@ TEST(fsio, testLogicExpressions) {
testExpression2(0, "rpm cranking_rpm > ", 1, engine);
}
}
TEST(fsio, fuelPump) {
// this will init fuel pump fsio logic
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// Mock a fuel pump pin
CONFIG(fuelPumpPin) = GPIOA_0;
// Re-init so it picks up the new config
enginePins.fuelPumpRelay.init(PASS_ENGINE_PARAMETER_SIGNATURE);
// ECU just started, haven't seen trigger yet
engine->fsioState.mockTimeSinceBoot = 0.5f;
engine->fsioState.mockTimeSinceTrigger = 100;
runFsio(PASS_ENGINE_PARAMETER_SIGNATURE);
// Pump should be on!
EXPECT_TRUE(efiReadPin(GPIOA_0));
// Long time since ecu start, haven't seen trigger yet
engine->fsioState.mockTimeSinceBoot = 60;
engine->fsioState.mockTimeSinceTrigger = 100;
runFsio(PASS_ENGINE_PARAMETER_SIGNATURE);
// Pump should be off!
EXPECT_FALSE(efiReadPin(GPIOA_0));
// Long time since ecu start, just saw a trigger!
engine->fsioState.mockTimeSinceBoot = 60;
engine->fsioState.mockTimeSinceTrigger = 0.1f;
runFsio(PASS_ENGINE_PARAMETER_SIGNATURE);
// Pump should be on!
EXPECT_TRUE(efiReadPin(GPIOA_0));
// ECU just started, and we just saw a trigger!
engine->fsioState.mockTimeSinceBoot = 0.5f;
engine->fsioState.mockTimeSinceTrigger = 0.1f;
runFsio(PASS_ENGINE_PARAMETER_SIGNATURE);
// Pump should be on!
EXPECT_TRUE(efiReadPin(GPIOA_0));
}