Javadrone - 如何在连接到无人机后获取无人机信息?例如。电池电量,海拔等?

时间:2015-06-16 13:34:26

标签: java ar.drone

我正在使用Javadrone API& amp;来处理控制Parrot Ar.Drone的应用程序。它的图书馆。我可以连接到无人机和让它成功起飞/降落。

可以在此处下载Javadrone API:https://code.google.com/p/javadrone/downloads/list

然而,我不知道如何提取我想要的无人机信息。我试图调用适当的函数。但它无法奏效。

我的代码:

import com.codeminders.ardrone.NavData;

In my class : -
    //declare a jlabel for battery level 
    public NavData data;
    public int value = data.getBattery();
    JLabel batteryStatus = new JLabel(); 

    batteryStatus.setForeground(Color.YELLOW);    
    batteryStatus.setText(data.getBattery()+ " %");

    if (value < 15) {
            batteryStatus.setForeground(Color.RED);
    } else if (value < 50) {
            batteryStatus.setForeground(Color.ORANGE);
    } else {
            batteryStatus.setForeground(Color.GREEN);
    }

知道如何让它有效吗?如果我运行这段代码,它将无法运行,因为它将编译卡在getBattery()方法。我想在项目中实现这个调用函数,以便相关的航班信息。例如海拔高度可以显示在我的应用程序上。感谢。

代码编译的输出:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at ardrone.arDroneFrame.jButtonConnectActionPerformed(arDroneFrame.java:462)
LINE 462 : batteryStatus.setText(data.getBattery()+ " %");

1 个答案:

答案 0 :(得分:0)

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

  1. 实施NavDataListener interface, and the navDataReceived method
  2. 使用ARDrone method addNavDataListener添加您的听众。
  3. 使用navDataRecieved方法 您将收到带有有效遥测数据的NavData对象。