Board index FlightGear Development New features

Wind Correction Angle

Discussion and requests for new features. Please note that FlightGear developers are volunteers and may or may not be able to consider these requests.

Wind Correction Angle

Postby awexome » Fri Apr 06, 2012 10:37 pm

Hello Aero-Smurfs :)

I like to introduce discussions and code magic to help improve flight and course tracking by applying wind correction to autopilot heading and pilot's manual course adjustments.

The limited research conducted did not lead to a seemingly simple and understandable code. By extending the range of my 'ND', I came upon a seemingly simple formula for wind correction angle (WCA). The Nasal implementation illustrated below is still under testing. 'Caution, you may get blown away' :)

Code: Select all
## ##### BEGIN GPL LICENSE BLOCK #####
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# More topping for your chocolate, you ask? READ below!
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details. <http://www.gnu.org/licenses/>
## ##### BEGIN GPL LICENSE BLOCK #####

# Designer and Developer: awexome[2318]
#

var asin = func(x) {
  math.atan2(x,math.sqrt(math.pow(2,1-x)));
}
###############################################################################
# calc WCA for AC course dCrs, speed of aV; and wind speed of wV,
# and direction wDir, and unit [nil,0-deg; 1-rad]
#=============================================================================#
var getWCA = func {
# arguments: TCrs, TAS, WDir, WS [, optional - DEG[0|nil] | RAD[1]]
# output: WCA - Wind Correction Angle

  var TCrs = arg[0] ? geo.normdeg(arg[0]) : getprop("/orientation/heading-deg");
  var TAS = arg[1] ? arg[1] : getprop("/velocities/airspeed-kt");
  var WDir = arg[2] ? arg[2] : geo.normdeg(getprop("/environment/wind-from-heading-deg") + 180);
  var WS = arg[3] ? arg[3] : getprop("/environment/wind-speed-kt");

# WCA = asin(WS90 / TAS) : WS90 - wind speed (90deg component); TAS - True Air Speed
# WS90 = WS * sin(AC - Wind)[direction in degrees];
  var WTAngle = (TCrs - WDir);
  var WScoef = math.sin(WTAngle);
  var WS90 = WS * WScoef;
  var WCA = asin(WS90 / TAS);
  return WCA * (arg[4] ? DEG2RAD : 1);
 
# example use for heading correction for course newCrs
# var hdg = newCrs + getWCA(newCrs);
} # getWCA

Code status: under development

I have intentionally made the algorighm super simplified. The entire calculation can be represented in a single line of code, if necessary.

The current implementation can be modified, on request, to return an adjusted heading, saving the user further processing to compute a corrected heading. I welcome constructive criticisms and requests for additional functionality. As always, your feedbacks are also welcome.

Gone with thy wind
awexome :)
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU

Re: Wind Correction Angle

Postby Hooray » Sat Apr 07, 2012 5:18 pm

awexome wrote in Fri Apr 06, 2012 10:37 pm:The limited research conducted did not lead to a seemingly simple and understandable code.


Maybe, these might help:
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11835
Joined: Tue Mar 25, 2008 8:40 am

Re: Wind Correction Angle

Postby awexome » Sat Apr 07, 2012 9:51 pm

Hi,

thanx for your response.

So, how would you evaluate the code already presented here? Any merits, bugs, room for improvement? (recommend a delete file :)

awexome.
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU

Re: Wind Correction Angle

Postby Hooray » Sat Apr 07, 2012 10:32 pm

Actually, I don't think there's any need to discuss or even evaluate your Nasal code, because the Nasal code snippets you tend to post here usually demonstrate a fairly solid knowledge of advanced programming concepts, your snippets are definitely more succinct and more advanced than most of the usual "copy/paste" Nasal code that we get to see here.

It's actually pretty refreshing to see someone posting short and comprehensible code snippets that are not huge blobs of spaghetti code ;-)

That's why I only posted links related to WCA algorithms and why I didn't bother commenting on your Nasal code itself.

To be honest, I think, it'd be kind of moot to make stylistic suggestions (especially in cases like this one, where a function is already very short and readable) - but if you're really looking for ways to write even more succinct code, you can use "or" instead of the ternary operator (or even introduce a wrapper to handle all the argument defaulting):

Code: Select all
  var TCrs = arg[0] ? geo.normdeg(arg[0]) : getprop("/orientation/heading-deg");
  var TAS =  arg[1] or getprop("/velocities/airspeed-kt");
  var WDir = arg[2] or geo.normdeg(getprop("/environment/wind-from-heading-deg") + 180);
  var WS = arg[3] or getprop("/environment/wind-speed-kt");
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11835
Joined: Tue Mar 25, 2008 8:40 am

Re: Wind Correction Angle

Postby awexome » Sat Apr 07, 2012 11:50 pm

Hi,

Nice. You just helped me scratch a far to reach part of my brain.

If you noticed in other code, I use ... and ... quite alot.
So, it makes sense to use ... or ... as well

This should save me more typing and related typos, and close more doors to other human-error related bugs.

