获取大疆无人机的飞控记录数据并绘制曲线

这篇具有很好参考价值的文章主要介绍了获取大疆无人机的飞控记录数据并绘制曲线。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

机型M350RTK,其飞行记录文件为加密的,我的完善代码如下

git@github.com:huashu996/DJFlightRecordParsing2TXT.git

一、下载安装官方的DJIFlightRecord

git clone git@github.com:dji-sdk/FlightRecordParsingLib.git

飞行记录文件在打开【我的电脑】,进入遥控器内存,
文件路径:此电脑 > pm430 > 内部共享存储空间> DJI > com.dji.industry.pilot > FlightRecord 

二、注册成为大疆开发者获取SDK 密钥

网址如下DJI Developer

注册完之后新建APP获得密钥

  1. 登录 DJI 开发者平台,点击"创建应用",App Type 选择 "Open API",自行填写“App 名称”“分类”和“描述”,点击 "创建"。

  2. 通过个人邮箱激活 App,在开发者网平台个人点击查看对应 App 信息,其中 App Key 即为下文所需的 SDK 密钥参数。 

获取大疆无人机的飞控记录数据并绘制曲线,无人机协同,无人机,python

三、编译运行

编译 

cd FlightRecordParsingLib-master/dji-flightrecord-kit/build/Ubuntu/FlightRecordStandardizationCpp
sh generate.sh

运行

cd ~/FlightRecordParsingLib-master/dji-flightrecord-kit/build/Ubuntu/FRSample
export SDK_KEY=your_sdk_key_value
./FRSample /home/cxl/FlightRecordParsingLib-master/DJrecord/DJIFlightRecord_2023-07-18_[16-14-57].txt

 此时会在终端打印出一系列无人机的状态信息,但还是不能够使用

于是我更改了main.cc文件,使它能够保存数据到txt文件

获取大疆无人机的飞控记录数据并绘制曲线,无人机协同,无人机,python

四、获取单个数据

上一步生成的txt文件由于参数众多是巨大的,这里我写了一个py文件用于提取重要的信息,例如提取经纬度和高度

import json

# Read JSON fragment from txt file
with open("output.txt", "r") as file:
    json_data = json.load(file)

# Extract all "aircraftLocation" and "altitude" data
location_altitude_data = []
for frame_state in json_data["info"]["frameTimeStates"]:
    aircraft_location = frame_state["flightControllerState"]["aircraftLocation"]
    altitude = frame_state["flightControllerState"]["altitude"]
    location_altitude_data.append({"latitude": aircraft_location["latitude"], "longitude": aircraft_location["longitude"], "altitude": altitude})

# Write values to a new txt file
with open("xyz_output.txt", "w") as f:
    for data in location_altitude_data:
        f.write(f"latitude: {data['latitude']}, longitude: {data['longitude']}, altitude: {data['altitude']}\n")

print("Values extracted and written to 'output.txt' file.")

就能够生成只有这几个参数的txt文件 

获取大疆无人机的飞控记录数据并绘制曲线,无人机协同,无人机,python

 五、生成轨迹

将经纬度和高度生成xyz坐标和画图,暂定以前20个点的均值作为投影坐标系的原点

from pyproj import Proj
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as mplot3d
def read_coordinates_from_txt(file_path):
    coordinates = []
    with open(file_path, 'r') as file:
        for line in file:
            parts = line.strip().split(',')
            latitude = float(parts[0].split(':')[1].strip())
            longitude = float(parts[1].split(':')[1].strip())
            altitude = float(parts[2].split(':')[1].strip())
            coordinates.append((latitude, longitude, altitude))
    return coordinates

def calculate_avg_coordinates(coordinates):
    num_points = len(coordinates)
    avg_latitude = sum(coord[0] for coord in coordinates) / num_points
    avg_longitude = sum(coord[1] for coord in coordinates) / num_points
    return avg_latitude, avg_longitude


def project_coordinates_to_xyz(coordinates, avg_latitude, avg_longitude, origin_x, origin_y):
    # Define the projection coordinate system (UTM zone 10, WGS84 ellipsoid)
    p = Proj(proj='utm', zone=20, ellps='WGS84', preserve_units=False)

    # Project all points in the coordinates list to xy coordinate system
    projected_coordinates = [p(longitude, latitude) for latitude, longitude, _ in coordinates]

    # Calculate the relative xyz values for each point with respect to the origin
    relative_xyz_coordinates = []
    for (x, y), (_, _, altitude) in zip(projected_coordinates, coordinates):
        relative_x = x - origin_x
        relative_y = y - origin_y
        relative_xyz_coordinates.append((relative_x, relative_y, altitude))
    return relative_xyz_coordinates
    
