The Museum of HP Calculators

# True Heading and Ground Speed

This program is supplied without representation or warranty of any kind. The author and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

## Description

• This routine calculates the heading to be used and the resultant ground speed given true airspeed, desired course, wind speed and direction.
• Works equally well on HP-29C, HP-41C and an HP-15C which I've tried.
• Much easier than trying to fumble with general purpose triangle solvers (and lighter weight too). Loaded into the HP-29C, it still leaves considerable room for other routines.
• A listing for the HP-48G is also included. Note that I'm not as proficient at HP-48G programming, but it weighs in at 177 bytes versus the approximate 30 bytes of the other calculators! (It does have one extra feature, which if taken out brings it down to 142 bytes.)
• On the HP-41C or HP-48 it would be easy to add a wrapper function to prompt the user if you're so inclined.
• You might also want to check for a negative heading and add 360. This is also easy to add. At step 27 add a test X<0? and then branch to a subroutine which adds 360. It's also possible that the heading will be over 360 degrees, but this is also easy to manually correct for, so I've left it as is.
• I haven't figured out a way to get the results without using a register. (If anyone does see a way, please let me know!) I've used register 09, as this seemed out of the way of most things. It's just a scratch register however, and any register can be used.
(Note: on the 29C this is actually somewhat useful. The 29C only saves the X register from the stack if you power off. If you need the heading again when you power it back on, just recall R09.)
• I was going to draw a fancy picture of the wind triangle etc., but you've all probably seen them anyway. (If anyone wants to draw one with all the references etc., I'll include it.)
```
Input:
T = Desired course (track)
Z = True Airspeed (TAS)
Y = Wind direction
X = Wind velocity

Output:
Y = Heading to steer to make course true
X = Ground speed

R09 = Heading also stored here (useful on 29C if turned off
as the Y register is not saved)

```

## Notes

The calculations will not work if the wind is directly along the course, either as a headwind or tailwind (0 degrees or 180 degrees relative to desired course). This is not a problem, as the heading is the same as the course and wind speed is just added or subtracted from the true airspeed in this case. (To avoid the divide by zero error, you could actually just add something like .001 to the wind direction and have it work if you must.)

Also make certain that the velocities and headings are in the same units. eg. MPH vs knots and true or magnetic north. Also note that the wind direction is the direction the wind is coming from (actually 180 degrees relative to the direction the wind is traveling).

I recently purchased a book called Cockpit Computers by Paul Garrison from eBay hoping that it might provide more insight into some useful routines for flying. No such luck. The book was published in 1982 and is interesting mostly for historical purposes, but did not even mention the clock module for the HP-41C for example (which I think was available by then). It also had an interesting comment for the problem this routine solves:

"Also, these problems [ground speed and heading with wind] cannot be solved with a standard calculator. The mathematics involved are so complicated that even the computers take 5 or more seconds to come up with an answer."

Final note: if anyone has other routines they use for flying, or anything else for that matter, I'd like to encourage you to share them here. We need to build up a library again! Let me know if anyone is interested in seeing other routines for flying or ham radio. (I've had my ham license for awhile, but I've just started on pilot training...) Thanks.

Final final note: This program is free and I hope you find it useful. I believe that the formulae are correct and will produce the desired results. It does not come with any warrantees however. Use at your own risk and with common sense. Don't blame me for any plane crashes! Having said that, it does seem to work correctly with the testing I've done to date. If anyone sees any mistakes, please let me know.

## Example

Desired course is 30 degrees. True airspeed (TAS) is 170 knots. The wind is 20 knots and coming from 80 degrees. Find ground speed and heading to steer to make true.

`     30 ENTER↑ 170 ENTER↑ 80 ENTER↑ 20  GSB 0`

The display will pause briefly showing the course correction (5.17 degrees). (You could also call this the negative drift from the heading?) It will finish with the heading to steer (35.17 degrees) in the Y register and ground speed (156.45 knots) in X.

You can verify this is correct by using the polar to rectangular conversions and summation function. (Use Sigma- for winds because the convention is to report winds 180 degrees from the direction they are blowing.)

```     CLEAR Sigma
35.17  ENTER↑ 170  →R   Sigma+
80     ENTER↑  20  →R   Sigma-
RCL Sigma
→P ```

You should now have the course (30 degrees) in Y and ground speed (156.45 knots) in X.

## Program Listings

My convention is to have comments preceded with a "#" hash symbol for most calculators except the listing for the HP-48G. The HP-15C listing is the same as the HP-29C listing without the comments and using the HP-15C keycodes.

For the HP-41C, just pick either listing and ignore the keycodes. The arcsin function on the keyboard is sin-1 but of course displays as asin in programs on the 41C.

The first listing for the HP-29C has many comments to help you follow the way I use the stack to save intermediate results.

### HP-29C Listing

