Jump to content

Ace9

LUA VOR1-2 ADF Fast spin encoder code wont work.

Recommended Posts

Hey there.

Having copied the HDG Bug code (hdg plusfast & hdg minusfast) which allows a fast spin of a physical encoder and works a treat, I am completely baffled why the Fast Spin code below for VOR1 - VOR2 & ADF will not work, any ideas / help please.

I confirm that the normal calls work (VOR1_plus (and minus) | VOR2_plus (and minus) ADF_plus (and minus) but they are painfully slow.

I have used the User.lua to enter the code in to Linda 3.0.9 v2 (FSUIPC is up to date) Shut Linda down and restarted no luck.

Many Thanks

Roger

PS Sorted now - I had forgotten to set the variables.. see below 

-- ## Rotaries functions
-- ## VOR1

--Orignal function _VOR1_OBI_DEC (p) 	ipc.control( 65662, p )  end
--Orignal function _VOR1_OBI_INC (p) 	ipc.control( 65663, p )  end


function VOR1_plus (a, b, c)
	if c == nil then
		_VOR1_OBI_INC ()
		return
	end
	sync_vor1 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor1)
end

function VOR1_plusfast (a, b, c)
	if c == nil then
		for i = 1, fast_vor1 do
			_VOR1_OBI_INC ()
		end
		return
	end
	sync_vor1 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor1)
end

function VOR1_minus (a, b, c)
	if c == nil then
		_VOR1_OBI_DEC ()
		return
	end
	sync_vor1 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor1)
end

function VOR1_minusfast (a, b, c)
	if c == nil then
		for i = 1, fast_vor1 do
			_VOR1_OBI_DEC ()
		end
		return
	end
	sync_vor1 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor1)
end

-- ## VOR2
-- Orignal function _VOR2_OBI_DEC (p) 	ipc.control( 65664, p )  end
-- Orignal function _VOR2_OBI_INC (p) 	ipc.control( 65665, p )  end

function VOR2_plus (a, b, c)
	if c == nil then
		_VOR2_OBI_INC ()
		return
	end
	sync_vor2 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor2)
end

function VOR2_plusfast (a, b, c)
	if c == nil then
		for i = 1, fast_vor2 do
			_VOR2_OBI_INC ()
		end
		return
	end
	sync_vor2 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor2)
end

function VOR2_minus (a, b, c)
	if c == nil then
		_VOR2_OBI_DEC ()
		return
	end
	sync_vor2 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor2)
end

function VOR2_minusfast (a, b, c)
	if c == nil then
		for i = 1, fast_vor2 do
			_VOR2_OBI_DEC ()
		end
		return
	end
	sync_vor2 = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_vor2)
end

-- ## ADF
-- Orignal function _ADF_CARD_DEC (p) 	ipc.control( 65882, p )  end
-- Orignal function _ADF_CARD_INC (p) 	ipc.control( 65881, p )  end

function ADF_plus (a, b, c)
	if c == nil then
		_ADF_CARD_INC ()
		return
	end
	sync_adf = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_adf)
end

function ADF_plusfast (a, b, c)
	if c == nil then
		for i = 1, fast_adf do
			_ADF_CARD_INC ()
		end
		return
	end
	sync_adf = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_adf)
end

function ADF_minus (a, b, c)
	if c == nil then
		_ADF_CARD_DEC ()
		return
	end
	sync_adf = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_adf)
end

function ADF_minusfast (a, b, c)
	if c == nil then
		for i = 1, fast_adf do
			_ADF_CARD_DEC ()
		end
		return
	end
	sync_adf = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_adf)
end


-- ## DUPLICATE HDG BUG
function HDG_plus (a, b, c)
	if c == nil then
		_HEADING_BUG_INC ()
		return
	end
	sync_hdg = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_hdg)
end

function HDG_plusfast (a, b, c)
	if c == nil then
		for i = 1, fast_hdg do
			_HEADING_BUG_INC ()
		end
		return
	end
	sync_hdg = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_hdg)
end

function HDG_minus (a, b, c)
	if c == nil then
		_HEADING_BUG_DEC ()
		return
	end
	sync_hdg = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_hdg)
end

function HDG_minusfast (a, b, c)
	if c == nil then
		for i = 1, fast_hdg do
			_HEADING_BUG_DEC ()
		end
		return
	end
	sync_hdg = round(c / 360 * 65536)
	ipc.writeUW(0x07CC, sync_hdg)
end

 

Edited by Ace9

All The Best

Roger

Share this post


Link to post
Share on other sites

I had forgotten to set the variables - fast_vor1 etc...

🙂  

-- Initial variables
function FallbackInitVars ()
	-- Tuning fast rotation speeds
    fast_vor1 = 10
    fast_vor2 = 10
    fast_adf = 10
	--fast_alt = 10 -- << increment value when rotary in fast mode
	--fast_hdg = 10
	--fast_crs = 5
	--fast_ias = 10
	--fast_baro = 10
    --fast_spd = 10
	-- init CRS direction
    --crs_hdg = ipc.readUW(0x0C4E)
    if _MCP1 () then
        -- don't need this on MCP2
	    ipc.writeUW(0x0C4E, 0)
    end
	-- Setting initial varibles values
	prev_mask = 0
	prev_num = 0
	tcas_mode = 0
	ipc.writeUW("0D0C", 0)
    AUTO_SAVE_ENABLED = true
end

 

Edited by Ace9

All The Best

Roger

Share this post


Link to post
Share on other sites

Glad you got it sorted. Using user.lua is the correct method to user. Any function defined there will override (replace) common or default functions with the same name (case sensitive).


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Thanks for your response Andrew.

Just to confirm that a separate user.lua file needs to be created for every plane, or is there a global one? 

I have finally fully programmed the default C172 but fly in A2A C172 - PA28 and use the user.lua for A2A specific cases, so will I need to copy the VOR ADF fast spin code on to the separate A2A user.lua for each AC?

Thanks again

 


All The Best

Roger

Share this post


Link to post
Share on other sites

There can be 2 user.lua. One is global and the other is stored in each aircraft folder alongside the actions.lua file. It is your choice where to place you code. 


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Awesome Thanks, I must have missed it because when I programme the buttons there is only ever 1 user file in the available list, if I am in A2A C172, the fsx default (Global) one is not displayed to choose from..

Sorry to be a pain, what am I missing?

 


All The Best

Roger

Share this post


Link to post
Share on other sites

Sorry. The global user file is called user-lib.lua located in the /linda/system/libs (from memory but I may be wrong). This is loaded along with the other library files after the core/common code but before the aircraft user.lua file. The last loaded overrides previously loaded functions of the same name. 

Edited by ScotFlieger

Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Andrew, I am sorry but I am struggling with my next obstacle's which I do not seem to be able to over come despite several hours fiddling about, here is my goals.

1) amend the A2A Linda code (below) for the Heading bug to operate the KR87 ADF and KN64 DME knobs in the A2A PA128 Cherokee
2) programme the 3 position function switch on the KN64 DME unit, also in the in the A2A PA128 Cherokee

I can find the ip.control 's in the FSUIPC controls list, but unlike the code above, I cannot find where to start, could you point out please what I have to amend, do I need to have any initial variables, particularly for the 3 position switch?

My frustration is because I do not know, what ApMode, ApTurn,  _MCP2, DspHDG in the code below is? the A2A LvAR list only states (L:ApModeYokeSwitch,bool) which is not ApMode, is it? I am sorry to bother you with this, I am finding it not as straight forward as the above for a non programmer like me I am sorry to say. But a huge thank you again for all the help you have given me over the years.

-- A2A LvArs

-- KR87 ADF
ADF outer knob - (L:AdfFreqOuterKnob,percent)(range: 0  100)
ADF inner knob - (L:AdfFreqInnerKnob,percent) (range: 0  100)
ADF inner knob pull - (L:AdfFreqInnerKnobPull,bool)

-- KN64
DME outer knob - (L:Kn62OuterKnob,percent) (range: 0  100)
DME inner knob - (L:Kn62InnerKnob,percent) (range: 0  100)
DME inner knobPull - (L:Kn62InnerKnobPull,bool)

