Instrument Converting

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
beechraft P3D
Posts: 6
Joined: Tue Jul 04, 2017 1:39 am

Instrument Converting

#1 Post by beechraft P3D »

hello everybody,.,.. special greets to those that can help me a little. I would like a helping hand here in regards to converting the generic EADI EHSI from XPLANE to P3D.. I don't know how I can put them to work with P3D and I have tried a lot, but I havent been able to do it. Please help me.. I'd really appreciate this!

Regards
Juan P

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

Re: Instrument Converting

#2 Post by Ralph »

You'll have to find the correct variables and shoot those into the Xplane callbacks. That's it in a nutshell ;)

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

Re: Instrument Converting

#3 Post by JackZ »

Good news for you, it is already the case!
Here's the last part of the code of the Generic EADI

See, there are for each variable an XPlane variable subscription (starting with xpl_dataref_subscribe())
and an FSX variable subscription (starting with fsx_variable_subscribe())

Code: Select all

-------------------
-- Bus subscribe --
-------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/roll_AHARS_deg_pilot", "FLOAT",
					  "sim/cockpit2/gauges/indicators/pitch_AHARS_deg_pilot", "FLOAT",
					  "sim/cockpit2/autopilot/flight_director_roll_deg", "FLOAT",
					  "sim/cockpit2/autopilot/flight_director_pitch_deg", "FLOAT",
					  "sim/cockpit2/autopilot/flight_director_mode", "INT", new_attitude)
					  
fsx_variable_subscribe("ATTITUDE INDICATOR BANK DEGREES", "Radians",
					   "ATTITUDE INDICATOR PITCH DEGREES", "Radians",	
						"AUTOPILOT FLIGHT DIRECTOR BANK","Radians",
						"AUTOPILOT FLIGHT DIRECTOR PITCH","Radians",
					    "AUTOPILOT FLIGHT DIRECTOR ACTIVE","Boolean",new_attitude_fsx)
				 

xpl_dataref_subscribe("sim/cockpit2/radios/indicators/outer_marker_lit", "INT",
					  "sim/cockpit2/radios/indicators/middle_marker_lit", "INT",
					  "sim/cockpit2/radios/indicators/inner_marker_lit", "INT", new_marker_beacons)

fsx_variable_subscribe("OUTER MARKER","Boolean",
						"MIDDLE MARKER","Boolean",
						"INNER MARKER","Boolean",new_marker_beacons_fsx)
					  
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot", "FLOAT",
                      "sim/cockpit/misc/radio_altimeter_minimum", "FLOAT",	new_radio_height)

fsx_variable_subscribe("RADIO HEIGHT", "FEET",
						"DECISION HEIGHT", "FEET", new_radio_height_fsx)					  
xpl_dataref_subscribe("sim/cockpit2/radios/actuators/HSI_source_select_pilot", "INT", -- 0 = nav1, 1 = nav2, 2 = GNSS
					  "sim/cockpit2/autopilot/heading_status", "INT", -- Autopilot Heading Status. 0=off,1=armed,2=captured
					  "sim/cockpit2/autopilot/nav_status", "INT",     -- Autopilot Nav status
					  "sim/cockpit/autopilot/autopilot_mode", "INT", -- The autopilot master mode (off=0, flight director=1, on=2)
					  "sim/cockpit/switches/yaw_damper_on", "INT",
					   lateral_mode)
					   
xpl_dataref_subscribe("sim/cockpit2/autopilot/glideslope_status", "INT",
					  "sim/cockpit2/autopilot/altitude_hold_status", "INT",
                      "sim/cockpit2/autopilot/vvi_status", "INT",
					  "sim/cockpit2/autopilot/speed_status", "INT",
					  "sim/cockpit2/autopilot/TOGA_status", "INT",
					  "sim/cockpit2/autopilot/pitch_status", "INT",
					  vertical_mode)
					  
xpl_dataref_subscribe("sim/cockpit2/radios/indicators/hsi_display_vertical_pilot", "INT",
                      --"sim/cockpit2/radios/indicators/hsi_flag_glideslope_pilot", "INT",
                      "sim/cockpit2/radios/indicators/hsi_vdef_dots_pilot", "FLOAT",
					  "sim/cockpit2/radios/indicators/hsi_display_horizontal_pilot", "INT",
					  "sim/cockpit2/radios/indicators/hsi_hdef_dots_pilot", "FLOAT",
					  vertHorPath)
So it should work as is in FSX/P3D (Did you really try it before calling for help? :D). Guess that the FSX/P3D feature icon has not been set on by the developper, just because all the Xplane functions have not (yet) been implemented for FSX.
The only things that appear to be missing are the AP mode annunciators, since those three last lines of the code don't have their FSX/P3D counterparts.

Code: Select all

xpl_dataref_subscribe("sim/cockpit2/radios/actuators/HSI_source_select_pilot", "INT", -- 0 = nav1, 1 = nav2, 2 = GNSS
					  "sim/cockpit2/autopilot/heading_status", "INT", -- Autopilot Heading Status. 0=off,1=armed,2=captured
					  "sim/cockpit2/autopilot/nav_status", "INT",     -- Autopilot Nav status
					  "sim/cockpit/autopilot/autopilot_mode", "INT", -- The autopilot master mode (off=0, flight director=1, on=2)
					  "sim/cockpit/switches/yaw_damper_on", "INT",
					   lateral_mode)
					   
xpl_dataref_subscribe("sim/cockpit2/autopilot/glideslope_status", "INT",
					  "sim/cockpit2/autopilot/altitude_hold_status", "INT",
                      "sim/cockpit2/autopilot/vvi_status", "INT",
					  "sim/cockpit2/autopilot/speed_status", "INT",
					  "sim/cockpit2/autopilot/TOGA_status", "INT",
					  "sim/cockpit2/autopilot/pitch_status", "INT",
					  vertical_mode)
					  
xpl_dataref_subscribe("sim/cockpit2/radios/indicators/hsi_display_vertical_pilot", "INT",
                      --"sim/cockpit2/radios/indicators/hsi_flag_glideslope_pilot", "INT",
                      "sim/cockpit2/radios/indicators/hsi_vdef_dots_pilot", "FLOAT",
					  "sim/cockpit2/radios/indicators/hsi_display_horizontal_pilot", "INT",
					  "sim/cockpit2/radios/indicators/hsi_hdef_dots_pilot", "FLOAT",
					  vertHorPath)
If you want those functions in FSX/P3D, you'll have to complement the brilliant SNAKE STACK work by yourself.
I won't do it completely for you, but I'll show you how it can be done for one function (the YD Yaw damper indicator), it's up to you to complete the puzzle.

[TUTORIAL MODE ON]
In order to use an XPlane Gauge to FSX/P3D, one has to find and translate the XPlane variables/events used into their FSX/P3D countereparts, subscribe to these new variables and convert them if needed, then call the Xplane function using the varaiables.

First, one has to look at the list of simconnect variables here https://msdn.microsoft.com/en-us/library/cc526981.aspx, and search for the equivalent FSX/P3D variables to the XPlane variables.
Let's search for the Yaw damper mode ststus variable:
the FSX equivalent of "sim/cockpit/switches/yaw_damper_on", "INT", is "AUTOPILOT YAW DAMPER", "Boolean".

You should then add at the end of the code a new fsx_variable subscribe() function, that should be something like that:

Code: Select all

fsx_variable_subscribe(xxxxxx,xx,-- variable#1
                                   		yyyyyyy,yyy, -- variable#2
				   		........,..., -- variable#3
						"AUTOPILOT YAW DAMPER", "Boolean", -- The variable we are working on
						lateral_mode_fsx)
See the lateral_mode_fsx at the end of the fsx_variable subscribe() function? This is a "callback" to a new function you will have to create, in order to translate FSX formats to Xplane formats, since XPLane is expecting an integer value (0 or 1) ("sim/cockpit/switches/yaw_damper_on", "INT"), but FSX is transmitting a boolean value (True, false) ("AUTOPILOT YAW DAMPER", "Boolean").

So the new lateral_mode_fsx() function should look like this:

Code: Select all

function lateral_mode_fsx(xxx,yyy,....,yd_mode)-- all the variables received in the callback function should be in the same order they are subscribed to in the fsx_variable-subscribe() function
... -- translation code for the variable #1
... -- translation code for the variable #2
... -- etc
yd_modexp=fif(yd_mode,1,0)---- <==== translation boolean to integer (1)
....
lateral_mode(xxx,yyy,....,yd_modexp) -- <==== calling the existing Xplane function (2)
end
Remarks:
(1)-the fif() function is used to translate a boolean value (received in the yd_mode variable) into an integer value (in the yd_modexp variable).
fif(boolean value, value to return if true, value to return if false) ==> fif(yd_mode,1,0) returns 1 if yd_mode is true, 0 if yd_mode is false

(2)-At the end of the lateral_mode_fsx() function, we then call the "real" (Xplane) lateral_mode function, passing the translated (boolean-->integer) parameters that are expected, in our case yd_modexp .

A final warning: the callback function should always be located in the code BEFORE the call (hence before the corresponding fsx_variable_subscribe()), and with the same logic the "translation" function should be located AFTER the original function, or else you'll end with Lua compiler errors.
[TUTORIAL MODE OFF]

Now you've got all the elements, time to get them into practice.... :mrgreen: If you ever encounter difficulties, publish your code here and cry for help.
A final word: some Xplane functions/variables merely DO NOT exist in Simconnect FSX/PD, for example the "Armed" status of the autopilot functions.
So you'll have to either forget them (no action), either invent somehing...

Hope this helps

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

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

Re: Instrument Converting

#4 Post by JackZ »

Silly Me. I forgot I already had an FSX translation in progress on this gauge!

So here's the new version of the code, where I had already added the FD bars display and fixed a bug when using the FSX version. The annunciators are still missing in FSX.
My advice is to create a clone of the existing EADI, then replace the existing code by the following code, BEFORE working on the tutorial.

Code: Select all

---------------------------------------------
-- Collins Rockwell EFIS 84 EADI --

-- Version 1.1 JZ FSX translation in progress
---------------------------------------------
--        Load and display images          --
---------------------------------------------
img_horizon1 = img_add("Horizon1.png", 0, 0, 1200, 1800)
img_horizon = img_add("Horizon.png", 0, 0, 600, 900)
img_pitchAtt = img_add("Pitch_Attitude.png", 0, 0, 600, 900)
--img_hViewport = img_add("viewport.png", -150, -150, 900, 900)
img_skypoint = img_add_fullscreen("Skypointer.png")

img_rollAtt = img_add_fullscreen("Roll_Attitude.png")
img_fltDir = img_add_fullscreen("Director.png")

img_add_fullscreen("Aircraft_Bars.png")
img_add_fullscreen("CRT_border.png")

img_pitch_up = img_add_fullscreen("Pitch_Up.png")
img_pitch_down = img_add_fullscreen("Pitch_Down.png")

img_om = img_add_fullscreen("OM.png")
img_mm = img_add_fullscreen("MM.png")
img_cdi = img_add("CDI.png", 0, -150, 600, 900)
img_glidepath = img_add("Glidepath.png", 0, -150, 600, 900)
img_GSvertpath = img_add("GSvertpath.png", 0, 0, 600, 900)
img_LLZhorpath = img_add("LLZhorpath.png", 0, -150, 600, 900)

txt_radio_minima = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: cyan; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 460, 500, 200, 200)
txt_dh = txt_add(" ", "-fx-font-family: arial; -fx-font-size:25px; -fx-fill: yellow; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 180, 235, 200, 200)
--visible(txt_radio_minima, false)
blink = true

txt_active_lateral = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: lightgreen; -fx-font-weight:normal; -fx-text-alignment: RIGHT;", 65, 65, 200, 200)
txt_active_vertical = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: lightgreen; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 330, 65, 200, 200)
txt_second_arm_vertical = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: white; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 450, 80, 200, 200)
txt_autopilot = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: white; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 90, 95, 200, 200)
txt_yawdamper = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: white; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 90, 110, 200, 200)




---------------
-- Functions --
---------------

function new_attitude(roll, pitch, dRoll, dPitch, dMode)

-- Roll outer ring and background
   -- roll = var_cap(roll, -90, 90)
        
-- Roll horizon
    img_rotate(img_horizon1  , roll * -1)
    img_rotate(img_horizon  , roll * -1)
	img_rotate(img_pitchAtt, roll * -1)
	--img_rotate(img_hViewport, roll * -1)
	img_rotate(img_skypoint, roll * -1)
    
-- Move horizon pitch
    pitch = var_cap(pitch, -90, 90)
    radial = math.rad(roll * -1)
    x = -(math.sin(radial) * pitch * 5) --3
    y = (math.cos(radial) * pitch * 5)
	img_move(img_horizon1, -300, y-600, nil, nil)
    img_move(img_horizon, x, y-150, nil, nil)
	img_move(img_pitchAtt, x, y-150, nil, nil)
	viewport_rect(img_pitchAtt, 200, 225, 200, 150)
	--img_move(img_hViewport, x-150, y-150, nil, nil)
	
-- Pull up//Pitch down arrows
   img_rotate(img_pitch_down, roll * -1)
   img_rotate(img_pitch_up, roll * -1)

if pitch >= 30 then
   visible(img_pitch_down, true)
   else
   visible(img_pitch_down, false)
   end
   
if pitch <= -20 then
   visible(img_pitch_up, true)
   else
   visible(img_pitch_up, false)
   end
	
-- Move director
   dPitch = var_cap(dPitch, -90, 90)
   dRadial = math.rad(dRoll * -1)
   dX = (math.sin(dRadial) * (dPitch - pitch) * 5)
   dY = (math.cos(dRadial) * (pitch - dPitch) * 5)
   img_rotate(img_fltDir, (dRoll * 1) - roll)
   img_move(img_fltDir, nil, dY, nil, nil)
   
-- Director Mode
   if dMode == 0 then
   visible(img_fltDir, false)
   else
   visible(img_fltDir, true)
   end
   
	
	
end


function new_marker_beacons(outer_marker, middle_marker, inner_marker)
   visible(img_om, false)
   visible(img_mm, false)
if outer_marker == 1 then
   visible(img_om, true)
   visible(img_mm, false)
   else
   visible(img_om, false)
   end
   
if middle_marker == 1 then
   visible(img_mm, true)
   visible(img_om, false)
   
   else
   visible(img_mm, false)
end
if inner_marker == 1 then
   visible(img_mm, true)
   visible(img_om, false)
   
   else
   visible(img_mm, false)
end

end

txt_add("DH", "-fx-font-size:17px; -fx-font-family:Arial; -fx-fill: cyan; -fx-font-weight:normal; -fx-text-alignment:left;", 425, 500, 150, 100)
txt_radio_height = txt_add(" ", "-fx-font-family: arial; -fx-font-size:30px; -fx-fill: cyan; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 458, 470, 200, 200)

timer = timer_start(0, 100, timer_blink)

function timer_blink()

blink = not blink

end

function new_radio_height(radalt, radio_minima)

txt_set(txt_radio_minima, radio_minima)

--DH annunciation

if ((radalt - radio_minima) <= 0) then
txt_set(txt_dh, "DH")
visible(txt_dh, true)

else
visible(txt_dh, false)
  end



if ((radalt - radio_minima) <= 50) then

visible(txt_radio_height, blink)
radalt = var_round(radalt,-1)

end
 
 if ((radalt - radio_minima) > 50 and (radalt - radio_minima) < 2500) then

visible(txt_radio_minima, true)
radalt = var_round(radalt,-2)

end

if radalt > 2500 then

visible(txt_radio_height, false)

else

--visible(txt_radio_height, true)

end

txt_set(txt_radio_height, radalt)

end

function new_radio_height_fsx(radalt, radio_minima)
	new_radio_height(radalt, radio_minima)
end

function lateral_mode(hsi_mode, hdg_mode, nav_mode, fd_mode, yd_mode)


--visible(txt_active_lateral, false)

if hdg_mode == 0 and nav_mode == 0 then

visible(txt_active_lateral, false)

  end
  
if hdg_mode == 2 then
txt_set(txt_active_lateral, "HDG")
visible(txt_active_lateral, true)

end

if nav_mode == 2 and hsi_mode == 0 then
txt_set(txt_active_lateral, "NAV1")
visible(txt_active_lateral, true)

  end
  
if nav_mode == 2 and hsi_mode == 1 then
txt_set(txt_active_lateral, "NAV2")
visible(txt_active_lateral, true)

  end
  
if nav_mode == 2 and hsi_mode == 2 then

txt_set(txt_active_lateral, "GPS")
visible(txt_active_lateral, true)

  end
  
  if fd_mode == 0 then
  visible(txt_active_vertical, false)
  
  end
  
if fd_mode == 0 or 1 then
visible(txt_autopilot, false)
  end
  
if fd_mode == 2 then
txt_set(txt_autopilot, "AP")
visible(txt_autopilot, true)

  end
  
if yd_mode == 0 then
visible(txt_yawdamper, false)
  end
  
if yd_mode == 1 then
txt_set(txt_yawdamper, "YD")
visible(txt_yawdamper, true)

  end

end

function vertical_mode(gs_mode, alt_mode, vs_mode, ias_mode, ga_mode, pitch_mode)

if gs_mode and alt_mode and vs_mode and ias_mode and ga_mode and pitch_mode == 0 then

visible(txt_active_vertical, false)

end

if alt_mode == 1 then

txt_set(txt_second_arm_vertical, "ALT ARM")
visible(txt_second_arm_vertical, true)
else
visible(txt_second_arm_vertical, false)


  end
  
 if gs_mode == 2 then

txt_set(txt_active_vertical, "GS")
visible(txt_active_vertical, true) 

elseif alt_mode == 2 then

txt_set(txt_active_vertical, "ALT")
visible(txt_active_vertical, true)

  
elseif vs_mode == 2 then

txt_set(txt_active_vertical, "VS")
visible(txt_active_vertical, true)

  --end
  
elseif ias_mode == 2 then

txt_set(txt_active_vertical, "IAS")
visible(txt_active_vertical, true)

  --end
  
elseif ga_mode == 2 then

txt_set(txt_active_vertical, "GA")
visible(txt_active_vertical, true)

  --end
  
elseif pitch_mode == 2 then

txt_set(txt_active_vertical, "PTCH")
visible(txt_active_vertical, true)

  --end

  else 
  visible(txt_active_vertical, false)

end
end

function vertHorPath(gFlag, glideFlagMove, vFlag, cdiFlagMove)

if gFlag == 1 then
img_visible(img_GSvertpath, true)
gY = (glideFlagMove * 28) - 150
img_move(img_GSvertpath, nil, gY, nil, nil)
  end
  
if gFlag == 0 then
img_visible(img_GSvertpath, false)
end
  
if vFlag == 1 then

img_visible(img_LLZhorpath, true)
gX = cdiFlagMove * 41
img_move(img_LLZhorpath, gX, nil, nil, nil)
  else
img_visible(img_LLZhorpath, false)

  end

end




function new_attitude_fsx(roll, pitch,FDRoll,FDPitch,FDmode)
	fd_mode=fif(FDmode,1,0)
	new_attitude(roll * -57, pitch * -37,FDRoll,FDPitch,fd_mode)

end

function new_marker_beacons_fsx(om, mm, im)
	outer_marker=fif(om,1,0)
	middle_marker=fif(mm,1,0)
	inner_marker=fif(im,1,0)
	new_marker_beacons(outer_marker, middle_marker, inner_marker)
end
-------------------
-- Bus subscribe --
-------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/roll_AHARS_deg_pilot", "FLOAT",
					  "sim/cockpit2/gauges/indicators/pitch_AHARS_deg_pilot", "FLOAT",
					  "sim/cockpit2/autopilot/flight_director_roll_deg", "FLOAT",
					  "sim/cockpit2/autopilot/flight_director_pitch_deg", "FLOAT",
					  "sim/cockpit2/autopilot/flight_director_mode", "INT", new_attitude)
					  
