Zibo 737 datarefs

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
Markjohn
Posts: 10
Joined: Wed Mar 24, 2021 10:30 pm

Zibo 737 datarefs

#1 Post by Markjohn »

Hi
I want to use air manager for some of my cockpit hardware. i use xplane and zibo and an arduino mega.

I have got a servo to work using the example "engine RPM" script on the siminnovations website

When I try and subscribe to a Zibo dataref the servo doesn't work. Ive tweaked some of the values in the script to make it work for a dataref value between 0 and 1

When I test the script in Air manager it works as expected and the servo moves. The servo moves approx 180 degrees for a dataref value between 0 and 1

It doesn't work thou when I am connected to the sim. The dataref in the sim also changes between 0 and 1. Its a valve position. It ramps up between 0 and 1 for closed and open.

Does anyone have any ideas? I will put the script below. This is the engine rpm script but with the zibo dataref

I am just trying to prove the concept and then I will tidy up the script

Thanks

Mark

pwm_engine_rpm = hw_output_pwm_add("RPM servo", 50, 0.02)


function new_rpm(rpm)

hw_output_pwm_duty_cycle(pwm_engine_rpm, 0.02 + ((0.10 - 0.02)/1) * rpm[1])

end

xpl_dataref_subscribe("laminar/B738/air/engine1/starter_valve", "FLOAT[8]", new_rpm)

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Zibo 737 datarefs

#2 Post by Sling »

Hi,

Some things spring to mind without my PC in front of me.

Is that dataref an array type because the dataref name already specifies engine1.

The above potential issue and others will show in the console if you run the instrument in Create/edit.

Have you tried putting a print or more into the code to help understand what’s happening with the variables?

Markjohn
Posts: 10
Joined: Wed Mar 24, 2021 10:30 pm

Re: Zibo 737 datarefs

#3 Post by Markjohn »

Hi
When I run the instrument in create/edit I get no errors

if I write to the script a value between 0 and 1 (in Run/create/edit) the servo moves roughly between 0 and 180 degrees

Its just when I run the instrument with Xplane. I can see the dataref go between 0 and 1 using datareftool but the servo doesn't move

i'm sure its something really simple

I havent added anything to the code. Im new to lua so learning as I go

Mark

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Zibo 737 datarefs

#4 Post by Sling »

So we are back to if that dataref is an array type or not. That must be a later zibo dataref because I’m not seeing it in dataref tool with my older zibo install.

Can you post a picture of the dataref tool window showing that dataref?

Markjohn
Posts: 10
Joined: Wed Mar 24, 2021 10:30 pm

Re: Zibo 737 datarefs

#5 Post by Markjohn »

Pic Attached
Its the 2nd dataref down. When the valve is fully open or closed it reads exactly a 0 or 1. When the valve is moving it reads the decimal places - As in the pic - Sorry its not very clear - You might have to zoom in.

I know its a floating point number but I dont know how to tell which type

Dataref types are a bit of a black art

Im sure its something easy like a wrong dataref type

Thanks

Mark
Pic.PNG

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Zibo 737 datarefs

#6 Post by Sling »

Thats a shocking picture. Better to use the snipping tool rather than a phone camera. Can you try again?

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Zibo 737 datarefs

#7 Post by Sling »

Perhaps this will work better. Not sure about the servo you are using and hence your duty cycle maths so i kept it the same as yours.

Code: Select all

pwm_engine_rpm = hw_output_pwm_add("RPM servo", 50, 0.02)

function valve_update(pos)

    hw_output_pwm_duty_cycle(pwm_engine_rpm, 0.02 + ((0.10 - 0.02)/1) * pos)

end

xpl_dataref_subscribe("laminar/B738/air/engine1/starter_valve", "FLOAT", valve_update)

Markjohn
Posts: 10
Joined: Wed Mar 24, 2021 10:30 pm

Re: Zibo 737 datarefs

#8 Post by Markjohn »

Thanks for the code. I will try it later

I have attached another pic. I didnt think to use the snipping tool

I cant show you when the valve moves. its too quick.

When it goes between 0 and 1 its a decimal number with 6 decimal places

I will let you know how I get on with the code
Thanks
Mark
Capture.PNG

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Zibo 737 datarefs

#9 Post by Sling »

Yep as i initially suspected. That dataref is a regular FLOAT type and not an array of FLOATS. The code i posted should work.

For future reference an array type is easily spotted in Dataref Tool by a collection of values separated by commas as can be seen just above the dataref in question. There are other data types but by far the most common are

INT - a single integer number. 0 or 5 for example.

INT[8] - a collection of 8 integer numbers. [2,5,7,1,0,0,0,0] for example

FLOAT - a single floating point number. 21.435 for example

FLOAT(4) - a collection of 4 floating point numbers. [1.23,56.1,0.,0.]

When trying to access data from a dataref you need to subscribe with the correct dataref name and the correct data type for it to work.

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

Re: Zibo 737 datarefs

#10 Post by Keith Baxter »

Hi,

If you click on the edit button a popup window tells you what type and where the dataref origins.
ice_screenshot_20210326-184733.png

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 

Post Reply