However, at one time I thought that an expression such as;
Code: Select all
arg[0] or geo.normdeg(arg[0])

would return a boolean value(not the desired outcome), and not either of the two operands.

However, if Nasal will grant me the privelege of commanding non-boolean expressions and operands using 'or', then I am quite happy to apply it.

Do you still reckon that ... or ... is most appropriate in this context?
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU

Re: Wind Correction Angle

Postby Hooray » Sun Apr 08, 2012 10:24 am

would return a boolean value(not the desired outcome), and not either of the two operands.

it's simply short circuiting that is used here: http://en.wikipedia.org/wiki/Short-circuit_evaluation

Code: Select all
var foo=arg[0] or geo.normdeg(arg[0]);


What will happen is: first arg[0] will be evaluated to check if it's true (boolean) - if it is, the remaining or expression will be ignored (i.e. short-circuited), if it evaluates to false (nil, 0) however - the remainder of the expression will be evaluated and assigned to the lvale of the whole expression.

You can see this being used in many Nasal library files ($FG_ROOT/Nasal), where it is used for variable defaulting:

Code: Select all
var x = getprop("/sim/foo/x") or 0.00


This way, you can easily assign a sane default value to variables, while ensuring that it's safe to use it (i.e. in mathematical expression).

awexome wrote in Sat Apr 07, 2012 11:50 pm:Do you still reckon that ... or ... is most appropriate in this context?

No, not at all. Frankly, it really doesn't matter. I only posted that comment because you asked for coding feedback, and because your code was obviously written such that it's short and readable.

Like I said, I wouldn't waste time stylistically optimizing code which is already short and readable enough.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11835
Joined: Tue Mar 25, 2008 8:40 am

Review of Generic Functions

Postby awexome » Tue Apr 10, 2012 4:00 pm

Fellow Aviators, Designers, Engineers, Fans and Scholars [AVDEFS :!: ]

The Nasal code of generic functions is NOW available to see and critic at the FG wiki @ http://wiki.flightgear.org/User:Awexome/WCA

All welcome to provide critical remarks and insights that help to improve quality and functionality of code and design for the wider FGFS community.
UPDATE:
Following some useful feedback, the 'Hot Pot' hass been update. Fewer Nasal lines to your eyes.

... now. Hmm . AVDEFS ... AVIDEFS.. HAVIDEFS ... HAPPYDEFS ... HAPPY DEVS ... HAPPY DEVS!!! :!:

awexome-ly
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU

Re: Wind Correction Angle

Postby awexome » Fri Apr 13, 2012 8:48 pm

Hello all,

PROJECT UPDATE

Following futhter tests with a focus on flexibility and constrains in varying input parameters, the WCA Nasal code has been upgraded. Once again, the upgraded Nasal code is open to review @ http://wiki.flightgear.org/User:Awexome/WCA

awexome
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU

Re: Wind Correction Angle

Postby awexome » Fri May 04, 2012 4:36 pm

PROJECT UPDATE

Hello, Hello.

I hereby announce that the WCA Nasal code has been upgraded to enhance portability as a 'service' accessible to other Nasal code, FMS and their device UI, CDUs , EFB, autopilot controllers and filters.
In demonstrating a use case, the WCA system has been fitted to the still developing 787-8 - see pictures below.
The upgraded code is now open for general review and comments @ http://wiki.flightgear.org/User:Awexome/WCA

mijiny <aka awexome[2138]>

Illustrative images now in the luggage check-in ...

Below is a view of the near latest version of the WCA UI

Image


The following images provide a compative glimpse of the development stages, thus far.

Image

Image

Image

Image
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU

Re: Wind Correction Angle

Postby awexome » Sat May 19, 2012 5:48 pm

Hello All,

following recent development in other project (the advanced track mode system), there have been much lessons learned. This will likely be benefitial in the current Wind Correction Angle project. For example, there may be potentials to enhance the accuracy of WCA calculations, better debug routines, further optimization of 'property3' usage, and general code re-structure(if there is found to be enough merit and potential for improving performance).

It is expected that the WCA project in general will see some upgrade in the very near future.

awexomely :)


.... huhh ... need to drink more water ...
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU

Re: Wind Correction Angle

Postby awexome » Thu Jun 07, 2012 11:39 am

NEWS HEADLINE

Following much tests, advancement and upgrade of the 'wind correction angle' Nasal implementation, the code base of this project has now been ported to C++. Awexomely.

The following images illustrates the build process and the general initial tests of the C++ code using the FG Nasal console.


Image


Image

Future work in this project will aim to improve the performance, input tolerance and flexibility of the 'Wind Correction Angle Computer' code using C++ performance features where applicable.
When one thinks, one looks up to the skies.
I inspire, think, and seek the skies ------- mijiny <aka awexome[2138]>
awexome
 
Posts: 111
Joined: Sat Jan 21, 2012 11:24 am
Location: GMT
Callsign: SHA7
Version: GIT
OS: GNU


Return to New features

Who is online

Users browsing this forum: No registered users and 1 guest