R22 Gauge Formula Assistance

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
checkyourmirrors
Posts: 11
Joined: Sat Dec 12, 2020 11:47 pm

R22 Gauge Formula Assistance

#1 Post by checkyourmirrors »

I've been trying to understand the following formula which @HeliEngineer built although being new I can't PM him. These are for the R22 fuel tanks however they don't match the weight or gallons and I believe X-Plane returns the fuel quantity back in KG's. Appreciate any insight and I'm trying to do something similar for the R44 from VSKYLABS which uses the standard datarefs and not anything custom.

--Aux Tank
rotate (img_needle_3, (68/31) * console[3] - 34)

--Main Tank
rotate (img_needle_5, (68/50) * console[5] - 34)

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

Re: R22 Gauge Formula Assistance

#2 Post by Sling »

It would be useful to see them in context with the rest of the code. What is console for instance? Also what part specifically don’t you understand. What rotate does etc

checkyourmirrors
Posts: 11
Joined: Sat Dec 12, 2020 11:47 pm

Re: R22 Gauge Formula Assistance

#3 Post by checkyourmirrors »

I’ll post the code when I can get back to my computer and the fuel quantity is coming back from X-Plane in KG’s. I’m assuming there is some “normalization” of the weight to tank weight total capacity so the fuel gauge reads correctly. The logic is escaping me......

Fuel capacity:
Main tank total capacity: 19.8 US gal (16 imp gal; 75 l), 164Lbs, 74.3 Kg
Optional auxiliary tank total capacity: 10.9 US gal (9 imp gal; 41 l) 90.47 lbs, 41 Kg’s

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

Re: R22 Gauge Formula Assistance

#4 Post by Sling »

I had a quick look at this for you. I had to download the instrument to get the rest of the code so next time remember to post all the relevant code.

Your fuel weight conversions are incorrect which is why it’s probably not making sense.

The formula parameters are as follows.

68 is the full scale needle movement in degrees
34 is half of the full scale needle deflection. This sets the needle starting point to the lowest tick mark on the gauges.
31 and 50 are the max fuel capacities for each of the tanks in Kg. This is why your converted Kg values didn’t make much sense.
console[3] and console[5] are the respective fuel quantities from the sim in Kg.

As an example the formula could be rewritten as follows as it reads a little easier. Here the console value is converted to a 0 to 1 value, where 0 is min and 1 is max. Then all you do is multiply by the full scale angle of 68 and apply the starting position offset of 34.

68 * (console[3] / 31) - 34

If you have a look at any of the other online gauges that use needles you will see a pretty similar method used across them all. The values may vary but the method is the same. For anyone new to gauge development in Air Manager it’s important to master this as it’s the foundation of needle movement. Once you get your head round it you can see the maths is real easy.

I hope this helps

Tony

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

Re: R22 Gauge Formula Assistance

#5 Post by Keith Baxter »

Hi,

EDIT: Oh WOW Tony beat me to it while I was doing exactly what he had to do and typing this. Anyway it is done so I will leave it here. Basically says the same as his post.

Firstly the instrument you are trying to use is for the DreamFoil R22 Beta11. That instrument uses a custom dataref and will not work on other design-house aircraft.

So I take it you want to change the dataref to one that is not custom.

Code: Select all

rotate (img_needle_3, (68/31) * console[3] - 34)
Lets look at the above code and observe the pointer position on the image and the dial scale.
1) the needle "img_needle_3" is in a °270 position.
2) the dial scale gos from °236 to °304 which is a total of °68

So what does the math do.

1) the 68 in the equation is the total number of degrees the pointer has to rotate.
2) the 31 is the full value in kg's
3) Using this calculator 10.5 US Gal is close to 31 kg's. http://mye6b.com/Fuel/
4) the -34 rotates the pointer -°34 to the "E" position
5) the console[3] is the dataref value
6) The 68/31 gives you the rotation of degrees the pointer must rotate for each kg.



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 

checkyourmirrors
Posts: 11
Joined: Sat Dec 12, 2020 11:47 pm

Re: R22 Gauge Formula Assistance

#6 Post by checkyourmirrors »

Thank you both so much and yes, the Kg math being off slightly is what threw me from doing the easy change and thank you for the online calc URL. The missing piece of information which was an educational/understanding gap for me was the degrees. I'm curious how were you so easily able to measure the degrees? Barring throwing a protractor on the screen I'm hoping there is some tool that makes this easier?

