Skip to main content

Flight Control

The header file for flight control-related functions is uav_flight_control.h. This document describes the key information and usage of the function prototypes in the uav_flight_control.h file.

Table of Contents

  • Macros, Enums, and Structures
    typedef enum E_UAVFlithtControl_Mode
    typedef enum E_UAVFlightControl_RCLost_Action
    typedef enum E_UAVFlightControl_Emergency_Stop_Motor
    typedef enum E_HEADING_MODE
    typedef enum E_OBSTACLE_MODE
    typedef struct T_UAVFlightControllerRidInfo
    typedef struct T_UAVFlightControlPos
    typedef struct T_UAVFlightControlSpeed
    typedef struct T_UAVFlightControllerHomeLocation
    typedef uint16_t E_UAVFlightControllerGoHomeAltitude
    typedef struct T_UAVFlightControllerGeneralInfo

  • Function Prototypes
    function UAV_FlightControl_Init
    function UAV_FlightControl_Deinit
    function UAV_FlightControl_SetControlMode
    function UAV_FlightControl_GetControlMode
    function UAV_FlightControl_POSControl
    function UAV_FlightControl_SpeedControl
    function UAV_FlightControl_SetRCLostAction
    function UAV_FlightControl_GetRCLostAction
    function UAV_FlightControl_TurnOnMotors
    function UAV_FlightControl_TurnOffMotors
    function UAV_FlightControl_EmergencyStopMotor
    function UAV_FlightControl_StartTakeoff
    function UAV_FlightControl_StartLanding
    function UAV_FlightControl_CancelLanding
    function UAV_FlightControl_StartForceLanding
    function UAV_FlightControl_SetHomeLocationUsingGPSCoordinates
    function UAV_FlightControl_SetHomeLocationUsingCurrentAircraftLocation
    function UAV_FlightControl_SetGoHomeAltitude
    function UAV_FlightControl_GetGoHomeAltitude
    function UAV_FlightControl_StartGoHome
    function UAV_FlightControl_CancelGoHome
    function UAV_FlightControl_GetGeneralInfo

Macros, Enums, and Structures

typedef enum E_UAVFlithtControl_Mode

typedef enum {
UAV_FLIGHTCONTROL_MODE_UNKNOWN = 0,
UAV_FLIGHTCONTROL_MODE_POS_CTL = 1,
UAV_FLIGHTCONTROL_MODE_SPEED_CTL = 2,
}E_UAVFlithtControl_Mode;

typedef enum E_UAVFlightControl_RCLost_Action

The actions of the aircraft when it loses the remote control signal.

typedef enum {
UAV_FLIGHTCONTROL_RC_LOST_ACTION_HOVER = 0, /*!< Aircraft will execute hover cation when rc is lost. */
UAV_FLIGHTCONTROL_RC_LOST_ACTION_LANDING = 1, /*!< Aircraft will execute land cation when rc is lost. */
UAV_FLIGHTCONTROL_RC_LOST_ACTION_GOHOME = 2, /*!< Aircraft will execute go-home cation when rc is lost. */
}E_UAVFlightControl_RCLost_Action;

typedef enum E_UAVFlightControl_Emergency_Stop_Motor

  • Function: Enable/Disable emergency shutdown function enumeration.

    Note:

    • Enabling the emergency shutdown function while in the air is very dangerous and may lead to the aircraft crashing!
typedef enum {
UAV_FLIGHTCONTROL_ENABLE_EMERGENCY_STOP_MOTOR = 1, /*!< Execute emergency-stop-motor action */
}E_UAVFlightControl_Emergency_Stop_Motor;

typedef enum E_HEADING_MODE

typedef enum {
UAV__HEADING_MODE_NONE = 0, /*!< No heading mode. */
UAV__HEADING_MODE_ALONG = 1, /*!< Along the waypoint line direction. */
UAV__HEADING_MODE_BY_PSDK = 2,/*!< Control the heading by psdk from user. */
}E_HEADING_MODE;

typedef enum E_OBSTACLE_MODE

