Overview
This module determines the desired heading and altitude of the aircraft and manages the waypoints (also called “path nodes”) of the plane’s flight path. The module takes in GPS coordinates and altitude measurements and calculates the heading and altitude the plane needs to stay on course. Additionally, the module takes instructions from the state machine to modify the waypoints in the plane’s flight path.
...
Figuring out where the tangent will touch requires some basic trigonometry. [WILL TOUCH ON LATER]. The coordinates at which this occurs can be calculated using:
...
When the state machine creates a new waypoint, it will need to assign it a unique ID. This can be as simple as assigning the first waypoint an ID of 1, and the nth an ID of n. The ID of the waypoint, which is the waypointID
parameter in the _PathData
structure, is an essential feature for finding waypoints within the waypiointBuffer
array.
Here's an explanation I gave on a PR earlier:
When a waypoint is created, it is stored in the waypointBuffer array. However, as waypoints are inserted, deleted, etc. the index of the waypoints will change during the duration of the flight.
For example, say when you initialized the waypointBuffer array, you put w1 at waypointBuffer[2] and w2 at waypointBuffer[3]. However because of deletions and insertions, w1 and w2 are now found at waypointBuffer[5] and waypointBuffer[6]. Now, say you want to insert a new waypoint, w3, between w1 and w2, the state machine cannot do this since it does not know the indices of w1 and w2.
This is where the ID system comes into play. We give each waypoint an ID and make the state machine store an array of integers, where each element is the ID of a waypoint. The order of the elements in the array will match the order with which the waypoint manager executes the waypoints (this will make it easier insert waypoints). If the state machine wants to update or insert a waypoint, it will pass in the IDs of the affected waypoints to the waypoint manager. Using the IDs, the waypoint manager will call a method called get_waypoint_index_from_id(int)
, which will use the ID of the waypoint to get its index in the waypointBuffer array. As a result, we have a reliable way to find the waypoints within the waypointBuffer array :)
...
State Machine and
...
Inputs
Getting desired directions
...
Current GPS Coordinates (longitude and latitude)
...
Waypoints
Since the state machine will be creating waypoints, a question that comes up is: what exactly does the state machine need to initialize within the _PathData
structure before passing it to the waypoint manager:
Previous and next
_PathData
objects → Doesn’t need to be initialized. Waypoint manager will take care of it.Constructor of waypoint manager object:
Ensure the array of
_PathData
objects stores the waypoints in order of execution, the waypoint manager can link them together, so these parameters do not need to be initialized.
Latitude and longitude → Initialize this
Altitude → Initialize this
turnRadius → Only initialize this if the waypoint is a “hold” waypoint.
At a “hold” waypoint, the plane will circle in the sky and wait until further instruction.
waypointType → Initialize this. This has a few allowable values
0 → regular waypoint. Plane will use it to navigate to destination
2 → “Hold” waypoint. Plane will circle and await further instruction
waypointId → Initialize this. This parameter must be unique to each object, otherwise array navigation will be messed up
Inputs and Outputs
Inputs
Getting desired directions
Current GPS Coordinates (longitude and latitude)
Current Altitude
Current Heading
Updating waypointBuffer array
Appending waypoint → structure of new waypoint
Insert waypoint → structure of new waypoint, ID of previous and next waypoint
Updating waypoint → structure of updated waypoint, ID of waypoint that needs to be updated
Deleting waypoint → ID of waypoint that is to be deleted.
...
State machine calls the
get_next_directions()
and passes in appropriate parameters (GPS data and pointer to the output data structure).Algorithm stuff [ADD LATER]
Waypoint manager updates the parameters in the
_WaypointManager_Data_Out
structure that was passed intoget_next_directions()
.
Modifying waypointBuffer Array:
...