-- KN63 3 Position Switch
DME - 3 position function switch  (L:kn62Function,enum) (0  Remote, 1  Frequency, 2  Groundspeed/Time to station

-- Linda A2A PA-28 Cherokee Module code I am trying to amend to have normal and fast spin encoders
    
function A2A_AP_HDGandTurn_plus ()
    ApMode = ipc.readLvar("ApMode")

    if ApMode == 1 then  --ST
        ApTurn = ipc.readLvar("ApTurnKnob")
            if ApTurn <= 50 and ApTurn >= -50 then ApTurn = ApTurn + 1
            else ApTurn = 50
            end
        if _MCP2 () then DspHDG(ApTurn) end
        ipc.writeLvar("ApTurnKnob", ApTurn)
    else
        ipc.control(65879)
        if _MCP2 () then DspHDG(HDG) end
    end
end

 


All The Best

Roger

Share this post


Link to post
Share on other sites

Welcome to the mysteries of real time programming. 

You have me out on a limb. I don't own the A2A PA28 so can not load the existing module. However, reading the actions.lua download I will attempt a partial answer.

I have no idea about the KR87 or KN64. For multi position switches, take a look at other modules like Aerosoft or FSLabs A320 for similar functions. Normally, we would use and _inc and _dec function limited min and max positions. We then have a _cycle function which steps from min to max position and then back to min by calling the _inc function. Sometimes a _toggle function will toggles between 2 common positions. On top of that we use for example a _off, _on or _test function to go to defined positions.

The Lvars/functions you are frustrating over can normally be found using the LINDA Tracer. APmode and APturn are likely to be Lvars defined for the A2A PA28. Just enter these in the search box and start monitoring to see how they change when you change the AP mode or turn knob. _MCP2 is an internal LINDA LUA variable to test if you have a VRi MCP Combo 2 connected. DspHDG is a built-in function that displays the current heading on the VRi panel.

When we start to develop a new module it requires much time investigating was Lvar or offset changes when a control is operated. It can be very frustrating, as you have found, with many false starts. Sometimes a solution is not always available or can be determined. Keep trying.

Edited by ScotFlieger
  • Like 1

Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Thanks for the quick reply Andrew, that's something for me to look into, I never thought about other Linda Modules either.. the KR87 and KN64 are BendixKing avionics ADF & DME units very similar if not the same as fitted to the A2A Cessna C172. 

I'm on it, many thanks again 

Roger


All The Best

Roger

Share this post


Link to post
Share on other sites

Hi Andrew.

Been working on this for the last 5 hours or so and I've gotten the DME rotary to work, 🙂 but there is a 3-5 seconds delay before the display on the DME radio updates 🤔 i.e alters from 108.40 to 109.40 hz.

I could not find any variables to set in the A2A B17 Linda module for the copied function B17_C1TurnControl_inc () seen amended as PA28_DME_Outer_inc below. 

Can you suggest a reason why this may be so in the DME Outer Knob code below please? 

(Looking at the Linda lib-fsx.lua there is no DME rotary code as there is for the ADF unit eg > function _ADF_100_DEC (p) ipc.control( 65666, p ) end < etc. Also looking at the P3D Event Id list  and FSUIPC lists there is nothing there either, so its aircraft specific and not part of P3D I guess? I have trawled through all the A2A Modules and found this rotary code in the B17 module function B17_C1TurnControl_inc () it's the only code that I have so far found that is for a inc / dec rotary encoder subtitle for the DME radio frequency rotary encoder. )

-- A2A LvAR List
-- DME outer knob - (L:Kn62OuterKnob,percent) (range: 0 – 100)

function PA28_DME_Outer_inc ()
	Def = "Kn62OuterKnob"
	Var = ipc.readLvar(Def)
	if Var < 100 then
	Var = Var + 1
	end
	ipc.writeLvar(Def, Var)
	DME_Outer_show ()
end

function PA28_DME_Outer_dec ()
	Def = "Kn62OuterKnob"
	Var = ipc.readLvar(Def)
	if Var > -100 then
	Var = Var - 1
	end
	ipc.writeLvar(Def, Var)
	DME_Outer_inc_show ()
end

On the other hand, I've done pretty well the 3 position switch I think?  😁

Please will you check its robust, it works like a dream. 👍

-- A2A LvAR List 
-- Function switch - (L:kn62Function,enum) (0 – Remote, 1 – Frequency, 2 – Groundspeed/Time to station

function A2A_DME_Function_Switch_RMT ()
    ipc.writeLvar("kn62Function", 0)
    DspShow ("DME", "RMT", "DME Func", " RMT")
end
function A2A_DME_Function_Switch_FREQ ()
    ipc.writeLvar("kn62Function", 1)
    DspShow ("DME", "FRQ", "DME Func", " FRQ")
end
function A2A_DME_Function_Switch_GS_T ()
    ipc.writeLvar("kn62Function", 2)
    DspShow ("DME", "GS/T", "DME Func", " GS/T")
end

 

Edited by Ace9
Typo

All The Best

Roger

Share this post


Link to post
Share on other sites

Welcome to the world of real time computing.

LINDA uses a one sec timer for updating most displays and values. Any routines that change displays or values need to include a display update (like the DspHDG you queried before).

Check out why different show functions DME_Outer_show and DME_Outer_inc_show are used and what each does.

Edited by ScotFlieger
  • Like 1

Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Andrew, I love your teaching style 👍 I have investigated and delved, failed, been up and down like a fiddlers elbow all afternoon, but just now - BINGO - 😁 the penny dropped.

Once I understood and removed the lines DME_Outer_show and DME_Outer_inc_show It works perfectly.

A Huge Huge Thank you my friend for all the time you have given me, I think I've learnt am awful lot because of it.  

All the best

Roger 


All The Best

Roger

Share this post


Link to post
Share on other sites

You are very welcome. Self-learning with a little guidance works better than spoon feeding a solution. 


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...