不间断地发送AT命令TakeOffCommand[ID=REF,param=,290718208]



我正在开发AR.Drone 2.0控制应用程序。我在我的项目中使用javadrone API和库。这是我的代码问题:每当我在应用程序中按下起飞按钮时,它就会一直向无人机发送起飞命令。它忽略了发出我想要发送的下一个AT命令。例如,我连接到无人机,按下起飞按钮(它应该发送AT起飞命令,它工作正常),但下一个命令(例如飞起来)不会发出&发送到无人机。为什么会发生这种情况?知道这个bug是什么原因吗?

My Java Code: 
**Connect Button in my apps**
private void jButtonConnectActionPerformed(java.awt.event.ActionEvent evt) {                                               
try {
// Create ARDrone object,
// connect to drone and initialize it.
drone = new ARDrone();
drone.playLED(10,10,10);
drone.connect();
drone.clearEmergencySignal();
// Wait until drone is ready
drone.waitForReady(CONNECT_TIMEOUT);
System.err.println("Drone State: " + drone.getState());
// do TRIM operation
drone.trim();  
} catch (UnknownHostException ex) {
Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
}              
} 
**Take Off Button in my apps**
private void jButtonTakeOffActionPerformed(java.awt.event.ActionEvent evt){
try
{     
// Take off
System.err.println("Taking off");
drone.takeOff();
Thread.sleep(5000);
}catch (IOException ex) {  
Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
}  
}  
**Flying Up Button in java apps:**
private void jButtonUpActionPerformed(java.awt.event.ActionEvent evt) {                                          
try
{           
// Flying Up
drone.playAnimation(1,10);
drone.move(0,0,5,0);
// Fly a little :)
Thread.sleep(5000);                  
} catch (UnknownHostException ex) {
Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
}                                         
}
**Output here:**
Current Drone State : CONNECTING 
Taking off 
6819 [AWT-EventQueue-0] DEBUG ardrone.ARDrone  - State changed from CONNECTING to TAKING_OFF 
6819 [Thread-6] DEBUG ardrone.CommandSender  - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208] 
Take off command! 
7028 [Thread-6] DEBUG ardrone.CommandSender  - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208] 
7129 [Thread-6] DEBUG ardrone.CommandSender  - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208] 
7230 [Thread-6] DEBUG ardrone.CommandSender  - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208] [These TakeOff AT commands will continuously send to drone] 
Flying Up! 
TakeOffCommand [ID=REF, param=,290718208]  
Movement Command Sending!
0.0
0.0
5.0
0.0 
9847 [Thread-6] DEBUG ardrone.CommandSender  - Q[2]Sending AT command TakeOffCommand [ID=REF, param=,290718208] <--Why it still sending TakeOffCommand instead of MoveCommand ? 
Movement Command Sent Done! 
9947 [Thread-6] DEBUG ardrone.CommandSender  - Q[3]Sending AT command TakeOffCommand [ID=REF, param=,290718208] 
10047 [Thread-6] DEBUG ardrone.CommandSender  - Q[3]Sending AT command TakeOffCommand [ID=REF, param=,290718208]

我已经在这个代码上工作了几个星期,仍然无法确定问题所在。请帮我解决这个问题。非常感谢。

这种行为是可以的,甚至是必要的。来自AR。无人机开发者指南:

当本地(客户端)序列计数器应重置:

  • 无人机在超过50ms的时间内不会接收任何流量;则它将在ARDRONE_state字段中设置其ARDRONE_COM_WATCHDOG_MASK位(第二字段)。要退出此模式,客户端必须发送AT命令AT*COMWDG
  • 无人机在超过2000毫秒的时间内不会接收任何交通;然后,它将停止与客户端的所有通信,并在内部在其状态变量中设置ARDRONE_COM_LOST_MASK位。客户然后必须重新初始化与无人机的网络通信

因此,无人机需要每50毫秒从您的应用程序接收一次信息才能继续正常运行。我看到的SDK通常发送REF和/或PCMD命令。javadrone的设计似乎有所不同,它发送COMWDG(通信看门狗)消息以防止超时)。

[编辑为包含小型工作测试程序]

我不知道为什么你的代码不起作用,但这里有一些你可以尝试的东西:

  • 我看到你在真正连接到无人机之前打了playLED;你可能不想那样做
  • 我认为move的论据应该是浮动的在[0.0,1.0]-你用5来称呼它

这是一个启动后开始向后移动的短程序。我已经在我的AR.Drone 2.0上测试了它,并对javadrone进行了新的检查和构建,它确实有效。有很多例外,但它是有效的:javadrone在这一点上已经过时了,主要针对AR.Drone 1.0。首先,它似乎无法解析无人机的导航数据。

当我运行这个程序时,我看到它从我告诉无人机起飞到无人机完成起飞发送REF命令。然后它发送COMWDG命令,直到代码告诉无人机移动,此时它再次发送PCMD,然后再发送COMWDG消息。

我建议用你的无人机试试这个程序,看看它是否有效。确保您使用的是javadrone的新签出。

import com.codeminders.ardrone.ARDrone;
import java.io.IOException;
import java.net.UnknownHostException;
public class DroneTest {
private static final long CONNECT_TIMEOUT = 10000L;
public static void main(String[] args) {
try {
ARDrone drone = new ARDrone();
drone.connect();
// Wait until drone is ready
drone.waitForReady(CONNECT_TIMEOUT);
drone.clearEmergencySignal();
System.err.println("Drone State: " + drone.getState());
// do TRIM operation
System.err.println("**********nTRIMn**********");
drone.trim();
Thread.sleep(5000);
System.err.println("**********nTAKEOFFn**********");
drone.takeOff();
Thread.sleep(10000);
System.err.println("**********nMOVEn**********");
drone.move(0.0f, 0.5f, 0.0f, 0.0f);
} catch (UnknownHostException ex) {
System.err.println(ex);
} catch (IOException ex) {
System.err.println(ex);
} catch (InterruptedException ex) {
System.err.println(ex);
}
}
}

相关内容

  • 没有找到相关文章

最新更新