Jump to content
Sign in to follow this  
scottb613

Autopilot Altitude Arm - button - FSUIPC ?

Recommended Posts

Hi Folks,

On generic aircraft - generic autopilot - is there a function defined to map the "AP Altitude Arm" - to a joystick button ???

I've gone through the normal controller setup and FSUIPC several times - either I'm blind - or it's not there ?

Anyone know how to map this function ?

Thanks...

Regards,
Scott


imageproxy.png.c7210bb70e999d98cfd3e77d7

Share this post


Link to post

I don't think there is such a generic autopilot function. There is a 'hold target altitude' function, which you can call with a target altitude. FSX (P3D) tracks the target altitude in a variable, which you need to retrieve so you can supply it to the hold function. So in essence you probably need to write some Lua code to make things happen as you want. I wrote some functions to handle the Bendix-King style autopilot in the Beech Baron and such, and from memory I think it mostly sort of works. (This is LINDA code, so if you want to use just FSUIPC you will need to use this as a starting point. It's also extracted from a larger module so some of the functions aren't defined here. If you want the whole thing you can send me a PM.)

-- ## Autopilot ###############

local function QueryAltHold()
	return ipc.readUD(0x07D0)
end

local function GetCurrentAlt()
	ipc.log("Current ALT = " .. ipc.readSD(0x3324))
	return ipc.readSD(0x3324)  -- In feet or metres (see below)
end

local function QueryUnitsFeet()
	ipc.log("Units are FEET = " .. tostring(ipc.readUW(0x0C18) ~= 2))
	return ipc.readUW(0x0C18) ~= 2	-- 0 is US units, 1 is hybrid, 2 is metric
end

local function MetresToFeet(Metres)
	return 3.28 * Metres
end

local function GetTargetAltitude()
	-- Returns the current target altitude in metres or feet, depending on
	-- current units system in use.
	if QueryUnitsFeet() then
		--ipc.log("Target ALT = " .. MetresToFeet(RoundNearest(ipc.readUD(0x07D4) / 65536), 1))
		return MetresToFeet(RoundNearest(ipc.readUD(0x07D4) / 65536, 1))
	else
		--ipc.log("Target ALT = " .. RoundNearest(ipc.readUD(0x07D4) / 65536, 1))
		return RoundNearest(ipc.readUD(0x07D4) / 65536, 1) -- Metres
	end
end

local function EngageAltHold(TargetAlt)
	if QueryUnitsFeet() then
		ipc.log("TargetAlt = " .. TargetAlt .. " feet")
		_AP_ALT_VAR_SET_ENGLISH(TargetAlt)
	else
		ipc.log("TargetAlt = " .. TargetAlt .. " metres")
		_AP_ALT_VAR_SET_METRIC(TargetAlt)
	end
	_AP_ALT_HOLD_ON()
end

function AAL_AP_ALT_Hold_Current_Altitude()
	if QueryAltHold() == 1 then
		_AP_ALT_HOLD_OFF()
	else
		EngageAltHold(GetCurrentAlt())
	end
end

function AAL_AP_Decrease_Target_Altitude()
	AP_UsingCustomTargetAlt = 0

	_AP_ALT_HOLD_OFF()
	
	local nSteps = 1
	
	if AAL_RotaryShiftActive == 1 then
		nSteps = BUG_MULTIPLIER
	end

	for n = 1, nSteps do
		_AP_ALT_VAR_DEC()
	end
end

function AAL_AP_Increase_Target_Altitude()
	AP_UsingCustomTargetAlt = 0

	_AP_ALT_HOLD_OFF()

	local nSteps = 1
	
	if AAL_RotaryShiftActive == 1 then
		nSteps = BUG_MULTIPLIER
	end

	for n = 1, nSteps do
		_AP_ALT_VAR_INC()
	end
end

-- The following two functions do the same job as the two
-- above but they track the target altitude in a local variable
-- instead of relying on the FSX internal value. They also briefly
-- display the target altitude each time it is changed. This is
-- intended for use in aircraft that don't have a visual indication
-- of the target altitude.

local AP_TargetAltitude = 0  -- In metres or feet, depending on current units system
local AP_UsingCustomTargetAlt = 0

