Very stupid LAU question

It's all about the code!
Post Reply
FFG_Garage
Posts: 16
Joined: Tue Jul 11, 2023 8:37 pm

Very stupid LAU question

Post by FFG_Garage »

Hello! I'm using a very simple board with a F405RGT6 cpu, and the rusefi.snapshot.f407-discovery image. Everithing is working good. I wanna try the LUA scripting, but I stucked in the very beginning :D

I tried to read a sensor value and print it to first test, but I only get nil not a value. I tried clt, Tps1, rpm, but no one working

function onTick()
clt = getSensor("Clt")
print(clt)
end



my queston is: the LUA srcipting all features is available in all the pre compiled images?
User avatar
AndreyB
Site Admin
Posts: 14334
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: Very stupid LAU question

Post by AndreyB »

FFG_Garage wrote:
Fri Nov 03, 2023 11:18 am
the LUA srcipting all features is available in all the pre compiled images?
No, Lua is not available in most _debug configurations like f407-discovery_debug but you said f407-discovery?

Now you have an answer to the question you've asked but how it would help you I have no idea.

There was a defect in small-can-board https://github.com/rusefi/rusefi/commit/66759b1cff096327fb50acfa2c0c3cdba45d969b but that's not the one you are using. Not sure what's broken on your end.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
FFG_Garage
Posts: 16
Joined: Tue Jul 11, 2023 8:37 pm

Re: Very stupid LAU question

Post by FFG_Garage »

AndreyB wrote:
Fri Nov 03, 2023 11:40 am
FFG_Garage wrote:
Fri Nov 03, 2023 11:18 am
the LUA srcipting all features is available in all the pre compiled images?
No, Lua is not available in most _debug configurations like f407-discovery_debug but you said f407-discovery?

Now you have an answer to the question you've asked but how it would help you I have no idea.

There was a defect in small-can-board https://github.com/rusefi/rusefi/commit/66759b1cff096327fb50acfa2c0c3cdba45d969b but that's not the one you are using. Not sure what's broken on your end.
I use f407-discovery, not the _debug version. But I can try another package.
User avatar
AndreyB
Site Admin
Posts: 14334
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: Very stupid LAU question

Post by AndreyB »

FFG_Garage wrote:
Fri Nov 03, 2023 2:17 pm
I use f407-discovery
You are using the right bundle. The problem you are experiencing is about something else.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
FFG_Garage
Posts: 16
Joined: Tue Jul 11, 2023 8:37 pm

Re: Very stupid LAU question

Post by FFG_Garage »

AndreyB wrote:
Fri Nov 03, 2023 7:42 pm
FFG_Garage wrote:
Fri Nov 03, 2023 2:17 pm
I use f407-discovery
You are using the right bundle. The problem you are experiencing is about something else.
I made a full chip erase, reload the firmware, and now everything working good. I don't know what was the problem.

One more question: is there any reason to set the rpm and the throttle target with a lua script from a can broadcasted rpm and pedal terget value?

thank you
User avatar
AndreyB
Site Admin
Posts: 14334
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: Very stupid LAU question

Post by AndreyB »

TPS target yes https://github.com/rusefi/rusefi/wiki/Lua-Scripting#setetbaddpercent

RPM target not at the moment there is only https://github.com/rusefi/rusefi/wiki/Lua-Scripting#setidleaddpercent

Are you working on a generator or something?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
FFG_Garage
Posts: 16
Joined: Tue Jul 11, 2023 8:37 pm

Re: Very stupid LAU question

Post by FFG_Garage »

AndreyB wrote:
Mon Nov 06, 2023 2:20 pm
TPS target yes https://github.com/rusefi/rusefi/wiki/Lua-Scripting#setetbaddpercent

RPM target not at the moment there is only https://github.com/rusefi/rusefi/wiki/Lua-Scripting#setidleaddpercent

Are you working on a generator or something?
No, I have a stand alone ETB controller. In the LUA script example files I see somebody create the can output script for megasquirt, and I think if the rpm signal and the ETB Position Target can work from the broadcansted can bus massage, my little board will be a fully implemented can bus ETB controller. Right now I use the setetbaddpercent lua script to control the idle with ETB from the ecu pwm idle signal
FFG_Garage
Posts: 16
Joined: Tue Jul 11, 2023 8:37 pm

Re: Very stupid LAU question

Post by FFG_Garage »

the script:

function onTick()
aux2 = getSensor("AuxLinear2")
print(aux2)
setEtbAdd(aux2)
end

The TS menu:
auxlinear2.png
auxlinear2.png (45.93 KiB) Viewed 9380 times
and use this to convert the pwm to analog:
open_collector_to_analog.png
open_collector_to_analog.png (9.59 KiB) Viewed 9380 times
FFG_Garage
Posts: 16
Joined: Tue Jul 11, 2023 8:37 pm

Re: Very stupid LAU question

Post by FFG_Garage »

The rpm signal over can bus not working, but if I connect the Rusefi trigger input with the megasquirt tachometer output, and connect each together with can, the megasquirt can work with a full integrated can bus DBW controller, on the DBW controller run RusEfi code.

LUA script:

-- DBW protocol for legacy standalone systems

BASE_CAN_ID = 256

setTickRate(100)

-- MOTOROLA order, MSB (Most Significant Byte/Big Endian) comes first
function setTwoBytesMsb(data, offset, value)
value = math.floor(value)
data[offset + 1] = value >> 8
data[offset + 2] = value & 0xff
end

function getTwoBytesMSB(data, offset, factor)
return (data[offset + 1] * 256 + data[offset + 2]) * factor
end

function printPacket(bus, id, dlc, data)
local TpsTarget = getTwoBytesMSB(data, 0, 1)
TpsTarget = TpsTarget/1024 * 1000
TpsTarget = TpsTarget / 10
local Pedal = getSensor("AcceleratorPedal")
Throttle = TpsTarget - Pedal
setEtbAdd(Throttle)
end

canRxAdd(1, BASE_CAN_ID + 4, printPacket)
protocolPacket = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
protocolPacket2 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

function onTick()
local ppsValue = getSensor("AcceleratorPedal")
ppsValue = (ppsValue == nil and 0 or ppsValue)
local TPS = getSensor("Tps1")
TPS = (TPS == nil and 0 or TPS)

setTwoBytesMsb(protocolPacket, 0, ppsValue / 100 * 1024)
setTwoBytesMsb(protocolPacket, 2, TPS / 100 * 1024)

txCan(1, BASE_CAN_ID + 0, 0, protocolPacket)
local PedalError = getOutput("isPedalError")
local TpsError = getOutput("isTpsError")
PedalError = 1000 - (PedalError * 1000)
TpsError = 1000 - (TpsError * 1000)
if PedalError == 0 then
setTwoBytesMsb(protocolPacket2, 0, 150)
elseif TpsError == 0 then
setTwoBytesMsb(protocolPacket2, 0, 0)
else
setTwoBytesMsb(protocolPacket2, 0, 1000)
end

txCan(1, BASE_CAN_ID + 10, 0, protocolPacket2)
end
Post Reply