TinyCircuits Forum

General Category => User Projects / Code Examples => Topic started by: cwleveck on February 04, 2019, 06:12:13 AM

Title: GPS "Pointer" with servos
Post by: cwleveck on February 04, 2019, 06:12:13 AM
Has anyone seen something like this?
I want to do the opposite of GPS navigation...
I would like to input a fixed GPS position and have the Tinyduino use two servos, one for elevation and the other for direction, like a pan and tilt.
I want to mount a pointer to the pan and tilt that will ALWAYS point directly, as the crow flies, to the saved coordinates.
Like a return to home.
No matter where you go, anywhere in the world, the pointer will always point back to home....
I have seen something EXACTLY like this in the past, many years ago, and for the life of me can't find it again....
Title: Re: GPS "Pointer" with servos
Post by: mjculross on February 07, 2019, 10:26:00 PM
Not sure about the tilt part, but would the pan part correspond to the "bearing" in this distance & bearing calculation:

Algorithms for calculating distance & bearing between two points, taken from the following URL:

   http://williams.best.vwh.net/avform.htm

NOTE: These formulas assume the following:

   North latitudes and West longitudes are treated as positive
   South latitudes and East longitudes negative

   The arguments given to cos, sin, and arctan are all in RADIANS

The great circle distance d between two points, where point 1 has coordinates {lat1,lon1} and point 2 has coordinates {lat2,lon2} is given by the following:

   d = acos (sin (lat1) * sin (lat2) + cos (lat1) * cos (lat2) * cos (lon1 - lon2))

The bearing, tc1, looking from point 1 to point 2, is given by the following (NOTE: This formula fails if point 1 is located at one of the two poles).

   IF sin (lon2 - lon1) < 0
      tc1 = acos ((sin (lat2) - sin (lat1) * cos (d)) / (sin (d) * cos (lat1)))
   ELSE
      tc1 = 2 * pi - acos ((sin (lat2) - sin (lat1) * cos (d)) / (sin (d) * cos (lat1)))
   ENDIF

Where the following applies:

   asin (x) = 2 * atan (x / (1 + sqrt (1 - x * x)))

   acos (x) = 2 * atan (sqrt ((1 - x) / (1 + x)))       [ for x >= 0        ]
   acos (x) = pi - 2 * atan (sqrt ((1 + x) / (1 - x)))  [ for x < 0         ]

   atan2 (y, x) = atan (y / x)                          [ for x > 0         ]
   atan2 (y, x) = atan (y / x) + pi                     [ for x < 0, y >= 0 ]
   atan2 (y, x) = pi / 2                                [ for x = 0, y > 0  ]
   atan2 (y, x) = atan (y / x) - pi                     [ for x < 0, y < 0  ]
   atan2 (y, x) = -pi / 2                               [ for x = 0, y < 0  ]
   atan2 (0, 0) is undefined and should give an error.

Mark J Culross
KD5RXT