Click here to Skip to main content
15,922,533 members
Articles / Programming Languages / C#

C# Avionic Instrument Controls

Rate me:
Please Sign up or sign in to vote.
4.91/5 (72 votes)
17 Jul 2008CPOL2 min read 341.7K   25.2K   197   64
The aim of this C# project is to purpose six aircraft cockpit instruments usable in forms as any other C# controls.
Image 1

Introduction

The aim of this C# project is to purpose six aircraft cockpit instruments usable in forms as any other C# controls and to define a generic instrument class in order to design any kind of dashboard instruments.

Description

The controls are built with bitmaps which are rotated, translated or scaled before to be displayed. The basic methods for rotate, translate and scale images are defined in the mother class. Each control then uses its dedicated parameters (related to a physical signification) in order to manipulates the images.

Aircraft Instruments

  • Air speed indicator: airspeed (kts)
  • Attitude Indicator: pitch (deg), roll (deg)
  • Altimeter: altitude (ft)
  • Turn Coordinator: turn rate (deg/min)
  • Vertical speed indicator: vertical speed (ft/min)
  • Heading indicator: heading (deg)

Details of the Key Functions

This section explains in detail the implementation of the basic functions defined in the InstrumentControl class.

Rotate Image

Implementation

The rotation of the image is divided in two main parts:

First, the rotation of the PaintEventArgs coordinate system around the upper left corner of the drawing area.

Second, the drawing of the image corrected by translation offset in order to display the image as if it has turned around a user defined point.

AvionicsControlDemo_RotationMainSteps.JPG

Let’s see step by step:

Step 0: Initial situation.

AvionicsControlDemo_RotationPhase0.JPG

Step 1: Rotate the PaintEventArgs coordinate system around the left upper corner of the paint area.

AvionicsControlDemo_RotationPhase1.JPG

Corresponding code sample:

C#
// Rotate image support
pe.Graphics.RotateTransform((float)(alpha * 180 / Math.PI));

Step 2: Draw the image and apply the translation correction.

AvionicsControlDemo_RotationPhase2.JPG

Corresponding code sample:

C#
// Display image
pe.Graphics.DrawImage(img, (ptImg.X + deltaX) * scaleFactor, (ptImg.Y + deltaY) * 
	scaleFactor, img.Width * scaleFactor, img.Height * scaleFactor);

Step 3 (Final step): Put the PainEventArgs coordinate system as found.

AvionicsControlDemo_RotationPhase3.JPG

Corresponding code sample:

C#
// Put image support as found
pe.Graphics.RotateTransform((float)(-alpha * 180 / Math.PI));

The key point in those operations is the calculation of the translation correction coefficients.

The next figure explains the geometrics considerations:

AvionicsControlDemo_RotationDetailedScheme.JPG

G0 is the user defined rotation center
G1 is the G0 position after the step 1.

The aim of this section is to identify the G1G0 translation and apply the corresponding offset in order to draw the rotation point as if it has not moved.

Then we work with the geometrics definitions:

a. AvionicsControlDemo_RotationCalcs1.JPG
b. AvionicsControlDemo_RotationCalcs2.JPG
c. AvionicsControlDemo_RotationCalcs3.JPG
d. AvionicsControlDemo_RotationCalcs4.JPG

As a result, the offset coefficients are:

AvionicsControlDemo_RotationCalcs5.JPG

The corresponding code sample is as follows:

C#
// Computed offset
deltaX = (float)(d * (Math.Cos(alpha - beta) - Math.Cos(alpha)* 
	Math.Cos(alpha + beta) - Math.Sin(alpha) * Math.Sin(alpha+ beta)));
deltaY = (float)(d * (Math.Sin(beta - alpha) + Math.Sin(alpha)* 
	Math.Cos(alpha + beta) - Math.Cos(alpha) * Math.Sin(alpha + beta)));

Parameters

  • "pe": The paint area event where the image will be displayed
  • "img": The image to display
  • "alpha": The angle of rotation in radian
  • "ptImg": The location of the left upper corner of the image to display in the paint area in nominal situation
  • "ptRot": The location of the rotation point in the paint area
  • "scaleFactor": Multiplication factor on the display image

