Jump to content
The simFlight Network Forums
Sign in to follow this  
Detlef_747

P3D C-130 autopilot will not lock in heading hold mode using Lua script

Recommended Posts

Hello everybody,

I have difficulties to get a Lua script to set the heading hold mode of the C-130 aircraft. I have tried the 0x7c8 variable as well as using ipc.control(65798).
If I press the heading hold button per mouse, I can activate the autopilot. So A/P power is on and the A/P master switch is on. However, if I try per Lua script, the A/P heading lock mode toggles on and off without even showing the A/P heading(track) lock light coming on.

I try this Lua script:

while 1 do

  has_ap = ipc.readStruct(0x764, "1UD")
  ap_masterswitch = ipc.readStruct(0x7bc, "1UD")
  ap_hdg = ipc.readStruct(0x7cc, "1UW")/65536*360
  hdg = ipc.readUD(0x580)/65536/65536*360
  
--  ipc.writeUD(0x7c8, 1)
  ipc.control(65798)
  hdg_lock = ipc.readUD(0x7c8)
  
  ipc.display("ap_masterswitch="..ap_masterswitch.. "\nap_hdg="..ap_hdg.."\nhdg_lock="..hdg_lock)

  ipc.sleep(50)
end


hdg_lock shows 1, 0, 1, 0 and so on.

Any help with this is appreciated.

Thank you
Detlef
 

Share this post


Link to post
Share on other sites

Hi,

that AC might not use standard controls but maybe L:Vars.

You can check both via Logging tab, -

- enable Send to console window and Events (non-axis controls) that will log the control when you press the button via mouse, if it is a control

- i.e. set a Key to List Local Panel Vars to list all L:Vars for the currect AC, then find in what is listed the name (Lvar) for the function. You can send then the LVar with Lua

image.png.5e543076c107e31fb4b0698cf19fe6dd.png

Thomas

Share this post


Link to post
Share on other sites
10 hours ago, Thomas Richter said:

that AC might not use standard controls but maybe L:Vars.

Hello Thomas,

thank you again for your advice. I did never use L:vars and ignored documentation about it until now. I tried arround a lot today. I think you are right, for some features the P3D autopilot at least for the C-130 aircraft seems to use L:vars. I don't like that so much since those variables probably differ between aircrafts.

I have a very old self made hardware with switches and LEDs mainly that communicates via COM serial interface with the PC. That used to work fine for many years with FSX. Now, recently I decided to switch to P3D and I have re-programmed all my software from Visual Basic (FSX) to Lua (P3D) using FSUIPC. A couple of things do work, but I have still a lot to do.

And I bought PanelBuilder to design my own instrument panel. I dont need 3D cockpits because I have my own switch console and a beamer for the outside picture.

Now with the autopilot there seem to be three ways:

(1) try to find out the Lvars for the aircrafts I want to use and write to them using Lua.

(2) Program mouse macros to set the switches on the original aircraft gauges.

(3) Forget about the built-in autopilot and bank or pitch the Aircraft, by  directy writing to appropriate variables.

A lot to do any way I look at it. Now,

With Lvars I need to do detective work to find out the right ones then try to make them work for me. And this would probably be different for different aircrafts. Actually I don't like to fly military aircrafts so much so in the near future I would like to find a 747, 737 that works fine for me.

Mouse macros are also dependent on different aircrafts, and I plan to configure my own panel. And probably the autopilot gauge needs to be in the same spot all the time to make the mouse macros work. But I never tried that. Maybe I will e.g. to use the build in gauge to open cargo doors or so.

And finally if I forget the built-in autopilot: at least I can probably do that for every aircraft. But my gauges (from PanelBuilder) will then not show the autopilot engaged. And I need to find a way to disconnect the joystick axis with Lua.

Well... whatever way I look at it, there's lot to do. I am not decided yet how to proceed. Maybe I start to find some attractive civil jet / airliner first.

Thank you
Detlef


 

Share this post


Link to post
Share on other sites

Hi,

mouse macros can be programmed with profiles. I think L:Vars actually as well by using macros but check the manual.

Quote

Mouse macros are also dependent on different aircrafts, and I plan to configure my own panel. And probably the autopilot gauge needs to be in the same spot all the time to make the mouse macros work. But I never tried that. Maybe I will e.g. to use the build in gauge to open cargo doors or so.

Thomas

 

Share this post


Link to post
Share on other sites

Hello Thomas,

using Lvars did the trick for me. I experimented using the following Lua code:

 

local lvname={}
local k=1
local disp, n, val
local aircraft = ""
local len, stop


lvname[k]="AP_PWR"; k=k+1
lvname[k]="bAPPowerSwVar"; k=k+1
lvname[k]="Track"; k=k+1
lvname[k]="bAPEngageSwVar"; k=k+1
lvname[k]="Pitch Hold"; k=k+1
lvname[k]="IAS Hold"; k=k+1
lvname[k]="bAPBankSwVar"; k=k+1
lvname[k]="KBank"; k=k+1
lvname[k]="MotorA"; k=k+1
lvname[k]="CurBank"; k=k+1
lvname[k]="MotorE"; k=k+1
lvname[k]="bAPHeightIASSwVar"; k=k+1
lvname[k]="bAPTrackSwVar"; k=k+1
lvname[k]="bAPGlideSwVar"; k=k+1
lvname[k]="bAPPitchSwVar"; k=k+1
lvname[k]="HeadingModeKnob"; k=k+1
lvname[k]="LogicHeadingMode"; k=k+1
lvname[k]="MotorR"; k=k+1
lvname[k]="Normal-Heading"; k=k+1
lvname[k]="FD_OnClick"; k=k+1

aircraft = ipc.readSTR(0x3d00, 256)
len, stop = string.find (aircraft, "\0", 1, false)
aircraft = string.sub(aircraft, 1, len-1)

while 1 do

  disp = aircraft
  for n=1,k-1 do
    val = 0
    val = ipc.readLvar("L:"..lvname[n])
    if val==nil then
      val = "nil"
    end
    disp = disp.."\n"..lvname[n].."="..val
  end
    
  ipc.display(disp)
  ipc.sleep(50)
end

 

Thanks for your help

Detlef
 

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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.