def three_plot_coordinates(coordinates):
    # Separate the x, y, z coordinates for plotting
    x_values, y_values, z_values = zip(*coordinates)

    # Create a new figure for the 3D plot
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    # Plot points as a 3D scatter plot
    ax.scatter(x_values, y_values, z_values, c='blue', label='Points')

    # Connect points with lines
    for i in range(1, len(x_values)):
        ax.plot([x_values[i - 1], x_values[i]], [y_values[i - 1], y_values[i]], [z_values[i - 1], z_values[i]], 'k-', linewidth=0.5)

    # Add labels and title
    ax.set_xlabel('X (meters)')
    ax.set_ylabel('Y (meters)')
    ax.set_zlabel('Z (meters)')
    ax.set_title('Projected Coordinates - 3D')

    # Display the 3D plot in a separate window
    plt.show()

def two_plot_coordinates(coordinates):
    # Separate the x, y, z coordinates for plotting
    x_values, y_values, z_values = zip(*coordinates)

    # Create a new figure for the 2D plot
    fig = plt.figure()

    # Plot points
    plt.scatter(x_values, y_values, c='blue', label='Points')

    # Connect points with lines
    for i in range(1, len(x_values)):
        plt.plot([x_values[i - 1], x_values[i]], [y_values[i - 1], y_values[i]], 'k-', linewidth=0.5)

    # Add labels and title
    plt.xlabel('X (meters)')
    plt.ylabel('Y (meters)')
    plt.title('Projected Coordinates - 2D')
    plt.legend()

    # Display the 2D plot in a separate window
    plt.show()
    
if __name__ == "__main__":
    input_file_path = "xyz_output.txt"  # Replace with the actual input file path

    coordinates = read_coordinates_from_txt(input_file_path)

    # Use the first 10 points to define the projection coordinate system
    num_points_for_avg = 20
    avg_coordinates = coordinates[:num_points_for_avg]
    avg_latitude, avg_longitude = calculate_avg_coordinates(avg_coordinates)

    # Project the average latitude and longitude to xy coordinate system
    p = Proj(proj='utm', zone=20, ellps='WGS84', preserve_units=False)
    origin_x, origin_y = p(avg_longitude, avg_latitude)

    print(f"Average Latitude: {avg_latitude}, Average Longitude: {avg_longitude}")
    print(f"Projected Coordinates (x, y): {origin_x}, {origin_y}")

    # Project all points in the coordinates list to xy coordinate system
    first_coordinates = [(0, 0, 0)] * min(len(coordinates), num_points_for_avg)
    projected_coordinates2 = project_coordinates_to_xyz(coordinates[num_points_for_avg:], avg_latitude, avg_longitude, origin_x, origin_y)
    projected_coordinates = first_coordinates+projected_coordinates2
    # Save projected coordinates to a new text file
    output_file_path = "projected_coordinates.txt"
    with open(output_file_path, 'w') as output_file:
        for x, y, z in projected_coordinates:
            output_file.write(f"x: {x}, y: {y}, z: {z}\n")
    three_plot_coordinates(projected_coordinates)
    two_plot_coordinates(projected_coordinates)

生成xyz的txt文档 

获取大疆无人机的飞控记录数据并绘制曲线,无人机协同,无人机,python

 获取大疆无人机的飞控记录数据并绘制曲线,无人机协同,无人机,python

获取大疆无人机的飞控记录数据并绘制曲线,无人机协同,无人机,python 

上述只以坐标为例子,想获取其他数据,改变参数即可。文章来源地址https://www.toymoban.com/news/detail-601697.html

