Update B6-temp.md
This commit is contained in:
parent
e4c7a8aa76
commit
a6daefaa56
92
B6-temp.md
92
B6-temp.md
|
@ -58,10 +58,10 @@ ECU_BUS = 1
|
||||||
TCU_BUS = 2
|
TCU_BUS = 2
|
||||||
|
|
||||||
function setTwoBytes(data, offset, value)
|
function setTwoBytes(data, offset, value)
|
||||||
value = math.floor(value)
|
value = math.floor(value)
|
||||||
data[offset + 2] = value >> 8
|
data[offset + 2] = value >> 8
|
||||||
data[offset + 1] = value & 0xff
|
data[offset + 1] = value & 0xff
|
||||||
end
|
end
|
||||||
|
|
||||||
hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
|
hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
|
||||||
|
|
||||||
|
@ -92,80 +92,82 @@ end
|
||||||
totalEcuMessages = 0
|
totalEcuMessages = 0
|
||||||
totalTcuMessages = 0
|
totalTcuMessages = 0
|
||||||
|
|
||||||
motor1Data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
motor1Data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
canMotorInfo = { 0x00, 0x00, 0x00, 0x14, 0x1C, 0x93, 0x48, 0x14 }
|
canMotorInfo = { 0x00, 0x00, 0x00, 0x14, 0x1C, 0x93, 0x48, 0x14 }
|
||||||
canMotor3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
canMotor3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
motor6Data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
motor6Data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
motor7Data = { 0x1A, 0x66, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
motor7Data = { 0x1A, 0x66, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
|
|
||||||
function onMotor1(bus, id, dlc, data)
|
function onMotor1(bus, id, dlc, data)
|
||||||
rpm = getBitRange(data, 16, 16) * 0.25
|
rpm = getBitRange(data, 16, 16) * 0.25
|
||||||
tps = getBitRange(data, 40, 8) * 0.4
|
tps = getBitRange(data, 40, 8) * 0.4
|
||||||
|
|
||||||
fakeTorque = interpolate(0, 6, 100, 60, tps)
|
fakeTorque = interpolate(0, 6, 100, 60, tps)
|
||||||
|
|
||||||
-- engineTorque = getBitRange(data, 8, 8) * 0.39
|
-- engineTorque = getBitRange(data, 8, 8) * 0.39
|
||||||
-- innerTorqWithoutExt = getBitRange(data, 32, 8) * 0.4
|
-- innerTorqWithoutExt = getBitRange(data, 32, 8) * 0.4
|
||||||
-- torqueLoss = getBitRange(data, 48, 8) * 0.39
|
-- torqueLoss = getBitRange(data, 48, 8) * 0.39
|
||||||
-- requestedTorque = getBitRange(data, 56, 8) * 0.39
|
-- requestedTorque = getBitRange(data, 56, 8) * 0.39
|
||||||
|
|
||||||
engineTorque = fakeTorque
|
engineTorque = fakeTorque
|
||||||
innerTorqWithoutExt = fakeTorque
|
innerTorqWithoutExt = fakeTorque
|
||||||
torqueLoss = 10
|
torqueLoss = 10
|
||||||
requestedTorque = fakeTorque
|
requestedTorque = fakeTorque
|
||||||
|
|
||||||
motor1Data[2] = engineTorque / 0.39
|
motor1Data[2] = engineTorque / 0.39
|
||||||
setTwoBytes(motor1Data, 2, rpm / 0.25)
|
setTwoBytes(motor1Data, 2, rpm / 0.25)
|
||||||
motor1Data[5] = innerTorqWithoutExt / 0.4
|
motor1Data[5] = innerTorqWithoutExt / 0.4
|
||||||
motor1Data[6] = tps / 0.4
|
motor1Data[6] = tps / 0.4
|
||||||
motor1Data[7] = torqueLoss / 0.39
|
motor1Data[7] = torqueLoss / 0.39
|
||||||
motor1Data[8] = requestedTorque / 0.39
|
motor1Data[8] = requestedTorque / 0.39
|
||||||
|
|
||||||
print ('fakeTorque ' .. fakeTorque)
|
print ('fakeTorque ' ..fakeTorque)
|
||||||
print ('engineTorque ' .. engineTorque .. ' RPM ' .. rpm)
|
print ('engineTorque ' ..engineTorque ..' RPM ' ..rpm)
|
||||||
print ('innerTorqWithoutExt ' .. innerTorqWithoutExt .. ' tps ' .. tps)
|
print ('innerTorqWithoutExt ' ..innerTorqWithoutExt ..' tps ' ..tps)
|
||||||
|
|
||||||
print ('torqueLoss ' .. torqueLoss .. ' requestedTorque ' .. requestedTorque)
|
print ('torqueLoss ' ..torqueLoss ..' requestedTorque ' ..requestedTorque)
|
||||||
|
|
||||||
txCan(TCU_BUS, id, 0, motor1Data)
|
txCan(TCU_BUS, id, 0, motor1Data)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onMotor3(bus, id, dlc, data)
|
function onMotor3(bus, id, dlc, data)
|
||||||
iat = getBitRange(data, 8, 8) * 0.75 - 48
|
iat = getBitRange(data, 8, 8) * 0.75 - 48
|
||||||
pps = getBitRange(data, 16, 8) * 0.40
|
pps = getBitRange(data, 16, 8) * 0.40
|
||||||
tps = getBitRange(data, 56, 8) * 0.40
|
tps = getBitRange(data, 56, 8) * 0.40
|
||||||
print ('pps ' .. pps .. ' tps ' .. tps .. ' iat ' .. iat)
|
print ('pps ' ..pps ..' tps ' ..tps ..' iat ' ..iat)
|
||||||
|
|
||||||
canMotor3[2] = (iat + 48) / 0.75
|
|
||||||
canMotor3[3] = tps / 0.4
|
desired_wheel_torque = fakeTorque
|
||||||
canMotor3[5] = 0x20
|
canMotor3[2] = (iat + 48) / 0.75
|
||||||
setBitRange(canMotor3, 24, 12, math.floor(desired_wheel_torque / 0.39))
|
canMotor3[3] = tps / 0.4
|
||||||
canMotor3[8] = tps / 0.4
|
canMotor3[5] = 0x20
|
||||||
txCan(TCU_BUS, id, 0, canMotor3)
|
setBitRange(canMotor3, 24, 12, math.floor(desired_wheel_torque / 0.39))
|
||||||
|
canMotor3[8] = tps / 0.4
|
||||||
|
txCan(TCU_BUS, id, 0, canMotor3)
|
||||||
end
|
end
|
||||||
|
|
||||||
function printAndDrop(bus, id, dlc, data)
|
function printAndDrop(bus, id, dlc, data)
|
||||||
print('Dropping ' ..arrayToString(data))
|
print('Dropping ' ..arrayToString(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
function onAnythingFromECU(bus, id, dlc, data)
|
function onAnythingFromECU(bus, id, dlc, data)
|
||||||
totalEcuMessages = totalEcuMessages + 1
|
totalEcuMessages = totalEcuMessages + 1
|
||||||
txCan(TCU_BUS, id, 0, data) -- relay non-TCU message to TCU
|
txCan(TCU_BUS, id, 0, data) -- relay non-TCU message to TCU
|
||||||
end
|
end
|
||||||
|
|
||||||
function onAnythingFromTCU(bus, id, dlc, data)
|
function onAnythingFromTCU(bus, id, dlc, data)
|
||||||
totalTcuMessages = totalTcuMessages + 1
|
totalTcuMessages = totalTcuMessages + 1
|
||||||
txCan(ECU_BUS, id, 0, data) -- relay non-ECU message to ECU
|
txCan(ECU_BUS, id, 0, data) -- relay non-ECU message to ECU
|
||||||
end
|
end
|
||||||
|
|
||||||
-- VAG Motor_1 just as example
|
-- VAG Motor_1 just as example
|
||||||
canRxAdd(ECU_BUS, MOTOR_1, onMotor1)
|
canRxAdd(ECU_BUS, MOTOR_1, onMotor1)
|
||||||
|
|
||||||
canRxAdd(ECU_BUS, MOTOR_3, onMotor3)
|
canRxAdd(ECU_BUS, MOTOR_3, onMotor3)
|
||||||
-- canRxAdd(ECU_BUS, MOTOR_5, printAndDrop)
|
canRxAdd(ECU_BUS, MOTOR_5, printAndDrop)
|
||||||
canRxAdd(ECU_BUS, MOTOR_INFO, printAndDrop)
|
canRxAdd(ECU_BUS, MOTOR_INFO, printAndDrop)
|
||||||
canRxAdd(ECU_BUS, MOTOR_6, printAndDrop)
|
canRxAdd(ECU_BUS, MOTOR_6, printAndDrop)
|
||||||
-- canRxAdd(ECU_BUS, MOTOR_7, printAndDrop)
|
canRxAdd(ECU_BUS, MOTOR_7, printAndDrop)
|
||||||
|
|
||||||
-- last option: unconditional forward of all remaining messages
|
-- last option: unconditional forward of all remaining messages
|
||||||
canRxAddMask(ECU_BUS, 0, 0, onAnythingFromECU)
|
canRxAddMask(ECU_BUS, 0, 0, onAnythingFromECU)
|
||||||
|
@ -187,4 +189,6 @@ function onTick()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue