File Exchange

## Artificial horizon

version 1.3.0.1 (10.8 KB) by Eric Ogier

### Eric Ogier (view profile)

On screen artificial horizon for aircraft

Updated 16 Mar 2019

"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

### Cite As

Eric Ogier (2019). Artificial horizon (https://www.mathworks.com/matlabcentral/fileexchange/56078-artificial-horizon), MATLAB Central File Exchange. Retrieved .

Eric Ogier

### Eric Ogier (view profile)

Hello,
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:

persistent AH

if isempty(AH)
AH = Artificial_horizon(PROPERTY1,VALUE1,PROPERTY2,VALUE2,...);
else
end

end

Ken Yano

### Ken Yano (view profile)

Hello Eric, is there any way I can link your GUI into a Simulink system and feed it with MPU9250 data?

Eric Ogier

### Eric Ogier (view profile)

Hello Kelly,

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.

Kelly Lachkar

### Kelly Lachkar (view profile)

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..
Thanks

Mariya Efimenko

Kai Lehmkuehler

### Kai Lehmkuehler (view profile)

Forgot the stars ;)

Kai Lehmkuehler

### Kai Lehmkuehler (view profile)

Very nice! Thanks for sharing.

Mo Wo

### Mo Wo (view profile)

Really gerat work! Thanks a lot!

Alexander Dallinger

### Alexander Dallinger (view profile)

Great work!

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.

Javensius Sembiring

Two thumbs up!

Eric Ogier

### Eric Ogier (view profile)

Could you confirm the artificial horizon doesn't remain static with the following test (make sure the unit you use is radian) ?

% Figure
S = get(0,'ScreenSize');
d = 500;
P = [(S(3)-d)/2 (S(4)-d)/2 d d];
figure('Color', 'w',...
'Position', P);

% Creation of an artificial horizon
AH = Artificial_horizon('Axes',gca,'ReticleType','-.-','Reticlecolor','y','EdgeColor','w');

% Test
AH.update(0,0,0);
pause(0.5);
AH.update(0,pi/8,0);
pause(0.5);
AH.update(0,pi/4,0);
pause(0.5);
AH.update(0,3*pi/8,0);

sebincicco Incicco

### sebincicco Incicco (view profile)

the problem is that not appear the value's scale in the graph (for example +10º, +20º, +30º). Only appears 0º.

Thanks

Eric Ogier

### Eric Ogier (view profile)

Hello,

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.PitchIndicator.StaticBox, 'String',sprintf('%+.0f°',180/pi*Pitch));
set(Object.RollIndicator.StaticBox, 'String', sprintf('%+.0f°',180/pi*Roll));

• % Creation of a pitch indicator
function Creation_pitch_indicator(Axes)

[...]

Object.PitchIndicator.StaticBox = ...
text(0.75,0,'0°',...
'Parent', Axes,...
'Color', 'y',...
'EdgeColor', 'y',...
'Backgroundcolor', 'k',...
'FontSize', Object.FontSize,...
'FontWeight', Object.FontWeight,...
'HorizontalAlignment', 'Center',...
'VerticalAlignment', 'Middle');

• % Creation of a roll indicator
function Creation_roll_indicator(Axes)

[...]

Object.RollIndicator.StaticBox = ...
text(0,-rdr,'0°',...
'Parent', Axes,...
'Color', 'y',...
'EdgeColor', 'y',...
'Backgroundcolor', 'k',...
'FontSize', Object.FontSize,...
'FontWeight', Object.FontWeight,...
'HorizontalAlignment', 'Center',...
'VerticalAlignment', 'Middle');

• % Creation of a heading indicator

[...]

'Parent', Axes,...
'Color', 'y',...
'EdgeColor', 'y',...
'Backgroundcolor', 'k',...
'FontSize', Object.FontSize,...
'FontWeight', Object.FontWeight,...
'HorizontalAlignment', 'Center',...
'VerticalAlignment', 'Bottom');

This solution works well for me.

sebincicco Incicco

### sebincicco Incicco (view profile)

Hi Eric

the values of heading, pitch and roll not appear in the graph. Why?

good job
thanks

Eric Ogier

### Eric Ogier (view profile)

Hello Alexander,

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
set(hObject,'Unit','normalized');
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.

Alexandre

### Alexandre (view profile)

Hi Eric,

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?

Thank you,

Alexandre

 16 Mar 2019 1.3.0.1 Minor modification to avoid errors if the parent figure is closed by user. 2 Dec 2018 1.3.0.0 Update with flight path marker and new reticles 21 Nov 2017 1.2.0.0 Minor modification for taking into account the dimensions of an existing axis in 'create' function. 23 Mar 2016 1.1.0.0 Modification of video demonstrations links. 23 Mar 2016 1.1.0.0 Modification of heading gauge to indicate horizon line direction. 21 Mar 2016 1.0.0.0 Adding of video demonstrations link.
##### MATLAB Release Compatibility
Created with R2018a
Compatible with R2016b to any release
##### Platform Compatibility
Windows macOS Linux