Guidance SDK参考文档

(注:本文档精简总结自 https://developer.dji.com/guidance-sdk/documentation/cn/introduction/index.html,获取更多信息请访问网址)

demo: 用Guidance SDK实现的示例应用
doc: 文档
examples: USB和串口的简单示例程序
include: Guidance SDK头文件
lib: Windows下的库文件
2010/x64: 使用 Visual Studio 2010 64 bit 编译
2010/x86: 使用 Visual Studio 2010 32 bit 编译
2013/x64: 使用 Visual Studio 2013 64 bit 编译
2013/x86: 使用 Visual Studio 2013 32 bit 编译
so: Linux下的库文件
x64: 在64位Linux系统上用 g++ 编译
x86: 在32位Linux系统上用 g++ 编译
XU3: 在XU3上用 g++ 编译
arm: 使用最新的 arm-linux-gnueabi-g++ 编译,供嵌入式ARM系统使用。使用时,请先安装交叉编译工具链:sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

Makefile代码示例

定义编译器

CXX = g++

定义生成文件

TARGET = main

定义生成依赖文件

OBJECTS = main.o DJI_utility.o

定义头文件包含目录

CFLAGS = -g -Wall -I/usr/local/include -I../../../include

定义动态链接库路径、opencv路径及选项

LDFLAGS = -Wl,-rpath,./ -lpthread -lrt -L./ -L/usr/local/lib/ -lDJI_guidance -lusb-1.0 pkg-config --cflags --libs opencv
$(TARGET) : $(OBJECTS)
$(CXX) -o $(TARGET) $(OBJECTS) $(LDFLAGS)
main.o : main.cpp DJI_utility.h
$(CXX) $(CFLAGS) -c main.cpp DJI_utility.h
DJI_utility.o : DJI_utility.cpp DJI_utility.h
$(CXX) $(CFLAGS) -c DJI_utility.cpp DJI_utility.h
clean:
rm -rf *.o *.gch *.avi $(TARGET)

//USE_GUIDANCE_ASSISTANT_CONFIG
数据类型

支持的数据类型描述如下。

数据结构
e_sdk_err_code

描述: 定义SDK的错误代码。

enum e_sdk_err_code
{
e_timeout = -7, // USB传输超时
e_libusb_io_err = -1, // libusb库IO错误
e_sdk_no_err = 0, // 成功,没有错误
e_load_libusb_err=1, // 加载的libusb库错误
e_sdk_not_inited=2, // SDK软件还没有准备好
e_hardware_not_ready=3, // Guidance硬件还没有准备好
e_disparity_not_allowed=4, // 视差图或深度图不允许被选择
e_image_frequency_not_allowed=5, // 图像频率必须是枚举类型e_image_data_frequecy之一
e_config_not_ready=6, // 配置没有准备好
e_online_flag_not_ready=7, // 在线标志没有准备好
e_stereo_cali_not_ready = 8, // 摄像头标定参数没有准备好
e_max_sdk_err = 100 // 错误最大数量
};

解释:

e_vbus_index

描述: 定义VBUS的逻辑方向,即Guidance传感模块的方向。注意它们只取决于Guidance处理模块上的VBUS接口,而不是Guidance传感模块。

每个枚举值的注释说明了当Guidance以默认方式安装在Matrice 100上时该枚举值代表的方向。但开发者可以任意方式安装Guidance在任意的设备上,因此

enum e_vbus_index
{
e_vbus1 = 1, // M100上为前视
e_vbus2 = 2, // M100上为右视
e_vbus3 = 3, // M100上为后视
e_vbus4 = 4, // M100上为左视
e_vbus5 = 0 // M100上为下视
};

e_image_data_frequecy

描述: 定义图像数据的频率。可选的频率有:5Hz, 10Hz, 20Hz. 订阅的图像越多,传输的频率就越低。

enum e_image_data_frequecy
{
e_frequecy_5 = 0, // frequecy of image data: 5Hz
e_frequecy_10 = 1, // frequecy of image data: 10Hz
e_frequecy_20 = 2 // frequecy of image data: 20Hz
};

e_guidance_event

描述: 定义回调的事件类型。

enum e_guidance_event
{
e_image = 0, // called back when image comes
e_imu, // called back when imu comes
e_ultrasonic, // called back when ultrasonic comes
e_velocity, // called back when velocity data comes
e_obstacle_distance, // called back when obstacle data comes
e_motion, // called back when global position comes
e_event_num
};

image_data

描述: 定义图像的数据结构。每个方向的深度图与双目灰度图中的左图对齐。

typedef struct _image_data
{
unsigned int frame_index; // frame index
unsigned int time_stamp; // time stamp of image captured in ms
char *m_greyscale_image_left[CAMERA_PAIR_NUM]; // greyscale image of left camera
char *m_greyscale_image_right[CAMERA_PAIR_NUM]; // greyscale image of right camera
char *m_depth_image[CAMERA_PAIR_NUM]; // depth image in *128 meters
char *m_disparity_image[CAMERA_PAIR_NUM]; // disparity image in *16 pixels
}image_data;

解释:

ultrasonic_data

描述: 定义超声波的数据结构。ultrasonic是超声波传感器检测到的最近物体的距离,单位是mm。reliability是该距离测量的可信度,1为可信,0为不可信。由于观测数据存在噪声,建议对数据进行滤波后再使用。

typedef struct _ultrasonic_data
{
unsigned int frame_index; // corresponse frame index
unsigned int time_stamp; // time stamp of corresponse image captured in ms
short ultrasonic[CAMERA_PAIR_NUM]; // distance in mm. -1 means invalid measurement.
unsigned short reliability[CAMERA_PAIR_NUM]; // reliability of the distance data
}ultrasonic_data;

velocity

描述: 定义体坐标系下的速度。单位是mm/s。

typedef struct _velocity
{
unsigned int frame_index; // corresponse frame index
unsigned int time_stamp; // time stamp of corresponse image captured in ms
short vx; // velocity of x in mm/s
short vy; // velocity of y in mm/s
short vz; // velocity of z in mm/s
}velocity;

obstacle_distance

描述: 定义由视觉和超声波融合得到的障碍物距离。单位是cm。

typedef struct _obstacle_distance
{
unsigned int frame_index; // corresponse frame index
unsigned int time_stamp; // time stamp of corresponse image captured in ms
unsigned short distance[CAMERA_PAIR_NUM]; // distance of obstacle in cm
}obstacle_distance;

imu

描述: 定义IMU数据结构。加速度单位为m/s^2。

typedef struct _imu
{
unsigned int frame_index; // corresponse frame index
unsigned int time_stamp; // time stamp of corresponse image captured in ms
float acc_x; // acceleration of x in unit of m/s^2
float acc_y; // acceleration of y in unit of m/s^2
float acc_z; // acceleration of z in unit of m/s^2
float q[4]; // quaternion: [w,x,y,z]
}imu;

stereo_cali

描述: 摄像头的标定参数。如果某个方向的传感器不在线,则所有值为0.

typedef struct _stereo_cali
{
float cu; // x position of focal center in units of pixels
float cv; // y position of focal center in units of pixels
float focal; // focal length in units of pixels
float baseline; // baseline of stereo cameras in units of meters
_stereo_cali() { }
_stereo_cali(float _cu, float _cv, float _focal, float _baseline)
{
cu = _cu, cv = _cv;
focal = _focal, baseline = _baseline;
}
}stereo_cali;

exposure_param

描述: 摄像头的曝光参数。当m_expo_time = m_expected_brightness=0时,变成默认的自动曝光控制。

typedef struct _exposure_param
{
float m_step; // adjustment step for auto exposure control (AEC). Default is 10.
float m_exposure_time; // constant exposure time in mini-seconds. Range is 0.1~20. Default is 7.25.
unsigned int m_expected_brightness;// constant expected brightness for AEC. Range is 50~200. Default is 85.
unsigned int m_is_auto_exposure; // 1: auto exposure; 0: constant exposure
int m_camera_pair_index; // index of Guidance Sensor
_exposure_param(){
m_step = 10;
m_exposure_time = 7.68;
m_expected_brightness = 85;
m_is_auto_exposure = 1;
m_camera_pair_index = 1;
}
}exposure_param;

motion

描述: 定义全局位置数据结构。位置单位为m,速度单位为m/s.

typedef struct _motion
{
unsigned int frame_index;
unsigned int time_stamp;
int corresponding_imu_index;
float q0;
float q1;
float q2;
float q3;
int attitude_status; // 0:invalid; 1:valid
float position_in_global_x; // position in global frame: x
float position_in_global_y; // position in global frame: y
float position_in_global_z; // position in global frame: z
int position_status; // lower 3 bits are confidence. 0:invalid; 1:valid
float velocity_in_global_x; // velocity in global frame: x
float velocity_in_global_y; // velocity in global frame: y
float velocity_in_global_z; // velocity in global frame: z
int velocity_status; // lower 3 bits are confidence. 0:invalid; 1:valid
float reserve_float[8];
int reserve_int[4];
float uncertainty_location[3];// uncertainty of position
float uncertainty_velocity[3];// uncertainty of velocity
} motion;

API
概述

对USB接口,Guidance API提供了配置和控制Guidance的C接口。下面是该API提供的关键方法的概览。

当使用UART传输时请参考第2.​​1.2节的协议,以及uart_example示例代码。

方法
user_callback

typedef int (*user_call_back)( int event_type, int data_len, char *data );

reset_config

SDK_API int reset_config ( void );

init_transfer

SDK_API int init_transfer ( void );

select_imu

SDK_API void select_imu ( void );

select_ultrasonic

SDK_API void select_ultrasonic ( void );

select_velocity

SDK_API void select_velocity ( void );

select_obstacle_distance

SDK_API void select_obstacle_distance ( void );

set_image_frequecy

SDK_API int set_image_frequecy ( e_image_data_frequecy frequecy );

select_depth_image

SDK_API int select_depth_image ( e_vbus_index camera_pair_index );

示例:

include “DJI_guidance.h”

include “DJI_utility.h”

include “opencv2/opencv.hpp”

include

include

e_vbus_index sensor_id = e_vbus1;
Mat g_depth;
int my_callback(int data_type, int data_len, char content) { g_lock.enter(); if (e_image == data_type && NULL != content) { image_data data = (image_data* )content;
if ( data->m_depth_image[sensor_id] ){
g_depth = Mat::zeros(HEIGHT,WIDTH,CV_16SC1);
memcpy( g_depth.data, data->m_depth_image[sensor_id], IMAGE_SIZE * 2 );
}
}
g_lock.leave();
g_event.set_event();
return 0;
}
int main(int argc, const char** argv)
{
reset_config(); // clear all data subscription
int err_code = init_transfer(); //wait for board ready and init transfer thread
err_code = select_depth_image( sensor_id );

}

select_disparity_image

SDK_API int select_disparity_image ( e_vbus_index camera_pair_index );

示例:

include “DJI_guidance.h”

include “DJI_utility.h”

include “opencv2/opencv.hpp”

include

include

e_vbus_index sensor_id = e_vbus1;
Mat g_disparity;
int my_callback(int data_type, int data_len, char content) { g_lock.enter(); if (e_image == data_type && NULL != content) { image_data data = (image_data* )content;
if ( data->m_disparity_image[sensor_id] ){
g_disparity = Mat::zeros(HEIGHT,WIDTH,CV_16SC1);
memcpy( g_disparity.data, data->m_disparity_image[sensor_id], IMAGE_SIZE * 2 );
}
}
g_lock.leave();
g_event.set_event();
return 0;
}
int main(int argc, const char** argv)
{
reset_config(); // clear all data subscription
int err_code = init_transfer(); //wait for board ready and init transfer thread
err_code = select_disparity_image( sensor_id );

}

select_greyscale_image

SDK_API int select_greyscale_image ( e_vbus_index camera_pair_index, bool is_left );

select_motion

SDK_API void select_motion( void );

set_sdk_event_handler

SDK_API int set_sdk_event_handler ( user_call_back handler );

start_transfer

SDK_API int start_transfer ( void );

stop_transfer

SDK_API int stop_transfer ( void );

release_transfer

SDK_API int release_transfer ( void );

get_online_status

SDK_API int get_online_status (int online_status[CAMERA_PAIR_NUM] );

get_device_type

SDK_API int get_device_type(e_device_type* device_type);

get_image_size

SDK_API int get_image_size(int* width, int* height);

wait_for_board_ready

SDK_API int wait_for_board_ready();

set_exposure_param

SDK_API int set_exposure_param( exposure_param *param );

0


说点什么

avatar
50
  关注  
提醒