For the model M350RTK, its flight record files are encrypted, and my complete code is as follows
[email protected]:huashu996/DJFlightRecordParsing2TXT.git
1. Download and install the official DJIFlightRecord
git clone [email protected]:dji-sdk/FlightRecordParsingLib.git
The flight record file is opened in [My Computer], enter the remote control memory,
the file path: this computer > pm430 > internal shared storage space > DJI > com.dji.industry.pilot > FlightRecord
2. Register as a DJI developer to obtain the SDK key
The URL is as followsDJI Developer
After registration, create a new APP to obtain the key
-
Log in to the DJI developer platform , click "Create App", select "Open API" for the App Type, fill in the "App Name", "Category" and "Description" by yourself, and click "Create".
-
Activate the App through your personal mailbox, and click to view the corresponding App information on the Developer Network platform, where the App Key is the SDK key parameter required below.
3. Compile and run
compile
cd FlightRecordParsingLib-master/dji-flightrecord-kit/build/Ubuntu/FlightRecordStandardizationCpp
sh generate.sh
run
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
At this time, a series of status information of the drone will be printed on the terminal, but it still cannot be used
So I changed the main.cc file so that it can save data to txt file
Fourth, get a single data
The txt file generated in the previous step is huge due to the large number of parameters. Here I wrote a py file to extract important information, such as extracting latitude, longitude and altitude
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.")
You can generate a txt file with only these parameters
5. Generate trajectory
Generate xyz coordinates and draw the latitude, longitude and height, tentatively set the mean value of the previous 20 points as the origin of the projected coordinate system
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)
Generate xyz txt document
The above only takes the coordinates as an example. If you want to obtain other data, just change the parameters.