fsx_variable_subscribe("ATTITUDE INDICATOR BANK DEGREES", "Radians",
					   "ATTITUDE INDICATOR PITCH DEGREES", "Radians",	
						"AUTOPILOT FLIGHT DIRECTOR BANK","Radians",
						"AUTOPILOT FLIGHT DIRECTOR PITCH","Radians",
					    "AUTOPILOT FLIGHT DIRECTOR ACTIVE","Boolean",new_attitude_fsx)
				 

xpl_dataref_subscribe("sim/cockpit2/radios/indicators/outer_marker_lit", "INT",
					  "sim/cockpit2/radios/indicators/middle_marker_lit", "INT",
					  "sim/cockpit2/radios/indicators/inner_marker_lit", "INT", new_marker_beacons)

fsx_variable_subscribe("OUTER MARKER","Boolean",
						"MIDDLE MARKER","Boolean",
						"INNER MARKER","Boolean",new_marker_beacons_fsx)
					  
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot", "FLOAT",
                      "sim/cockpit/misc/radio_altimeter_minimum", "FLOAT",	new_radio_height)

fsx_variable_subscribe("RADIO HEIGHT", "FEET",
						"DECISION HEIGHT", "FEET", new_radio_height_fsx)					  
xpl_dataref_subscribe("sim/cockpit2/radios/actuators/HSI_source_select_pilot", "INT", -- 0 = nav1, 1 = nav2, 2 = GNSS
					  "sim/cockpit2/autopilot/heading_status", "INT", -- Autopilot Heading Status. 0=off,1=armed,2=captured
					  "sim/cockpit2/autopilot/nav_status", "INT",     -- Autopilot Nav status
					  "sim/cockpit/autopilot/autopilot_mode", "INT", -- The autopilot master mode (off=0, flight director=1, on=2)
					  "sim/cockpit/switches/yaw_damper_on", "INT",
					   lateral_mode)
					   
xpl_dataref_subscribe("sim/cockpit2/autopilot/glideslope_status", "INT",
					  "sim/cockpit2/autopilot/altitude_hold_status", "INT",
                      "sim/cockpit2/autopilot/vvi_status", "INT",
					  "sim/cockpit2/autopilot/speed_status", "INT",
					  "sim/cockpit2/autopilot/TOGA_status", "INT",
					  "sim/cockpit2/autopilot/pitch_status", "INT",
					  vertical_mode)
					  
xpl_dataref_subscribe("sim/cockpit2/radios/indicators/hsi_display_vertical_pilot", "INT",
                      --"sim/cockpit2/radios/indicators/hsi_flag_glideslope_pilot", "INT",
                      "sim/cockpit2/radios/indicators/hsi_vdef_dots_pilot", "FLOAT",
					  "sim/cockpit2/radios/indicators/hsi_display_horizontal_pilot", "INT",
					  "sim/cockpit2/radios/indicators/hsi_hdef_dots_pilot", "FLOAT",
					  vertHorPath)
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

xp-wym
Posts: 66
Joined: Fri Mar 04, 2016 11:13 am

Re: Instrument Converting

#5 Post by xp-wym »

I never got around to writing the Radalt logic correctly - that may need to be reworked.

Also the annunciators for AP modes etc may need to be looked at again for functionality.

You may also wish to add an inclinometer as well.

The rest works as advertised.

beechraft P3D
Posts: 6
Joined: Tue Jul 04, 2017 1:39 am

Re: Instrument Converting

#6 Post by beechraft P3D »

Mr Jackzz .. Thank you very much for being so gentle in replying my message:

Please apologize me for not having replied before .. I was out of the city for few days... And also please apologize me as I didn't get a word of what you said... :cry: :cry: .. english ain't the problem.. it's just that my knowledges about Flight SIm programing are just ZERO

In regards to programming, I gotta be honest when I say that I don't know a thing.. but believe me: I wanna learn and share... I'm gonna try to do my best with this but I'm almost sure that I won't be sucessful very easyly as I'm totally ignorant at this. I would like to have the EADI and EHSI from Mr Snack working for P3D. I know that Xplane goes far beyond the limits for the P3D in regards to the variables and the software developement, and even though I'd like to use it, I just cant as my PC is not that powerful.. that's why I'm looking for the best chance to make these two instruments work on P3D, and I know that they were originally designed for XPLANE... for now, I'd be more than pleased to have them work for P3D at least with the basis (for example the GS and LOC indicators, the markers and the DH which I think are the most important ones, and maybe the Auto Pilot ON/OFF indicator, the YD and FD).. I've tried to convert them using some pararelle instrument coding like the EADI and EHSI for the ATR, but no matter what I do, they always generates errors, bugss, or simply don't appear.
As I said before, I'll do my best but as far as I concern, the tutorial for instruments making aint that clear for me.. I' haven't found specific info or what is worst, my programming logic is just below standards. However, I'm gonna try your coding example wich I think will perfectly work.. If something doesn't go as planned, could I send you a message?

Mr Snake: Thanx for replying too... I'll do my best.. one more time: Congrants for such an awesome work...
Mr Ralph: I've been working on it but Ive not been succes so far.

I'll show my advance (or fails) through this topic.. I hope you don't get bored, and on the contrary, can help me a little bit more.

My best wishes for this week..

Juan P

beechraft P3D
Posts: 6
Joined: Tue Jul 04, 2017 1:39 am

