我正在编写一个 Node.js 应用程序来控制小型无人机。以下是 SDK 的说明:
使用 Wi-Fi 在 Tello 和 PC、Mac 或移动设备之间建立连接。
发送命令并接收响应
Tello IP:192.168.10.1 UDP 端口:8889 > PC/Mac/手机
步骤 1:在 PC、Mac 或移动设备上设置 UDP 客户端,通过同一端口从 Tello 发送和接收消息。
步骤 2:在发送任何其他命令之前,通过 UDP 端口 8889 向 Tello 发送“命令”以启动 SDK 模式。
接收特洛状态
Tello IP: 192.168.10.1 -->> PC/Mac/手机 UDP 服务器: 0.0.0.0 UDP 端口: 8890
步骤 3:在 PC、Mac 或移动设备上设置 UDP 服务器,并通过 UDP 端口 8890 检查来自 IP 0.0.0.0 的消息。在尝试步骤 3 之前必须完成步骤 1 和 2。
接收 Tello 视频流
Tello IP: 192.168.10.1 -->> PC/Mac/手机 UDP 服务器: 0.0.0.0 UDP 端口: 11111
步骤4:在PC、Mac或移动设备上设置UDP服务器,并通过UDP端口11111检查来自IP 0.0.0.0的消息。
第 5 步:通过 UDP 端口 8889 向 Tello 发送“streamon”以开始流式传输。在尝试步骤 5 之前必须完成步骤 1 和 2。
命令和接收部分工作起来就像一个魅力,我在端口 8889 上向无人机发送数据报或从无人机接收数据报。我的问题是,看起来我没有在其他端口上接收任何状态或视频流消息,并且我'我很确定这不是无人机的问题,而是我没有正确设置 Node.js 的问题。任何人都可以看到我的实现中问题出在哪里。这是我的代码:
tello.ts
import dgram from 'dgram';
export class Tello {
private LOCAL_IP_ = '0.0.0.0';
private TELLO_IP_ = '192.168.10.1';
private COMMAND_PORT_ = 8889;
private commandSocket_ = dgram.createSocket('udp4');
private STATE_PORT_ = 8890;
private stateSocket_ = dgram.createSocket('udp4');
private VIDEO_PORT_ = 11111;
private videoSocket_ = dgram.createSocket('udp4');
constructor() {}
startCommandSocket() {
this.commandSocket_.addListener('message', (msg, rinfo) => {
const message = msg.toString();
console.log(`from ${rinfo.address}: ${message}`);
});
this.commandSocket_.bind(this.COMMAND_PORT_, this.LOCAL_IP_, () => {
console.log('Started listening on the command socket');
});
}
startStateSocket() {
this.stateSocket_.addListener('message', (msg, rinfo) => {
const message = msg.toString();
console.log(`from ${rinfo.address}: ${message}`);
});
this.stateSocket_.bind(this.STATE_PORT_, this.LOCAL_IP_, () => {
console.log('Started listening on the state socket');
});
}
startVideoSocket() {
this.videoSocket_.addListener('message', (msg, rinfo) => {
console.log('receiving video');
const message = msg.toString();
console.log(`from ${rinfo.address}: ${message}`);
});
this.videoSocket_.bind(this.VIDEO_PORT_, this.LOCAL_IP_, () => {
console.log('Started listening on the video socket');
});
}
private sendCommand_(command: string) {
// As this is sent over UDP and we have no guarantee that the packet is received or a response given
// we are sending the command 5 times in a row to add robustess and resiliency.
//for (let i = 0; i < 5; i++) {
this.commandSocket_.send(command, this.COMMAND_PORT_, this.TELLO_IP_);
//}
console.log(`sending command: ${command} to ${this.TELLO_IP_}`);
}
/**
* Enter SDK mode.
*/
command() {
this.sendCommand_('command');
}
/**
* Auto takeoff.
*/
takeoff() {
this.sendCommand_('takeoff');
}
/**
* Auto landing.
*/
land() {
this.sendCommand_('land');
}
streamVideoOn() {
this.sendCommand_('streamon');
}
streamVideoOff() {
this.sendCommand_('streamoff');
}
...
}
index.ts
import { waitForSeconds } from './utils';
import { Tello } from './tello'
const main = async () => {
const tello = new Tello();
tello.startCommandSocket();
await waitForSeconds(1);
tello.command();
await waitForSeconds(1);
tello.startStateSocket();
await waitForSeconds(1);
tello.startVideoSocket();
await waitForSeconds(1);
tello.streamVideoOn();
await waitForSeconds(1);
tello.takeoff();
await waitForSeconds(10);
tello.land();
};
main();