As far as the "custom" aspect I'm reusing the gauges for the VSKYLABS R44 which has the same gauge layout between the R22 and R44, however VSKYLABS uses standard X-Plane datarefs so I needed to pull a different dataref. There is little physical hardware for helicopter panels so I'm attempting to build one for a touchscreen and I've attached my current progress. It's not perfect but very functional and I'm working through the clutch switch which has a missile cover. Also I've got the ignition switch following the X-Plane cockpit panel however the xpl_writes don't error when I turn the key but it doesn't modify the panel.

I'm not a coder by job but I've done enough way back in the mainframe days I get the basic logic so I'm fumbling through this.....and thank you for the help.
R44_panel.jpg

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

Re: R22 Gauge Formula Assistance

#7 Post by Sling »

The needle rotation angles were just a visual estimate and a quick enter of some test values. When coding a new gauge you would start with your estimate and fine tune by using different values until you get the needle to line up with the min and max marks. This gives you the offset value and the full scale. In some cases the needle graphic may already be drawn on the min mark so all you need is the full scale angle with no offset required.

User avatar
HeliEngineer
Posts: 35
Joined: Thu Aug 04, 2016 10:46 am

Re: R22 Gauge Formula Assistance

#8 Post by HeliEngineer »

G’day @checkyourmirrors. Sorry for not replying sooner, but I don’t frequent the forums often.
How did you get on with your R44 gauges?
Like the guys have said, the R22 console gauges, and carb temp gauge were written for the dreamfoil R22, and uses the custom dataref "R22/ConsoleGages". This is a “FLOAT” type data ref, and has 10 functions.
1/10 = Amps
2/10 = Oil pressure
3/10 = Aux fuel
4/10 = Oil temp
5/10 = Main fuel
6/10 = cylinder head temp
7/10 = Carb heat
8/10 = Engine RPM
9/10 = Rotor Rpm
10/10... I cant remember

The code in the console gauges, and carb temp gauge might not be exactly correct. I was sitting in the jungle in Paupa New Guinea, where I use to tour as a helicopter engineer, trying to teach myself how to write the lua code, and use skinman. This was a while ago, using airmanager 2.xx on a surface pro 2 laptop with a 10” screen! Nothing much else to do in the evenings.
I might have a look at them this weekend, and tidy them up.

I use the two plugins “datarefeditor”, and “datareftool”, and the files within the x-plane aircraft folder to find out what datarefs the developers have used. A good file to have a look at is the one in the objects folder that has the same name as the .png file that shows the instruments. Open this .obj file with Notepad++, and look towards the bottom of the info. You can start to pick what datarefs have been used for most things this way.

When I made the Bell 412 gauges, I also had to run the sim, and compare the dataref data (using the datarefeditor plugin), with the gauges themselves. Some of the data is not linear.

Keith mentioned a different way to write the code. There are plenty of ways to write the code to do the same thing. I write the code you were looking at, as I find it easier to keep up with where I am at. Especially when writing code for non linear gauges.
It is: change in degrees(angle) / change in data x (dataref – start data) + start angle

68/31 * (console[3]) -34

So for the aux fuel, the scale is 68 degrees, and 31kg from 0 to full. If you look in the gauges resource folder, you can see that the needle in the image is in the vertical, or zero degree position.
That is why the code is 68degrees / 31 Kg x (console[3] - 0) + -34 , where 0 = start data of empty, and +start angle = + -34 degrees, which is -34.
Needle movement from the zero position is positive clockwise, and negative anticlockwise.

Anyway. If you do still need some help, just sing out. I will be checking in a bit more often. I am converting a few hardware panels that I made a while ago using Ardsim, and ArdsimX to airmanager. I have most things sorted, but have been hitting the forums to figure a few things out.

checkyourmirrors
Posts: 11
Joined: Sat Dec 12, 2020 11:47 pm

Re: R22 Gauge Formula Assistance

#9 Post by checkyourmirrors »

Thanks for the reply and I did get them all working however I ended up switching to VR since it really helps with handling the aircraft.

User avatar
HeliEngineer
Posts: 35
Joined: Thu Aug 04, 2016 10:46 am

Re: R22 Gauge Formula Assistance

#10 Post by HeliEngineer »

No worries. I also have a VR headset, and it is definitely entertaining. I tend to spend more time on my hardware based sim though. I find it much better for keeping up with procedures, and VFR flights. I do a lot of night and low viz flying, and VFR cross country flights with a map, stopwatch, and the local weather dialed up. It helps a lot with the real world flying that I do.

Post Reply