Flight control API: high-level actions and low-level control modes. More...

#include <dji_control.hpp>

Classes

struct  AdvancedCtrlData
 AdvancedCtrlData. More...
 
struct  CtrlData
 CtrlData used for flight control. More...
 
class  FlightCommand
 Flight control commands. More...
 

Public Types

enum  VerticalLogic {
  VERTICAL_VELOCITY = 0x00,
  VERTICAL_POSITION = 0x10,
  VERTICAL_THRUST = 0x20
}
 bit 5:4 of the 8-bit (7:0) CtrlData.flag More...
 
enum  HorizontalLogic {
  HORIZONTAL_ANGLE = 0x00,
  HORIZONTAL_VELOCITY = 0x40,
  HORIZONTAL_POSITION = 0x80,
  HORIZONTAL_ANGULAR_RATE = 0xC0
}
 bit 7:6 of the 8-bit (7:0) CtrlData.flag More...
 
enum  YawLogic {
  YAW_ANGLE = 0x00,
  YAW_RATE = 0x08
}
 bit 3 of the 8-bit (7:0) CtrlData.flag More...
 
enum  HorizontalCoordinate {
  HORIZONTAL_GROUND = 0x00,
  HORIZONTAL_BODY = 0x02
}
 bit 2:1 of the 8-bit (7:0) CtrlData.flag More...
 
enum  StableMode {
  STABLE_DISABLE = 0x00,
  STABLE_ENABLE = 0x01
}
 bit 0 of the 8-bit (7:0) CtrlData.flag. More...
 
enum  KillSwitch {
  ENABLE = 0x01,
  DISABLE = 0x02
}
 turn on or off the motors for emergency reasons More...
 
typedef struct DJI::OSDK::Control::CtrlData CtrlData
 CtrlData used for flight control. More...
 
typedef struct DJI::OSDK::Control::AdvancedCtrlData AdvancedCtrlData
 AdvancedCtrlData. More...
 
typedef struct DJI::OSDK::Control::LegacyCMDData LegacyCMDData
 
typedef struct DJI::OSDK::Control::KillSwitchData KillSwitchData
 

Public Member Functions

 Control (Vehicle *vehicle=0)
 
void obtainCtrlAuthority (VehicleCallBack callback=0, UserData userData=0)
 Obtain the control authority of the api (non-blocking call) More...
 
ACK::ErrorCode obtainCtrlAuthority (int timeout)
 Obtain the control authority of the api (blocking call) More...
 
void releaseCtrlAuthority (VehicleCallBack callback=0, UserData userData=0)
 Release the control authority of the api (non-blocking call) More...
 
ACK::ErrorCode releaseCtrlAuthority (int timeout)
 Release the control authority of the api (blocking call) More...
 
void action (const int cmd, VehicleCallBack callback=0, UserData userData=0)
 Basic action command for the vehicle, see FlightCommand for cmd choices. More...
 
ACK::ErrorCode action (const int cmd, int timeout)
 Control the vehicle using user-specified mode, see FlightCommand for cmd choices. More...
 
ACK::ErrorCode armMotors (int wait_timeout)
 Wrapper function for arming the motors. More...
 
void armMotors (VehicleCallBack callback=0, UserData userData=0)
 Wrapper function for arming the motors. More...
 
ACK::ErrorCode disArmMotors (int wait_timeout)
 Wrapper function for disarming the motors. More...
 
void disArmMotors (VehicleCallBack callback=0, UserData userData=0)
 Wrapper function for disarming the motors. More...
 
ACK::ErrorCode takeoff (int wait_timeout)
 Wrapper function for take off. More...
 
void takeoff (VehicleCallBack callback=0, UserData userData=0)
 Wrapper function for take off. More...
 
ACK::ErrorCode goHome (int wait_timeout)
 Wrapper function for go Home. More...
 
void goHome (VehicleCallBack callback=0, UserData userData=0)
 Wrapper function for go Home. More...
 
ACK::ErrorCode land (int wait_timeout)
 Wrapper function for landing. More...
 
void land (VehicleCallBack callback=0, UserData userData=0)
 Wrapper function for landing. More...
 
