Help with TAS indication

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
astroseus
Posts: 46
Joined: Sun Jul 18, 2021 9:02 am
Location: Belgium

Help with TAS indication

#1 Post by astroseus »

Hello fellow simmers, enthusiasts and pro's (I hope I didn't leave anyone out).

Although having reached an age of 36 and being a aviation enthusiast for many many years already, I'm still a rookie at many many things.
Air Manager is one of those items on my list. So my apologies up front for the upcoming potentially stupid questions.

I wanted to make my own panel for X-plane 11 using Air Manager 4. I wanted to make a night-flight panel and started with this design of an airspeed indicator.
(It doesn't have the upper cutout and dial in place yet, still working on that)
C172-AS-night.jpg
Coding it isn't easy for me but I managed to code the airspeed indication with the help of duplication and changing Jason Tatum's C172 code.
I noticed though his TAS indicator doesn't link to the one in X-plane 11.
What I did notice is that the one from a the C172SP premium panel from Sim Innovations theirs is working properly.
But there isn't a way to extract code from premium panels or am I missing something here?

Is there anyone who could help me/guide me in how to make it working properly?
Because drawing gauges is one, making them work is something entirely different :mrgreen:

Many thanks in advance.
I appreciate all help!

Regards,
Pieter

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Help with TAS indication

#2 Post by jph »

Hello Pieter and welcome to the forums.
You cannot extract code from premium panels as they are, quite rightly locked down and not open source.
If that is your work on the graphics you are really doing well, it is pretty damn good.
Regarding the questions re the other code, there are FAR more experts here than me in that area.
Also, with regards to being 36....... :? ??? You are a mere youngster haha :D -- I can vaguely remember being that young..... yikes...
Joe
Joe. CISSP, MSc.

astroseus
Posts: 46
Joined: Sun Jul 18, 2021 9:02 am
Location: Belgium

Re: Help with TAS indication

#3 Post by astroseus »

Hi @jph,


I appreciate the warm welcome and the kind words on the design.

In all honesty I have to admit (although being schooled as a welder/metal fabricator via an external training, and IT management in high school) my heart goes out to design over programming.
I was already drawing buttons and switches in high school during the Visual Basic development classes :mrgreen:
Back then it was still in Macromedia Fireworks before it all became Adobe Photoshop stuff.
This design is made in Affinity Designer though.

Before ending up on disability (due to medical reasons) my daytime job was also drawing interfaces for mobile applications and web +3D design.
So the design is the easy part for me. It's specially the development I don't understand much from.
But if I can ever help someone with drawing some stuff, let me know. I'm happy to help and the graphic programs don't have many secrets to me anymore.

Regards,
Pieter

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

Re: Help with TAS indication

#4 Post by Sling »

Hi Pieter,

First up welcome to the forum. You will find a helpful bunch here so don’t be afraid to ask away. May I suggest if the coding part is where you lack the experience that you spend some time studying some of the methods employed amongst the growing list of community instruments and also take the time at your own pace to follow along with API tutorial videos linked in my signature below. If you have specific questions relating to any of this or your airspeed indicator then ask away. All we generally ask is that you provide as much information as you can and do the leg work and we will help fill in the gaps when you get stuck. It seems you fall into that category anyhow judging by the great start you made on the graphics.

Rest assured if it’s possible someone will have the answer.

Tony

astroseus
Posts: 46
Joined: Sun Jul 18, 2021 9:02 am
Location: Belgium

Re: Help with TAS indication

#5 Post by astroseus »

Hey Tony,


Thanks for the help and for linking me into the right direction.
I will start with watching those video's and we'll take it from there.

Appreciate it!
Regards,
Pieter

astroseus
Posts: 46
Joined: Sun Jul 18, 2021 9:02 am
Location: Belgium

Re: Help with TAS indication

#6 Post by astroseus »

Hi Guys,


I figured some stuff out from watching some video's that Tony was referring too. I still need to watch 20 or more so it will take time.
So far I have this code below.

I also figured out that Laminar Research updated the datarefs with this one some time ago: "laminar/c172/knob_TAS"
My assumption is that's the one I need to write too to get my dial going.
I don't know how it fits in with the code below though.
I'm pretty sure after more video's of the API things will become clearer but off course hints to fill in the blanks are welcome of course :mrgreen: since I'm pretty excited to get the stuff going asap.

Ow also I still have to recalculate the rotation angles for the speed needle.
Since I had a glitch in mine which made it stutter at the transitions. No biggie that shouldn't be rocket science.

Code: Select all

-- Add images --

tas_card = img_add_fullscreen("tasdial.png")
img_add_fullscreen("airspeedwbgilluminated.png")
as_needle = img_add("needle.png",0,0,512,512)
card = 0


-- Functions --

function new_speed(speed)

speed = var_cap(speed, 0, 220)

    if speed >= 160 then
        rotate(as_needle,266 + ((speed-160)*1.3))
    elseif speed >= 120 then
        rotate(as_needle,205 + ((speed-120)*1.525))
    elseif speed >= 100 then
        rotate(as_needle,162 + ((speed-100)*2.15))
    elseif speed >= 70 then
        rotate(as_needle,92 + ((speed-70)*2.29))
    elseif speed >= 40 then
        rotate(as_needle,31 + ((speed-40)*2.033))
    else
        rotate(as_needle, (speed*0.775))
    end

end


function new_knob(value)

card = card + value
    if card > 49 then
        card = 49
    end
    if card < -135 then
        card = -135
    end

card = var_cap(card, -135, 49)
rotate(tas_card, card)

end


-- Controls Add --

dial_knob = dial_add("tasknob.png", 31, 395, 85, 85, new_knob)
dial_click_rotate(dial_knob,6)


-- Simulator Subscriptions --

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", new_speed)

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

Re: Help with TAS indication

#7 Post by Sling »

Hi,

A few things.

Dials pass a direction argument to their corresponding callback which will either be 1 or -1 so this needs to be added to an existing rotation angle to get the tas disc to move. It’s normal for the argument to be named something meaningful so most use dir or direction rather than value.

Code: Select all

var_cap(card + dir, -135, 49) 
The var_cap does what those if statements do in the dial callback so they can be deleted because they achieve nothing. If you haven’t found it yet the Sim innovations wiki is a great resource. Locate the API pages and look for the var_cap() function to help explain what this does.

Doing the above will move the tas disc locally but if you want the sim an AM instrument to move the disc in unison you will need to incorporate the dataref you identified. This is a little more involved but not at all complicated. It involves reading the sim value, adding or subtracting the dial movement to its value and then writing the new value back to the sim. In this case the disc rotation is set based on the sim value only. This is the basis of a very common technique used in many AM instruments. Read, alter, send back.

Hope this helps.

Tony

astroseus
Posts: 46
Joined: Sun Jul 18, 2021 9:02 am
Location: Belgium

Re: Help with TAS indication

#8 Post by astroseus »

OK, it doesn't work and will never work. I gave up on it. Lol.
I'm tired, frustrated and the more I read and try stuff the more it breaks.
This is were I left off:

Code: Select all

-- Add images --

tas_card = img_add_fullscreen("tasdial.png")
img_add_fullscreen("airspeedwbgilluminated.png")
as_needle = img_add("needle.png",0,0,512,512)
card = 0


-- Functions --

function new_speed(speed)

speed = var_cap(speed, 0, 220)

    if speed >= 160 then
        rotate(as_needle,266 + ((speed-160)*1.3))
    elseif speed >= 120 then
        rotate(as_needle,205 + ((speed-120)*1.525))
    elseif speed >= 100 then
        rotate(as_needle,162 + ((speed-100)*2.15))
    elseif speed >= 70 then
        rotate(as_needle,92 + ((speed-70)*2.29))
    elseif speed >= 40 then
        rotate(as_needle,31 + ((speed-40)*2.033))
    else
        rotate(as_needle, (speed*0.775))
    end

end


function tas(dir)

    local new_tas = gbl_tas_knob + dir * 0.01
    xpl_dataref_write("laminar/c172/knob_TAS", "FLOAT", new_tas)

end


function tas_knob_update(tas_knob)

    gbl_tas_knob = tas_knob

end


-- Controls Add --

tas_knob = dial_add("tasknob.png", 31, 395, 85, 85, tas_knob)
dial_click_rotate(tas_knob,6)


-- Simulator Subscriptions --

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", new_speed)
xpl_dataref_subscribe("laminar/c172/knob_TAS","FLOAT", tas_knob_update)

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Help with TAS indication

#9 Post by JackZ »

Hi

I understand your frustration, but most of your issues is basically because you didn’t follow the kind advices of Uncle Tony :)

According to the wiki for dials functions:
https://siminnovations.com/wiki/index.p ... e=Dial_add
The values sent by the dial_add to the callback function are as follow.

Code: Select all

function callback(direction)
  -- Direction will have the value
  --  1: When the dial is being turned clockwise
  -- -1: When the dial is being turned anti-clockwise
  print("dial has been turned into direction " .. direction)
end
So the only information we get from the dial is the direction it has been turned.

No wonder that if you take this value of -1 or 1 and send it straight like this to the XPlane TAS Dataref it doesn’t work!

One has to figure out first what is the expected value of the dataref, THEN create the proper expected value by adding/substracting a specific increment to an initial value that can be read from the Dataref itself at instrument startup.

The second issue you are facing is the scope of variable in Lua.
If you declare (in Lua it’s simply done by first use, or mention in the code) a variable in a function the variable is considered local and is hence not « visible » outside the function it was created first. Search for variable scope in Lua for more insight

gbl_tas_knob is not declared before outside of any function, so it’s value is not propagated from one function to another.
I suggest you abundantly use

Code: Select all

print(« Value of gbl_tas_knob: ».. gbl_tas_knob)
in your code, in order to see what I mean (don’t forget to comment out the print() statement once the debugging is done, as print() tends to slow things a bit.)

What you want to achieve and what Tony explained is a three step procedure.
1- create a global variable by initializing it first early in the code and outside of any function

Code: Select all

gbl_tas_knob=0.0
2-READ the dataref at startup and setup the gbl_tas_knob value to the current sim value
3- according to to the dial movements, in the function you modify the current gbl_tas_knob by adding/subtracting a set value. You can then WRITE the dataref with the new value and see the dial move accordingly. In the same function you will calculate the new rotation angle of the TAS disk image and rotate it as well.

Lastly, be warned that the TAS disk is linked to the OAT temperature & pressure altitude displayed on the top of the gauge (actually it is the same disk). Basically you set the current pressure altitude aligned with the actual OAT on the instrument and this shifts the entire TAS scale accordingly.
I noticed that a while ago it was completely wrong in XPlane, as the values were off when compared to the real ones.
Check the actual TAS formulae correction with temperature and pressure altitude.

TAS=39Msqrt(T)
With
M: current Mach number
T: current temperature in degrees K

A small advice on the graphic side: I suggest you randomly turn each mounting screw so the Phillips cross engraving are not aligned, as the screws never are IRL. Devil is in the detail, and since you are into graphics with a very nice looking result BTW, felt like I had to mention this :twisted:

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

astroseus
Posts: 46
Joined: Sun Jul 18, 2021 9:02 am
Location: Belgium

Re: Help with TAS indication

#10 Post by astroseus »

A small advice on the graphic side: I suggest you randomly turn each mounting screw so the Phillips cross engraving are not aligned, as the screws never are IRL. Devil is in the detail, and since you are into graphics with a very nice looking result BTW, felt like I had to mention this
Maybe you can teach me how to code it so they get randomly rotated on everyone's PC differently :lol:
Haha just kidding, you're absolutely right, I will fix that, thanks for pointing it out.

Sorry for me getting frustrated. It just happens when I want to do something and I can't get my head wrapped around it.
Specially when I don't even understand the examples I read.
Programming (even simple things) always got me struggling. I just don't see the logic in those things.
Ask me do draw an airplane in 3D, check. But please don't ask me to code anything more then a 90's VCR :D

Anyways, I'll read more in the wiki and take it from there with the help you guys gave me.
Tnx!

Post Reply