Re: Instrument Converting

#7 Post by beechraft P3D »

Hello Mr JackZ... me again... I've been trying to make the GS and LOC instrument work, but so far I haven't been able to... I made several changes in the code, following your instructions, and also taking the ATR EADI as an example of how I could do it... However, the results are totally useless... It generates an error .. don't know what to do... :cry: :cry: :cry:

Could you take a look please on the new parts of the code and help me a little?

Regards
JP

Here is the changes I've made so far.. (I bolded the letter so that you can notice a bit easier)

---------------------------------------------
-- Collins Rockwell EFIS 84 EADI --

-- Version 1.1 JZ FSX translation in progress
---------------------------------------------
-- Load and display images --
---------------------------------------------
img_horizon1 = img_add("Horizon1.png", 0, 0, 1200, 1800)
img_horizon = img_add("Horizon.png", 0, 0, 600, 900)
img_pitchAtt = img_add("Pitch_Attitude.png", 0, 0, 600, 900)
--img_hViewport = img_add("viewport.png", -150, -150, 900, 900)
img_skypoint = img_add_fullscreen("Skypointer.png")

img_rollAtt = img_add_fullscreen("Roll_Attitude.png")
img_fltDir = img_add_fullscreen("Director.png")

img_add_fullscreen("Aircraft_Bars.png")
img_add_fullscreen("CRT_border.png")

img_pitch_up = img_add_fullscreen("Pitch_Up.png")
img_pitch_down = img_add_fullscreen("Pitch_Down.png")

img_om = img_add_fullscreen("OM.png")
img_mm = img_add_fullscreen("MM.png")
img_cdi = img_add("CDI.png", 0, -150, 600, 900)
img_glidepath = img_add("Glidepath.png", 0, -150, 600, 900)
img_GSvertpath = img_add("GSvertpath.png", 0, 0, 600, 900)
img_LLZhorpath = img_add("LLZhorpath.png", 0, -150, 600, 900)

