...
...
...
...
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.
For details on implementation, refer below.
How does Waypoint/Path Management Work?
Note that a lot of this information in this section comes from the PicPilot docs, which was last updated on January 6, 2016.
...
Ensure that the radius input is greater than 0 and that the turn direction is either -1 or 1. If the parameters are incorrect, then the get_next_directions() method will return INVALID_PARAMETERS
(equal to 4) and will result in the output data not being updated. (NB: Work will be done to handle this case so the plane does not fly aimlessly)
In all cases, to exit the holding pattern, call the start_circling()
method and pass in true
as the cancelTurning
parameter.
...
As for return values, when the goingHome
parameter is set to true, the method returns true. If it is set to false, then it returns false. (NB: Work will be done to make this an enum so there is no ambiguity between errors and setting the parameter to false)
When this method is called, the waypointBuffer is cleared and the goingHome
parameter is set to true. Afterwards, the state machine should call get_next_directions()
as normal.
...
This section basically just gives a “summary” of how the state machine will interact with the waypoint manager.
Public Functions
All public functions and their basic tasks are included below:
WaypointManager()
→ constructor_WaypointStatus initialize_flight_path()
→ initialize flight path (overloaded)_PathData * initialize_waypoint()
→ initialize waypoint (overloaded)_WaypointStatus get_next_directions()
→ updates _WaypointManager_Data_Out structure with desired heading, altitude, etc.void start_circling()
→ puts plane in hold patternCan be called to exit hold pattern
bool head_home()
Empties waypointBuffer array and tells manager to take plane to homeBase
Makes plane return to following waypointBuffer array
_WaypointStatus change_current_index()
→ changes index of current waypoint_WaypointStatus update_path_nodes()
→ called if you want to update the flight pathvoid clear_path_nodes()
→ empties waypointBuffer array (DANGER)_PathData** get_waypoint_buffer()
→ returns the waypointBuffer array_WaypointBufferStatus get_status_of_index()
→ returns the status of an index in the waypointBuffer array (FREE [0] means empty, FULL [1] means not empty)int get_current_index()
→ gets currentIndex parameter of WaypointManager classint get_id_of_current_index()
→ returns the id of the waypoint that is in waypointBuffer[currentIndex]_PathData * get_home_base()
→ returns the homeBase parameter of the WaypointManager class
Initializing WaypointManager Object
Method(s) you care about: 1
What to pass in:
Latitude and longitude of point used as origin for cartesian coordinate calculations
UWaterloo coordinates:
Lat: 43.467998128
Long: -80.537331184
Initializing Waypoints
Method(s) you care about: 3
What to pass in: refer above
Initializing Flight Path
Method(s) you care about: 2
What to pass in: refer above
Getting Next Directions
Method(s) you care about: 4
What to pass in: refer above
Modifying Flight Path
Method(s) you care about: 6, 7
What to pass in: refer above
Changing Current Waypoint
Method(s) you care about: 5
What to pass in: refer above
Status Methods
Method(s) you care about: 8, 9, 10, 11, 12
What to pass in: (This is method-dependent)
_WaypointBufferStatus get_status_of_index()
→ pass in index of wayponitBuffer array you care about
Error Codes and What they Mean
Useful resources
http://www.movable-type.co.uk/scripts/latlong.html#destPoint
This link came in clutch to understand the calculations that go behind some of the stuff.
PICpilot waypoint manager