- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在开发 Parrot AR。无人机项目。这些库是从 JavaDrone 网站 ( https://code.google.com/p/javadrone/downloads/list ) 下载并在该项目中实现的。但是,尽管我确实包含了所有正确的库并进行了正确的类调用来获取该方法,但它仍然无法返回正确的信息。所有返回的结果似乎都是“假”。知道这段代码发生了什么吗?请帮助我:(
所以我所做的是我有 2 个按钮:(i) 连接 (ii) 起飞按钮。连接按钮功能用于建立与无人机的连接,而起飞按钮用于使无人机飞行一点并返回无人机的 NAV 导航数据。遗憾的是,所有返回的 NAV 数据似乎都不起作用。
注意:此代码在代码编译后工作正常。但它只是无法从无人机返回正确且有效的导航数据。
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();
}
输出:
******************************************
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
********************************************
更新:我所做的就是遵循约翰的建议。我确实实现了从无人机获取 NavData 所需的所有方法和 NavDataListener。
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);
}
}
});
}
最佳答案
问题是您没有做任何事情来实际获取导航数据。您不能只创建一个 NavData
对象并希望它填充有效数据 - 它不会。
您需要使用com.codeminders.ardrone.NavDataListener
接口(interface)。
NavDataListener
interface, and thenavDataReceived
method .ARDrone
method addNavDataListener
添加您的监听器.navDataRecieved
方法中您将收到一个包含有效遥测数据的 NavData 对象。关于java - Parrot AR.Drone 2.0 - JavaDrone(获取无人机详细信息,例如电池电量、高度、速度等)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30907840/
我正在开发 Parrot AR。无人机项目。这些库是从 JavaDrone 网站 ( https://code.google.com/p/javadrone/downloads/list ) 下载并在
我是一名优秀的程序员,十分优秀!