我正在开发 AR.Drone 2.0 控制应用程序。我在我的项目中使用 javadrone API 和库。这是我的代码问题:每当我在应用程序中按下起飞按钮时,它都会继续向无人机发送起飞命令。它忽略了发出我想发送的下一个 AT 命令。例如,我连接到无人机,按下起飞按钮(它应该发送 AT TakeOffCommand,它工作正常)但下一个命令(例如Flying Up)不会发出并发送到无人机。为什么会这样?知道是什么导致了这个错误吗?
My Java Code:
**Connect Button in my apps**
private void jButtonConnectActionPerformed(java.awt.event.ActionEvent evt) {
try {
// Create ARDrone object,
// connect to drone and initialize it.
drone = new ARDrone();
drone.playLED(10,10,10);
drone.connect();
drone.clearEmergencySignal();
// Wait until drone is ready
drone.waitForReady(CONNECT_TIMEOUT);
System.err.println("Drone State: " + drone.getState());
// do TRIM operation
drone.trim();
} 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);
}
}
**Take Off Button in my apps**
private void jButtonTakeOffActionPerformed(java.awt.event.ActionEvent evt){
try
{
// Take off
System.err.println("Taking off");
drone.takeOff();
Thread.sleep(5000);
}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);
}
}
**Flying Up Button in java apps:**
private void jButtonUpActionPerformed(java.awt.event.ActionEvent evt) {
try
{
// Flying Up
drone.playAnimation(1,10);
drone.move(0,0,5,0);
// Fly a little :)
Thread.sleep(5000);
} 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);
}
}
**Output here:**
Current Drone State : CONNECTING
Taking off
6819 [AWT-EventQueue-0] DEBUG ardrone.ARDrone - State changed from CONNECTING to TAKING_OFF
6819 [Thread-6] DEBUG ardrone.CommandSender - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208]
Take off command!
7028 [Thread-6] DEBUG ardrone.CommandSender - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208]
7129 [Thread-6] DEBUG ardrone.CommandSender - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208]
7230 [Thread-6] DEBUG ardrone.CommandSender - Q[1]Sending AT command TakeOffCommand [ID=REF, param=,290718208] [These TakeOff AT commands will continuously send to drone]
Flying Up!
TakeOffCommand [ID=REF, param=,290718208]
Movement Command Sending!
0.0
0.0
5.0
0.0
9847 [Thread-6] DEBUG ardrone.CommandSender - Q[2]Sending AT command TakeOffCommand [ID=REF, param=,290718208] <--Why it still sending TakeOffCommand instead of MoveCommand ?
Movement Command Sent Done!
9947 [Thread-6] DEBUG ardrone.CommandSender - Q[3]Sending AT command TakeOffCommand [ID=REF, param=,290718208]
10047 [Thread-6] DEBUG ardrone.CommandSender - Q[3]Sending AT command TakeOffCommand [ID=REF, param=,290718208]
我已经在这段代码上工作了几个星期,但仍然无法确定问题所在。请帮我解决这个问题。非常感谢。