Page 1 of 2

Zibo 737 datarefs

Posted: Wed Mar 24, 2021 10:39 pm
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)

Re: Zibo 737 datarefs

Posted: Thu Mar 25, 2021 3:02 am
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?

Re: Zibo 737 datarefs

Posted: Thu Mar 25, 2021 3:32 pm
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

Re: Zibo 737 datarefs

Posted: Thu Mar 25, 2021 9:07 pm
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?

Re: Zibo 737 datarefs

Posted: Fri Mar 26, 2021 11:19 am
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

Re: Zibo 737 datarefs

Posted: Fri Mar 26, 2021 11:43 am
by Sling
Thats a shocking picture. Better to use the snipping tool rather than a phone camera. Can you try again?

Re: Zibo 737 datarefs

Posted: Fri Mar 26, 2021 11:55 am
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)

Re: Zibo 737 datarefs

Posted: Fri Mar 26, 2021 1:09 pm
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

Re: Zibo 737 datarefs

Posted: Fri Mar 26, 2021 3:07 pm
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.

Re: Zibo 737 datarefs

Posted: Fri Mar 26, 2021 4:49 pm
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