mohankreddy / javadrone

Automatically exported from code.google.com/p/javadrone
0 stars 0 forks source link

Cannot TakeOff and Land AR.Drone 2.0 (State Error occurred) #55

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to implement javadrone (AR.Drone Java API) in my project. However, 
it was occurred state changed error when I compile my java code and try to fly 
it. I was able to send command to AR.Drone and fly for the first time. After 
successfully take off for the first time,it won't take off again due to "state 
changed" error. I have no idea what went wrong in my code. Please help me out. 
Thanks! There are 3 files that are required in this project. My java 
file(arDroneFrame.java),NavData.java(from javadrone), and ARDrone.java(from 
javadrone).The The main java file: arDroneFrame.java. When I press the TakeOff 
button, it should make AR.Drone fly and land afterwards.

In my arDroneFrame.java,

private void jButtonTakeOffActionPerformed(java.awt.event.ActionEvent evt) {
com.codeminders.ardrone.ARDrone drone;

    try{           
        drone = new com.codeminders.ardrone.ARDrone();
        drone.connect();
        drone.clearEmergencySignal();

        // Wait until drone is ready
        drone.waitForReady(CONNECT_TIMEOUT);

        // do TRIM operation
        drone.trim();

        // Take off
        System.err.println("Taking off");
        drone.takeOff();

        // Fly a little :)
        Thread.sleep(5000);

        //Land
        System.err.println("Landing");
        drone.land();

        // Give it some time to land
        Thread.sleep(2000);

        // Disconnect from the done
        drone.disconnect();

} catch (UnknownHostException ex) {
    Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
    Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
    Logger.getLogger(arDroneFrame.class.getName()).log(Level.SEVERE, null, ex);
} 
}

In ARDrone.java, I had commented out some java coding.This is because only when 
I comment out those java code, it can only works. If I uncomment them, my 
program will be stuck there (no respond at all).

public void waitForReady(long how_long) throws IOException
{
    /*long since = System.currentTimeMillis();
    synchronized(state_mutex)
    {
        while(true)
        {
            if((System.currentTimeMillis() - since) >= how_long)
            {
                try
                {
                    disconnect();
                } catch(IOException e)
                {
                }
                // Timeout, too late
                throw new IOException("Timeout connecting to ARDrone");
            } else if(state == State.DEMO)
            {
                return; // OK! We are now connected
            } else if(state == State.ERROR || state == State.DISCONNECTED)
            {
                throw new IOException("Connection Error");
            }

            long p = Math.min(how_long - (System.currentTimeMillis() - since), how_long);
            if(p > 0)
            {
                try
                {
                    state_mutex.wait(p);
                } catch(InterruptedException e)
                {
                    // Ignore
                }
            }
        }
    }*/
    while(state == State.DEMO)
    {
        System.out.println("Changed to DEMO !");
                return; // OK! We are now connected
    }
}
}

Program Output:

126 [Thread-7] DEBUG ardrone.ARDrone - State changed from TAKING_OFF to ERROR   
with exception java.lang.NullPointerException

at com.codeminders.ardrone.NavData$FlyingState.fromControlState(NavData.java:58)

at com.codeminders.ardrone.NavData.getFlyingState(NavData.java:622)

at com.codeminders.ardrone.ARDrone.navDataReceived(ARDrone.java:431)

at com.codeminders.ardrone.NavDataReader.run(NavDataReader.java:92)

at java.lang.Thread.run(Thread.java:745)

Original issue reported on code.google.com by iseethem...@gmail.com on 28 Mar 2015 at 9:50

Attachments: