Project Autopilot ScriptMFD by Thunder Chicken

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
This is probably another issue with my understanding how to render multiple page MFDs.
I suspect it might have more to do with a significant misunderstanding (and very common... basically everyone falls for it the first time) of how MFDs work rather than with multiple pages.
There is a reason why the orbiter API talks about MFD modes, rather than just MFDs. An MFD mode is a singleton. Only one instance of each mode exists in the simulation. You can even open the MFD in another vessel, it will still be talking tothe same instance in the back.
If you want the same MFD mode to work concurrently with different data in different MFDs, it needs to manage data and state of the various instances by itself. At least that's what I remember of it...
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I meant it was probably just a misprint of the button label (HOL instead of HLD).

I'm not sure where you are seeing HLD. Here are the button key menus from the script. All use HOL for hold:

Code:
-- List of MFD buttons and menu entries for all pages

btn_label_0 = {'SPD','CRD','ALT','HDG'}                 -- MFD Main Page
btn_label_1 = {'MNU','ENG','REL','HOL',' + ',' - '}     -- Airspeed Autopilot
btn_label_2 = {'MNU','ENG','REL'}                       --Coordinate Autopilot
btn_label_3 = {'MNU','ENG','REL','HOL','   ','   ','+10','-10', '+1','-1', '+.1 ','-.1'} --Altitude Autopilot
btn_label_4 = {'MNU','ENG','REL','HOL','VOR','WPT',' + ',' - ','+10','-10','UP','DN'}  --Heading Autopilot

Perhaps it is a font issue on your machine? I really have no idea about this.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I suspect it might have more to do with a significant misunderstanding (and very common... basically everyone falls for it the first time) of how MFDs work rather than with multiple pages.
There is a reason why the orbiter API talks about MFD modes, rather than just MFDs. An MFD mode is a singleton. Only one instance of each mode exists in the simulation. You can even open the MFD in another vessel, it will still be talking tothe same instance in the back.
If you want the same MFD mode to work concurrently with different data in different MFDs, it needs to manage data and state of the various instances by itself. At least that's what I remember of it...
I think the intent was that it would be convenient to display different autopilot functions on separate instances. For example, maybe have the heading autopilot displayed on the left MFD and the airspeed autopilot displayed on the right MFD. Working one autopilot function shouldn't change data for the other.
 

misha.physics

Well-known member
Joined
Dec 22, 2021
Messages
399
Reaction score
515
Points
108
Location
Lviv
Preferred Pronouns
he/him

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
As far as I can remember (long time ago) the Markers have been incorporated into the binary, packed, "Archive" structure in the Textures Folder (for example .\Textures\Earth\Archive\Label.tree)

This has to do with performance considerations as reading those Text-files is not the fastest way to do.

And just before you ask... I will not provide a Lua interface for that ;)
As Orbiter is open-source now, could I potentially bundle the Orbiter 2016 files with this add-on with proper attribution? It's a rather useful autopilot IMO as it allows point-to-point navigation on Earth.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
4) I get a crash when I click on HOL in the HDG mode.
I actually get this behavior as well when I am stationary on the runway and hit HOL. I'm adding it to my bug list and will investigate.
7) It would be nice to add different change steps for SPD mode like for the ALT mode.
I'll put this on the to-do list.

I'd also like to work on the waypoint interface as there are several hundred waypoint markers and scanning through them one by one works, but is tedious. Something where I can get a dialog and search by keyword would be nice, but I'm not familiar with any such MFD capability.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I think the crash that occurs when hitting the heading hold feature is something to do with the heading vector and the heading target being precisely the same, but I'm actually having a hard time isolating the problem because I'm getting curious behavior when I comment out certain code. Basically the heading hold autopilot is implemented like this:

Code:
function poststep(simt,simdt,mjd)
.
.
.
    if heading_hold == true then

        control_heading()

    end
.
.
.
end

If I comment out the call to control_heading(), it doesn't crash, so it's something in this function.

However, if I restore the call to this function and comment out all the code within that function, it still crashes:

Code:
function control_heading()
[[
...
lots of commented out code here
...
]]
end

However, if I change the name of that function so it can't be called and make a new empty function control_heading(), that doesn't crash.

Code:
function control_heading()

end

Functionally the commented out function and the empty function should have the same behavior, but they do not. I must be hallucinating something stupid but for the life of me I can't see a problem with what I am trying to do.

Insanity is doing the same thing twice and expecting to get a different result. But am I insane when I actually get a different result?

EDIT: VS Code put itself in restricted mode without my knowledge. Just updated my OS the other day and it seems it wanted to protect me from myself. Bad bot, no cookies or applets for you.

Heading hold crash issue is fixed. When I fix up some more issues I'll post a new test version.(y)
 
