我正在开发AR.Drone 2.0控件应用程序。我在我的项目中使用javadrone API和库。这是我的代码问题:每当我在我的应用程序中按下TakeOff按钮,它就会继续向无人机发送起飞命令。它忽略了发出我想要发送的下一个AT命令。例如,我连接到无人机,按下TakeOff按钮(它应该发送AT TakeOffCommand,它工作得很好),但下一个命令(e.g.Flying Up)将不会发出&发送到无人机。为什么会发生这种情况?知道是什么导致了这个bug吗?
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]我已经在这段代码上工作了几个星期,仍然找不到问题所在。请帮我解决这个问题。非常感谢。
发布于 2015-04-25 13:01:34
这种行为是可以的,甚至是必要的。从AR.Drone Developer Guide
在两种情况下,应重置本地(客户端)顺序计数器:
因此,无人机需要每隔50毫秒从你的应用程序接收一些东西,才能继续正常操作。我见过的SDK通常会发送REF和/或PCMD命令。javadrone似乎有不同的设计,它发送COMWDG (通信看门狗)消息来防止超时)。
编辑包括一个小的工作测试程序
我不知道为什么你的代码不能工作,但是这里有几个你可以尝试的东西:
playLED;你可能不想这样做。move的参数应该是0.0,1.0范围内的浮点数--你用5调用它。这是一个简短的程序,它开始腾飞,然后开始向后移动。我已经在我的AR.Drone 2.0上用一个新的javadrone签出和构建测试了它,它工作正常。有很多例外,但它是有效的: AR.Drone在这一点上已经很过时了,它主要针对javadrone 1.0。首先,它似乎无法解析无人机的导航数据。
当我运行这个程序时,我看到它发送REF命令,从我告诉无人机起飞到无人机完成起飞。然后,它发送COMWDG命令,直到代码告诉无人机移动,在这一点上,它发送一个PCMD,随后再次发送COMWDG消息。
我建议在你的无人机上试试这个程序,看看它是否有效。确保你使用的是javadrone的最新版本。
import com.codeminders.ardrone.ARDrone;
import java.io.IOException;
import java.net.UnknownHostException;
public class DroneTest {
private static final long CONNECT_TIMEOUT = 10000L;
public static void main(String[] args) {
try {
ARDrone drone = new ARDrone();
drone.connect();
// Wait until drone is ready
drone.waitForReady(CONNECT_TIMEOUT);
drone.clearEmergencySignal();
System.err.println("Drone State: " + drone.getState());
// do TRIM operation
System.err.println("**********\nTRIM\n**********");
drone.trim();
Thread.sleep(5000);
System.err.println("**********\nTAKEOFF\n**********");
drone.takeOff();
Thread.sleep(10000);
System.err.println("**********\nMOVE\n**********");
drone.move(0.0f, 0.5f, 0.0f, 0.0f);
} catch (UnknownHostException ex) {
System.err.println(ex);
} catch (IOException ex) {
System.err.println(ex);
} catch (InterruptedException ex) {
System.err.println(ex);
}
}
}https://stackoverflow.com/questions/29668371
复制相似问题