From aefdf10a7bd25be2f5ca08215956327eb97d7d9b Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 5 Mar 2023 18:56:26 -0500 Subject: [PATCH] minor progress only:proteus_f7 --- firmware/config/engines/vw_b6.lua | 45 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/firmware/config/engines/vw_b6.lua b/firmware/config/engines/vw_b6.lua index 5b92683b16..3e0e479671 100644 --- a/firmware/config/engines/vw_b6.lua +++ b/firmware/config/engines/vw_b6.lua @@ -99,12 +99,6 @@ function onAirBag(bus, id, dlc, data) hadIgnitionEvent = true end -function setTwoBytes(data, offset, value) - value = math.floor(value) - data[offset + 2] = value >> 8 - data[offset + 1] = value & 0xff -end - function xorChecksum(data, targetIndex) local index = 1 local result = 0 @@ -156,6 +150,29 @@ canRxAdd(TCU_1, onTcu1) canRxAdd(TCU_2, onTcu2) --canRxAdd(BRAKE_2) +function sendMotor1() + engineTorque = fakeTorque * 0.9 + innerTorqWithoutExt = fakeTorque + torqueLoss = 20 + requestedTorque = fakeTorque + + motor1Data[2] = engineTorque / 0.39 + setTwoBytes(motor1Data, 2, rpm / 0.25) + motor1Data[5] = innerTorqWithoutExt / 0.4 + motor1Data[6] = tps / 0.4 + motor1Data[7] = torqueLoss / 0.39 + motor1Data[8] = requestedTorque / 0.39 + +-- print ('MOTOR_1 fakeTorque ' ..fakeTorque) +-- print ('MOTOR_1 engineTorque ' ..engineTorque ..' RPM ' ..rpm) +-- print ('MOTOR_1 innerTorqWithoutExt ' ..innerTorqWithoutExt ..' tps ' ..tps) + +-- print ('MOTOR_1 torqueLoss ' ..torqueLoss ..' requestedTorque ' ..requestedTorque) + + txCan(TCU_BUS, MOTOR_1, 0, motor1Data) +end + + function onMotor1(bus, id, dlc, data) rpm = getSensor("RPM") or 0 @@ -168,20 +185,7 @@ function onMotor1(bus, id, dlc, data) torqueLoss = 20 requestedTorque = fakeTorque - motor1Data[2] = engineTorque / 0.39 - setTwoBytes(motor1Data, 2, rpm / 0.25) - motor1Data[5] = innerTorqWithoutExt / 0.4 - motor1Data[6] = tps / 0.4 - motor1Data[7] = torqueLoss / 0.39 - motor1Data[8] = requestedTorque / 0.39 - --- print ('MOTOR_1 fakeTorque ' ..fakeTorque) --- print ('MOTOR_1 engineTorque ' ..engineTorque ..' RPM ' ..rpm) --- print ('MOTOR_1 innerTorqWithoutExt ' ..innerTorqWithoutExt ..' tps ' ..tps) - --- print ('MOTOR_1 torqueLoss ' ..torqueLoss ..' requestedTorque ' ..requestedTorque) - - txCan(TCU_BUS, MOTOR_1, 0, motor1Data) + sendMotor1() end function sendMotor3() @@ -264,7 +268,6 @@ canMotorInfoCounter = 0 function onMotorInfo(bus, id, dlc, data) canMotorInfoTotalCounter = canMotorInfoTotalCounter + 1 canMotorInfoCounter = (canMotorInfoCounter + 1) % 16 --- canMotorInfoCounter = getBitRange(data, 0, 4) baseByte = canMotorInfoTotalCounter < 6 and 0x80 or 0x90 canMotorInfo[1] = baseByte + (canMotorInfoCounter)