typedef enum {
UAV__OBSTACLE_MODE_NONE = 0, /*!< No obstacle avoidance. */
UAV__OBSTACLE_MODE_LOITER = 1, /*!< Loiter mode. */
UAV__OBSTACLE_MODE_OBS = 2, /*!< Obstacle avoidance mode. */
}E_OBSTACLE_MODE;

typedef struct T_UAVFlightControllerRidInfo

typedef struct {
double latitude; /*!< Specifies latitude, unit: rad */
double longitude; /*!< Specifies longitude, unit: rad */
float altitude; /*!< Specifies altitude, unit: m */
}T_UAVFlightControllerRidInfo;

typedef struct T_UAVFlightControlPos

typedef struct {
float yaw; /*!< Specifies yaw angle. */
double latitude; /*!< Specifies latitude. */
double longitude; /*!< Specifies longitude. */
double altitude; /*!< Specifies altitude. */
int32_t obstacle_mode; /*!< Specifies obstacle mode, see E_OBSTACLE_MODE. */
}T_UAVFlightControlPos;

typedef struct T_UAVFlightControlSpeed

typedef struct {
float x; /*!< Specifies x coordinate. */
float y; /*!< Specifies y coordinate. */
float z; /*!< Specifies z coordinate. */
float yaw; /*!< Specifies yaw angle. */
int32_t heading_mode; /*!< Specifies heading mode, see E_HEADING_MODE. */
int32_t obstacle_mode; /*!< Specifies obstacle mode, see E_OBSTACLE_MODE. */
}T_UAVFlightControlSpeed;

typedef struct T_UAVFlightControllerHomeLocation

typedef struct {
double latitude; /*!< unit: rad */
double longitude; /*!< unit: rad */
} T_UAVFlightControllerHomeLocation; // pack(1)

typedef uint16_t E_UAVFlightControllerGoHomeAltitud

typedef uint16_t E_UAVFlightControllerGoHomeAltitude; /*!< Unit:meter, range 20~500 */

typedef struct T_UAVFlightControllerGeneralInfo

typedef struct {
char serialNum[32];
} T_UAVFlightControllerGeneralInfo;

Function Prototypes

function UAV_FlightControl_Init

  • Function: Flight control initialization request.
extern T_UAVReturnCode UAV_FlightControl_Init(T_UAVFlightControllerRidInfo ridInfo);

function UAV_FlightControl_Deinit

  • Function: Flight control de-registration request.
extern void UAV_FlightControl_Deinit(void);

function UAV_FlightControl_SetControlMode

  • Function: Set flight control mode.
extern T_UAVReturnCode UAV_FlightControl_SetControlMode(E_UAVFlithtControl_Mode mode);

function UAV_FlightControl_GetControlMode

  • Function: Get flight control mode.
extern T_UAVReturnCode UAV_FlightControl_GetControlMode(E_UAVFlithtControl_Mode &mode);

function UAV_FlightControl_POSControl

  • Function: Control flight using position information.
extern T_UAVReturnCode UAV_FlightControl_POSControl(T_UAVFlightControlPos pos);

function UAV_FlightControl_SpeedControl

  • Function: Control flight using speed information.
extern T_UAVReturnCode UAV_FlightControl_SpeedControl(T_UAVFlightControlSpeed speed);

function UAV_FlightControl_SetRCLostAction

Note:

  • This setting takes effect only when both the remote controller and OSDK are disconnected.
extern T_UAVReturnCode UAV_FlightControl_SetRCLostAction(E_UAVFlightControl_RCLost_Action rcLostAction);
  • Parameter
    • rcLostAction: Action to be taken when the remote controller is disconnected (Hover/Land/Return).

function UAV_FlightControl_GetRCLostAction

  • Function: Get the action to be taken when the remote controller is disconnected (Hover/Land/Return).

    Note:

    • This setting only takes effect when both the remote controller and OSDK are disconnected.
extern T_UAVReturnCode UAV_FlightControl_GetRCLostAction(E_UAVFlightControl_RCLost_Action &rcLostAction);
  • Parameters:
    • rcLostAction: The action to be taken when the remote controller is lost (Hover/Land/Return).

function UAV_FlightControl_TurnOnMotors

  • Function: The aircraft starts the motors while on the ground.
extern T_UAVReturnCode UAV_FlightControl_TurnOnMotors(void);

function UAV_FlightControl_TurnOffMotors

  • Function:The aircraft stops the motors while on the ground.
extern T_UAVReturnCode UAV_FlightControl_TurnOffMotors(void);

function UAV_FlightControl_EmergencyStopMotor

  • Function: Emergency stop of the motors under any circumstances.

    Note:

    • You need to use this interface to send a disable command to exit the motor lock state.
extern T_UAVReturnCode UAV_FlightControl_EmergencyStopMotor(E_UAVFlightControl_Emergency_Stop_Motor command, const  char debugMsg[32]);
  • Parameters:
    • debugMsg: Injects debug information into the flight control firmware for logging, with a size limit.
    • cmd: Refer to E_UAVFlightControl_Emergency_Stop_Motor for the reference.

function UAV_FlightControl_StartTakeoff

  • Function: Request takeoff when the aircraft is on the ground.
extern T_UAVReturnCode UAV_FlightControl_StartTakeoff(void);

function UAV_FlightControl_StartLanding

  • Function: Request landing when the aircraft is in the air.
extern T_UAVReturnCode UAV_FlightControl_StartLanding(void);

function UAV_FlightControl_CancelLanding

  • Function: Request to cancel landing when the aircraft is landing.
extern T_UAVReturnCode UAV_FlightControl_CancelLanding(void);

function UAV_FlightControl_StartForceLanding

  • Function: Force landing in any situation.
extern T_UAVReturnCode UAV_FlightControl_StartForceLanding(void);

function UAV_FlightControl_SetHomeLocationUsingGPSCoordinates

  • Function: Set custom GPS (non-RTK) home point location.

    Note:

    • Reasons for failure to set a custom take-off point may include: The distance between the new take-off point and the previous take-off point exceeds MAX_FLY_RADIUS (20km). Failure to record the initial take-off point after startup.
extern T_UAVReturnCode UAV_FlightControl_SetHomeLocationUsingGPSCoordinates(T_UAVFlightControllerHomeLocation homeLocation);

function UAV_FlightControl_SetHomeLocationUsingCurrentAircraftLocation

  • Function: Use the current aircraft's GPS (non-RTK) location to set the home point location.

    Note:

    • Reasons for failure to set the take-off point may include: The aircraft's GPS level does not meet the conditions for recording the take-off point. Failure to record the initial take-off point after startup.
extern T_UAVReturnCode UAV_FlightControl_SetHomeLocationUsingCurrentAircraftLocation(void);;

function UAV_FlightControl_SetGoHomeAltitude

  • Function: Set the return-to-home altitude.

    Note:

    • If the aircraft's current altitude is higher than the set return-to-home altitude, the aircraft will return using the current altitude. Otherwise, it will climb to the set return-to-home altitude and then perform the return-to-home operation. The return-to-home altitude can be set between 20m and 1500m.
extern T_UAVReturnCode UAV_FlightControl_SetGoHomeAltitude(E_UAVFlightControllerGoHomeAltitude altitude);

function UAV_FlightControl_GetGoHomeAltitude

  • Function: Get the return-to-home altitude.
extern T_UAVReturnCode UAV_FlightControl_GetGoHomeAltitude(E_UAVFlightControllerGoHomeAltitude *altitude);

function UAV_FlightControl_StartGoHome

  • Function: Request a return-to-home action when the aircraft is in the air.
extern T_UAVReturnCode UAV_FlightControl_StartGoHome(void);

function UAV_FlightControl_CancelGoHome

  • Function: Request to cancel the return-to-home action when the aircraft is returning home.
extern T_UAVReturnCode UAV_FlightControl_CancelGoHome(void);

function UAV_FlightControl_GetGeneralInfo

  • Function: Get general information about the aircraft.
extern T_UAVReturnCode UAV_FlightControl_GetGeneralInfo(T_UAVFlightControllerGeneralInfo *generalInfo);