ZIBO speed breaks

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
bebe100
Posts: 59
Joined: Sat Sep 19, 2020 3:22 pm

Re: ZIBO speed breaks

#21 Post by bebe100 »

hello Keith

I use this code:
==========================================================================
local sb_settings = { {0.171, 0},
{0.167, 0.2},
{0.37, 0.8},
{0.458, 1}}

-- Create a ADC input
hw_adc_input_add("speedbrake", function(value)
local brake_var = interpolate_linear(sb_settings,value)
xpl_dataref_write("laminar/B738/flt_ctrls/speedbrake_lever","FLOAT", brake_var)
print (value)
end)
==========================================================================
I receive this messege from AM and I dont know why

ERROR - logic.lua:15: Argument 'value(3)' in function 'xpl_dataref_write' is nil, which is not allowed

thx again

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#22 Post by SimPassion »

bebe100 wrote: Sun Nov 20, 2022 3:34 pm hello Keith

I use this code:
==========================================================================
local sb_settings = { {0.171, 0},
{0.167, 0.2},
{0.37, 0.8},
{0.458, 1}}

-- Create a ADC input
hw_adc_input_add("speedbrake", function(value)
local brake_var = interpolate_linear(sb_settings,value)
xpl_dataref_write("laminar/B738/flt_ctrls/speedbrake_lever","FLOAT", brake_var)
print (value)
end)
==========================================================================
I receive this messege from AM and I dont know why

ERROR - logic.lua:15: Argument 'value(3)' in function 'xpl_dataref_write' is nil, which is not allowed

thx again
Though I don't know how you will bind the ADC input, as using inline function to declare input, here's a small fix to get rid of the issue
Rather not use local for brake_var inside function, then declare it outside the function with initialization to default 0 value

Code: Select all

local brake_var = 0
local sb_settings = { {0.171, 0},
{0.167, 0.2},
{0.37, 0.8},
{0.458, 1}}

-- Create a ADC input
hw_adc_input_add("speedbrake", function(value)
brake_var = interpolate_linear(sb_settings,value)
xpl_dataref_write("laminar/B738/flt_ctrls/speedbrake_lever","FLOAT", brake_var)
print (value)
end)

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#23 Post by Keith Baxter »

Hi,

Yes @SimPassion is correct. I should have declared the local var outside of the function.

Inline functions are asynchronous and load in the background. In other words the lua script does not stop waiting for the function to end before moving on to the next lua call.

I am sure Gilles can explain better than I

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

bebe100
Posts: 59
Joined: Sat Sep 19, 2020 3:22 pm

Re: ZIBO speed breaks

#24 Post by bebe100 »

thanks i shall try

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#25 Post by Keith Baxter »

Hi,

I suppose a discussion on Asynchronous (in line functions) and Synchronous (std call back functions) could show some light into what they do and the difference.
Perhaps OT here but important for coders to know the difference and what each does.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

bebe100
Posts: 59
Joined: Sat Sep 19, 2020 3:22 pm

Re: ZIBO speed breaks

#26 Post by bebe100 »

yes it work perfect.
thanks Keith

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#27 Post by Keith Baxter »

bebe100 wrote: Sun Nov 20, 2022 8:57 pm yes it work perfect.
thanks Keith
Hi,

Glad it is working for you. Thank Gilles for the pointer to the issue.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#28 Post by SimPassion »

Keith Baxter wrote: Sun Nov 20, 2022 8:39 pm Hi,

I suppose a discussion on Asynchronous (in line functions) and Synchronous (std call back functions) could show some light into what they do and the difference.
Perhaps OT here but important for coders to know the difference and what each does.

Keith
Hi Keith

I could be wrong and Corjan may bring light on this, though how I see things are working inside AM, is the inline function doesn't allow to be initialized on first path, so the varaiables have to be set outside before the LUA consistency check find the function itself.
Again I can indeed miss the real reason

Gilles

User avatar
Keith Baxter
Posts: 4684
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: ZIBO speed breaks

#29 Post by Keith Baxter »

Gilles,

Inline functions (Asynchronous) allow for processes to be processed in the background while other processes do their thing. (Synchronous) processes "Halt" other processes until they are ended.

example with humor :mrgreen:

In this (Synchronous) example a wife go shopping for 4 hours. Once the <Function Wife shopping> has ended then the <Function Husband Drink bear> starts
So the Husband has to wait for four hours before he can have a bear, :lol:
Function Wife shopping... wife go's shopping and spends 4 hours
Function Husband Drink bear... pour a bear and sim

In a (Asynchronous) example a wife go shopping for 4 hours. The <Function Wife shopping> is started and runs in the background till ended. The <Function Husband Drink bear> is called on code pass
Function Wife shopping... wife go's shopping and spends 4 hours
Function Husband Drink bear... pour a bear and sim

The result is the husband does not have to wait 4 hours for the wife to complete her shopping and has a dozen peaceful bears ... A black eye sometimes :mrgreen:

I hope that gives some insight into the different approaches.

Keith
Last edited by Keith Baxter on Sun Nov 20, 2022 10:38 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: ZIBO speed breaks

#30 Post by SimPassion »

Amazing sample, my LUA embedded intellisense got crazy while trying to check syntax ... :lol:

Cheers

PS: you mentioned a dozen, though she take 10 and let 2 on the table : :D
(At Oktoberfest, from Gifer)
https://i.gifer.com/3J2.mp4
Last edited by SimPassion on Sun Nov 20, 2022 10:57 pm, edited 2 times in total.

Post Reply