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

所以我要做的是有2个按钮:(i)连接(ii)取下按钮。连接按钮功能用于建立与无人机的连接,而“起飞”按钮用于使无人机飞行一点点并返回无人机的NAV导航数据。遗憾的是,所有返回的NAV数据似乎均不起作用。

注意:此代码在代码编译时工作正常。但这无法从无人机返回我正确且有效的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);
            }
          }
       });
     }

最佳答案

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

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


实现NavDataListener interface, and thenavDataReceived method
使用ARDronemethod addNavDataListener添加您的侦听器。
在您的navDataRecieved方法中
您将收到带有有效遥测数据的NavData对象。

关于java - Parrot AR.Drone 2.0-JavaDrone(获取无人机详细信息,例如电池电量,海拔高度,速度等)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30907840/

10-10 07:32