diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 6624af3fae..b94d0ce23f 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -107,3 +107,43 @@ void prepareTimingMap(DECLARE_ENGINE_PARAMETER_F) { iatAdvanceCorrectionMap.init(config->ignitionIatCorrTable, config->ignitionIatCorrLoadBins, config->ignitionIatCorrRpmBins); } + +/** + * @param octane gas octane number + * @param bore in mm + */ +float getTopAdvanceForBore(chamber_style_e style, int octane, double compression, double bore) { + int octaneCorrection; + if ( octane <= 90) { + octaneCorrection = -2; + } else if (octane < 94) { + octaneCorrection = -1; + } else { + octaneCorrection = 0; + } + + int compressionCorrection; + if (compression <= 9) { + compressionCorrection = 2; + } else if (compression <= 10) { + compressionCorrection = 1; + } else if (compression <= 11) { + compressionCorrection = 0; + } else { + // compression ratio above 11 + compressionCorrection = -2; + } + int base; + if (style == CS_OPEN) { + base = 33; + } else if (style == CS_CLOSED) { + base = 28; + } else { + // CS_SWIRL_TUMBLE + base = 22; + } + + float boreCorrection = (bore - 4 * 25.4) / 25.4 * 6; + float result = base + octaneCorrection + compressionCorrection + boreCorrection; + return ((int)(result * 10)) / 10.0; +} diff --git a/firmware/controllers/algo/advance_map.h b/firmware/controllers/algo/advance_map.h index 47bec86fc4..6efd11b9de 100644 --- a/firmware/controllers/algo/advance_map.h +++ b/firmware/controllers/algo/advance_map.h @@ -13,5 +13,6 @@ angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S); void setDefaultIatTimingCorrection(DECLARE_ENGINE_PARAMETER_F); void prepareTimingMap(DECLARE_ENGINE_PARAMETER_F); +float getTopAdvanceForBore(chamber_style_e style, int octane, double compression, double bore); #endif /* ADVANCE_H_ */ diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 37b2ff859b..d9b9682c82 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -628,4 +628,13 @@ typedef enum { Internal_ForceMyEnumIntSize_timing_mode = ENUM_32_BITS, } timing_mode_e; +typedef enum { + CS_OPEN = 0, + CS_CLOSED = 1, + CS_SWIRL_TUMBLE = 2, + + Internal_ForceMyEnumIntSize_chamber_stype = ENUM_32_BITS, +} chamber_style_e; + + #endif /* RUSEFI_ENUMS_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 4ce57a60e4..6db015cbd2 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -275,5 +275,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20151218; + return 20151224; } diff --git a/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java b/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java index 16d93d4647..07e9ca4c72 100644 --- a/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java +++ b/java_console/ui/src/com/rusefi/logic/IgnitionMapBuilder.java @@ -8,7 +8,7 @@ public class IgnitionMapBuilder { public enum ChamberStyle { OPEN_CHAMBER(33), CLOSED_CHAMBER(28), - SWITL_TUMBLE(22); + SWIRL_TUMBLE(22); private final int advance; @@ -16,10 +16,6 @@ public class IgnitionMapBuilder { ChamberStyle(int advance) { this.advance = advance; } - - public int getAdvance() { - return advance; - } } diff --git a/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java b/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java index 5e0b832616..d2204a38b5 100644 --- a/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java +++ b/java_console/ui/src/com/rusefi/logic/test/IgnitionMapBuilderTest.java @@ -27,7 +27,7 @@ public class IgnitionMapBuilderTest { assertEquals(35.0, getTopAdvanceForBore(OPEN_CHAMBER, 98, 8, 101.6)); assertEquals(33.0, getTopAdvanceForBore(OPEN_CHAMBER, 98, 11, 101.6)); - assertEquals(22.0, getTopAdvanceForBore(SWITL_TUMBLE, 89, 9, 101.6)); - assertEquals(32.2, getTopAdvanceForBore(SWITL_TUMBLE, 89, 9, 145)); + assertEquals(22.0, getTopAdvanceForBore(SWIRL_TUMBLE, 89, 9, 101.6)); + assertEquals(32.2, getTopAdvanceForBore(SWIRL_TUMBLE, 89, 9, 145)); } } diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index d64509a087..afef1a38c9 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -140,6 +140,7 @@ int main(void) { testMenuTree(); testMafLookup(); + testIgnitionMapGenerator(); testMafFuelMath(); testPidController(); diff --git a/unit_tests/test_engine_math.cpp b/unit_tests/test_engine_math.cpp index b0737b8a83..1f08a66b59 100644 --- a/unit_tests/test_engine_math.cpp +++ b/unit_tests/test_engine_math.cpp @@ -13,6 +13,7 @@ #include "speed_density.h" #include "engine_test_helper.h" #include "maf.h" +#include "advance_map.h" void testIgnitionPlanning(void) { printf("*************************************************** testIgnitionPlanning\r\n"); @@ -45,6 +46,17 @@ void testEngineMath(void) { assertEquals(327.6667, getTCharge(4000, 100, 300, 350)); } +void testIgnitionMapGenerator(void) { + printf("*************************************************** testIgnitionMapGenerator\r\n"); + + assertEquals(35, getTopAdvanceForBore(CS_OPEN, 98, 8, 101.6)); + assertEquals(33, getTopAdvanceForBore(CS_OPEN, 98, 11, 101.6)); + + assertEquals(22.0, getTopAdvanceForBore(CS_SWIRL_TUMBLE, 89, 9, 101.6)); + assertEquals(32.2, getTopAdvanceForBore(CS_SWIRL_TUMBLE, 89, 9, 145)); + +} + void testMafLookup(void) { printf("*************************************************** testMafLookup\r\n"); diff --git a/unit_tests/test_engine_math.h b/unit_tests/test_engine_math.h index f507d17e19..d7b4e4fd90 100644 --- a/unit_tests/test_engine_math.h +++ b/unit_tests/test_engine_math.h @@ -11,5 +11,6 @@ void testEngineMath(void); void testIgnitionPlanning(void); void testMafLookup(void); +void testIgnitionMapGenerator(void); #endif /* TEST_ENGINE_MATH_H_ */