function AAL_AP_Decrease_Target_Altitude_With_Display()
	if AP_UsingCustomTargetAlt == 0 then
		-- First time we call this, initialise to current altitude
		AP_TargetAltitude = RoundNearest(GetCurrentAlt(), 100)
	end
	AP_UsingCustomTargetAlt = 1
	_AP_ALT_HOLD_OFF()
	if AAL_RotaryShiftActive == 1 then
		AP_TargetAltitude = math.max(AP_TargetAltitude - 1000, 0)
	else
		AP_TargetAltitude = math.max(AP_TargetAltitude - 100, 0)
	end
	AAL_FlashMessage("Target", AP_TargetAltitude, 500)
end

function AAL_AP_Increase_Target_Altitude_With_Display()
	if AP_UsingCustomTargetAlt == 0 then
		-- First time we call this, initialise to current altitude
		AP_TargetAltitude = RoundNearest(GetCurrentAlt(), 100)
	end
	AP_UsingCustomTargetAlt = 1
	_AP_ALT_HOLD_OFF()
	if AAL_RotaryShiftActive == 1 then
		AP_TargetAltitude = AP_TargetAltitude + 1000
	else
		AP_TargetAltitude = AP_TargetAltitude + 100
	end
	AAL_FlashMessage("Target", AP_TargetAltitude, 500)
end

function AAL_AP_ARM_Hold_Target_Altitude()
	if QueryAltHold() == 1 then
		_AP_ALT_HOLD_OFF()
	else
		if AP_UsingCustomTargetAlt == 1 then
			EngageAltHold(AP_TargetAltitude) -- local value
		else
			EngageAltHold(GetTargetAltitude()) -- FSX value
		end
	end
end

 

Edited by MarkDH
  • Like 1

MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
On ‎10‎/‎29‎/‎2018 at 2:15 PM, MarkDH said:

I don't think there is such a generic autopilot function.

Hi Mark,

Sorry - I missed your great response somehow... Thanks so much for taking the time... Hmm - I'm a little confused - so - it seems like in the script sample you're recreating the function to have an "Altitude Arm" capability - is all this required if the Altitude Arm function already exists in the aircraft in question and I simply want to activate the existing button ?

Thanks...

Regards,
Scott

Edited by scottb613

imageproxy.png.c7210bb70e999d98cfd3e77d7

Share this post


Link to post

If you're using FSUIPC, the controls you want to select are either

Ap Alt Hold or

Ap Panel Altitude Hold

The first will cause the aircraft to maintain its current altitude.  The second will command the aircraft to climb or descend to the altitude currently selected on the autopilot.,

  • Like 1

Share this post


Link to post

Hi...

Thanks - I'll give that a shot - much appreciated...

Regards,
Scott


imageproxy.png.c7210bb70e999d98cfd3e77d7

Share this post


Link to post
1 hour ago, scottb613 said:

is all this required if the Altitude Arm function already exists in the aircraft in question and I simply want to activate the existing button ?

It all comes down to the semantics of 'Altitude Arm' in any particular aircraft system. In the Twin Otter, for example, it will hold a pre-selected altitude when it arrives but it doesn't initiate a climb or descent to acquire that altitude. In the Bendix King-type system it will first acquire the selected altitude and then hold it. As you can see from my code above, if you want the latter you will need to select the altitude first. Assuming you want the latter, you will need to set the desired altitude first. You may be able to do this on the panel, or you can do it as I have shown above from code. In aircraft that don't use the standard P3D model (or which add to it) you may need to find appropriate Lvars to manipulate.


MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
5 minutes ago, MarkDH said:

It all comes down to the semantics of 'Altitude Arm' in any particular aircraft system. In the Twin Otter, for example, it will hold a pre-selected altitude when it arrives but it doesn't initiate a climb or descent to acquire that altitude. In the Bendix King-type system it will first acquire the selected altitude and then hold it. As you can see from my code above, if you want the latter you will need to select the altitude first. Assuming you want the latter, you will need to set the desired altitude first. You may be able to do this on the panel, or you can do it as I have shown above from code. In aircraft that don't use the standard P3D model (or which add to it) you may need to find appropriate Lvars to manipulate.

Hi Mark,

Ok - thanks for the clarification - let me play with this and see how it works in the aircraft in question...

Much appreciated...

Regards,
Scott


imageproxy.png.c7210bb70e999d98cfd3e77d7

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...