Last edited:

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
OK, Revision 1 is here. This should work in both Orbiter 2016 and OpenOrbiter.

The bugs in version 0 have been fixed:
  1. It will read any marker files available in Config/Earth/Markers and extract waypoints as they are available. If no files exist, the WPT function is simply disabled. Note that I have observed some font problems with some of the names of the files. I am on a Linux box, so you may have a different experience.
  2. The crashing when the heading hold (HOL) autopilot was engaged has been fixed.
Added features:
  1. The autopilot states can now be read from and written to scenario files for Orbiter Build 240117 and later (finally! Woo hoo!). It cannot work for earlier versions or for Orbiter 2016 or earlier as the necessary Lua functions do not exist in those versions.
There were several other feature requests that I will need to ponder, stay tuned.
 

Attachments

  • Autopilot ScriptMFD by Thunder Chicken rev 1.zip
    8.8 KB · Views: 4

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I suspect it might have more to do with a significant misunderstanding (and very common... basically everyone falls for it the first time) of how MFDs work rather than with multiple pages.
There is a reason why the orbiter API talks about MFD modes, rather than just MFDs. An MFD mode is a singleton. Only one instance of each mode exists in the simulation. You can even open the MFD in another vessel, it will still be talking tothe same instance in the back.
If you want the same MFD mode to work concurrently with different data in different MFDs, it needs to manage data and state of the various instances by itself. At least that's what I remember of it...
I understand this. However, it should be possible to have two autopilot MFDs up to manipulate different pages. Right now the problem is that there is a page number associated with each autopilot display, and that is common to all MFD instances. I would have to somehow allow different MFDs to be on different pages. I think that is possible, but I need to think about how.
 

misha.physics

