简体   繁体   中英

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. 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.

  1. Implement the NavDataListener interface, and the navDataReceived method .
  2. Add your listener using the ARDrone method addNavDataListener .
  3. In your navDataRecieved method you will receive a NavData object with valid telemetry data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM