File size: 1,025 Bytes
be39a04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

import matplotlib.pyplot as plt
from pymavlink import mavutil

# Open the MAVLink log file
mlog = mavutil.mavlink_connection('data/2023-01-04 20-51-25.tlog')

# Initialize lists to store the data
time_stamps = []
latitudes = []
longitudes = []
altitudes = []

# Loop through the log file and extract the data
while True:
    msg = mlog.recv_match()
    if not msg:
        break
    if msg.get_type() == 'GLOBAL_POSITION_INT':
        time_stamps.append(msg.time_boot_ms / 1000.0)
        latitudes.append(msg.lat / 1e7)
        longitudes.append(msg.lon / 1e7)
        altitudes.append(msg.alt / 1000.0)

# Plot the data
plt.plot(time_stamps, latitudes)
plt.xlabel('Time (s)')
plt.ylabel('Latitude')
plt.title('Aircraft Position Over Time')
plt.show()

plt.plot(time_stamps, longitudes)
plt.xlabel('Time (s)')
plt.ylabel('Longitude')
plt.title('Aircraft Position Over Time')
plt.show()

plt.plot(time_stamps, altitudes)
plt.xlabel('Time (s)')
plt.ylabel('Altitude (km)')
plt.title('Aircraft Position Over Time')
plt.show()