Well-known member
Joined
Dec 22, 2021
Messages
399
Reaction score
515
Points
108
Location
Lviv
Preferred Pronouns
he/him
I tried the update. Now it doesn't crash when clicking HOL in HDG mode, and a vessel is trying to follow a set course. But another problem occurs with HDG mode (I'm running Orbiter build v240111, but you could check it in the last one). Take off on Delta-glider, keep horizontal flight, then enable Autopilot MFD, choose HDG, press HOL, and now bank the vessel too much trying to turn left or right. And during this press on "+" on the MFD. After this the heading hold is released, but the plane starts to roll so much and I can't stabilize it as if autopilot continues to operate. The REL command and closing the Autopilot MFD can't help to stabilize the plane. It just rotates in a circle around its longitudinal axis without stopping.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I tried the update. Now it doesn't crash when clicking HOL in HDG mode, and a vessel is trying to follow a set course. But another problem occurs with HDG mode (I'm running Orbiter build v240111, but you could check it in the last one). Take off on Delta-glider, keep horizontal flight, then enable Autopilot MFD, choose HDG, press HOL, and now bank the vessel too much trying to turn left or right. And during this press on "+" on the MFD. After this the heading hold is released, but the plane starts to roll so much and I can't stabilize it as if autopilot continues to operate. The REL command and closing the Autopilot MFD can't help to stabilize the plane. It just rotates in a circle around its longitudinal axis without stopping.
I am seeing this behavior too. It seems that the last flight control setting is persisting even when the autopilot is released. This might be causing some quirks in the CRD and ALT autopilots as well. I'll look into it.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I tried the update. Now it doesn't crash when clicking HOL in HDG mode, and a vessel is trying to follow a set course. But another problem occurs with HDG mode (I'm running Orbiter build v240111, but you could check it in the last one). Take off on Delta-glider, keep horizontal flight, then enable Autopilot MFD, choose HDG, press HOL, and now bank the vessel too much trying to turn left or right. And during this press on "+" on the MFD. After this the heading hold is released, but the plane starts to roll so much and I can't stabilize it as if autopilot continues to operate. The REL command and closing the Autopilot MFD can't help to stabilize the plane. It just rotates in a circle around its longitudinal axis without stopping.
This one is a head-scratcher. For some reason the aileron flight control level is being set to -1 when the heading hold is released. It is taking manual inputs, but the user can only get it to 0 by holding hard right roll.

I am wondering if I am misunderstanding something about how the flight controls are set:

Code:
v:set_adclevel(adctype,lvl)

Updates the position of an aerodynamic control surface.
Parameters:
adctype (number):    control surface type(see Aerodynamic control surface types)
lvl (number):    new level [-1..+1]
Notes:

Parameter lvl defines a target state for the surface. Control surfaces generally require a finite amount of time to move from the current to the target state.

This method affects the permanent setting of the control surface, while manual input via keyboard or joystick affects the transient setting. The total target state of the control surface is the sum of both settings, clamped to the range [-1...+1]

It seems that attempting to manually control the flight surface when engaging the autopilot causes it to offset the "permanent" setting. When the manual controls are released, neutral isn't at level 0 anymore, it's at something else. I tried setting the level to zero when the autopilot is released but that doesn't seem to help.

It may be necessary to disable manual flight control when the autopilot is engaged. There is a method for that, but I am not clear on how the modes work:

Code:
v:set_adcmode(mode)

Configure manual input mode for aerodynamic control surfaces.
Parameters:
mode (number):    bit flags defining the address mode for aerodynamic control surfaces
Notes:

The returned control mode contains bit flags as follows:

    bit 0: elevator enabled/disabled
    bit 1 rudder enabled/disabled
    bit 2 ailerons enabled/disabled

Therefore, mode=0 indicates control surfaces disabled, mode=7 indicates fully enabled.

I'm not getting the "mode=0 indicates control surfaces disabled, mode=7 indicates fully enabled" bit. What do I enter to just disable ailerons, and what do I do to re-enable them?
 

misha.physics

Well-known member
Joined
Dec 22, 2021
Messages
399
Reaction score
515
Points
108
Location
Lviv
Preferred Pronouns
he/him
It may be necessary to disable manual flight control when the autopilot is engaged.
I think it probably can make sense, but only partially. For example, we should be able to manually control the control surfaces when SPD autopilot is enabled, and we should be able to manually control the elevation rudder when HDG autopilot is working, and so on.

Maybe someone knows how the simultaneous operation of the autopilot and manual control is combined on real airplanes.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I think it probably can make sense, but only partially. For example, we should be able to manually control the control surfaces when SPD autopilot is enabled, and we should be able to manually control the elevation rudder when HDG autopilot is working, and so on
These are independent autopilot functions. This is how they already behave and I won't change that.
Maybe someone knows how the simultaneous operation of the autopilot and manual control is combined on real airplanes.
It really depends on the aircraft manufacturer and how much they want to protect the pilot from doing something stupid (or sane).

The problem here is that in Orbiter, manual flight control inputs are temporary, but setting the adclevel in the autopilot sets a persistent flight control level. It seems that I need to set the adclevel to 0 when the autopilot is released.
 

misha.physics

Well-known member
Joined
Dec 22, 2021
Messages
399
Reaction score
515
Points
108
Location
Lviv
Preferred Pronouns
he/him
Oh, I'm sorry for my inattention. You've been writing in your starting post that every autopilot mode controls only its own control surfaces and throttles.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
OK, here is revision 2.

Screenshot at 2024-01-27 19-08-42.png
  • Fixed issue with ailerons offsetting when heading autopilot and manual controls are used simultaneously.
  • Improved incrementing of airspeed target.
  • Added autopilot status screen to main menu.
  • Tweaked proportional gain for heading autopilot downward so chonky DeltaGlider doesn't overshoot in roll so badly when changing heading.
Enjoy.
 

Attachments

  • Autopilot ScriptMFD by Thunder Chicken rev 2.zip
    9.1 KB · Views: 8
Last edited:

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
Level flight at 1000m, 30 deg. angle of attack at 40 m/s (78 knots) with altitude and airspeed autopilots engaged.

30_alpha_40_ms.png
Increasing speed to 100 knots gives an alpha of about 25 degrees which is just about spot on correct for low speed flight in a Mirage2000. The delta wing model by Polhausen seems to be doing a great job.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
So I am considering a reorganization of my Autopilot code as I seem to have some logic conflicts between my heading and waypoint autopilots that prevents heading from being changed under certain circumstances, and my code is pretty bloaty and (I suspect) redundant. I also want to be able to fix the problem of opening multiple instances of the autopilot on different MFDs all being forced to the same menu page when one is selected.

Right now I have a specified number of menu pages (n_pages). To allow different pages to be viewed in different MFD instances, I would need to be able to determine how many MFDs (n_mfd) are running the autopilot, get some sort of handle for them, so the pages could be set like page(i_mfd) = number. I am not seeing a Lua method to determine and identify MFD instances in this manner.

IIRC, it's possible to have more than two MFD instances (not just left and right MFD)? I want to make sure that whatever I implement can be generally applied to n_mfds.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
it's possible to have more than two MFD instances (not just left and right MFD)?
Short answer: Yes. Slightly longer answer: It depends on the cockpit implementation. So for the standard glass cockpit the answer is not, unless you count external mfds.
Keep in mind however that, somewhat counterintuitively, what we describe as an "MFD instance" here is merely its representation in the cockpit (drawing surface and input controls). MFD MODES only exist once per MFD. They're effectively singletons. That's why rendering the same MFD mode in two different MFDs is such a hassle (even if they're displayed in different vessels!).
 
Top