关键词:OSDK USB通信
根据DJI 官方信息,OSDK4.x仅支持M210 / RTK v2 和 M300 RTK型号飞机。且OSDK4.x与无人机的通信机制相比之前有些许变动,更多的功能将采取USB通信机制来完成。
本地为方便开发,采用Linux虚拟机跑OSDK来控制无人机,因为涉及到无人机与DJI Assistant2、Linux连接之间的切换,经常出现USB通信异常的情况。简单了解一下USB的机制,可能在实际应用中问题不大,但方便后续开发使用中出现USB通信异常时,提供一个排查思路。
首先,关于DJI 设备:
记录一下代码中的设备 PID和VID,万一后续有支变动,也便于确认查找。
LinuxUSBDevice:: LinuxUSBDevice() :foundDJIDevice(false)
{
DJI_usb_dev_filter[0].pid = 0x001F; DJI_usb_dev_filter[0].vid = 0xFFF0;
DJI_usb_dev_filter[1].pid = 0x0020; DJI_usb_dev_filter[1].vid = 0xFFF0;
DJI_usb_dev_filter[2].pid = 0xd008; DJI_usb_dev_filter[2].vid = 0x18d1;
DJI_usb_dev_filter[3].pid = 0xd009; DJI_usb_dev_filter[3].vid = 0x18d1;
DJI_usb_dev_filter[4].pid = 0x001F; DJI_usb_dev_filter[4].vid = 0x2CA3;
DJI_usb_dev_filter[5].pid = 0x0020; DJI_usb_dev_filter[5].vid = 0x2CA3;
}
对应官网介绍上
在DJIDevice.rules文件中添加SUBSYSTEM=="usb", ATTRS{idVendor}=="2ca3", MODE="0666"
ubuntu中也可通过dmesg 查看到:
[ 635.352119] usb 1-1: New USB device found, idVendor=2ca3, idProduct=001f
采用官方推荐的Ubuntu1604系统,USB设备驱动系统已经自带了,暂没有研究不带驱动的情况。
再谈谈遇到的问题,
在切换USB与虚拟机的连接后,很容易出现获取不到IP的情况。
ens33 Link encap:Ethernet HWaddr 00:0c:29:63:a6:8a
inet addr:192.168.74.129 Bcast:192.168.74.255 Mask:255.255.255.0
inet6 addr: fe80::1051:cbf6:709d:f0a7/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1013861 errors:0 dropped:0 overruns:0 frame:0
TX packets:1052653 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:238238741 (238.2 MB) TX bytes:399361262 (399.3 MB)
ens35u1 Link encap:Ethernet HWaddr ea:d3:33:9b:2d:cd
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:110 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:24534 (24.5 KB)
lo Link encap: Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:566 errors:0 dropped:0 overruns:0 frame:0
TX packets:566 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:68420 (68.4 KB) TX bytes:68420 (68.4 KB)
接上USB连接线后出现网口:ens35u1,但此时并未获取到IP,代码中可以看到
#define UDT_SERVER_IP "192.168.42.2"
#define UDT_SERVER_PORT_MAIN "40001"
#define UDT_SERVER_PORT_FPV "40003"
此时通信会有异常。找到问题了再来考虑解决办法,
考虑这是个动态网口,最简单的方式就是在使用时,要使用USB通信,先检查一下ping 192.168.42.2,若不通,手动设置IP为192.168.42.3即可
ifconfig [eth] down
ifconfig [eth] 192.168.42.3 up
但是对于M300,看到的IP貌似有变了,为192.168.44.3 ping无人机 192.168.44.2。M300与OSDK4.0通信部分在OSDK4.0中暂时还没有看到相关源码,具体细节可能与M210相比可能要具体再看看。
虽然实际使用过程中问题可能不大,但作为一名开发者本地环境配置可以帮助我们更好的理解SDK相关原理功能。
2021-04-22 补充:
关于M300 与OSDK 4.x版本的USB通信问题,上面的描述还留了点关于M300的疑问,将这部分简单的补充一下,其实当IP不为 192.168.44.3时,也可以获取视频流,但是M210 通信时IP不设置为192.168.42.x时,就无法正常获取视频。这个问题就针对获取视频流方式,贴一下代码,也许更好理解一下。
AdvancedSensing::AdvancedSensing(Vehicle* vehiclePtr) :
vehicle_ptr(vehiclePtr),
advancedSensingProtocol(NULL),
liveview(NULL),
perception(NULL),
fpvCam_ptr(NULL),
mainCam_ptr(NULL)
{
stereoHandler.callback = 0;
stereoHandler.userData = 0;
vgaHandler.callback = 0;
vgaHandler.userData = 0;
streamDecoder.clear();
// call a closed-source version of getDroneVersion() to prevent hacking
internalGetDroneVersion(vehiclePtr);
// wait for half sec
sleep(0.5);
if (!versionPass())
{
DERROR("Please make sure the connected drone is a M210 and "
"firmware version is supported.\n");
return;
}
if (vehiclePtr->isM300()) {
/*! Linker add liveview USB Bulk channel */
if (!vehiclePtr->linker->addUSBBulkChannel(0x001F, 0x2CA3, 3, 0x84, 0x03,
USB_BULK_LIVEVIEW_CHANNEL_ID)) {
DERROR("Failed to initialize USB Bulk Linker channel for liveview!");
} else {
DSTATUS("Start bulk channel for M300's liveview!");
}
/*! Linker create liveview handle task */
if (!vehiclePtr->linker->createLiveViewTask()) {
DERROR("Failed to create task for liveview!");
} else {
DSTATUS("Create task for M300's liveview!");
}
/*! Linker add perception USB Bulk channel */
if (!vehiclePtr->linker->addUSBBulkChannel(0x001F, 0x2CA3, 6, 0x87, 0x05,
USB_BULK_ADVANCED_SENSING_CHANNEL_ID)) {
DERROR("Failed to initialize USB Bulk Linker channel for perception!");
} else {
DSTATUS("Start bulk channel for M300's perception");
}
/*! Linker create advanced sensing handle task */
if (!vehiclePtr->linker->createAdvancedSensingTask()) {
DERROR("Failed to create task for advanced sensing!");
} else {
DSTATUS("Create task for M300's advanced sensing!");
}
DSTATUS("Advanced Sensing init for the M300 drone");
liveview = new LiveView(vehiclePtr);
perception = new Perception(vehiclePtr);
streamDecoder = {
{LiveView::OSDK_CAMERA_POSITION_FPV, (new DJICameraStreamDecoder())},
{LiveView::OSDK_CAMERA_POSITION_NO_1, (new DJICameraStreamDecoder())},
{LiveView::OSDK_CAMERA_POSITION_NO_2, (new DJICameraStreamDecoder())},
{LiveView::OSDK_CAMERA_POSITION_NO_3, (new DJICameraStreamDecoder())},
};
} else {
DSTATUS("Advanced Sensing init for the M210 drone");
this->advancedSensingProtocol = new AdvancedSensingProtocol();
liveview = new LiveView(vehiclePtr);
fpvCam_ptr = new DJICameraStream(FPV_CAMERA);
mainCam_ptr = new DJICameraStream(MAIN_CAMERA);
}
}
可以看到M210 和M300 走的通道不一样,M300使用的是bulk channel,而M210通过UDT读取USB数据,M210需要安装RNDIS驱动使用虚拟IP进行通信。
UDT数据读取线程:(文件:dji_camera_stream_link.cpp)
void* DJICameraStreamLink::readThreadEntry
评论
0 条评论
请登录写评论。