"Artificial horizon" is a graphical object consisting of an on screen artificial horizon for aircraft, including:
- Virtual horizon line between sky and ground symbols
- Reticle symbolising aircraft longitudinal axis
- Flight path marker
- Attitude indicators :
. Pitch indicator, range : ]-180°,+180°], field of view : 40°
. Roll indicator, range : ]-180°,+180°], field of view : 60°
. Heading indicator, range : [-90°,+90°], field of view : 60°
All attitude gauges have the following characteristics:
- Reference markings : cardinal points, null pitch and null roll
- Resolution of 2.5° for graduating
- Specific graduatings for modulo 2.5°, 5° and 10° angles
Attitude can be updated by an object method through the three Euler angles [rad], respecting this aeronautical convention: from an initial attitude (North, horizontal flight), heading, pitch and roll angles respectively increase when:
- Aircraft turns to the East
- Aircraft climbs
- Right wing goes down
Eric Ogier (2019). Artificial horizon (https://www.mathworks.com/matlabcentral/fileexchange/56078-artificial-horizon), MATLAB Central File Exchange. Retrieved .
It should be possible to use a block "Embedded MATLAB Function" that creates an artificial horizon and then to provide HEADING, PITCH and ROLL to it or to update HEADING, PITCH and ROLL with angle increments from an initial attitude:
AH = Artificial_horizon(PROPERTY1,VALUE1,PROPERTY2,VALUE2,...);
Hello Eric, is there any way I can link your GUI into a Simulink system and feed it with MPU9250 data?
You can add an artificial horizon programmatically in your own figure by specifying its axes.
At the end of the instructions creating the figure of your application, you can create axes belonging to the figure and call Artificial_horizon object specifying the axes you created as the value of "axes" property:
Axes = axes('parent',YourFigure);
AH = Artificial_horizon('axes',Axes);
Then, you can update it with your attitude data through "update" method. If you want to update the location of the horizon, e.g when the main figure is resized, you have to update "position" property.
I hope it will help.
Hi Eric ,
Do you think it is possible to add your artificial horizon "inside" an app made in app designer ?
For the moment I can only have it in a separate "figure" window so it is not really integrated in my app..
Forgot the stars ;)
Very nice! Thanks for sharing.
Really gerat work! Thanks a lot!
There is a small bug in heading indicator update (line 571):
Object.HeadingIndicator.Lines(n) should be updated by using the set function (not line), otherwise wrong axes are used.
Two thumbs up!
Could you confirm the artificial horizon doesn't remain static with the following test (make sure the unit you use is radian) ?
S = get(0,'ScreenSize');
d = 500;
P = [(S(3)-d)/2 (S(4)-d)/2 d d];
% Creation of an artificial horizon
AH = Artificial_horizon('Axes',gca,'ReticleType','-.-','Reticlecolor','y','EdgeColor','w');
the problem is that not appear the value's scale in the graph (for example +10º, +20º, +30º). Only appears 0º.
It is an arbitrary choice not to display too much information.
If you need the precise values of roll, pitch and heading, typically in yellow in black boxes, you can add the following lines at the end of the given functions:
• % Artificial horizon update
set(Object.RollIndicator.StaticBox, 'String', sprintf('%+.0f°',180/pi*Roll));
set(Object.HeadingIndicator.StaticBox, 'String', sprintf('%+.0f°',180/pi*Heading));
• % Creation of a pitch indicator
Object.PitchIndicator.StaticBox = ...
• % Creation of a roll indicator
Object.RollIndicator.StaticBox = ...
• % Creation of a heading indicator
Object.HeadingIndicator.StaticBox = ...
This solution works well for me.
the values of heading, pitch and roll not appear in the graph. Why?
I managed to link this artificial horizon to a test GUI including axes and a push button.
I created axes titled ‘axes1’ and defined the following ‘Create function’:
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
AH = Artificial_horizon('Axes',hObject,'Position',[0 0 0.5 0.5]);
This callback function is called at the creation of the axes, whose handles, ‘hObject’, will be injected in Artificial_horizon object as ‘Axes’ property. There is a little subtlety in the fact you must use 'normalized' unit (the default unit in GUIDE is ‘character’). In this example, an artificial horizon should appear in the bottom left quadrant of the GUI.
I hope it will help you.
I am trying to add this artificial horizon in a GUI that I've created.
The issue is that I am not able to add it inside an axes object, that is already embedded in the GUI.
Do you have any hints?
Minor modification to avoid errors if the parent figure is closed by user.
Update with flight path marker and new reticles
Minor modification for taking into account the dimensions of an existing axis in 'create' function.
Modification of video demonstrations links.
Modification of heading gauge to indicate horizon line direction.
Adding of video demonstrations link.
Create scripts with code, output, and formatted text in a single executable document.