AvionicsControlDemo_RotationFunctionParameters.JPG

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAppreciated this code Pin
Member 114322751-May-24 11:00
Member 114322751-May-24 11:00 
Questiondoesn't work Pin
Member 1613878615-Nov-23 9:43
Member 1613878615-Nov-23 9:43 
QuestionNice controls Pin
bone krusher17-Oct-21 19:55
bone krusher17-Oct-21 19:55 
QuestionI got an error when try to add it to my project.. Pin
Member 1312901818-Oct-17 5:45
Member 1312901818-Oct-17 5:45 
AnswerRe: I got an error when try to add it to my project.. Pin
Member 140462382-Apr-19 23:48
Member 140462382-Apr-19 23:48 
QuestionExcellent Pin
Pablo Odysseus8-Jun-16 3:34
Pablo Odysseus8-Jun-16 3:34 
AnswerRe: Excellent Pin
Member 140462382-Apr-19 23:51
Member 140462382-Apr-19 23:51 
Questioni love you my bro Pin
armanfx28-Mar-16 5:49
armanfx28-Mar-16 5:49 
QuestionHow d I add this toolbox to my project? there is no .dll file. Pin
Member 118586067-Jan-16 3:54
Member 118586067-Jan-16 3:54 
QuestionUpgraded altimeter Pin
Redgum20-Nov-14 10:58
professionalRedgum20-Nov-14 10:58 
If anyone has contact with the original author, I need his permission to post an updated version of the altimeter.

I added a 10K needle and increased the maximum useful indicated altitude to 99,999 feet (using all 5 digits in the counter) as this control was useful for a high altitude balloon project. I made a telemetry package and wrote a WPF application to track the balloon in real time. The altimeter was used in the tracking project and updated to indicate altitudes above 10,000 feet.

The code is pretty simple and thought it'd be easier just to post the updated control, but the guidelines ask that the original author be contacted first.
The madman is not the man who has lost his reason; the madman is the man who has lost everything except his reason.

--G.K. Chesterton

Question!Need Help in Creating a VB.NET Avionics Intsrument Control Pin
schematicsman7-Jan-14 1:30
schematicsman7-Jan-14 1:30 
QuestionHow to use these controls for an existing project PinPopular
Member 1016504020-Jul-13 11:15
Member 1016504020-Jul-13 11:15 
QuestionHow to add these controls to my project? Pin
Haytham.Breaka18-Apr-13 15:34
Haytham.Breaka18-Apr-13 15:34 
GeneralVery very nice Code Project sample... Pin
Destiny77718-Sep-12 8:35
Destiny77718-Sep-12 8:35 
GeneralRe: Very very nice Code Project sample... Pin
Member 140462382-Apr-19 23:57
Member 140462382-Apr-19 23:57 
QuestionAide Pin
bbjodel27-Jun-12 5:53
bbjodel27-Jun-12 5:53 
QuestionVery nice controls Pin
Mike Hankey15-Apr-12 0:30
mveMike Hankey15-Apr-12 0:30 
QuestionImport to VB.Net Pin
JTmetoo28-Aug-11 9:06
JTmetoo28-Aug-11 9:06 
QuestionGreat Job Pin
Lamar Seifuddin29-Jul-11 21:36
Lamar Seifuddin29-Jul-11 21:36 
GeneralRe: Great Job Pin
Destiny77718-Sep-12 8:42
Destiny77718-Sep-12 8:42 
QuestionC# avionic controls Pin
JPC0624020-Jun-11 3:31
JPC0624020-Jun-11 3:31 
Generalthank you Pin
yardloun4-Apr-11 4:56
yardloun4-Apr-11 4:56 
GeneralMy vote of 5 Pin
YEBM Knight8-Feb-11 3:14
YEBM Knight8-Feb-11 3:14 
GeneralGreat work - I am using these with the AR Drone Pin
shobley17-Oct-10 6:52
shobley17-Oct-10 6:52 
GeneralRe: Great work - I am using these with the AR Drone Pin
Destiny77718-Sep-12 8:43
Destiny77718-Sep-12 8:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.