dji_advanced_sensing.hpp
Go to the documentation of this file.
1 
12 #ifndef ONBOARDSDK_DJI_ADVANCED_SENSING_H
13 #define ONBOARDSDK_DJI_ADVANCED_SENSING_H
14 
15 #include "dji_type.hpp"
16 #include <cstring>
17 #include "dji_advanced_sensing_protocol.hpp"
18 #include "dji_version.hpp"
19 #include "dji_liveview.hpp"
20 #include "dji_perception.hpp"
21 
22 #include "dji_camera_stream.hpp"
23 
24 namespace DJI {
25 namespace OSDK {
26 
27 // Forward Declaration
28 class Vehicle;
29 
30 #pragma pack(1)
31 typedef struct DataConfig
32 {
33  uint32_t data_flag : 1;
34  uint32_t data_freq : 4;
35  uint32_t data_reserved : 27;
36 } DataConfig;
37 
38 typedef struct ImgConfig
39 {
40  uint32_t img_flag : 1;
41  uint32_t img_freq : 4;
42  uint32_t img_resolution : 4;
43  uint32_t img_reserved : 23;
44 } ImgConfig;
45 
46 typedef struct VGAConfig
47 {
48  ImgConfig image_selection[2][CAMERA_PAIR_NUM];
49  DataConfig reserved_0;
50  DataConfig reserved_1;
51  DataConfig reserved_2;
52  DataConfig reserved_3;
53  DataConfig reserved_4;
54 } VGAConfig;
55 
56 typedef struct AdvancedSensingConfig
57 {
58  bool is_stereo_img_subscribed;
59  uint32_t image_selected[CAMERA_PAIR_NUM][IMAGE_TYPE_NUM];
60  bool is_vga_img_subscribed;
61  VGAConfig vga_subscription;
62 } AdvancedSensingConfig;
63 #pragma pack()
64 
70 public:
71 #pragma pack(1)
72 
76  typedef struct ImageSelection {
77  uint16_t front_left : 1;
78  uint16_t front_right : 1;
79  uint16_t down_front : 1;
80  uint16_t down_back : 1;
81  uint16_t back_left : 1;
82  uint16_t back_right : 1;
83  uint16_t reserved : 10;
85 #pragma pack()
86 
90  {
91  RECV_FRONT_LEFT = 10,
92  RECV_FRONT_RIGHT = 11,
93  RECV_DOWN_BACK = 0,
94  RECV_DOWN_FRONT = 1,
95  RECV_FRONT_DEPTH = 15,
96  };
97 
98 public:
99  AdvancedSensing(Vehicle* vehiclePtr);
100 
101  ~AdvancedSensing();
109  void init();
110 
111  void deinit();
120  void subscribeStereoImages(const ImageSelection *select, VehicleCallBack callback = 0, UserData userData = 0);
128  void subscribeFrontStereoVGA(const uint8_t freq, VehicleCallBack callback = 0, UserData userData = 0);
135  void subscribeFrontStereoDisparity(VehicleCallBack callback = 0, UserData userData = 0);
147  void unsubscribeVGAImages();
156  static void stereoCallback(Vehicle* vehiclePtr, RecvContainer recvFrame, UserData userData);
165  static void VGACallback(Vehicle* vehiclePtr, RecvContainer recvFrame, UserData userData);
176  bool startFPVCameraStream(CameraImageCallback cb = NULL, void * cbParam = NULL);
187  bool startMainCameraStream(CameraImageCallback cb = NULL, void * cbParam = NULL);
194  void setAcmDevicePath(const char *acm_path);
195 
202  void stopFPVCameraStream();
203 
210  void stopMainCameraStream();
235  bool getFPVCameraImage(CameraRGBImage& copyOfImage);
246  bool getMainCameraImage(CameraRGBImage& copyOfImage);
247 
258  LiveView::LiveViewErrCode changeH264Source(LiveView::LiveViewCameraPosition pos,
259  LiveView::LiveViewCameraSource source);
260 
275  LiveView::LiveViewErrCode startH264Stream(LiveView::LiveViewCameraPosition pos, H264Callback cb, void *userData);
276 
288  LiveView::LiveViewErrCode stopH264Stream(LiveView::LiveViewCameraPosition pos);
289 
301  Perception::PerceptionErrCode subscribePerceptionImage(Perception::DirectionType direction, Perception::PerceptionImageCB cb, void* userData);
302 
311  Perception::PerceptionErrCode unsubscribePerceptionImage(Perception::DirectionType direction);
312 
321  Perception::PerceptionErrCode triggerStereoCamParamsPushing();
322 
335  void setStereoCamParamsObserver(Perception::PerceptionCamParamCB cb, void *userData);
336 
337 private:
338  void sendCommonCmd(uint8_t *data, uint8_t data_len, uint8_t cmd_id);
339 
340 private:
341 AdvancedSensingProtocol* advancedSensingProtocol;
342 Vehicle* vehicle_ptr;
343 DJICameraStream* mainCam_ptr;
344 DJICameraStream* fpvCam_ptr;
345 LiveView *liveview;
346 Perception *perception;
347 const char* acm_dev;
348 map<LiveView::LiveViewCameraPosition, DJICameraStreamDecoder*> streamDecoder;
349 
350 public:
351 AdvancedSensingProtocol* getAdvancedSensingProtocol();
352 
353 public:
354 VehicleCallBackHandler stereoHandler;
355 VehicleCallBackHandler vgaHandler;
356 };
357 
358 } // OSDK
359 } // DJI
360 
361 #endif //ONBOARDSDK_DJI_ADVANCED_SENSING_H
void * UserData
This is used as the datatype for all data arguments in callbacks.
Definition: dji_type.hpp:75
void stopMainCameraStream()
Stop the Main Camera RGB Stream.
void setStereoCamParamsObserver(Perception::PerceptionCamParamCB cb, void *userData)
Set the callback to catch the perception camera parameters. (Only for M300 series)
Perception::PerceptionErrCode triggerStereoCamParamsPushing()
Trigger the perception parameters to be passed to the callback which is registered by DJI::OSDK::Perc...
static void stereoCallback(Vehicle *vehiclePtr, RecvContainer recvFrame, UserData userData)
A default callback function for QVGA stereo images.
Perception::PerceptionErrCode unsubscribePerceptionImage(Perception::DirectionType direction)
Unsubscribe the perception camera image stream (Only for M300 series)
LiveView::LiveViewErrCode startH264Stream(LiveView::LiveViewCameraPosition pos, H264Callback cb, void *userData)
Start the FPV or Camera H264 Stream.
void stopFPVCameraStream()
Stop the FPV RGB Stream.
void unsubscribeVGAImages()
unsubscribe to VGA (480x640) stereo images
void setAcmDevicePath(const char *acm_path)
Set the ACM device path, mainly for M210V2.
void subscribeFrontStereoDisparity(VehicleCallBack callback=0, UserData userData=0)
subscribe to QVGA (240x320) stereo depth map at 10 fps
void(* VehicleCallBack)(Vehicle *vehicle, RecvContainer recvFrame, UserData userData)
Function prototype for all callback functions used in the OSDK.
Definition: dji_vehicle_callback.hpp:76
Perception::PerceptionErrCode subscribePerceptionImage(Perception::DirectionType direction, Perception::PerceptionImageCB cb, void *userData)
Subscribe the perception camera image stream (Only for M300 series)
static const uint8_t CAMERA_PAIR_NUM
Definition: dji_type.hpp:99
Definition: dji_advanced_sensing.hpp:69
bool getFPVCameraImage(CameraRGBImage &copyOfImage)
Get a copy of the new image from the FPV camera.
void subscribeFrontStereoVGA(const uint8_t freq, VehicleCallBack callback=0, UserData userData=0)
subscribe to VGA (480x640) front stereo images at 10 or 20 fps
void init()
subscribe to QVGA (240x320) stereo images at 20 fps
bool newFPVCameraImageIsReady()
Check if a new image from the FPV camera is received.
Received info.
Definition: dji_vehicle_callback.hpp:59
ReceivedImgDesc
This struct is used to pair img data with camera.
Definition: dji_advanced_sensing.hpp:89
struct DJI::OSDK::AdvancedSensing::ImageSelection ImageSelection
This struct provides an interface for user to determine what images to subscribe to.
Camera dji perception API of OSDK.
The CallBackHandler struct allows users to encapsulate callbacks and data in one struct.
Definition: dji_vehicle_callback.hpp:83
static void VGACallback(Vehicle *vehiclePtr, RecvContainer recvFrame, UserData userData)
A default callback function for VGA stereo images.
This struct provides an interface for user to determine what images to subscribe to.
Definition: dji_advanced_sensing.hpp:76
void unsubscribeStereoImages()
unsubscribe to QVGA (240x320) stereo depth map or images
Camera liveview API of OSDK.
bool startMainCameraStream(CameraImageCallback cb=NULL, void *cbParam=NULL)
Start the Main Camera Stream.
bool newMainCameraImageReady()
Check if a new image from the main camera is received.
bool startFPVCameraStream(CameraImageCallback cb=NULL, void *cbParam=NULL)
Start the FPV Camera Stream.
Data type and Data Structure definitions for use throughout DJI OSDK.
bool getMainCameraImage(CameraRGBImage &copyOfImage)
Get a copy of the new image from the main camera.
void subscribeStereoImages(const ImageSelection *select, VehicleCallBack callback=0, UserData userData=0)
subscribe to 240p stereo images at 20 fps
Definition: dji_ack.cpp:38
Drone/SDK Version definition for DJI onboardSDK library.
LiveView::LiveViewErrCode stopH264Stream(LiveView::LiveViewCameraPosition pos)
Stop the FPV or Camera H264 Stream.
LiveView::LiveViewErrCode changeH264Source(LiveView::LiveViewCameraPosition pos, LiveView::LiveViewCameraSource source)
Change the camera stream source from one payload device. (Beta API)