1

我正在开发 AR.Drone 2.0 控制应用程序。我在我的项目中使用 javadrone API 和库。这是我的代码问题:每当我在应用程序中按下起飞按钮时,它都会继续向无人机发送起飞命令。它忽略了发出我想发送的下一个 AT 命令。例如,我连接到无人机,按下起飞按钮(它应该发送 AT TakeOffCommand,它工作正常)但下一个命令(例如Flying Up)不会发出并发送到无人机。为什么会这样?知道是什么导致了这个错误吗?

    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]

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

4

1 回答 1

0

这种行为是可以的,甚至是必要的。来自AR.Drone 开发人员指南

应该重置本地(客户端)序列计数器有两种情况:

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

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

[编辑包括一个小的工作测试程序]

我不知道为什么您的代码不起作用,但是您可以尝试以下几件事:

  • 我看到你playLED在真正连接到无人机之前打电话;你可能不想那样做。
  • 我相信 to 的参数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("**********\nTRIM\n**********");
      drone.trim();
      Thread.sleep(5000);

      System.err.println("**********\nTAKEOFF\n**********");
      drone.takeOff();
      Thread.sleep(10000);

      System.err.println("**********\nMOVE\n**********");
      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);
    }
  }
}
于 2015-04-25T05:01:33.570 回答