[英]Javadrone - How to get the drone info after connected into drone? E.G. Battery level, Altitude etc?
I am working on an application to control Parrot Ar.Drone using Javadrone API & its libraries. 我正在开发一个使用Javadrone API及其库来控制Parrot Ar.Drone的应用程序。 I am able to connect into drone & make it take off/land successfully.
我能够连接无人机并成功起飞/降落。
Javadrone API can be download here : https://code.google.com/p/javadrone/downloads/list 您可以在此处下载Javadrone API: https : //code.google.com/p/javadrone/downloads/list
However, I have no idea how to extract out drone's info that I wanted. 但是,我不知道如何提取我想要的无人机信息。 I was trying to call the appropriate function.
我试图调用适当的函数。 But it can't works.
但这行不通。
My code: 我的代码:
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);
}
Any idea how to make it works ? 知道如何使它起作用吗? If I run this snippet of code, it won't run since it will compilation stucks at getBattery() method.
如果我运行此代码段,它将无法运行,因为它将编译卡在getBattery()方法上。 I wanted to implement this calling function in project so that relevant flight info.
我想在项目中实现此调用功能,以便获得相关的航班信息。 such as altitude can be shown on my apps.
例如海拔高度可以显示在我的应用程序上。 Thanks.
谢谢。
The output of code compilation: 代码编译的输出:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ardrone.arDroneFrame.jButtonConnectActionPerformed(arDroneFrame.java:462)
LINE 462 : batteryStatus.setText(data.getBattery()+ " %");
You need to use the com.codeminders.ardrone.NavDataListener
interface. 您需要使用
com.codeminders.ardrone.NavDataListener
接口。
NavDataListener
interface, and the navDataReceived
method . NavDataListener
接口和navDataReceived
方法 。 ARDrone
method addNavDataListener
. ARDrone
方法addNavDataListener
添加您的侦听器。 navDataRecieved
method you will receive a NavData object with valid telemetry data. navDataRecieved
方法中,您将收到带有有效遥测数据的navDataRecieved
对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.