Help with TAS indication

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

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

Re: Help with TAS indication

#11 Post by JackZ »

As per the dataref to use, you can check with Dataref Tool and see what dataref changes when the Airspeed Dial changes.

Code: Select all

laminar/c172/knob_TAS
Apparently the expected value is a float that continuously varies from -1.0 to +1.0 by 0.01 increments.

So based on Jason Tatum's C172 Airspeed indicator, this snippet of code below works and the TAS scale can be operated either from AM or Xplane.
Of course the values of step and initial rotation angle of -27° needs to be adjusted to your own graphics. Some trial and error is required for fine tuning

Code: Select all

function new_knob(direction)-- The AM dial is turned
    card_value=card_value-(0.01*direction) -- We increment/decrement the Xplane TAS value by +/-0.01
    card_value=var_cap(card_value,-1.0,1.0) -- We keep it within range
    xpl_dataref_write("laminar/c172/knob_TAS","FLOAT",card_value) --and we update the Dataref
end

step=4.5*10 -- Empirical step value to obtain the actual rotation of the card, found by trial and error
function card_pos(knob_TAS)-- The Xplane TAS dial is turned, hence the Dataref is changed
    --print(knob_TAS)
    card_value=var_cap(knob_TAS,-1.0,1.0)
    rotate(as_card, -27-(card_value*step)) -- The initial card rotation angle when the Xplane TAS value is 0.0 is found to be -27 degrees, we turn the card according to the TAS value ranging between -1.0 to +1.0 times the step (note the negative value  to turn counterclockwise)
    --print( -27-(card_value*step))
end

---------------------------------------------
--   Controls Add                          --
---------------------------------------------
dial_knob = dial_add("airknob.png", 31, 395, 85, 85, new_knob)
dial_click_rotate(dial_knob,6)
hw_dial_add("KIAS/TAS card dial", 3, new_knob)-- hardware dial
---------------------------------------------
--   Simulator Subscriptions               --
---------------------------------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", new_speed)
xpl_dataref_subscribe("laminar/c172/knob_TAS","FLOAT",card_pos) -- new dataref subscribe for the Xplane TAS dial position
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

#12 Post by astroseus »

