dji_control.hpp
Go to the documentation of this file.
1 
30 #ifndef DJI_CONTROL_H
31 #define DJI_CONTROL_H
32 
33 #include "dji_ack.hpp"
34 #include "dji_type.hpp"
35 #include "dji_vehicle_callback.hpp"
36 
37 namespace DJI
38 {
39 namespace OSDK
40 {
41 
42 // Forward Declarations
43 class Vehicle;
44 
48 class Control
49 {
50 
51 public:
55  {
56  public:
57  /*
58  * @note Matrice 100 flight commands
59  */
60  typedef struct LegacyCMD
61  {
62  const static int goHome = 1;
63  const static int takeOff = 4;
64  const static int landing = 6;
65  } LegacyCMD;
66 
67  /*
68  * @note OSDK release 3.3
69  */
70  const static int takeOff = 1;
71  const static int landing = 2;
72  const static int courseLock = 5;
75  const static int goHome = 6;
76  const static int startMotor = 7;
77  const static int stopMotor = 8;
78  const static int calibrateCompass = 9;
79  const static int exitGoHome = 12;
80  const static int exitTakeOff = 13;
81  const static int exitLanding = 14;
82  const static int exitCalibrateCompass = 21;
83  const static int landingGearDown = 28;
84  const static int landingGearUp = 29;
85  };
86  // clang-format off
97  {
114  };
115 
127  {
160  };
163  enum YawLogic
164  {
170  YAW_ANGLE = 0x00,
176  YAW_RATE = 0x08
177  };
178 
182  {
187  };
188 
200  {
201  STABLE_DISABLE = 0x00,
203  };
204 
209  {
210  ENABLE = 0x01,
211  DISABLE = 0x02
212  };
213 // clang-format on
214 
218 #pragma pack(1)
219 
222  typedef struct CtrlData
223  {
224  uint8_t flag;
232  float32_t x;
234  float32_t y;
236  float32_t z;
237  float32_t yaw;
247  CtrlData(uint8_t in_flag, float32_t in_x, float32_t in_y, float32_t in_z,
248  float32_t in_yaw);
249  } CtrlData; // pack(1)
250 
255  typedef struct AdvancedCtrlData
256  {
257  uint8_t flag;
258  uint8_t advFlag;
259  float32_t x;
260  float32_t y;
261  float32_t z;
262  float32_t yaw;
263  float32_t xFeedforward;
264  float32_t yFeedforward;
265 
266  AdvancedCtrlData(uint8_t in_flag, float32_t in_x, float32_t in_y,
267  float32_t in_z, float32_t in_yaw, float32_t x_forw,
268  float32_t y_forw);
269  } AdvancedCtrlData; // pack(1)
270 
271  typedef struct LegacyCMDData
272  // CMD data supported in Matrice 100
273  {
274  uint8_t sequence;
275  uint8_t cmd;
276  } LegacyCMDData; // pack (1)
277 
278  typedef struct KillSwitchData
279  {
280  uint8_t high_version;
281  uint8_t low_version;
282  uint8_t debug_description[10];
283  uint8_t cmd : 2;
284  uint8_t reserved : 6;
285  } KillSwitchData; // pack(1)
286 
287 
288 #pragma pack()
289 
300 private:
301  const int wait_timeout;
302 
303 public:
304  Control(Vehicle* vehicle = 0);
305  ~Control();
306 
307  Vehicle* vehicle;
308 
309 
311 
320  void obtainCtrlAuthority(VehicleCallBack callback = 0, UserData userData = 0);
328  ACK::ErrorCode obtainCtrlAuthority(int timeout);
337  void releaseCtrlAuthority(VehicleCallBack callback = 0,
338  UserData userData = 0);
347 
356  void action(const int cmd, VehicleCallBack callback = 0,
357  UserData userData = 0);
366  ACK::ErrorCode action(const int cmd, int timeout);
367 
373  ACK::ErrorCode armMotors(int wait_timeout);
380  void armMotors(VehicleCallBack callback = 0, UserData userData = 0);
381 
387  ACK::ErrorCode disArmMotors(int wait_timeout);
394  void disArmMotors(VehicleCallBack callback = 0, UserData userData = 0);
395 
401  ACK::ErrorCode takeoff(int wait_timeout);
408  void takeoff(VehicleCallBack callback = 0, UserData userData = 0);
409 
415  ACK::ErrorCode goHome(int wait_timeout);
422  void goHome(VehicleCallBack callback = 0, UserData userData = 0);
423 
429  ACK::ErrorCode land(int wait_timeout);
436  void land(VehicleCallBack callback = 0, UserData userData = 0);
437 
470  void flightCtrl(CtrlData data);
471 
493  void flightCtrl(AdvancedCtrlData data);
494 
506  void positionAndYawCtrl(float32_t x, float32_t y, float32_t z, float32_t yaw);
507 
520  void velocityAndYawRateCtrl(float32_t Vx, float32_t Vy, float32_t Vz,
521  float32_t yawRate);
522 
534  void attitudeAndVertPosCtrl(float32_t roll, float32_t pitch, float32_t yaw,
535  float32_t z);
536 
549  void angularRateAndVertPosCtrl(float32_t rollRate, float32_t pitchRate,
550  float32_t yawRate, float32_t z);
551 
557  void emergencyBrake();
558 
565  static void actionCallback(Vehicle* vehiclePtr, RecvContainer recvFrame,
566  UserData userData);
567 
577  ACK::ErrorCode killSwitch(KillSwitch cmd, int wait_timeout = 10, char debugMsg[10] = (char *)"OSDK_API");
589  void killSwitch(KillSwitch cmd, char debugMsg[10] = (char *)"OSDK_API", VehicleCallBack callback = 0, UserData userData = 0);
590 
591 private:
597  ACK::ErrorCode setArm(bool armSetting, int timeout);
603  void setArm(bool armSetting, VehicleCallBack callback = 0,
604  UserData userData = 0);
605 
606  static void controlAuthorityCallback(Vehicle* vehiclePtr,
607  RecvContainer recvFrame,
608  UserData userData);
609  /*
610  * Task CMD data to send to the flight controller (supported in Matrice 100)
611  */
612  LegacyCMDData legacyCMDData;
613 }; // class Control
614 
615 } // OSDK
616 } // DJI
617 
618 #endif // DJI_CONTROL_H
void * UserData
This is used as the datatype for all data arguments in callbacks.
Definition: dji_type.hpp:75
void action(const int cmd, VehicleCallBack callback=0, UserData userData=0)
Basic action command for the vehicle, see FlightCommand for cmd choices.
Definition: dji_control.cpp:49
float32_t yaw
Definition: dji_control.hpp:237
ACK::ErrorCode land(int wait_timeout)
Wrapper function for landing.
Definition: dji_control.cpp:287
Definition: dji_control.hpp:184
float32_t z
Definition: dji_control.hpp:236
ACK::ErrorCode takeoff(int wait_timeout)
Wrapper function for take off.
Definition: dji_control.cpp:219
static void actionCallback(Vehicle *vehiclePtr, RecvContainer recvFrame, UserData userData)
A callback function for action non-blocking calls.
Definition: dji_control.cpp:499
struct DJI::OSDK::Control::CtrlData CtrlData
CtrlData used for flight control.
static const int courseLock
Definition: dji_control.hpp:74
struct DJI::OSDK::RecvContainer RecvContainer
Received info.
ACK::ErrorCode killSwitch(KillSwitch cmd, int wait_timeout=10, char debugMsg[10]=(char *)"OSDK_API")
Turn on or off the kill switch.
Definition: dji_control.cpp:437
static const int takeOff
Definition: dji_control.hpp:70
Type definition for new Vehicle-style callbacks.
struct DJI::OSDK::Control::AdvancedCtrlData AdvancedCtrlData
AdvancedCtrlData.
void attitudeAndVertPosCtrl(float32_t roll, float32_t pitch, float32_t yaw, float32_t z)
Control the attitude and vertical position of the vehicle.
Definition: dji_control.cpp:375
Flight control API: high-level actions and low-level control modes.
Definition: dji_control.hpp:48
void releaseCtrlAuthority(VehicleCallBack callback=0, UserData userData=0)
Release the control authority of the api (non-blocking call)
Definition: dji_control.cpp:589
ACK::ErrorCode armMotors(int wait_timeout)
Wrapper function for arming the motors.
Definition: dji_control.cpp:151
CtrlData used for flight control.
Definition: dji_control.hpp:222
void flightCtrl(CtrlData data)
Control the vehicle using user-specified mode.
Definition: dji_control.cpp:321
Definition: dji_control.hpp:143
void(* VehicleCallBack)(Vehicle *vehicle, RecvContainer recvFrame, UserData userData)
Function prototype for all callback functions used in the OSDK.
Definition: dji_vehicle_callback.hpp:76
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::HOR...
Definition: dji_control.cpp:350
Definition: dji_control.hpp:159
CtrlData(uint8_t in_flag, float32_t in_x, float32_t in_y, float32_t in_z, float32_t in_yaw)
CtrlData initialize the CtrlData variable.
Definition: dji_control.cpp:521
struct DJI::OSDK::ACK::ErrorCode ErrorCode
This struct is returned from all blocking calls, except certain mission calls that have explicit type...
KillSwitch
turn on or off the motors for emergency reasons
Definition: dji_control.hpp:208
AdvancedCtrlData.
Definition: dji_control.hpp:255
static const int goHome
Definition: dji_control.hpp:75
void emergencyBrake()
Stop the vehicle in horiz velocity, vert velocity, yaw rate mode (body frame)
Definition: dji_control.cpp:413
static const int landing
Definition: dji_control.hpp:71
StableMode
bit 0 of the 8-bit (7:0) CtrlData.flag.
Definition: dji_control.hpp:199
Definition: dji_control.hpp:210
Definition: dji_control.hpp:201
Definition: dji_control.hpp:135
Definition: dji_control.hpp:211
Definition: dji_control.hpp:151
ACK::ErrorCode goHome(int wait_timeout)
Wrapper function for go Home.
Definition: dji_control.cpp:253
HorizontalCoordinate
bit 2:1 of the 8-bit (7:0) CtrlData.flag
Definition: dji_control.hpp:181
float32_t x
Definition: dji_control.hpp:232
Definition: dji_control.hpp:113
ACK::ErrorCode disArmMotors(int wait_timeout)
Wrapper function for disarming the motors.
Definition: dji_control.cpp:185
Data type and Data Structure definitions for use throughout DJI OSDK.
uint8_t flag
Definition: dji_control.hpp:224
Definition: dji_control.hpp:202
Definition: dji_control.hpp:170
YawLogic
bit 3 of the 8-bit (7:0) CtrlData.flag
Definition: dji_control.hpp:163
Definition: dji_ack.cpp:38
void angularRateAndVertPosCtrl(float32_t rollRate, float32_t pitchRate, float32_t yawRate, float32_t z)
Control the attitude rate and vertical position of the vehicle.
Definition: dji_control.cpp:387
Definition: dji_control.hpp:186
HorizontalLogic
bit 7:6 of the 8-bit (7:0) CtrlData.flag
Definition: dji_control.hpp:126
All DJI OSDK ACK parsing.
void obtainCtrlAuthority(VehicleCallBack callback=0, UserData userData=0)
Obtain the control authority of the api (non-blocking call)
Definition: dji_control.cpp:548
Flight control commands.
Definition: dji_control.hpp:54
VerticalLogic
bit 5:4 of the 8-bit (7:0) CtrlData.flag
Definition: dji_control.hpp:96
Definition: dji_control.hpp:176
Definition: dji_control.hpp:103
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::HORI...
Definition: dji_control.cpp:363
Definition: dji_control.hpp:108
float32_t y
Definition: dji_control.hpp:234