-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint_processor.py
More file actions
58 lines (53 loc) · 1.78 KB
/
point_processor.py
File metadata and controls
58 lines (53 loc) · 1.78 KB
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
import json
from math import sin,cos,radians,pi
import matplotlib.pyplot as plt
from constants import *
def process_point_cloud(file_name):
points = []
with open(file_name,'r') as f:
result = json.load(f)
num_readings = len(result['positions'])
for i in range(num_readings):
point_result = calculate_points_from_reading(result['positions'][i],result['readings'][i])
points = points + point_result
graph_points(points,result['positions'])
print(points)
def calculate_points_from_reading(position,reading):
point_result = []
x = position['x']
y = position['y']
heading_r = radians(position['heading'])
left = reading['left']
right = reading['right']
center = reading['center']
if center<SENSOR_THRESHOLD:
center_point_x = x+sin(heading_r)*center
center_point_y = y+cos(heading_r)*center
point_result.append([center_point_x,center_point_y])
if right<SENSOR_THRESHOLD:
right_point_x = x+sin(heading_r+pi/2)*right
right_point_y = y+cos(heading_r+pi/2)*right
point_result.append([right_point_x,right_point_y])
if left<SENSOR_THRESHOLD:
left_point_x = x+sin(heading_r-pi/2)*left
left_point_y = y+cos(heading_r-pi/2)*left
point_result.append([left_point_x,left_point_y])
return point_result
def graph_points(points,positions):
x = []
y = []
for point in points:
x.append(point[0])
y.append(point[1])
plt.scatter(x,y)
ax = plt.gca()
ax.set_aspect(1)
x_position = []
y_position = []
for position in positions:
x_position.append(position['x'])
y_position.append(position['y'])
ax.scatter(x_position,y_position)
plt.show()
if __name__ == '__main__':
process_point_cloud('results.json')