void flightCtrl (CtrlData data)
 Control the vehicle using user-specified mode. More...
 
void flightCtrl (AdvancedCtrlData data)
 Control the vehicle using user-specified mode (overloaded) More...
 
void positionAndYawCtrl (float32_t x, float32_t y, float32_t z, float32_t yaw)
 Control the position and yaw angle of the vehicle. The reference frame is the DJI::OSDK::Control::HORIZONTAL_GROUND (NEU). More...
 
void velocityAndYawRateCtrl (float32_t Vx, float32_t Vy, float32_t Vz, float32_t yawRate)
 Control the velocity and yaw rate of the vehicle. The reference frame is the DJI::OSDK::Control::HORIZONTAL_GROUND (NEU). More...
 
void attitudeAndVertPosCtrl (float32_t roll, float32_t pitch, float32_t yaw, float32_t z)
 Control the attitude and vertical position of the vehicle. More...
 
void angularRateAndVertPosCtrl (float32_t rollRate, float32_t pitchRate, float32_t yawRate, float32_t z)
 Control the attitude rate and vertical position of the vehicle. More...
 
void emergencyBrake ()
 Stop the vehicle in horiz velocity, vert velocity, yaw rate mode (body frame) More...
 
ACK::ErrorCode killSwitch (KillSwitch cmd, int wait_timeout=10, char debugMsg[10]=(char *)"OSDK_API")
 Turn on or off the kill switch. More...
 
void killSwitch (KillSwitch cmd, char debugMsg[10]=(char *)"OSDK_API", VehicleCallBack callback=0, UserData userData=0)
 Turn on or off the kill switch. More...
 

Static Public Member Functions

static void actionCallback (Vehicle *vehiclePtr, RecvContainer recvFrame, UserData userData)
 A callback function for action non-blocking calls. More...
 

Public Attributes

Vehicle * vehicle
 

Detailed Description

Flight control API: high-level actions and low-level control modes.

Member Typedef Documentation

◆ AdvancedCtrlData

AdvancedCtrlData.

Note
for flag, x, y, z, yaw definition see CtrlData.

◆ CtrlData

CtrlData used for flight control.

The struct for CtrlData

Member Enumeration Documentation

◆ HorizontalCoordinate

bit 2:1 of the 8-bit (7:0) CtrlData.flag

Enumerator
HORIZONTAL_GROUND 

Set the x-y of ground frame as the horizontal frame (NEU)

HORIZONTAL_BODY 

Set the x-y of body frame as the horizontal frame (FRU)

◆ HorizontalLogic

bit 7:6 of the 8-bit (7:0) CtrlData.flag

Note
  • Only when the GPS signal is good (health_flag >=3),horizontal position control (HORIZONTAL_POSITION) related control modes can be used.
  • Only when GPS signal is good (health_flag >=3),or when AdvancedSensing system is working properly with Autopilot, horizontal velocity control(HORIZONTAL_VELOCITY)related control modes can be used.
Enumerator
HORIZONTAL_ANGLE 
  • Set the control-mode to control pitch & roll angle of the vehicle.
  • Need to be referenced to either the ground or body frame by HorizontalCoordinate setting.
  • Limit: 35 degree
HORIZONTAL_VELOCITY 
  • Set the control-mode to control horizontal vehicle velocities.
  • Need to be referenced to either the ground or body frame by HorizontalCoordinate setting.
  • Limit: 30 m/s
HORIZONTAL_POSITION 
  • Set the control-mode to control position offsets of pitch & roll directions
  • Need to be referenced to either the ground or body frame by HorizontalCoordinate setting.
  • Limit: N/A
HORIZONTAL_ANGULAR_RATE 
  • Set the control-mode to control rate of change of the vehicle's attitude
  • Need to be referenced to either the ground or body frame by HorizontalCoordinate setting.
  • Limit: 150.0 deg/s

◆ KillSwitch

turn on or off the motors for emergency reasons

Enumerator
ENABLE 

Enable the killswitch

DISABLE 

Disable the killswitch

◆ StableMode

bit 0 of the 8-bit (7:0) CtrlData.flag.

Only works in Horizontal velocity control mode In velocity stable mode, drone will brake and hover at one position once the input command is zero. Drone will try to stay in position once in hover state.

In velocity non-stable mode, drone will follow the velocity command and doesn’t hover when the command is zero. That’s to say drone will drift with the wind.

Enumerator
STABLE_DISABLE 

Disable the stable mode

STABLE_ENABLE 

Enable the stable mode

◆ VerticalLogic

bit 5:4 of the 8-bit (7:0) CtrlData.flag

We suggest developers do not use VERTICAL_POSITION control mode indoor when your UAV flight height is larger than 3 meters. This is because in indoor environments, barometer can be inaccurate, and the vertical controller may fail to keep the height of the UAV.

Enumerator
VERTICAL_VELOCITY 
  • Set the control-mode to control the vertical speed of UAV, upward is positive
  • Limit: -5 to 5 m/s
VERTICAL_POSITION 
  • Set the control-mode to control the height of UAV
  • Limit: 0 to 120 m
VERTICAL_THRUST 
  • Set the control-mode to directly control the thrust
  • Range: 0% to 100%

◆ YawLogic

bit 3 of the 8-bit (7:0) CtrlData.flag

Enumerator
YAW_ANGLE 
  • Set the control-mode to control yaw angle.
  • Yaw angle is referenced to the ground frame.
  • In this control mode, Ground frame is enforeced in Autopilot.
YAW_RATE 
  • Set the control-mode to control yaw angular velocity.
  • Same reference frame as YAW_ANGLE.
  • Limite: 150 deg/s

Member Function Documentation

◆ action() [1/2]

