Parrot AR.Drone 2.0 - JavaDrone (Get the drone details E.G. Battery Level, Altitude, Speed etc)?

1.8k views Asked by At

I am working on Parrot AR. Drone project. The libraries are downloaded and implemented in this project from JavaDrone website (https://code.google.com/p/javadrone/downloads/list). However, although I did included the all the correct libraries and make the right class call to get the method, it still cannot return me the correct information. All the results returned appeared to be "false". Any idea what happening on this code? Please help me :(

So what I did is I have 2 buttons : (i) connect (ii) take off buttons. The Connect button function is for establish connection to drone while Take off button is used for make the drone fly move a bit and return me the drone's NAV navigation data. Sadly all the returned NAV data appears not working.

Note : This code is working fine upon code compilation. But it just cannot return me the correct & valid NAV data from drone.

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();
}

Output :

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

Update: What I did was followed John's suggestion. I did implemented all the neccessary methods and NavDataListener for getting the NavData from drone.

    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);
            }
          }
       });
     }
2

There are 2 answers

5
John Wiseman On BEST ANSWER

The problem is that you are not doing anything to actually get navdata. You can't just create a NavData object and hope it gets filled in with valid data--It won't.

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.
3
WeMakeSoftware On

Do you set the Drone IP address? According to sources the default IP for the drone is 192.168.1.1.

You can call another constructor to set the IP:

drone = new ARDrone(InetAddress.getByName("xxx.xxx.xxx.xxx"));

replace xxx.xxx.xxx.xxx with the actual drone IP.