-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
226 lines (173 loc) · 5.14 KB
/
plot.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import pandas as pd
import matplotlib.pyplot as plt
filename = 'FLY061.csv'
df = pd.read_csv(filename, low_memory=False)
i=0
for i in range(len(df)):
if df['Clock:offsetTime'][i] >0:
index = i
break
print("index= ",index)
clock = df['Clock:offsetTime'][index:].values
imu_posN = df['IMUCalcs(0):PosN:C'][index:].values
imu_posE = df['IMUCalcs(0):PosE:C'][index:].values
imu_h = df['IMUCalcs(0):height:C'][index:].values
gps_lat = df['GPS:Lat'][index:].values
gps_long = df['GPS:Long'][index:].values
gps_h = abs(df['GPS:heightMSL'][index:].values)
imu1_posN = df['IMUCalcs(1):PosN:C'][index:].values
imu1_posE = df['IMUCalcs(1):PosE:C'][index:].values
imu1_posD = abs(df['IMUCalcs(1):height:C'][index:].values)
imu_lat = df['IMUCalcs(0):Lat:C'][index:].values
imu_long = df['IMUCalcs(0):Long:C'][index:].values
roll,pitch,yaw = [], [], []
magX,magY,magZ = [], [], []
gyroX, gyroY, gyroZ = [], [], []
accX, accY, accZ = [], [], []
velN, velE, velD = [], [], []
roll = df['IMU_ATTI(0):roll:C'][index:].values
pitch= df['IMU_ATTI(0):pitch:C'][index:].values
yaw = df['IMU_ATTI(0):yaw:C'][index:].values
accX = df['IMU_ATTI(0):accelX'][index:].values
accY =df['IMU_ATTI(0):accelY'][index:].values
accZ =df['IMU_ATTI(0):accelZ'][index:].values
gyroX = df['IMU_ATTI(0):gyroX'][index:].values
gyroY =df['IMU_ATTI(0):gyroY'][index:].values
gyroZ =df['IMU_ATTI(0):gyroZ'][index:].values
magX =df['IMU_ATTI(0):magX'][index:].values
magY =df['IMU_ATTI(0):magY'][index:].values
magZ =df['IMU_ATTI(0):magZ'][index:].values
velN= df['IMU_ATTI(0):velN'][index:].values
velE=df['IMU_ATTI(0):velE'][index:].values
velD=df['IMU_ATTI(0):velD'][index:].values
# 建立 3D 圖形
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
color_code = '#3B80D0'
# 產生 3D 座標資料
z = imu_h
x = imu_posN
y = imu_posE
# 繪製 3D 座標點
ax.scatter3D(x[0],y[0],z[0],color = 'green', marker = '.', label='start point')
ax.scatter3D(x[-1],y[-1],z[-1],color = 'purple', marker = '.', label='end point')
plt.plot(x,y,z,color_code, label = 'imu_0')
plt.plot(imu1_posN,imu1_posE,imu1_posD, 'red', label = 'imu_1')
ax.set_xlabel("imu_posN")
ax.set_ylabel("imu_posE")
ax.set_zlabel("imu_height")
ax.view_init(20, 132)
plt.title('IMU Flight trajectory')
plt.legend(loc = 'upper right')
# X, Y , Z vs time
plt.figure(2)
plt.subplot(131)
plt.title("posN over time")
plt.ylabel('posN')
plt.xlabel("clock")
plt.plot(clock,x)
plt.subplot(132)
plt.title('posE over time')
plt.ylabel('posE')
plt.xlabel('clock')
plt.plot(clock, y)
plt.subplot(133)
plt.title('height over time')
plt.ylabel('Height')
plt.xlabel('clock')
plt.plot(clock, z)
#GPS plot
fig3 = plt.figure(3)
az = fig3.add_subplot(111, projection = '3d')
plt.plot(gps_lat,gps_long,gps_h, color = 'green', label ='gps')
plt.plot(imu_lat, imu_long,imu_h,color = 'blue', label = 'imu')
az.scatter3D(gps_lat[0],gps_long[0],gps_h[0],color = 'black', marker = '.', label='start point')
az.scatter3D(gps_lat[-1],gps_long[-1],gps_h[-1],color = 'red', marker = '.', label='end point')
az.view_init(28, 130)
az.set_xlabel("lat")
az.set_ylabel("long")
az.set_zlabel("altitude")
#az.set_xlim([22.3758, 22.3766])
#az.set_ylim([114.1798,114.18])
plt.title('GPS vs IMU Flight trajectory')
plt.legend(loc = 'upper right')
#yaw, pitch, roll, vel plot
plt.figure(4)
plt.subplot(231)
plt.title("pitch over time")
plt.ylabel('pitch')
plt.xlabel("clock")
plt.plot(clock,pitch)
plt.subplot(232)
plt.title('Roll over time')
plt.ylabel('roll')
plt.xlabel('clock')
plt.plot(clock, roll)
plt.subplot(233)
plt.title('Yaw over time')
plt.ylabel('Yaw')
plt.xlabel('clock')
plt.plot(clock, yaw)
plt.subplot(234)
plt.title('VelN over time')
plt.ylabel('VelN')
plt.xlabel('clock')
plt.plot(clock, velN)
plt.subplot(235)
plt.title("velE over time")
plt.ylabel('velE')
plt.xlabel("clock")
plt.plot(clock,velE)
plt.subplot(236)
plt.title('velD over time')
plt.ylabel('velD')
plt.xlabel('clock')
plt.plot(clock, velD)
#acc, gyro,mag 2d plot
plt.figure(5)
plt.subplot(331)
plt.title("AccelX over time")
plt.ylabel('Accel X')
plt.xlabel("clock")
plt.plot(clock,accX)
plt.subplot(332)
plt.title('AccelY over time')
plt.ylabel('Accel Y')
plt.xlabel('clock')
plt.plot(clock, accY)
plt.subplot(333)
plt.title('Accel Z over time')
plt.ylabel('AccelZ')
plt.xlabel('clock')
plt.plot(clock, accZ)
plt.subplot(334)
plt.title("gyroX over time")
plt.ylabel('gyroX')
plt.xlabel("clock")
plt.plot(clock,gyroX)
plt.subplot(335)
plt.title('gyroY over time')
plt.ylabel('gyroY')
plt.xlabel('clock')
plt.plot(clock, gyroY)
plt.subplot(336)
plt.title('gyroZ over time')
plt.ylabel('gyroZ')
plt.xlabel('clock')
plt.plot(clock, gyroZ)
plt.subplot(337)
plt.title("magX over time")
plt.ylabel('magX')
plt.xlabel("clock")
plt.plot(clock,magX)
plt.subplot(338)
plt.title('magY over time')
plt.ylabel('magY')
plt.xlabel('clock')
plt.plot(clock, magY)
plt.subplot(339)
plt.title('magZ over time')
plt.ylabel('magZ')
plt.xlabel('clock')
plt.plot(clock, magZ)
plt.show()