From 2055c1a1be93f054c9eac44e43fa009ae7d236d5 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 14 Jan 2022 16:38:05 -0500 Subject: [PATCH] hard code canned tune for harley #3789 --- firmware/config/engines/custom_engine.cpp | 129 --------------------- firmware/config/engines/engines.mk | 1 + firmware/config/engines/harley.cpp | 131 ++++++++++++++++++++++ 3 files changed, 132 insertions(+), 129 deletions(-) create mode 100644 firmware/config/engines/harley.cpp diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index af17406cb4..7bb4cdc863 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -801,135 +801,6 @@ void setTest33816EngineConfiguration() { setBoschHDEV_5_injectors(); } -/** - * set engine_type 6 - */ -void proteusHarley() { - strcpy(engineConfiguration->scriptSettingName[0], "compReleaseRpm"); - engineConfiguration->scriptSetting[0] = 300; - strcpy(engineConfiguration->scriptSettingName[1], "compReleaseDur"); - engineConfiguration->scriptSetting[1] = 5000; - - // for now we need non wired camInput to keep TS field enable/disable logic happy - engineConfiguration->camInputs[0] = PROTEUS_DIGITAL_6; - engineConfiguration->vvtMode[0] = VVT_MAP_V_TWIN_ANOTHER; - - engineConfiguration->luaOutputPins[0] = PROTEUS_LS_12; -#if HW_PROTEUS - strncpy(config->luaScript, R"( -outputIndex = 0 -startPwm(outputIndex, 100, 0) - -rpmLimitSetting = findSetting("compReleaseRpm", 300) -compReleaseDulationLimit = findSetting("compReleaseDur", 6000) - -every200msTimer = Timer.new(); -everySecondTimer = Timer.new(); -every50msTimer = Timer.new(); -offCounter = 0 --- cranking! -packet542 = {0x20, 0x82, 0x81, 0xd9, 0x00, 0x00, 0x00, 0x00} -packet543 = {0x13, 0x57, 0x13, 0x45, 0x00, 0xe8, 0x00, 0x00} -packet541 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0xFF} - --- every 200ms -packet540 = {0x00, 0x00, 0x5a, 0x4c, 0xff, 0x00, 0x00, 0x00} - --- every 1000ms -packet502 = {0x01} -packet546 = {0x35, 0x48, 0x44, 0x31, 0x46, 0x48} -packet547 = {0x50, 0x41, 0x31, 0x4b, 0x42, 0x36} -packet548 = {0x33, 0x34, 0x38, 0x32, 0x32, 0x00} - -counter543 = 0; -setTickRate(66); - -canRxAdd(0x570) -canRxAdd(0x500) - -function onCanRx(bus, id, dlc, data) - --print('got CAN id=' .. id .. ' dlc=' .. dlc) - id11 = id % 2048 - - if id11 == 0x500 then --Check can state of BCM - canState = data[1] - if canState == 01 then - packet502[1] = 0x01 - else - packet502[1] = 0x00 - end - if id11 == 0x570 then - curState = data[1] - if curState == 06 then -- Cranking TODO: MUST ONLY DO THIS ON RPM TILL STARt - packet542[2] = 0x82 - end - if curState == 04 then -- Kill off - packet542[2] = 0x82 - end - if curState == 01 then -- Kill - packet542[2] = 0xA2 - end - end - end -end - - -function onTick() - - if packet502[1] == 01 then - offCounter = 0 - counter543 = (counter543 + 1) % 64 - packet543[7] = 64 + counter543 - packet543[8] = crc8_j1850(packet543, 7) - APP = getSensor("AcceleratorPedal") - if APP == nil then - packet543[5] = 0 - else - packet543[5] = APP *2 - end - - txCan(1, 0x543, 0, packet543) - txCan(1, 0x541, 0, packet541) - - if every200msTimer:getElapsedSeconds() > 0.2 then - every200msTimer:reset(); - txCan(1, 0x540, 0, packet540) - end - - if every50msTimer:getElapsedSeconds() > 0.05 then - every50msTimer:reset(); - txCan(1, 0x542, 0, packet542) - end - - if everySecondTimer:getElapsedSeconds() > 1 then - everySecondTimer:reset(); - txCan(1, 0x502, 0, packet502) - txCan(1, 0x546, 0, packet546) - txCan(1, 0x547, 0, packet547) - txCan(1, 0x548, 0, packet548) - end - - - rpm = getSensor("RPM") --- handle nil RPM, todo: change firmware to avoid nil RPM - rpm = (rpm == nil and 0 or rpm) - --print('Rpm ' .. rpm) - --print('getTimeSinceTriggerEventMs ' .. getTimeSinceTriggerEventMs()) - enableCompressionReleaseSolenoid = getTimeSinceTriggerEventMs() < compReleaseDulationLimit and rpm < rpmLimitSetting - duty = enableCompressionReleaseSolenoid and 1 or 0 - print("Compression release solenoid " .. duty) - setPwmDuty(outputIndex, duty) - else - if offCounter == 0 then --goodbye sweet love - txCan(1, 0x502, 0, packet502) --goodbye - offCounter = 1 --One shot - end - end -end -)", efi::size(config->luaScript)); -#endif -} - void proteusLuaDemo() { #if HW_PROTEUS engineConfiguration->tpsMin = 889; diff --git a/firmware/config/engines/engines.mk b/firmware/config/engines/engines.mk index 27ca4982db..68c243db8e 100644 --- a/firmware/config/engines/engines.mk +++ b/firmware/config/engines/engines.mk @@ -15,6 +15,7 @@ ENGINES_SRC_CPP = $(PROJECT_DIR)/config/engines/ford_aspire.cpp \ $(PROJECT_DIR)/config/engines/ford_1995_inline_6.cpp \ $(PROJECT_DIR)/config/engines/nissan_primera.cpp \ $(PROJECT_DIR)/config/engines/nissan_vq.cpp \ + $(PROJECT_DIR)/config/engines/harley.cpp \ $(PROJECT_DIR)/config/engines/mazda_miata_nb.cpp \ $(PROJECT_DIR)/config/engines/mercedes.cpp \ $(PROJECT_DIR)/config/engines/honda_accord.cpp \ diff --git a/firmware/config/engines/harley.cpp b/firmware/config/engines/harley.cpp new file mode 100644 index 0000000000..749831acd3 --- /dev/null +++ b/firmware/config/engines/harley.cpp @@ -0,0 +1,131 @@ +#include "pch.h" +#include "proteus_meta.h" + +/** + * set engine_type 6 + */ +void proteusHarley() { + strcpy(engineConfiguration->scriptSettingName[0], "compReleaseRpm"); + engineConfiguration->scriptSetting[0] = 300; + strcpy(engineConfiguration->scriptSettingName[1], "compReleaseDur"); + engineConfiguration->scriptSetting[1] = 5000; + + // for now we need non wired camInput to keep TS field enable/disable logic happy + engineConfiguration->camInputs[0] = PROTEUS_DIGITAL_6; + engineConfiguration->vvtMode[0] = VVT_MAP_V_TWIN_ANOTHER; + + engineConfiguration->luaOutputPins[0] = PROTEUS_LS_12; +#if HW_PROTEUS + strncpy(config->luaScript, R"( +outputIndex = 0 +startPwm(outputIndex, 100, 0) + +rpmLimitSetting = findSetting("compReleaseRpm", 300) +compReleaseDulationLimit = findSetting("compReleaseDur", 6000) + +every200msTimer = Timer.new(); +everySecondTimer = Timer.new(); +every50msTimer = Timer.new(); +offCounter = 0 +-- cranking! +packet542 = {0x20, 0x82, 0x81, 0xd9, 0x00, 0x00, 0x00, 0x00} +packet543 = {0x13, 0x57, 0x13, 0x45, 0x00, 0xe8, 0x00, 0x00} +packet541 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0xFF} + +-- every 200ms +packet540 = {0x00, 0x00, 0x5a, 0x4c, 0xff, 0x00, 0x00, 0x00} + +-- every 1000ms +packet502 = {0x01} +packet546 = {0x35, 0x48, 0x44, 0x31, 0x46, 0x48} +packet547 = {0x50, 0x41, 0x31, 0x4b, 0x42, 0x36} +packet548 = {0x33, 0x34, 0x38, 0x32, 0x32, 0x00} + +counter543 = 0; +setTickRate(66); + +canRxAdd(0x570) +canRxAdd(0x500) + +function onCanRx(bus, id, dlc, data) + --print('got CAN id=' .. id .. ' dlc=' .. dlc) + id11 = id % 2048 + + if id11 == 0x500 then --Check can state of BCM + canState = data[1] + if canState == 01 then + packet502[1] = 0x01 + else + packet502[1] = 0x00 + end + if id11 == 0x570 then + curState = data[1] + if curState == 06 then -- Cranking TODO: MUST ONLY DO THIS ON RPM TILL STARt + packet542[2] = 0x82 + end + if curState == 04 then -- Kill off + packet542[2] = 0x82 + end + if curState == 01 then -- Kill + packet542[2] = 0xA2 + end + end + end +end + + +function onTick() + + if packet502[1] == 01 then + offCounter = 0 + counter543 = (counter543 + 1) % 64 + packet543[7] = 64 + counter543 + packet543[8] = crc8_j1850(packet543, 7) + APP = getSensor("AcceleratorPedal") + if APP == nil then + packet543[5] = 0 + else + packet543[5] = APP *2 + end + + txCan(1, 0x543, 0, packet543) + txCan(1, 0x541, 0, packet541) + + if every200msTimer:getElapsedSeconds() > 0.2 then + every200msTimer:reset(); + txCan(1, 0x540, 0, packet540) + end + + if every50msTimer:getElapsedSeconds() > 0.05 then + every50msTimer:reset(); + txCan(1, 0x542, 0, packet542) + end + + if everySecondTimer:getElapsedSeconds() > 1 then + everySecondTimer:reset(); + txCan(1, 0x502, 0, packet502) + txCan(1, 0x546, 0, packet546) + txCan(1, 0x547, 0, packet547) + txCan(1, 0x548, 0, packet548) + end + + + rpm = getSensor("RPM") +-- handle nil RPM, todo: change firmware to avoid nil RPM + rpm = (rpm == nil and 0 or rpm) + --print('Rpm ' .. rpm) + --print('getTimeSinceTriggerEventMs ' .. getTimeSinceTriggerEventMs()) + enableCompressionReleaseSolenoid = getTimeSinceTriggerEventMs() < compReleaseDulationLimit and rpm < rpmLimitSetting + duty = enableCompressionReleaseSolenoid and 1 or 0 + print("Compression release solenoid " .. duty) + setPwmDuty(outputIndex, duty) + else + if offCounter == 0 then --goodbye sweet love + txCan(1, 0x502, 0, packet502) --goodbye + offCounter = 1 --One shot + end + end +end +)", efi::size(config->luaScript)); +#endif +}