Hi @JackZ thank you for all the information.
I will investigate on it tomorrow more closely (when I'm fresh minded) as I worked the entire evening on some visual improvements.
I randomized the Philips screws, added the TAS Pressure Alt cutout and added wear and tear to the dial.
Also added some dust into the illumination. Hope you like it.
background2-night4.png

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

Re: Help with TAS indication

#13 Post by astroseus »

I'm so excited right now! It seems WE fixed my problem.
I used the code as above and it works seamless.
The only problem I encounter is that I might need to tweak the parameters according to my graphics for the speed.
And it seems there is a problem with the pressure alt not resembling the right value in my graphics. I just the same angles as Jason did in his graphics though but we can fix that for sure tomorrow.

I'm really really happy. Belgian beers are on me :mrgreen: I'm not kidding.
I really appreciate your help guys. Tomorrow I will investigate the code further and the graphics, and try to learn more from it.
If I don't learn from it it's a waste of energy off course.
C172 - Airspeed night with TAS.siff
(438.6 KiB) Downloaded 154 times

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

Re: Help with TAS indication

#14 Post by JackZ »

Good work!
Try the following:

Code: Select all

step=6*10
start_angle=0

function card_pos(knob_TAS)
    --print(knob_TAS)
    card_value=var_cap(knob_TAS,-1.0,1.0)
    rotate(tas_card, start_angle-(card_value*step))
    --print(start_angle-(card_value*step))
end
I figured that a start_angle of 0 was best suited than -27 in your case for an XP returned value for TAS pos of 0.
Now what you have to experiment with is the step value (at the moment it's 6*10 but you have to find the correct one by trial and error) so each click on the dial matches the displacement of the dial in the sim. The easiest is to go all the way to an XP value of -1/+1 and work from here.

About the night lighting, I think you should create a separate semi-transparent image with only the "light ring" on it, so that you will be able to
1- bind it to the Nav lights of the sim by subscribing to the XPlane instrument lights dataref, that is turn the lighting on and off accordingly
2- play with the opacity() function of AM to mimic the light intensity variations achievable with the dial.

Talking about the light, to be more accurate, you should probably change the color of the needle and the scale, that can't be plain white but should be affected as well by the lighting yellowish color IMHO.

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

#15 Post by astroseus »

Cessna 172 - Airspeed night with TAS.siff
(243 KiB) Downloaded 148 times
Hey all.

I've updated the graphics again a little to match my scale with the scale of the in cockpit from LR C172.
I used their image from the aircraft folder and matched everything up.
This is as close as I can get it (for now at least) @JackZ.
Feel free to test it out and feedback and thank you for the help again.

I also added the illumination as a separate image. So I'll learn online about the opacity function.
Thanks for all the help everyone. It will be nice to continue on other dials in the same style so we can end up with a full panel.


Regards,
Pieter

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

Re: Help with TAS indication

#16 Post by JackZ »

Hope you didn't micmic the LR's C172 TAS scale which, as said previously, is plain wrong.
The real TAS speed scale should aligned with the IAS when flying under ISA conditions, namely 15°C at Sea Level, since ISA conditions are the ones where the IAS instrument is calibrated for.
This is not the case in the Xplane stock C172.

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

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

Re: Help with TAS indication

#17 Post by JackZ »

Here's the version with the lighting linked to the brightness dial of the C172 (could be a hardware or an AM one, via inter-instrument communication),and of course, tied to the BUS voltage, so there is no lighting when the MASTER BAT is OFF, and the light eventually goes Off when MASTER ALT is OFF or a GEN failure leading to a bus voltage <23 volts.

You can see there why the lighting had to be on a separate image, in order to use the opacity() function.

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)
img_illumination=img_add_fullscreen("illumination.png")
opacity(img_illumination,0.0)-- no light at startup


-- Functions --
card_value=0.0

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(direction)
    card_value=card_value-(0.01*direction)
    card_value=var_cap(card_value,-1.0,1.0)
    xpl_dataref_write("laminar/c172/knob_TAS","FLOAT",card_value)
end


step=4.7*10

function card_pos(knob_TAS)
    --print(knob_TAS)
    card_value=var_cap(knob_TAS,-1.0,1.0)
    rotate(tas_card, -26-(card_value*step))
    --print( -26-(card_value*step))
end
    
function set_lighting(brightness_level,bus_voltage)
    --print(bus_voltage[1])
    if bus_voltage[1]>=23 then -- the elec bus voltage is sufficient for lighting
        opacity(img_illumination,brightness_level)-- we use the brightness level ratio returned by Xplane directly since it is between 0.0 and 1.0
    else
        opacity(img_illumination,0)-- no power for lighting, light is off
    end
end

-- Controls Add --

dial_knob = dial_add("airknob.png", 31, 395, 85, 85, new_knob)
dial_click_rotate(dial_knob,6)
hw_dial_add("KIAS/TAS card dial", 3, new_knob)


-- Simulator Subscriptions --

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", "FLOAT", new_speed)
xpl_dataref_subscribe("laminar/c172/knob_TAS","FLOAT",card_pos)
xpl_dataref_subscribe("sim/cockpit/electrical/instrument_brightness","FLOAT",
	                              "sim/cockpit2/electrical/bus_volts","FLOAT[6]",set_lighting)
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

#18 Post by astroseus »

JackZ wrote: Tue Jul 20, 2021 12:39 pm Hope you didn't micmic the LR's C172 TAS scale which, as said previously, is plain wrong.
I did because I wanted to mimic the flight sim itself as much as possible. But I noticed indeed it's wrong.
And with reading back I read the comment about it previously. I must have missed that earlier sorry.
I can roll back anytime though since I always save in versions. So it's not really a big issue.
I want to find more information on the logic behind the IAS as well. (In the stock C172 from LR) There seems to be no consistency in how much the 10 lines angle if you know what I mean.

But now that we know how the code should look, I can perfect the images and adapt the code to it.
So again my big appreciation to you guys.

Regards,
Pieter

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

Re: Help with TAS indication

#19 Post by JackZ »

The scale of any IAS indicator is more than often non linear, that’s because of compressibility factor among others.
The system of dynamic vs static pressure induces many errors, that impact on the accuracy of the instrument. The slower the airplane, the less the rate of pressure change in the pressure sensing capsule, so the spring and counterweight have less work.

Moreover the accuracy in speed display is more important at low speed during approach and take off where 2 knots of difference in speed can make a big one.
IMHO there is no point to mimic the LR instrument, you’d better be up using a stock image of the real Cessna instrument as a guide.

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

#20 Post by astroseus »

JackZ wrote: Tue Jul 20, 2021 2:43 pmIMHO there is no point to mimic the LR instrument, you’d better be up using a stock image of the real Cessna instrument as a guide.
You're right sir, that would have been the best approach.
Let me fix this and republish at some point.


Greets,
Pieter

Post Reply