-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
85 lines (68 loc) · 2.1 KB
/
scan.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
#!/usr/bin/env python3
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
from mayavi import mlab
from mpl_toolkits.mplot3d import Axes3D
def plots_(axes_, x_, y_, label_=None, xlabel_="", ylabel_="", title_=""):
axes_.plot(x_, y_, 'o-', label=label_)
axes_.set_xlabel(xlabel_)
axes_.set_ylabel(ylabel_)
axes_.set_title(title_)
axes_.grid()
def main():
load = True
DEBUG = False
np.set_printoptions(suppress=True)
if not load:
lidar_points = np.random.rand(75,161)
height_robot = 0.58
np.savez('lidar.npz', lidar_points=lidar_points, height_robot=height_robot)
else:
data = np.load('lidar.npz')
lidar_points = data['lidar_points']
height_robot = data['height_robot']
head_pitch = 85
tilt_rate = -1
z_list=[]
y_list=[]
x_list=[]
for points in lidar_points:
z = points * np.cos(np.radians(90 - head_pitch))
ho = height_robot - z
z_list.append(ho)
x = points * np.sin(np.radians(90 - head_pitch))
y_list.append(x)
y = np.arange(0, len(points))
x_list.append(y)
head_pitch += tilt_rate
# if head_pitch < 10:
# break
# plot point cloud
# fig = plt.figure()
# ax = fig.add_subplot(111, projection='3d')
x_list= np.array(x_list)
y_list= np.array(y_list)
z_list= np.array(z_list)
# ax.scatter(x_list, y_list, z_list)
# ax.plot_wireframe(x_list, y_list, z_list, rstride=10, cstride=10)
mlab.points3d(x_list, y_list, z_list, y_list, scale_mode='none', scale_factor=1)
mlab.axes()
mlab.show()
layers = np.mean(lidar_points, axis=1)
angle = np.arange(85, 10, -1)
if DEBUG:
print(lidar_points)
print(layers)
print(angle)
print(height_robot)
# plot layers point
fig1, axes = plt.subplots(nrows=1, ncols=1)
plots_(axes, angle, layers, None, "", "", "")
plt.show()
# plt.show(block=False)
# plt.pause(0.1)
# input("Press [enter] to close.")
# plt.close('all')
if __name__ == '__main__':
main()