This repository was archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
PM Takeoff/Landing Implementation #25
Open
nehasriva025
wants to merge
15
commits into
main
Choose a base branch
from
PM/New_Arch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7221414
Fun new PM branch
nehasriva025 e47a388
Added Common/Inc
nehasriva025 8887527
Adding SM-PM queue and PM-AM queue
nehasriva025 d6e5a97
Fun new PM branch
nehasriva025 cadf9e2
Added Common/Inc
nehasriva025 bb0e928
Adding SM-PM queue and PM-AM queue
nehasriva025 c12daa8
Using CommonDataTypes file
nehasriva025 4aca166
Merge branch 'PM/New_Arch' of https://github.com/UWARG/ZeroPilot-SW-3…
nehasriva025 80869ad
Don't need AM_DataTypes
nehasriva025 daf34f8
added docker pull to docker script
uwuarg 9da3723
More build fixes
nehasriva025 d26fdc1
Merge branch 'PM/New_Arch' of https://github.com/UWARG/ZeroPilot-SW-3…
nehasriva025 11291d7
Build fixes
nehasriva025 49cd137
Making SM Changes
nehasriva025 df85cfb
SM Changes
nehasriva025 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #ifndef ZPSW3_PM_HPP | ||
| #define ZPSW3_PM_HPP | ||
|
|
||
| #include <stdint.h> | ||
| #include "cmsis_os.h" | ||
|
|
||
| #include "PM_StateManager.hpp" | ||
| #include "CommonDataTypes.hpp" | ||
| #include "PM_DataTypes.hpp" | ||
| #include "PM_LandingTakeoffManager.hpp" | ||
|
|
||
| namespace PM | ||
| { | ||
| class PathManagerState; | ||
|
|
||
| // Gives status of Path Manager so we know when it has completed a cycle, or entered failure mode. | ||
| enum Path_Manager_Cycle_Status {COMPLETED_CYCLE = 0, IN_CYCLE, FAILURE_MODE}; | ||
|
|
||
| class PathManager | ||
| { | ||
| public: | ||
| PathManager(); | ||
| inline PathManagerState* getCurrentState() const {return currentState;} | ||
| void execute(); | ||
| void setState(PathManagerState& newState); | ||
| Path_Manager_Cycle_Status getStatus() {return status;} | ||
|
|
||
| //used to determine the stage of the landing sequence | ||
| LandingTakeoffManager vtol_manager; | ||
| FlightStage flight_stage; | ||
| bool isError; | ||
|
|
||
| void storeSmPmQueue(osMessageQId queueId); | ||
| osMessageQId getSmPmQueue(); | ||
|
|
||
| void storePmAmQueue(osMessageQId queueId); | ||
| osMessageQId getPmAmQueue(); | ||
|
|
||
| // void storeUsePmFlag(); | ||
|
|
||
| //GlobalFlag getUsePmFlag(); | ||
|
|
||
| void setSmStruct(const SM_PM_Commands &from_sm_data); | ||
| SM_PM_Commands getSmStruct(); | ||
|
|
||
| AM::AttitudeManagerInput getAmStruct(); | ||
| void setAmStruct(const AM::AttitudeManagerInput &am_instructions); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| private: | ||
| PathManagerState* currentState; | ||
| Path_Manager_Cycle_Status status; | ||
|
|
||
| // Message Q | ||
| osMessageQId SM_to_PM_queue; | ||
| osMessageQId PM_to_AM_queue; | ||
|
|
||
| SM_PM_Commands sm_instructions; | ||
| AM::AttitudeManagerInput am_data; | ||
| }; | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| #endif | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #ifndef PM_DATATYPES_HPP | ||
| #define PM_DATATYPES_HPP | ||
|
|
||
| #include <cstdint> | ||
|
|
||
|
|
||
| /******************************************************************** | ||
| * Enums | ||
| ********************************************************************/ | ||
|
|
||
|
|
||
| // Used by PM to determine the stage of flight | ||
| enum FlightStage{PREFLIGHT = 0, TAKEOFF, CRUISING, LANDING, LANDED, DISARMED, TELEOP}; | ||
|
|
||
|
|
||
| // Used to specify the type of output | ||
| // Where TELEOP_MODE is used by SM to indicate to PM to pass data directly to AM | ||
| enum WaypointType {PATH_FOLLOW = 0, ORBIT_FOLLOW, HOVER_WAYPOINT, TAKEOFF_WAYPOINT, LANDING_WAYPOINT, TRANSITION_WAYPOINT, TELEOP_MODE}; | ||
|
|
||
| enum ModifyFlightPathCommand { NO_FLIGHT_PATH_EDIT = 0, INITIALIZE_FLIGHT_PATH, APPEND, INSERT, UPDATE, DELETE, NUKE }; // Used by cruisingState | ||
| enum GetNextDirectionsCommand { REGULAR_PATH_FOLLOWING = 0, TOGGLE_HOLDING, TOGGLE_HEAD_HOME }; // Used by cruisingState | ||
|
|
||
|
|
||
| /******************************************************************** | ||
| * Important Structs | ||
| ********************************************************************/ | ||
|
|
||
|
|
||
| /** | ||
| * Structure stores information about the waypoints along our path to the destination and back. | ||
| */ | ||
| struct WaypointData { | ||
| int waypointId; // Id of the waypoint | ||
| WaypointData * next; // Next waypoint | ||
| WaypointData * previous; // Previous waypoint | ||
| long double latitude; // Latitude of waypoint | ||
| long double longitude; // Longitude of waypoint | ||
| int altitude; // Altitude of waypoint | ||
| WaypointType waypoint_type; | ||
| double velocity_target; | ||
| }; | ||
|
|
||
| // Used in Cruising State | ||
| struct WaypointManager_Data_In { | ||
| long double latitude; | ||
| long double longitude; | ||
| int altitude; | ||
| double track; | ||
| }; | ||
|
|
||
| struct WaypointManager_Data_Out{ | ||
| float desiredTrack; // Desired track to stay on path | ||
| int desiredAltitude; // Desired altitude at next waypoint | ||
| long double distanceToNextWaypoint; // Distance to the next waypoint (helps with airspeed PID) | ||
| float distanceX, distanceY, distanceZ; | ||
| float rotation; | ||
| //WaypointStatus errorCode; // Contains error codes | ||
| bool isDataNew; // Notifies PID modules if the data in this structure is new | ||
| int desiredAirspeed; // FUN FACT WE NEED THIS | ||
| uint32_t timeOfData; // The time that the data in this structure was collected | ||
| WaypointType waypoint_type; // Output type (determines which parameters are defined) | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| #endif | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #ifndef ZPSW3_PM_INTERFACE_HPP | ||
| #define ZPSW3_PM_INTERFACE_HPP | ||
| /***This interface exists so that freeRTOS can call C-Style functions while not messing up the fact that most of our development is in C++***/ | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| void PathManagerInterfaceInit(void); | ||
|
|
||
| bool PathManagerInterfaceExecute(void); | ||
|
|
||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
|
|
||
| /* Related Confluence Pages | ||
| https://uwarg-docs.atlassian.net/wiki/spaces/ZP/pages/1607630921/Landing+and+Takeoff | ||
| */ | ||
|
|
||
| #ifndef ZPSW3_LANDING_TAKEOFF_MANAGER_HPP | ||
| #define ZPSW3_LANDING_TAKEOFF_MANAGER_HPP | ||
| #include "CommonDataTypes.hpp" | ||
| #include "PM_DataTypes.hpp" | ||
|
|
||
| /******************************************************************** | ||
| * Constants | ||
| ********************************************************************/ | ||
|
|
||
| const double TAKEOFF_TARGET = 4.0; | ||
| const double LANDING_SPEED = 0.2; | ||
| const double MAX_SPEED = 1.0; | ||
|
|
||
| class LandingTakeoffManager{ | ||
|
|
||
| public: | ||
| /****************** | ||
| * EXTERNAL FUNCTIONS | ||
| ******************/ | ||
|
|
||
| /* | ||
| This function sets the ground height if it is called for the first time | ||
| This function returns the takeoff altitude target (ground height + TAKEOFF_TARGET) | ||
|
|
||
| @param double currentAltitude - this variable holds the current altitude value of the aircraft | ||
|
|
||
| @return double - this structure holds the altitude point | ||
| */ | ||
| double getTakeoffAltitudeTarget(double currentAltitude); | ||
|
|
||
| /* | ||
| This function returns the ground height that was set during takeoff | ||
|
|
||
| @param double currentAltitude - this variable holds the current altitude value of the aircraft | ||
|
|
||
| @return double - this structure holds the altitude point | ||
| */ | ||
| double getLandingAltitudeTarget(double currentAltitude); | ||
|
|
||
| /****************** | ||
| * LANDING FUNCTIONS | ||
| ******************/ | ||
|
|
||
| /* | ||
| This function returns a waypoint that the drone should follow | ||
| This waypoint does not have a horizontal component yet, this will come as corrections from the CV team | ||
|
|
||
| @param const SFOutput_t & input - this variable holds the sensor fusion module output | ||
|
|
||
| @return WaypointData - this structure holds the climb point, which the plane will follow until it exits below a certain altitude | ||
| */ | ||
| AM::AttitudeManagerInput createLandingWaypoint(const LOS::LosSFData & input); | ||
|
|
||
| /****************** | ||
| * TAKEOFF FUNCTIONS | ||
| *****************/ | ||
| /* | ||
|
|
||
| /* | ||
| This function returns a waypoint that the drone should follow | ||
| This waypoint does not have a horizontal component yet, this will come as corrections from the CV team | ||
|
|
||
| @param const SFOutput_t & input - this variable holds the sensor fusion module output | ||
|
|
||
| @return WaypointData - this structure holds the climb point, which the plane will follow until it exits at a certain altitude | ||
| */ | ||
| AM::AttitudeManagerInput createTakeoffWaypoint(const LOS::LosSFData & input); | ||
|
|
||
| /*********************************** | ||
| COMMON LANDING AND TAKEOFF FUNCTIONS | ||
| ************************************/ | ||
|
|
||
| /* | ||
| This function returns the desired climb/descend speed given the current altitude | ||
| Because the takeoff and landing target velocities | ||
|
|
||
| @param double currentAltitude - this double holds the current aircraft altitude | ||
|
|
||
| @param double rangeConstant - this double holds the range constant for the path | ||
|
|
||
| @return double - this function will return the desired climb speed for the aircraft | ||
| */ | ||
| double getSpeedTarget(double currentAltitude, double rangeConstant); | ||
|
|
||
| /* | ||
| This function returns a waypoint that the drone should follow | ||
| This waypoint does not have a horizontal component yet, this will come as corrections from the CV team | ||
|
|
||
| @param double midpointAltitude - this variable holds the midpoint of the altitude range. | ||
|
|
||
| @return double - this structure holds the range constant to determine the velocity based on altitude. | ||
| */ | ||
| double getRangeConstant(double midpointAltitude); | ||
|
|
||
| private: | ||
| double groundHeight = -1; // Set by takeoff and used by landing | ||
| double takeoffRangeConstant = 0; // Value set based on the drone altitude when transitioning to takeoff | ||
| double landingRangeConstant = 0; // Value set based on the drone altitude when transitioning to landing | ||
| // TODO: Reset these constants to 0 in case landing is transitioned into multiple times in a flight | ||
| // Note: a range constant value of 0 means a velocity of 0, so drone only moves once value set. | ||
| }; | ||
|
|
||
| #endif | ||
nehasriva025 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Path Manager State Machine Header | ||
| */ | ||
|
|
||
| #ifndef ZPSW3_PM_STATE_MANAGER_HPP | ||
| #define ZPSW3_PM_STATE_MANAGER_HPP | ||
|
|
||
| #include "PM.hpp" | ||
|
|
||
| namespace PM { | ||
| class PathManager; | ||
|
|
||
| class PathManagerState | ||
| { | ||
| public: | ||
| virtual void enter(PathManager* pathMgr) = 0; | ||
| virtual void execute(PathManager* pathMgr) = 0; | ||
| virtual void exit(PathManager* pathMgr) = 0; | ||
|
|
||
| bool operator==(const PathManagerState& rhs) const {return (this == &rhs);} | ||
|
|
||
| virtual ~PathManagerState() {} | ||
|
|
||
| }; | ||
| } | ||
|
|
||
| #endif | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.