简体   繁体   English

Javadrone-连接到无人机后如何获取无人机信息? EG电池电量,海拔高度等?

[英]Javadrone - How to get the drone info after connected into drone? E.G. Battery level, Altitude etc?

I am working on an application to control Parrot Ar.Drone using Javadrone API & its libraries. 我正在开发一个使用Javadrone API及其库来控制Parrot Ar.Drone的应用程序。 I am able to connect into drone & make it take off/land successfully. 我能够连接无人机并成功起飞/降落。

Javadrone API can be download here : https://code.google.com/p/javadrone/downloads/list 您可以在此处下载Javadrone API: https//code.google.com/p/javadrone/downloads/list

However, I have no idea how to extract out drone's info that I wanted. 但是,我不知道如何提取我想要的无人机信息。 I was trying to call the appropriate function. 我试图调用适当的函数。 But it can't works. 但这行不通。

My code: 我的代码:

import com.codeminders.ardrone.NavData;

In my class : -
    //declare a jlabel for battery level 
    public NavData data;
    public int value = data.getBattery();
    JLabel batteryStatus = new JLabel(); 

    batteryStatus.setForeground(Color.YELLOW);    
    batteryStatus.setText(data.getBattery()+ " %");

    if (value < 15) {
            batteryStatus.setForeground(Color.RED);
    } else if (value < 50) {
            batteryStatus.setForeground(Color.ORANGE);
    } else {
            batteryStatus.setForeground(Color.GREEN);
    }

Any idea how to make it works ? 知道如何使它起作用吗? If I run this snippet of code, it won't run since it will compilation stucks at getBattery() method. 如果我运行此代码段,它将无法运行,因为它将编译卡在getBattery()方法上。 I wanted to implement this calling function in project so that relevant flight info. 我想在项目中实现此调用功能,以便获得相关的航班信息。 such as altitude can be shown on my apps. 例如海拔高度可以显示在我的应用程序上。 Thanks. 谢谢。

The output of code compilation: 代码编译的输出:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at ardrone.arDroneFrame.jButtonConnectActionPerformed(arDroneFrame.java:462)
LINE 462 : batteryStatus.setText(data.getBattery()+ " %");

You need to use the com.codeminders.ardrone.NavDataListener interface. 您需要使用com.codeminders.ardrone.NavDataListener接口。

  1. Implement the NavDataListener interface, and the navDataReceived method . 实现NavDataListener接口和navDataReceived方法
  2. Add your listener using the ARDrone method addNavDataListener . 使用ARDrone方法addNavDataListener添加您的侦听器。
  3. In your navDataRecieved method you will receive a NavData object with valid telemetry data. navDataRecieved方法中,您将收到带有有效遥测数据的navDataRecieved对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Parrot AR.Drone 2.0-JavaDrone(获取无人机详细信息,例如EG电池电量,高度,速度等)? - Parrot AR.Drone 2.0 - JavaDrone (Get the drone details E.G. Battery Level, Altitude, Speed etc)? Javadrone-无法从Parrot AR.Drone 2.0获取图像 - Javadrone - Unable to get image from Parrot AR.Drone 2.0 如何获得电池电量 - How to get battery level Android Retrofit 错误 HTTP 方法注释是必需的(例如,@GET、@POST 等) - Android Retrofit error HTTP method annotation is required (e.g., @GET, @POST, etc.) Retrofi2 Android HTTP 方法注释是必需的(例如,@GET,@POST等) - Retrofi2 Android HTTP method annotation is required (e.g., @GET, @POST, etc.) 如何检查for循环中当前索引处的字符是否为特定字符(例如字母A,数字2等)? - How to check if character at current index in for loop is a specific character (e.g. the letter A, the number 2, etc)? 如何在Java中查看内置类的源代码(例如BigInteger等)? - How do I view source code of built-in classes in Java (e.g. BigInteger etc.)? 如何在组级别实施ACL? 例如,只有学校A的老师可以更新学校A的日历 - How to implement ACL at a group level? E.g. only teachers in school A can update school A's calendar 如何安全地为要启动的后台应用程序提供敏感信息(例如密码)? - How do you securely provide a sensitive info (e.g. password) to a background application to be started? 如何在无人机上使用 python 和 java.io? - How to use python and java on drone.io?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM