Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

This document concerns itself with cruisingState.hpp and cruisingState.cpp within the ./PathManager directory of ZeroPilot.

Responsibilities of Cruising State

Cruising State is responsible for two things: getting the plane’s desired direction and altitude during cruising flight; and updating the flight path if required. The module itself actually provides an API that the state machine (specifically cruisingState::execute()) can use to interact with the Waypoint Manager.

Sending Commands via Telemetry

In order to use the Cruising State module, data must be sent via telemetry. The following code snippet shows what needs to be sent in:

struct Telemetry_Waypoint_Data_t {
    long double latitude;
    long double longitude;
    int altitude;
    float turnRadius;
    int waypointType; // 0 = Path follow, 1 = Orbit, 2 = Hold
};

struct Telemetry_PIGO_t {

    ... other data sent by telemetry

    /* Parameters for the waypoint manager (crusingState) */
    int numWaypoints;
    
    char waypointModifyFlightPathCommand; // 0 = nothing, 1 = initialize flight path, 2 = append, 3 = insert, 4 = update, 5 = delete, 6 = nuke
    bool initializingHomeBase; // 0 = no, 1 = yes
    char waypointNextDirectionsCommand; // 0 = nothing, 1 = start/end holding, 2 = head home
    int holdingAltitude;
    int holdingTurnRadius;
    char holdingTurnDirection; // 0 = CW, 1 = CCW

    // When modifying the flight path.
    int nextId;
    int prevId;
    int modifyId;

    Telemetry_Waypoint_Data_t * waypoints[100]; // Somehow need to get PATH_BUFFER_SIZE here...
    Telemetry_Waypoint_Data_t homebase;
}

The first struct is a template for a waypoint. It contains the essential information and will be used to initialize waypoints in the Cruising State module.

The second struct is the general struct that contains all data sent in by telemetry (variables that don’t concern Cruising State are excluded for obvious reasons).

  • numWaypoints stores the number of waypoints initialized in the waypoints[100] array

  • waypointNextDirectionsCommand is used to indicate if the plane should enter/exit holding patterns, start/stop heading home, or just get the next direction and altitude as normal.

  • Holding specific data

    • holdingAltitude is the altitude that the plane will fly at when holding (in m)

    • holdingTurnRadius is the radius of the plane’s holding pattern (in m)

    • holdingTurnDirection is the direction that the plane will turn (when looking down from above)

  • Modifying flight path

    • waypointModifyFlightPathCommand is used when editing the plane’s flight path to call the correct API for the Waypoint Manager.

    • initilaizingHomeBase is used when initializing the flight path. It indicates that in addition to initializing the flight path, we are also initializing the home base.

    • nextId is used when inserting a waypoint and represents the id of the waypoint that will come after the inserted waypoint

    • prevId is used when inserting a waypoint and represents the id of the waypoint that will come before the inserted waypoint

    • modifyId is used when updating or deleting a waypoint and represents the id of the affected waypoint.

  • Other

    • waypoints[100] stores the waypoints that will be used to modify or initialize the plane’s flight path

      • Length should be 1 when updating, appending, or inserting

      • Length should be greater than 1 when initializing

      • Length should be 0 when deleting, nuking, or doing nothing

    • homebase stores the home base when it is being initialized.

Functions Declared

Here is cruisingState.hpp:

#include "pathDatatypes.hpp"
#include "waypointManager.hpp"

#ifndef CRUISING_STATE
#define CRUISING_STATE

struct _CruisingState_Telemetry_Return {
    char editingFlightPathErrorCode; // 0 = success, 1 = error, 2 = incorrect telemetry command
    char pathFollowingErrorCode; // 0 = success, 1 = error, 2 = home base not initialized, 3 = incorrect telemetry command
    int currentWaypointId; 
    int currentWaypointIndex;
    bool homeBaseInitialized;
};

// The following functions are used to interact with the Waypoint Manager module
int editFlightPath(Telemetry_PIGO_t * telemetryData, WaypointManager& cruisingStateManager, int * idArray);

int pathFollow(Telemetry_PIGO_t * telemetryData, WaypointManager& cruisingStateManager, _WaypointManager_Data_In input, _WaypointManager_Data_Out * output, bool& goingHome, bool& inHold);

void setReturnValues(_CruisingState_Telemetry_Return * _returnToGround, WaypointManager& cruisingStateManager, int editErrorCode, int pathErrorCode);

// The following functions are used to update the ID array that is a part of the CruisingState class
void appendNewElement(int * idArray, int newId);
int indexOfDesiredId(int * idArray, int id);
void insertNewElement(int * idArray, int prevId, int newId);
void updateElement(int * idArray, int oldid, int newId);
void removeElement(int * idArray, int id);
void clearArray(int * idArray);

#endif

The struct, _CruisingState_Telemetry_Return will be used by the commsWithTelemetry state when preparing to send data to the ground. It contains data regarding the current state of the waypoint manager and whether any commands executed properly. Error codes, which are included below, are also sent through this struct.

  • Error Codes:

    • editingFlightPathErrorCode:

      • 0 = success

      • 1 = error

      • 2 = incorrect telemetry command

    • pathFollowingErrorCode:

      • 0 = success

      • 1 = error

      • 2 = incorrect telemetry command

      • 3 = going home failed because the home base is not initialized

The function editFlightPath() is called every time cruisingState::execute() is run. Using commands sent from telemetry, it will update the plane’s flight path by calling the appropriate Waypoint Manager API.

The function pathFollow() is called every time cruisingState::execute() is run. Using commands sent from telemetry, it will either get the plane’s next directions and altitude, make the plane enter/exit a holding pattern, or make the plane start/stop heading home.

The function setReturnValues() populates an instance of the _CruisingState_Telemetry_Return with relevant data.

The functions on lines 23 through 28 are used to update an id array that is stored in the cruisingState class. The functions are called when needed by editFlightPath.

Testing

Unit tests were written in Test_CruisingState.cpp to test the functions declared in cruisingState.hpp. The unit tests tested the following:

  1. Incorrect telemetry commands returns error codes

  2. Initializing the flight path works

  3. Nuking the flight path works

  4. Appending a waypoint

    1. Case where it works

    2. Case where it fails

  5. Inserting a waypoint

    1. Case where it works

    2. Case where it fails

  6. Updating a waypoint

    1. Case where it works

    2. Case where it fails

  7. Deleting a waypoint

    1. Case where it works

    2. Case where it fails

  8. Successfully getting the next flight direction and altitude

  9. Entering a holding pattern successfully, and returning correct next flight direction and altitude

  10. Successfully start and stop heading to home base

  11. Fail to start heading to home base

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.