plot_post-process.py
Go to the documentation of this file.
1 import matplotlib.pyplot as plt
2 import numpy as np
3 from scipy.linalg import norm
4 
5 
6 def quat2euler(q):
7  w = q[0, :]
8  x = q[1, :]
9  y = q[2, :]
10  z = q[3, :]
11  return np.array([np.arctan2(2.0 * (w * x + y * z), 1. - 2. * (x * x + y * y)),
12  np.arcsin(2.0 * (w * y - z * x)),
13  np.arctan2(2.0 * (w * z + x * y), 1. - 2. * (y * y + z * z))])
14 
15 est = np.fromfile("/tmp/rosflight_post_process/estimate.bin", dtype=np.float64)
16 est = np.reshape(est, (-1, 8))
17 
18 cmd = np.fromfile("/tmp/rosflight_post_process/cmd.bin", dtype=np.float64)
19 cmd = np.reshape(cmd, (-1, 5))
20 
21 truth = np.fromfile("/tmp/rosflight_post_process/truth.bin", dtype=np.float64)
22 truth = np.reshape(truth, (-1, 5))
23 truth[:,0] -= 2.25
24 
25 # rotate quaternion to account for mocap stupidity
26 R = np.array([[0, -1, 0],
27  [0, 0, -1],
28  [1, 0, 0]])
29 truth[:,2:] = truth[:,2:].dot(R)
30 
31 imu_filt = np.fromfile("/tmp/rosflight_post_process/imu_filt.bin", dtype=np.float64)
32 imu_filt = np.reshape(imu_filt, (-1, 7))
33 
34 imu = np.fromfile("/tmp/rosflight_post_process/imu.bin", dtype=np.float64)
35 imu = np.reshape(imu, (-1, 7))
36 
37 est_labels=['t','qw','qx','qy','qz','bx','by','bz']
38 truth_labels=['t','qw','qx','qy','qz']
39 imu_filt_labels=['t','accx','accy','accz','gyrox','gyroy','gyroz']
40 
41 true_euler = quat2euler(truth[:,1:].T)
42 true_euler[2,:] -= true_euler[2,0]
43 est_euler = quat2euler(est[:,1:].T)
44 
45 
46 
47 plt.figure(1)
48 for i in range(1,5,1):
49  plt.suptitle('quaternion')
50  plt.subplot(4,1,i)
51  plt.ylabel(est_labels[i])
52  plt.plot(est[:,0], est[:,i], label="est")
53  plt.plot(truth[:,0], truth[:,i], label="truth")
54  plt.legend()
55 
56 plt.figure(2)
57 for i in range(5,8,1):
58  plt.suptitle('biases')
59  plt.subplot(3,1,i-4)
60  plt.ylabel(est_labels[i])
61  plt.plot(est[:,0], est[:,i])
62 
63 
64 # acc_max = 9.80665 * 1.1
65 # acc_min = 9.80665 * 0.9
66 # print imu_filt
67 # acc_mag = norm(imu_filt[:,1:4], axis=1)
68 # acc_within_bounds_idx = (acc_mag > acc_min) & (acc_mag < acc_max)
69 # good_acc = acc_mag.copy()
70 # bad_acc = acc_mag.copy()
71 # good_acc[~acc_within_bounds_idx]=np.nan
72 # bad_acc[acc_within_bounds_idx]=np.nan
73 # plt.figure(3)
74 # plt.title("accelerometer magnitude check")
75 # plt.plot(imu_filt[:,0], good_acc, '.', label="in bounds")
76 # plt.plot(imu_filt[:,0], bad_acc, '.', label="out of bounds")
77 # plt.plot([imu_filt[0,0], imu_filt[-1,0]], [acc_max, acc_max], ':', color=[0.2, 0.2, 0.2])
78 # plt.plot([imu_filt[0,0], imu_filt[-1,0]], [acc_min, acc_min], ':', color=[0.2, 0.2, 0.2])
79 # plt.legend()
80 
81 # plt.figure(4)
82 # for i in range(1,4,1):
83 # plt.subplot(3,1,i)
84 # plt.plot(imu[:,0], imu[:,i], label="unfiltered")
85 # plt.plot(imu_filt[:,0], imu_filt[:,i], label="filtered")
86 # plt.legend()
87 
88 plt.figure(5)
89 ax = None
90 for i in range(3):
91  plt.suptitle('euler')
92  ax = plt.subplot(3,1,i+1, sharex = ax)
93  plt.plot(truth[:,0], true_euler[i,:], label="truth")
94  plt.plot(est[:,0], est_euler[i,:], label="est")
95  plt.plot(cmd[:,0], cmd[:,i+1], label="cmd")
96  plt.legend()
97 
98 
99 
100 
101 plt.show()
def quat2euler(q)


rosflight_utils
Author(s):
autogenerated on Thu Apr 15 2021 05:10:06