fake motor_1 happy drive in the air

This commit is contained in:
rusEFI LLC 2024-06-30 19:03:33 -04:00
parent eb592e21d9
commit c9d25c4a9c
3 changed files with 25 additions and 1 deletions

View File

@ -25,7 +25,8 @@ function onMotor1(bus, id, dlc, data)
fakeTorque = interpolate(0, 6, 100, 60, tps) fakeTorque = interpolate(0, 6, 100, 60, tps)
txCan(TCU_BUS, MOTOR_1, 0, data) -- txCan(TCU_BUS, MOTOR_1, 0, motor1Data)
sendMotor1()
end end
canRxAdd(ECU_BUS, MOTOR_1, onMotor1) canRxAdd(ECU_BUS, MOTOR_1, onMotor1)

View File

@ -78,3 +78,20 @@ function sendMotor2()
txCan(TCU_BUS, MOTOR_2_648, 0, motor2Data) txCan(TCU_BUS, MOTOR_2_648, 0, motor2Data)
end end
motor1Data = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
function sendMotor1()
engineTorque = fakeTorque * 0.9
innerTorqWithoutExt = fakeTorque
torqueLoss = 20
requestedTorque = fakeTorque
motor1Data[2] = engineTorque / 0.39
setTwoBytesLsb(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
txCan(TCU_BUS, MOTOR_1, 0, motor1Data)
end

View File

@ -53,6 +53,12 @@ function getBitRange(data, bitIndex, bitWidth)
return (value >> shift) & mask return (value >> shift) & mask
end end
function setTwoBytesLsb(data, offset, value)
value = math.floor(value)
data[offset + 2] = value >> 8
data[offset + 1] = value & 0xff
end
function setTwoBytesMsb(data, offset, value) function setTwoBytesMsb(data, offset, value)
value = math.floor(value) value = math.floor(value)
data[offset + 1] = value >> 8 data[offset + 1] = value >> 8