[SOLVED] Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

Help creating logic scripts for Air Manager Instruments

Moderators: Ralph, russ

Post Reply
Message
Author
User avatar
flyhardt
Posts: 4
Joined: Sat Feb 27, 2021 11:18 am
Location: Germany
Contact:

[SOLVED] Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#1 Post by flyhardt » Sat Feb 27, 2021 11:50 am

Hello Community,

I am currently building a P28R Cockpit and have just wired up throttle, pitch, and mixture levers.
So far a lot of encoders, switches and potis are working magnificent.

However, I have trouble writing to the datarefs for throttle, mix and pitch.
I feel this is very basic and must have been asked a number of times, yet I was unable to find an answer in the forums and elsewhere, which finally lead to me asking for help here.
Should I have overlooked something, please excuse my oversight.

Okay, now to the point:

The Goal

Moving the three magic levers with my hardware.

What I tried

I am sending a float value, e.g. to the mixture_ratio dataref like this:
Note, that I tried each of them individually, of course.
All other inputs are disconnected.

Code: Select all

percent = 0.6 -- calculated value between 0.00 and 1
xpl_dataref_write("sim/cockpit/actuators/mixture_ratio_all", "FLOAT", {percent})
xpl_dataref_write("sim/cockpit/actuators/mixture_ratio_all", "FLOAT", percent)
xpl_dataref_write("sim/cockpit/actuators/mixture_ratio", "FLOAT[8]", {percent})
xpl_dataref_write("sim/cockpit/actuators/mixture_ratio", "FLOAT[8]", percent)
Before sending those I set the override true when the panel is loaded though that does not make a difference.

Code: Select all

xpl_dataref_write("sim/operation/override/override_mixture", "INT", 1)
Using the DataRef Editor Plugin I validated that the overrides work by toggling them between 0 and 1.

When I replace the percent value with a hardcoded value to rule out a problem with the hardware the effect remains.

The Symptom

Whenever the value (percent) is lower than 1, e.g. 0.93, the DataRef becomes 0.
So something is transmitted and I can see both the lever jumping to full aft, as well as the DataRef jump to 0.0000 in the DataRef Editor.

When the value is 1 (and only then) the DataRef becomes 1. Again: lever and DataRef jump to the new position.

I have also tested a premade PA28 panel for AM which features those levers and observed the same effect.

Either I do not understand the examples and oversee something very simple or it is more complicated than it seems.

Help would be greatly appreciated :)

Another thought...
Writing this made me realize that it only works when the value is exactly 1. There are no decimals then, so it is 1 and not 1.00.
In all the other cases it is actually a decimal number. Could it be, that the decimals are simply cut off and e.g. 0.4(...) becomes 0?

Anyways,

Kind regards and many thanks,
Christopher


Edit:
I am running:
x-plane 11.52 on Windows10
AirPlugin 3.2
AirManager 3.7.4 on Ubuntu 20.04
Last edited by flyhardt on Mon Mar 01, 2021 8:45 am, edited 1 time in total.

User avatar
jph
Posts: 646
Joined: Fri Apr 10, 2020 12:50 pm
Location: Portugal

Re: Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#2 Post by jph » Sat Feb 27, 2021 1:12 pm

"The Goal

Moving the three magic levers with my hardware."





Use a HID joystick unit. Either self programmed arduino unit with the 32U4 processor, or a Bodner unit. Then use the normal Windows game controller setup, and then X-Planes customisation if needed. Far easier.
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

User avatar
flyhardt
Posts: 4
Joined: Sat Feb 27, 2021 11:18 am
Location: Germany
Contact:

Re: Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#3 Post by flyhardt » Sat Feb 27, 2021 2:20 pm

Thank you,

I guess I need to rephrase my goal.

A little background:
As an interim solution, I bought a used Saitek throttle quadrant off of eBay only to find that it is not the USB version, but the one that is supposed to be attached to the yoke.
So I rewired it and attached it to the Arduino Mega which interfaces the rest of the cockpit.
Hardware works fine and the values that I get in AirManager are what I need, including calibration and all.

While I could take a second Arduino and load it with UnoJoy (It's a Pro Mini, old thing, Joystick Library unsupported) I would have to make or get a FTDI USB Adapter... such and such. Or a newer Arduino that provides a HID interface.

I would like to avoid buying anything that is not needed to make this part of the project work.
Especially since I believe that it should be possible to drive the DataRefs like that.

Hence the goal is: Understanding what is not working with transmitting float DataRefs and being able to use them correctly.
The subsequent goal then is what I stated earlier.

From that perspective, I would hope to find a one-liner that maybe fixes any error that I might have made.
Aside from the throttle quadrant working, it would be beneficial to understand the underlying technology (AM) better in order to more fully utilize it elsewhere in the project.
After all, I might need to use float DataRefs for other features in the future.

Since the functionality exists, I would think that it also works. Since I was not successful in finding topics about that problem, I have to assume that it works for others as expected.

Should it turn out, that it is really not possible using AM, of course then I will have to start over with a new Arduino.

But until then, I remain hopeful :)

User avatar
Ralph
Posts: 5075
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#4 Post by Ralph » Sat Feb 27, 2021 4:05 pm

I did not read your whole post, it's a bit busy with the family, but which version of Air Manager are you using? And did you print the value coming from the ADC pin?

User avatar
flyhardt
Posts: 4
Joined: Sat Feb 27, 2021 11:18 am
Location: Germany
Contact:

Re: Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#5 Post by flyhardt » Sat Feb 27, 2021 4:49 pm

Hello Ralph,
And did you print the value coming from the ADC pin?
yes, the values are fine. They range between 0 and 1 as a float with two decimals and are calculated after calibration.
From hardware up until the print() call the data looks good.

Only the actual values between 0 and 1, that is when they have a decimal part such as 0.62, always are received as 0 on the x-plane end.

I also observed that AM prints float values with a comma as the decimal separator, not with a point. I thought that might be the issue but when I convert and replace, I get Lua errors.
Even when I put a value in the xpl_dataref_write() function without any reading from the hardware, the behavior is the same.

The Versions:
Edit:
I am running:
x-plane 11.52 on Windows10
AirPlugin 3.2
AirManager 3.7.4 on Ubuntu 20.04

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

Re: Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#6 Post by Keith Baxter » Sat Feb 27, 2021 5:15 pm

Hi

I had that issue a few years back.
Check what windows separator is.
There is a thread somewhere here.

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 

User avatar
flyhardt
Posts: 4
Joined: Sat Feb 27, 2021 11:18 am
Location: Germany
Contact:

SOLUTION! Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#7 Post by flyhardt » Sat Feb 27, 2021 6:06 pm

Hi

I had that issue a few years back.
Check what windows separator is.
There is a thread somewhere here.

Keith
Thanks Keith,

I have changed the settings for the decimal separator on the windows/main sim machine and validated the format in the windows calculator.
Didn't work.
I then remembered that the decimal point in AM is printed as a comma, too!

After changing the format on the Ubuntu machine also - the magic arrived :)

Thank you very much, please take my gratitude: (gratitude handed over)
It would have taken me ages to find that out on my own.

Many many thanks!

Kindest,
Christopher

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

Re: Float values for DataRefs (Throttle, Mix, Pitch) become 0 and 1 in XPlane

#8 Post by Keith Baxter » Sat Feb 27, 2021 7:51 pm

Hi Christopher,

Glad you got it sorted

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

Who is online

Users browsing this forum: No registered users and 13 guests