```###########################################################
#
# For the HP-29C
#
01   15 13 00   LBL 0
02         22   RDN
03         21   X⇔Y
04         22   RDN
05         21   X⇔Y
06      23 09   STO 9
###########################################################
# we now have:  T = TAS
#               Z = Vw  Wind speed
#               Y = Dw  Wind direction
#               X = Dc  Desired course
(which is now stored in r09)
###########################################################
07         41   -
08         31   ENTER↑
09      14 52   sin
###########################################################
#               T = TAS
#               Z = Vw
#               Y = Dw-Dc
#               X = sin(Dw-Dc)
###########################################################
10         21   X⇔Y
11         22   RDN        # save Dw-Dc on stack for later
12         61   ×
###########################################################
#               T = Dw-Dc
#               Z = Dw-Dc
#               Y = TAS
#               X = Vw * sin(Dw-Dc)
###########################################################
13         21   X⇔Y
14         71   ÷
15      14 73   LASTx
###########################################################
#               Z = Dw-Dc
#               T = Dw-Dc
#               Y = Vw * sin(Dw-Dc)) / TAS
#               X = TAS
###########################################################
16         22   RDN        # save TAS on stack for later
17      15 52   sin-1      # the course correction factor
18      14 74   PAUSE      # display and add to course
19   23 51 09   STO + 9
###########################################################
#               Z = TAS
#               T = Dw-Dc
#               Y = Dw-Dc
#               X = asin((Vw * sin(Dw-Dc)) / TAS)
#
#  call this heading correction Drift
#
###########################################################
20         41   -
21      14 52   sin
22         21   X⇔Y
23      14 52   sin
###########################################################
#               Z = TAS
#               T = TAS
#               Y = sin(Dw-Dc-Drift)
#               X = sin(Dw-Dc)
###########################################################
24         71   ÷
25         61   ×          # Ground speed
26      24 09   RCL 9      # True heading
#
# Add a test for X<0? here and add 360 if you like.
#
27         21   X⇔Y        # my convention is angle in Y
28      15 12   RTN
29      13 00   GTO 0      # press R/S to start again
#
###########################################################
```

### HP-15C Listing

Same routine, different keycodes.

By the way, is anyone interested in a program lister for the HP-15C? I did one for the HP-29C and there didn't seem to be much interest. (The lister outputs line numbers and mnemonics given the keycodes. Both of these listings here were done with it.)

```###########################################################
#
# For the HP-15C
#
01   42,21,11   LBL A
02         33   RDN
03         34   X⇔Y
04         33   RDN
05         34   X⇔Y
06       44 9   STO 9
07         30   -
08         36   ENTER↑
09         23   SIN
10         34   X⇔Y
11         33   RDN
12         20   ×
13         34   X⇔Y
14         10   ÷
15      43 36   LSTx
16         33   RDN
17      43 23   sin-1
18      42 31   PSE
19    44,40,9   STO + 9
20         30   -
21         23   SIN
22         34   X⇔Y
23         23   SIN
24         10   ÷
25         20   ×
26       45 9   RCL 9
27         34   X⇔Y
28      43 32   RTN```

### HP-48 Listing

The HP-48 listing looks very small and tidy. I'm new at HP-48G programming, so I'm sure it is not all that efficient, but it works.

I've added the ability to round the display of results to a single decimal place if flag 02 is set. I normally have the calculator in STD format mode and having full precision is unnecessarily messy, but if called as a subroutine for other calculations you probably want to maintain the full precision.

The program as is is 177 bytes. If you delete the flag testing and rounding code (from the flag test down to IFT) it shaves it down to 142 bytes or about 5 times the code size on the legacy machines! I guess it's the named variables or something, but it seems a bit excessive for something this small. I know there are ways of compiling system level code, but perhaps someone could send me a better user RPL implementation? Perhaps strictly using the stack instead of variables would be better?

Instead of pausing to display the heading correction factor, this routine just leaves it on the stack (third level); otherwise it operates just like the others.

```WIND
«
0
→ tc tas dw vw t
«
dw tc - DUP
't' STO SIN vw *
tas / ASIN DUP DUP
tc + t ROT - SIN
tas * t SIN /
2 FS?
«
3 →LIST 1 RND OBJ→ DROP
»
IFT
»
»```

P.S. As an afterthought, I resubmitted this article (before it went up) after having taken a stab at redoing the routine without variables; just using the stack. It could probably be improved further, but is now a reasonable size (for me anyway) at 128 bytes. Perhaps a little harder to understand, but that's the tradeoff.

```WIND
«
SWAP 4 PICK - DUP
5 ROLLD SIN * OVER
/ ASIN
DUP DUP 6 ROLLD 4 ROLL +
4 ROLLD ROT DUP SIN
SWAP ROT - SIN SWAP / *

2 FS?
«
3 →LIST 1 RND OBJ→ DROP
»
IFT
»```

\$Id: wind.html,v 1.13 2000/07/09 17:44:28 bduncan Exp bduncan \$