void Control::action ( const int  cmd,
VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Basic action command for the vehicle, see FlightCommand for cmd choices.

Supported Platforms : M210V2, M300
Parameters
cmdaction command from FlightCommand
callbackcallback function
userDatauser data (void ptr)

◆ action() [2/2]

ACK::ErrorCode Control::action ( const int  cmd,
int  timeout 
)

Control the vehicle using user-specified mode, see FlightCommand for cmd choices.

Supported Platforms : M210V2, M300
Parameters
cmdaction command from FlightCommand
timeouttimeout to wait for ACK
Returns
ErrorCode

◆ actionCallback()

void Control::actionCallback ( Vehicle *  vehiclePtr,
RecvContainer  recvFrame,
UserData  userData 
)
static

A callback function for action non-blocking calls.

Parameters
recvFramethe data comes with the callback function
userDataa void ptr that user can manipulate inside the callback

◆ angularRateAndVertPosCtrl()

void Control::angularRateAndVertPosCtrl ( float32_t  rollRate,
float32_t  pitchRate,
float32_t  yawRate,
float32_t  z 
)

Control the attitude rate and vertical position of the vehicle.

Supported Platforms : M210V2, M300
Parameters
rollRateattitude rate set-point in x axis of body frame (FRU) (deg/s)
pitchRateattitude rate set-point in y axis of body frame (FRU) (deg/s)
yawRateattitude rate set-point in z axis of body frame (FRU) (deg/s), input limit see DJI::OSDK::Control::YAW_RATE
zz position set-point in z axis of ground frame (NED) (m), input limit see DJI::OSDK::Control::VERTICAL_POSITION
Note
218 is the flag value of this mode

◆ armMotors() [1/2]

ACK::ErrorCode Control::armMotors ( int  wait_timeout)

Wrapper function for arming the motors.

Supported Platforms : M210V2, M300
Returns
ACK::ErrorCode struct with the acknowledgement from the FC

◆ armMotors() [2/2]

void Control::armMotors ( VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Wrapper function for arming the motors.

Supported Platforms : M210V2, M300
Note
If user does not provide his/her own callback, default callback will be executed

◆ attitudeAndVertPosCtrl()

void Control::attitudeAndVertPosCtrl ( float32_t  roll,
float32_t  pitch,
float32_t  yaw,
float32_t  z 
)

Control the attitude and vertical position of the vehicle.

Supported Platforms : M210V2, M300
Parameters
rollattitude set-point in x axis of body frame (FRU) (deg), input limit see DJI::OSDK::Control::HORIZONTAL_ANGLE
pitchattitude set-point in y axis of body frame (FRU) (deg), input limit see DJI::OSDK::Control::HORIZONTAL_ANGLE
zz position set-point in z axis of ground frame (NED) (m), input limit see DJI::OSDK::Control::VERTICAL_POSITION
yawattitude set-point in z axis of ground frame (NED) (deg)
Note
18 is the flag value of this mode

◆ disArmMotors() [1/2]

ACK::ErrorCode Control::disArmMotors ( int  wait_timeout)

Wrapper function for disarming the motors.

Supported Platforms : M210V2, M300
Returns
ACK::ErrorCode struct with the acknowledgement from the FC

◆ disArmMotors() [2/2]

void Control::disArmMotors ( VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Wrapper function for disarming the motors.

Supported Platforms : M210V2, M300
Note
If user does not provide his/her own callback, default callback will be executed

◆ emergencyBrake()

void Control::emergencyBrake ( )

Stop the vehicle in horiz velocity, vert velocity, yaw rate mode (body frame)

Supported Platforms : M210V2, M300
Note
75 is the flag value of this mode

◆ flightCtrl() [1/2]

void Control::flightCtrl ( CtrlData  data)

Control the vehicle using user-specified mode.

Supported Platforms : M210V2, M300
Parameters
datacontrol set-points and flags

Control Mode Byte

bit 7:6 bit 5:4 bit 3 bit 2:1 bit 0
0b00: HORI_ATTI_TILT_ANG 0b00: VERT_VEL 0b00: YAW_ANG 0b00: ground frame 0b0: non-stable mode
0b01: HORI_VEL 0b01: VERT_POS 0b01: YAW_RATE 0b01: body frame 0b1: stable mode
0b10: HORI_POS 0b10: VERT_THRUST (horizontal frame)
0b11: HORI_ANG_VEL

Command Value

ctrl_flag ctrl_byte roll_or_x pitch_or_y thr_z yaw feedforward_x feedforward_y
uint8_t uint8_t float32 float32 float32 float32 float32 float32
Mode Input Limit
vert_thrust 0 to 100 %
vert_vel -5 to 5 m/s
vert_pos 0 to 120m
hori_ang 35 degrees
hori_vel 30 m/s
hori_acc 7 m/s^2
yaw_rate 150 deg/s

◆ flightCtrl() [2/2]

void Control::flightCtrl ( AdvancedCtrlData  data)

Control the vehicle using user-specified mode (overloaded)

Supported Platforms : M210V2, M300
Note
this mode only works in HORIZONTAL_VELOCITY and the unit of feedforward term is m/s^2
Parameters
datacontrol set-points and flags

Control Advanced Byte

bit 7 bit 6 bit 5 bit 4:3 bit 2:0
adv flag brake_flag yaw_ctrl_flag avoid_atti_limit_enable reserved
(1 for ON, 0 for OFF) (1 for ON, 0 for OFF) (1 for ON, 2 for OFF)

If adv_flag is ON, feedforward of x axis and y axis will work in horiz_vel

If brake_flag is ON, emergency brake will work when you use joystick.

If avoid_atti_limit_enable is ON, copter's atti limit will use avoid_atti_limit, that means the camera could not see the propeller.

If avoid_atti_limit_enable is OFF, copter's atti limit won't use avoid_atti_limit, that means the camera may see the propeller.

◆ goHome() [1/2]

ACK::ErrorCode Control::goHome ( int  wait_timeout)

Wrapper function for go Home.

Supported Platforms : M210V2, M300
Returns
ACK::ErrorCode struct with the acknowledgement from the FC

◆ goHome() [2/2]

void Control::goHome ( VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Wrapper function for go Home.

Supported Platforms : M210V2, M300
Note
If user does not provide his/her own callback, default callback will be executed

◆ killSwitch() [1/2]

ACK::ErrorCode Control::killSwitch ( KillSwitch  cmd,
int  wait_timeout = 10,
char  debugMsg[10] = (char *)"OSDK_API" 
)

Turn on or off the kill switch.

Supported Platforms : M210V2, M300
Parameters
cmdenable or disable the kill switch
wait_timeouttimeout for blocking call
debugMsginject debug message to flight control FW for logging, size limit: 10 bytes
Returns
ACK::ErrorCode struct with the acknowledgement from the FC

◆ killSwitch() [2/2]

void Control::killSwitch ( KillSwitch  cmd,
char  debugMsg[10] = (char *)"OSDK_API",
VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Turn on or off the kill switch.

Supported Platforms : M210V2, M300
Parameters
cmdenable or disable the kill switch
debugMsginject debug message to flight control FW for logging, size limit: 10 bytes
callbackcallback function you want called upon ACK
userDataadditional data you want the callback function to have access to
Note
If user does not provide his/her own callback, default callback will be executed

◆ land() [1/2]

ACK::ErrorCode Control::land ( int  wait_timeout)

Wrapper function for landing.

Supported Platforms : M210V2, M300
Returns
ACK::ErrorCode struct with the acknowledgement from the FC

◆ land() [2/2]

void Control::land ( VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Wrapper function for landing.

Supported Platforms : M210V2, M300
Note
If user does not provide his/her own callback, default callback will be executed

◆ obtainCtrlAuthority() [1/2]

void Control::obtainCtrlAuthority ( VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Obtain the control authority of the api (non-blocking call)

Supported Platforms : M210V2, M300
Parameters
callbackcallback function
userDatauser data (void ptr)

◆ obtainCtrlAuthority() [2/2]

ACK::ErrorCode Control::obtainCtrlAuthority ( int  timeout)

Obtain the control authority of the api (blocking call)

Supported Platforms : M210V2, M300
Parameters
timeouttime to wait for ACK

◆ positionAndYawCtrl()

void Control::positionAndYawCtrl ( float32_t  x,
float32_t  y,
float32_t  z,
float32_t  yaw 
)

Control the position and yaw angle of the vehicle. The reference frame is the DJI::OSDK::Control::HORIZONTAL_GROUND (NEU).

Supported Platforms : M210V2, M300
Parameters
xposition set-point in x axis of ground frame (m)
yposition set-point in y axis of ground frame (m)
zposition set-point in z axis of ground frame (m), input limit see DJI::OSDK::Control::VERTICAL_POSITION
yawyaw set-point (deg)
Note
145 is the flag value of this mode

◆ releaseCtrlAuthority() [1/2]

void Control::releaseCtrlAuthority ( VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Release the control authority of the api (non-blocking call)

Supported Platforms : M210V2, M300
Parameters
callbackcallback function
userDatauser data (void ptr)

◆ releaseCtrlAuthority() [2/2]

ACK::ErrorCode Control::releaseCtrlAuthority ( int  timeout)

Release the control authority of the api (blocking call)

Supported Platforms : M210V2, M300
Parameters
timeouttime to wait for ACK

◆ takeoff() [1/2]

ACK::ErrorCode Control::takeoff ( int  wait_timeout)

Wrapper function for take off.

Supported Platforms : M210V2, M300
Returns
ACK::ErrorCode struct with the acknowledgement from the FC

◆ takeoff() [2/2]

void Control::takeoff ( VehicleCallBack  callback = 0,
UserData  userData = 0 
)

Wrapper function for take off.

Supported Platforms : M210V2, M300
Note
If user does not provide his/her own callback, default callback will be executed

◆ velocityAndYawRateCtrl()

void Control::velocityAndYawRateCtrl ( float32_t  Vx,
float32_t  Vy,
float32_t  Vz,
float32_t  yawRate 
)

Control the velocity and yaw rate of the vehicle. The reference frame is the DJI::OSDK::Control::HORIZONTAL_GROUND (NEU).

Supported Platforms : M210V2, M300
Parameters
Vxvelocity set-point in x axis of ground frame (m/s), input limit see DJI::OSDK::Control::HORIZONTAL_VELOCITY
Vyvelocity set-point in y axis of ground frame (m/s), input limit see DJI::OSDK::Control::HORIZONTAL_VELOCITY
Vzvelocity set-point in z axis of ground frame (m/s), input limit see DJI::OSDK::Control::VERTICAL_VELOCITY
yawRateyawRate set-point (deg/s)
Note
72 is the flag value of this mode

The documentation for this class was generated from the following files: