Parrot AR.Drone 2.0 - JavaDrone(获取无人机详细信息,例如电池电量、海拔高度、速度等)?

Parrot AR.Drone 2.0 - JavaDrone (Get the drone details E.G. Battery Level, Altitude, Speed etc)?

我正在研究 Parrot AR。无人机项目。这些库是从 JavaDrone 网站 (https://code.google.com/p/javadrone/downloads/list) 下载并在这个项目中实现的。然而,尽管我确实包含了所有正确的库并进行了正确的 class 调用以获取方法,但它仍然无法 return 我获得正确的信息。 returned 的所有结果似乎都是 "false"。知道这段代码发生了什么吗?请帮助我:(

所以我所做的是我有 2 个按钮:(i) 连接 (ii) 关闭按钮。 Connect 按钮功能用于建立与无人机的连接,而 Take off 按钮用于使无人机飞行一点,return 无人机的 NAV 导航数据。遗憾的是,所有 returned NAV 数据似乎都不起作用。

注意:此代码在代码编译后工作正常。但它无法 return 我从无人机获得正确有效的 NAV 数据。

private void jButtonConnectActionPerformed(java.awt.event.ActionEvent evt) {    
          System.out.println("Connect?");
          drone = new ARDrone();
          data = new NavData();
          drone.playLED(10,10,10);
          drone.connect();
          drone.clearEmergencySignal();

          System.err.println("Ready to connect!!");
          // Wait until drone is ready
          drone.waitForReady(CONNECT_TIMEOUT);
          System.err.println("Drone State: " + drone.getState());
          // do TRIM operation
          drone.trim();  
          System.err.println("Congratulation! You have connected to Drone!");
          System.out.println("You can issue flight commands now!");
          batteryStatus.setText("0" + "%");
          batteryStatus.setForeground(Color.ORANGE);       
          batteryStatus.setText("" + data.getBattery());
    }

 private void jButtonTakeOffActionPerformed(java.awt.event.ActionEvent evt) {  
       System.err.println("Current Drone State : " + drone.getState().toString());           
       System.err.println("Taking off");
       drone.takeOff();
       Thread.sleep(4000);
       System.err.println("**********\nMOVE\n**********");
       drone.move(0.0f, 150.5f, 500.0f, 0.0f);
       Thread.sleep(1000);            
       System.err.println("******************************************");
       System.err.println("Drone Infomation"); 
       System.err.println("Battery Too High ? " + data.isBatteryTooHigh());
       System.err.println("Battery Too Low ? " + data.isBatteryTooLow());
       System.err.println("Drone Flying ? " + data.isFlying());
       System.err.println("Control Received ? " + data.isControlReceived());
       System.err.println("Motor Down ? " + data.isMotorsDown());
       System.err.println("Not Enough Power ?" +  data.isNotEnoughPower());
       System.err.println("Trim Received ? " + data.isTrimReceived());
       System.err.println("Trim Running? " + data.isTrimRunning());
       System.err.println("Trim succeded? " + data.isTrimSucceeded());
       System.err.println("PIC Number OK? "+ data.isPICVersionNumberOK());
       System.err.println("******************************************");
       Thread.sleep(5000);
       drone.sendAllNavigationData();
       drone.land();
}

输出:

******************************************
Drone Infomation
Battery Life: 0.0%
Battery Too High ? false
Battery Too Low ? false
Drone Flying ? false
Control Received ? false
Motor Down ? false
Not Enough Power ?false
Trim Received ? false
Trim Running? false
Trim succeded? false
PIC Number OK? false
********************************************

更新: 我所做的是听从约翰的建议。我确实实现了所有必要的方法和 NavDataListener 以从无人机获取 NavData。

    import com.codeminders.ardrone.ARDrone;
    import com.codeminders.ardrone.ARDrone.VideoChannel;
    import com.codeminders.ardrone.NavData;
    import com.codeminders.ardrone.NavDataListener;

    public class arDrone extends javax.swing.JFrame implements Runnable, NavDataListener{

    public ARDrone drone;
    public NavData data = new NavData();

    public arDrone(String text) {
       //FreeTTS speech text
       this.text=text;          
     }

    public arDrone() {
      initComponents(); 
      setIcon();
      initDrone();
    }

    private void initDrone() {
       try {
         drone = new ARDrone();
         data = new NavData();
         drone.addNavDataListener(this);
       } catch (UnknownHostException ex) {                        
         System.err.println(ex);
         return; 
       }      
   }

    public void navDataReceived(NavData nd) {
        System.err.println("Testing navDataReceived is running...");
        updateBatteryStatus(nd.getBattery());
        this.flying.set(nd.isFlying());
    }

    private void updateBatteryStatus(final int value) {
        java.awt.EventQueue.invokeLater(new Runnable() {      
        @Override
        public void run() {       
            batteryStatus.setText(value + "%");
            if (value < 15) {
                batteryStatus.setForeground(Color.RED);
            } else if (value < 50) {
                batteryStatus.setForeground(Color.ORANGE);
            } else {
                batteryStatus.setForeground(Color.GREEN);
            }
          }
       });
     }

你设置无人机IP地址了吗?根据消息来源,无人机的默认 IP 为 192.168.1.1。

您可以调用另一个构造函数来设置IP:

drone = new ARDrone(InetAddress.getByName("xxx.xxx.xxx.xxx"));

将xxx.xxx.xxx.xxx替换为实际的无人机IP。

问题是您没有做任何实际获取导航数据的事情。您不能只创建一个 NavData 对象并希望它填充有效数据——它不会。

您需要使用com.codeminders.ardrone.NavDataListener界面。

  1. 实现NavDataListener接口,并且 navDataReceived 方法.
  2. 使用 ARDrone 添加您的监听器 方法 addNavDataListener.
  3. 在你的navDataRecieved方法中 您将收到一个包含有效遥测数据的 NavData 对象。