txt_radio_minima = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: cyan; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 460, 500, 200, 200)
txt_dh = txt_add(" ", "-fx-font-family: arial; -fx-font-size:25px; -fx-fill: yellow; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 180, 235, 200, 200)
--visible(txt_radio_minima, false)
blink = true

txt_active_lateral = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: lightgreen; -fx-font-weight:normal; -fx-text-alignment: RIGHT;", 65, 65, 200, 200)
txt_active_vertical = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: lightgreen; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 330, 65, 200, 200)
txt_second_arm_vertical = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: white; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 450, 80, 200, 200)
txt_autopilot = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: white; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 90, 95, 200, 200)
txt_yawdamper = txt_add(" ", "-fx-font-family: arial; -fx-font-size:17px; -fx-fill: white; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 90, 110, 200, 200)




---------------
-- Functions --
---------------

function new_attitude(roll, pitch, dRoll, dPitch, dMode)

-- Roll outer ring and background
-- roll = var_cap(roll, -90, 90)

-- Roll horizon
img_rotate(img_horizon1 , roll * -1)
img_rotate(img_horizon , roll * -1)
img_rotate(img_pitchAtt, roll * -1)
--img_rotate(img_hViewport, roll * -1)
img_rotate(img_skypoint, roll * -1)

-- Move horizon pitch
pitch = var_cap(pitch, -90, 90)
radial = math.rad(roll * -1)
x = -(math.sin(radial) * pitch * 5) --3
y = (math.cos(radial) * pitch * 5)
img_move(img_horizon1, -300, y-600, nil, nil)
img_move(img_horizon, x, y-150, nil, nil)
img_move(img_pitchAtt, x, y-150, nil, nil)
viewport_rect(img_pitchAtt, 200, 225, 200, 150)
--img_move(img_hViewport, x-150, y-150, nil, nil)

-- Pull up//Pitch down arrows
img_rotate(img_pitch_down, roll * -1)
img_rotate(img_pitch_up, roll * -1)

if pitch >= 30 then
visible(img_pitch_down, true)
else
visible(img_pitch_down, false)
end

if pitch <= -20 then
visible(img_pitch_up, true)
else
visible(img_pitch_up, false)
end

-- Move director
dPitch = var_cap(dPitch, -90, 90)
dRadial = math.rad(dRoll * -1)
dX = (math.sin(dRadial) * (dPitch - pitch) * 5)
dY = (math.cos(dRadial) * (pitch - dPitch) * 5)
img_rotate(img_fltDir, (dRoll * 1) - roll)
img_move(img_fltDir, nil, dY, nil, nil)

-- Director Mode
if dMode == 0 then
visible(img_fltDir, false)
else
visible(img_fltDir, true)
end



end


function new_marker_beacons(outer_marker, middle_marker, inner_marker)
visible(img_om, false)
visible(img_mm, false)
if outer_marker == 1 then
visible(img_om, true)
visible(img_mm, false)
else
visible(img_om, false)
end

if middle_marker == 1 then
visible(img_mm, true)
visible(img_om, false)

else
visible(img_mm, false)
end
if inner_marker == 1 then
visible(img_mm, true)
visible(img_om, false)

else
visible(img_mm, false)
end

end

txt_add("DH", "-fx-font-size:17px; -fx-font-family:Arial; -fx-fill: cyan; -fx-font-weight:normal; -fx-text-alignment:left;", 425, 500, 150, 100)
txt_radio_height = txt_add(" ", "-fx-font-family: arial; -fx-font-size:30px; -fx-fill: cyan; -fx-font-weight:normal; -fx-text-alignment: LEFT;", 458, 470, 200, 200)

timer = timer_start(0, 100, timer_blink)

function timer_blink()

blink = not blink

end

function new_radio_height(radalt, radio_minima)

txt_set(txt_radio_minima, radio_minima)

--DH annunciation

if ((radalt - radio_minima) <= 0) then
txt_set(txt_dh, "DH")
visible(txt_dh, true)

else
visible(txt_dh, false)
end



if ((radalt - radio_minima) <= 50) then

visible(txt_radio_height, blink)
radalt = var_round(radalt,-1)

end

if ((radalt - radio_minima) > 50 and (radalt - radio_minima) < 2500) then

visible(txt_radio_minima, true)
radalt = var_round(radalt,-2)

end

if radalt > 2500 then

visible(txt_radio_height, false)

else

--visible(txt_radio_height, true)

end

txt_set(txt_radio_height, radalt)

end

function new_radio_height_fsx(radalt, radio_minima)
new_radio_height(radalt, radio_minima)
end

function lateral_mode(hsi_mode, hdg_mode, nav_mode, fd_mode, yd_mode)


--visible(txt_active_lateral, false)

if hdg_mode == 0 and nav_mode == 0 then

visible(txt_active_lateral, false)

end

if hdg_mode == 2 then
txt_set(txt_active_lateral, "HDG")
visible(txt_active_lateral, true)

end

if nav_mode == 2 and hsi_mode == 0 then
txt_set(txt_active_lateral, "NAV1")
visible(txt_active_lateral, true)

end

if nav_mode == 2 and hsi_mode == 1 then
txt_set(txt_active_lateral, "NAV2")
visible(txt_active_lateral, true)

end

if nav_mode == 2 and hsi_mode == 2 then

txt_set(txt_active_lateral, "GPS")
visible(txt_active_lateral, true)

end

if fd_mode == 0 then
visible(txt_active_vertical, false)

end

if fd_mode == 0 or 1 then
visible(txt_autopilot, false)
end

if fd_mode == 2 then
txt_set(txt_autopilot, "AP")
visible(txt_autopilot, true)

end

if yd_mode == 0 then
visible(txt_yawdamper, false)
end

if yd_mode == 1 then
txt_set(txt_yawdamper, "YD")
visible(txt_yawdamper, true)

end

end

function vertical_mode(gs_mode, alt_mode, vs_mode, ias_mode, ga_mode, pitch_mode)

if gs_mode and alt_mode and vs_mode and ias_mode and ga_mode and pitch_mode == 0 then

visible(txt_active_vertical, false)

end

if alt_mode == 1 then

txt_set(txt_second_arm_vertical, "ALT ARM")
visible(txt_second_arm_vertical, true)
else
visible(txt_second_arm_vertical, false)


end

if gs_mode == 2 then

txt_set(txt_active_vertical, "GS")
visible(txt_active_vertical, true)

elseif alt_mode == 2 then

txt_set(txt_active_vertical, "ALT")
visible(txt_active_vertical, true)


elseif vs_mode == 2 then

txt_set(txt_active_vertical, "VS")
visible(txt_active_vertical, true)

--end

elseif ias_mode == 2 then

txt_set(txt_active_vertical, "IAS")
visible(txt_active_vertical, true)

--end

elseif ga_mode == 2 then

txt_set(txt_active_vertical, "GA")
visible(txt_active_vertical, true)

--end

elseif pitch_mode == 2 then

txt_set(txt_active_vertical, "PTCH")
visible(txt_active_vertical, true)

--end

else
visible(txt_active_vertical, false)

end
end

function vertHorPath(gFlag, glideFlagMove, vFlag, cdiFlagMove)

if gFlag == 1 then
img_visible(img_GSvertpath, true)
gY = (glideFlagMove * 28) - 150
img_move(img_GSvertpath, nil, gY, nil, nil)
end

if gFlag == 0 then
img_visible(img_GSvertpath, false)
end

if vFlag == 1 then

img_visible(img_LLZhorpath, true)
gX = cdiFlagMove * 41
img_move(img_LLZhorpath, gX, nil, nil, nil)
else
img_visible(img_LLZhorpath, false)

end

end




function new_attitude_fsx(roll, pitch,FDRoll,FDPitch,FDmode)
fd_mode=fif(FDmode,1,0)
new_attitude(roll * -57, pitch * -37,FDRoll,FDPitch,fd_mode)

end

function new_marker_beacons_fsx(om, mm, im)
outer_marker=fif(om,1,0)
middle_marker=fif(mm,1,0)
inner_marker=fif(im,1,0)
new_marker_beacons(outer_marker, middle_marker, inner_marker)
end

function vertHorPath_fsx(nav_has_signal, nav_has_localizer, nav_has_gs, glideslope, localizer)

-- ILS
gbl_station_is_ils = nav_has_signal and nav_has_localizer
if gbl_station_is_ils then
visible(img_CDI, true)
visible(img_LLZhorpath, true)
visible(img_GSvertpath, true)
if gbl_nav_has_glideslope then
visible(img_GSvertpath, true)
visible(img_Glidepath, true)
else
visible(img_GSvertpath, false)
visible(img_Glidepath, false
end
else -- station is a VOR
visible(img_CDI, false)
visible(img_LLZhorpath, false)
visible(img_GSvertpath, false)
visible(img_Glidepath, false)

if gbl_station_is_ils then
localizer = localizer * 70/127 + localizer_zero -- localizer
move(img_localizer,localizer,nil,nil,nil)
if gbl_nav_has_glideslope then -- glideslope
glideslope = glideslope *70/119 + glideslope_zero
move(img_glideslope,nil,glideslope,nil,nil)
move(txt_glideslope,nil,glideslope + 2,nil,nil)
end
end



-------------------
-- Bus subscribe --
-------------------
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/roll_AHARS_deg_pilot", "FLOAT",
"sim/cockpit2/gauges/indicators/pitch_AHARS_deg_pilot", "FLOAT",
"sim/cockpit2/autopilot/flight_director_roll_deg", "FLOAT",
"sim/cockpit2/autopilot/flight_director_pitch_deg", "FLOAT",
"sim/cockpit2/autopilot/flight_director_mode", "INT", new_attitude)

fsx_variable_subscribe("ATTITUDE INDICATOR BANK DEGREES", "Radians",
"ATTITUDE INDICATOR PITCH DEGREES", "Radians",
"AUTOPILOT FLIGHT DIRECTOR BANK","Radians",
"AUTOPILOT FLIGHT DIRECTOR PITCH","Radians",
"AUTOPILOT FLIGHT DIRECTOR ACTIVE","Boolean",new_attitude_fsx)


xpl_dataref_subscribe("sim/cockpit2/radios/indicators/outer_marker_lit", "INT",
"sim/cockpit2/radios/indicators/middle_marker_lit", "INT",
"sim/cockpit2/radios/indicators/inner_marker_lit", "INT", new_marker_beacons)

fsx_variable_subscribe("OUTER MARKER","Boolean",
"MIDDLE MARKER","Boolean",
"INNER MARKER","Boolean",new_marker_beacons_fsx)

xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot", "FLOAT",
"sim/cockpit/misc/radio_altimeter_minimum", "FLOAT", new_radio_height)

fsx_variable_subscribe("RADIO HEIGHT", "FEET",
"DECISION HEIGHT", "FEET", new_radio_height_fsx)
xpl_dataref_subscribe("sim/cockpit2/radios/actuators/HSI_source_select_pilot", "INT", -- 0 = nav1, 1 = nav2, 2 = GNSS
"sim/cockpit2/autopilot/heading_status", "INT", -- Autopilot Heading Status. 0=off,1=armed,2=captured
"sim/cockpit2/autopilot/nav_status", "INT", -- Autopilot Nav status
"sim/cockpit/autopilot/autopilot_mode", "INT", -- The autopilot master mode (off=0, flight director=1, on=2)
"sim/cockpit/switches/yaw_damper_on", "INT",
lateral_mode)

xpl_dataref_subscribe("sim/cockpit2/autopilot/glideslope_status", "INT",
"sim/cockpit2/autopilot/altitude_hold_status", "INT",
"sim/cockpit2/autopilot/vvi_status", "INT",
"sim/cockpit2/autopilot/speed_status", "INT",
"sim/cockpit2/autopilot/TOGA_status", "INT",
"sim/cockpit2/autopilot/pitch_status", "INT",
vertical_mode)

xpl_dataref_subscribe("sim/cockpit/radios/indicators/hsi_display_vertical_pilot", "INT",
--"sim/cockpit2/radios/indicators/hsi_flag_glideslope_pilot", "INT",
"sim/cockpit2/radios/indicators/hsi_vdef_dots_pilot", "FLOAT",
"sim/cockpit2/radios/indicators/hsi_display_horizontal_pilot", "INT",
"sim/cockpit2/radios/indicators/hsi_hdef_dots_pilot", "FLOAT",
vertHorPath)

fsx_variable_subscribe("NAV HAS NAV:1", "Boolean",
"NAV HAS LOCALIZER:1", "Boolean",
"NAV HAS GLIDE SLOPE:1", "Boolean",
"NAV GSI:1", "Number",
"NAV CDI:1", "Number", vertHorPath_fsx)

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

Re: Instrument Converting

#8 Post by JackZ »

Hmmm

I'm away from my PC right now but what I noticed in your code is that you're not doing what I expected, i.e. translating Fsx values towards XPlane ones, then call the existing XPlane vertHorParh() function.
Instead you recreated completely the function.
In your VertHorPath_fsx function, you should:
1-try to retrieve the parameters in the same order that the original VertHorPath() function is expecting them.
2- translate the Boolean into integer(0,1) for the flags
3- see the difference in dots deviations of the GS/LOC needleS between XPlane and FSX and take this différence into account
4- call the original VertHorPath with the newly converted parameters.

That's it

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

Post Reply