Repository Case Labview Common GPS: Red: VI Contains Errors
Repository Case Labview Common GPS: Red: VI Contains Errors
RepositoryCASELabVIEWCommonGPS
*GPS Coordinate.ctl
A class for keeping GPS coordinates
*Line Object.ctl
A class of lines defined by two GPS coordinates
*deg to rad.vi
rad = pi/180 * deg, mod 2pi
*DegreesToRadians.vi
Unlike deg to rad.vi, output not necessarily between 0 and 2pi. Used by
IsLineCrossed.vi
*rad to deg.vi
rad * 180/pi, then coerce to 360
Find GPS Coordinate On Line That Is Given Distance From GPS Location.vi
(See revised version of VI)
Get Earth Radius.vi
Input: Latitude
Output: Radius of the earth at given latitude (in kilometers)
Method: Uses math formula since equatorial radius and polar radius are
different; since earth is not a perfect sphere...
GPS Midpoint.vi
Input: Two GPS coordinates
Output: GPS coordinate of midpoint
Method: Takes GPS coordinates of two points and averages the latitudes and
longitudes (midpoint rule)
Heading_From_GPS_Location_Pair.vi
Input: GPS Coordinate A, GPS Coordinate B
Output: Returns heading for direction A faces to reach B (0 to 360); North would
be 0, East 90, etc (also dy, dx, and GPS of temp point)
Method: Temporary point takes the latitude of A and the longitude of B. Gets
the distance in meters between the temporary point and A, temporary
point and B. If longitude of B is greater than that of A, dx is the former
distance, else negative the former distance. If latitude of B is greater than
that of A, dy is the latter distance, else negative the latter distance. Uses
the inverse tangent function to compute heading in radians, then converts
to degrees, then converts to polar heading and returns result.
Direct Sub-VI’s: Map_Angle-Heading_Converter.vi; Distance Between GPS
Coordinates in Meters.vi
Is A Ahead of B.vi
Input: GPS coordinates of A and B, heading of B(?)
Output: Boolean true or false
Method: Use "Heading_From_GPS_Location_Pair.vi" to get the heading from B
to A. Change from degrees to radians. Take the sine and cosine of both
headings. Think of the sines and cosines as x- and y-components as the
entries of 2-dimensional vectors, for the given heading and the calculated
heading. We can think of the second vector as the vector from B to A.
We then multiply the sines and cosines together, then sum them up, aka
taking the dot product of the two vectors. If the dot product is positive,
then the angle between the two vectors is between 0 and 90, or between
270 and 360, then the dot product is positive (and geometrically, the
vectors point in roughly the same direction), so point A is ahead of B
Direct Sub-VI: Heading_From_GPS_Location_Pair.vi
IsLineCrossed.vi
Input: GPS coordinate; Line Crossed Query (line is determined by GPS location
of a point on the line and a compass direction from -180 degrees to 180
degrees, with 0 degrees as north, > 0 as east, < 0 as west)
Output: Boolean (true for crossed, false for not crossed)
Note: Here angles are between -180 and 180 degrees, compared to 0 and 360 in
other VI's, which could be potentially confusing
Map_Angle-Heading_Converter.vi
Input: HeadDegIn, AnglDegIn
Output: AngDegOut, HeadDegOut
Method: Polar Heading --> Cartesian Angle: 360 - ((phi mod 360)+270) = 90 –
phi mod 360
(if < 0, 450 - phi mod 360)
Cartesian Angle --> Polar Heading: 90 - phi mod 360
(if < 0, 450 - phi mod 360)
Move NE.vi
Input: Distance north, distance east, GPS coordinate of cluster
Output: Latitude and longitude after move
Method: Uses "GPS Location From Given Position.vi" to find latitude and
longitude of cluster after moving NE. First uses sub-vi on cluster with
distance north and heading 0, then plugs in new coordinates for cluster with
distance east and heading 90, then unbundles coordinates to
output the latitude and longitude separately
Point to Line Distance.vi
Input: GPS of a point, GPS of two points determining line
Output: Distance to segment, distance to infinite line
Method: Math looks correct
RepositoryCASELabVIEWPlanner
Best_Path_Given_GPS_Location.vi
Converting a mapped area to a graph (in the math sense) representation: Each
intersection of roads is a “node,” and each segment of road between two nodes
constitutes an “edge.” The length of an edge is the “weight” of the edge.
Input: GPS point of Harlie; target GPS; number of nodes; adjacency matrix
(Format: Entry a_ij is the length of the path from node i to node j. If nodes
i and j are not connected, enter a very large number unlikely to be
confused with a real distance to serve as “infinity.” Also note that for
regular non-directed graphs, the matrix will be symmetric.);
edge table array
(Format: Entry a_i contains the initial and terminal nodes describing the
edge, the length/”weight” of the edge, and the GPS coordinates of
waypoints on the edge, including the two node endpoints).
Output: Closest edge and waypoint to Harlie (within threshold); the two nodal
endpoints of said edge; closest edge and waypoint to GPS target (within
threshold); the two nodal endpoints of said edge; array of nodes on the
shortest path from Harlie to target
Method: Looks up closest edges/waypoints to Harlie and target. For both Harlie
and the target, there are two nodal endpoints for their incident edges. In
both cases, the best path could take either node, so there are 2*2=4
choices. Once the nodes are chosen, then Dijkstra’s algorithm can be
used for the best node-to-node path. Thus the total length of the path is
Harlie-to-Node + Node-to-Node+Node-to-Target, and the shortest of the
four choices is chosen as the best path.
Direct Sub-VI’s: Distance Between GPS Coordinates in Meters.vi;
Dijkstra_Algorithm_for_Node_to_Node.vi; Closest_Edge_Given_
GPS_Location.vi
Dijkstra_Algorithm_for_Node_to_Node.vi
Input: Number of nodes; source node; target node; adjacency matrix; edge table
array
Output: Value table of shortest distances from source to all nodes; shortest
node-to-node path from source node to target node.
Method: Uses Dijkstra’s algorithm to find the shortest path (see pseudo-code on
Wikipedia). Makes use of three main arrays during operation: “Distance
List,” which is updated each iteration to produce the final value table;
“Previous Vertex List,” which is updated each iteration to produce the list
of immediate predecessor nodes for each node, based on its optimal path
from the source node; and the “List of Remaining Nodes,” which is
initialized the same as the distance list and updated the same as the
Distance List each iteration, but for the node to be deleted, which is
reassigned the value of infinity, and when all nodes are set to infinity, all
nodes have been optimized.
Closest_Edge_Given_GPS_Location.vi
Input: GPS point; edge table array
Output: Edge and waypoint closest to GPS point, within a two meter radius of
the given point; the two nodes describing said edge.
Method: Running outer loop, for each edge, looks up its waypoints. Running
inner loop, for each waypoint on the edge, get distance in meters from
GPS point; keep value and edge/waypoint information if distance is
smaller than two meters and smaller than that of previous waypoint. End
of the loops will result in optimal distance, unless there is no waypoint
closer than two meters, in which case the VI returns an error.
Direct Sub-VI: Distance Between GPS Coordinates in Meters.vi