I am working on an application to control Parrot Ar.Drone using Javadrone API & its libraries. 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
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. 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.
NavDataListener
interface, and the
navDataReceived
method.ARDrone
method addNavDataListener
.navDataRecieved
method
you will receive a NavData object with valid telemetry data.