到了这里,关于获取大疆无人机的飞控记录数据并绘制曲线的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 主流无人机开源飞控

    无人机是一个宽泛的概念,从美国高空高速的U2军用无人机,到中国最新声名鹊起的“猛龙\\\",再到淘宝网上随处可见的四轴飞行器,无论是外形,性能,还是价格,应用场景,都可谓是天差地别,不可同日而语。军用无人机自诞生之日起,从外形还是发动机,都是直接从有人

    2024年02月22日
    浏览(37)
  • 大疆精灵4A无人机航空摄影测量外业数据采集完整操作流程 - 点云处理

    无人机在航空摄影测量领域中发挥着重要的作用,能够高效地获取大范围地理信息数据。本文将介绍大疆精灵4A无人机的航空摄影测量外业数据采集的完整操作流程,并重点讨论点云处理的相关内容。以下是详细的操作步骤和源代码示例。 准备工作 在开始操作之前,需要完成

    2024年02月06日
    浏览(111)
  • PPK大疆无人机应用教程

    新建工程,设置项目名称,保存位置,控制等级,坐标系统(坐标系统选择高斯克吕格,中央子午线根据实际数据所在位置进行选择) 选择大疆数据,找到对应的文件夹 数据有:图片,EVENT.bin,PPKAW.bin,Rinex.ads和Time数据,以及静态数据 导入结果:

    2024年02月16日
    浏览(34)
  • Tello无人机飞控(Python)程序设计

    tello的几个不同的飞控库有什么区别吗,用哪个好些? Tello的几个不同飞控库主要是针对Python开发者提供的控制无人机的工具包,它们各有特点和使用方式。以下是对一些常见Tello飞控库的区别和推荐的概述: 1)tellopy:tellopy是一个功能齐全的库,提供了对Tello无人机的全面控

    2024年02月16日
    浏览(37)
  • 大疆飞卡30运载无人机技术分享

    大疆飞卡30是大疆公司面向运输领域推出的一款专业运载无人机。它采用了优秀的设计,装备了多种先进传感器,以解决运输中的难题。以下我们来了解一下其主要特点: 【应用领域】 飞卡30适用于山地救灾、农业化肥施用、工程材料运送等交通不便的山区应用,也适用于海岛联通

    2024年02月12日
    浏览(31)
  • 大疆无人机基于RTMP服务推流直播

    流程:配置nginx服务器---打开服务器----配置无人机rtmp地址,将无人机画面推流到服务器上----运行vlc从服务器上拉取视频流播放。 学习视频链接(可借鉴):https://www.youtube.com/watch?v=QNEjTGQL7wc 一、在linux服务器中(ubuntu18.04)下载安装docker容器,docker分为docker engine 和 docker desktop 我

    2024年02月05日
    浏览(60)
  • 大疆无人机空三建模干货分享(大疆智图集群建模超详细教程)

    Part 01 大疆无人机空三建模干货分享(大疆智图集群建模超详细教程) 大疆智图集群简介 大疆在今年5月推出的智图3.0.0及以上版本中加入了集群功能,有集群版许可的用户可以使用此功能。智图集群是由一台主节点分配任务控制多台同局域网内子节点设备进行空三和建模。集群

    2024年02月09日
    浏览(45)
  • 大疆无人机视频删了怎么恢复?尝试这些恢复技巧

    无人机拍摄的视频已经成为许多飞行爱好者和专业人士珍贵的记忆与资料。然而,误删视频是许多人都可能遇到的问题。当您不慎删除了大疆无人机中的视频时,不必过于焦虑。本文将为您详细介绍如何恢复这些误删的视频,帮助您找回宝贵的回忆。 图片来源于网络,如有侵

    2024年04月15日
    浏览(32)
  • ROS环境下大疆tello无人机源码安装&驱动代码解读

            大疆tello无人机是一款微小型无人机,可以支持多种开发模式。这里用的是ROS1的kinetic版本进行开发。参考文档来自http://wiki.ros.org/tello_driver         打开终端,键入以下命令进行二进制文件安装:         然后进入到ros工作空间,下载tello驱动源码         返回

    2024年02月13日
    浏览(52)
  • 心得:大疆无人机RTMP推流直播(Windows版本已成功)

    1、nginx的Gryphon版本,它内部已经集成了rtmp的推流编译(nginx-Gryphon) 2、服务器状态检查程序stat.xsl(nginx-rtmp-module) 3、ffmpeg(ffmpeg) 4、VLC(VLC) 1、将下载好的nginx 1.7.11.3 Gryphon解压修改文件名为nginx-1.7.11.3-Gryphon,绝对路径中不能有中文,必须全为英文! 2、在根目录中的con

    2024年02月03日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包