Skip to content

Commit 72e2f05

Browse files
committed
fixup! Add debug tool to follow_wall_angle.
1 parent 1cdd47a commit 72e2f05

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

osgar/lib/drawscan.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import cv2
2+
import numpy as np
3+
import math
4+
import osgar.explore
5+
6+
NO_MEASUREMENT = 0
7+
MAX_OBSTACLE_DISTANCE = 20
8+
9+
10+
def draw_scan(scan, max_obstacle_distance=None, scan_left=135, scan_right=-135):
11+
if max_obstacle_distance is None:
12+
max_obstacle_distance = MAX_OBSTACLE_DISTANCE
13+
n = len(scan)
14+
scan = np.asarray(scan) / 1000
15+
16+
angles = np.linspace(math.radians(scan_right), math.radians(scan_left), n).reshape((1, -1))
17+
angles_cos = np.cos(angles)
18+
angles_sin = np.sin(angles)
19+
is_valid = scan != NO_MEASUREMENT
20+
valid_scan = scan[is_valid]
21+
is_valid = is_valid.reshape((1, -1))
22+
acoss = angles_cos[is_valid]
23+
asins = angles_sin[is_valid]
24+
x = acoss * valid_scan
25+
y = asins * valid_scan
26+
far_map = valid_scan > max_obstacle_distance
27+
28+
height_px = 768
29+
width_px = 1024
30+
img = np.zeros((height_px, width_px, 3), dtype=np.uint8)
31+
32+
scale = 50
33+
for ix, iy, is_far in zip(x, y, far_map):
34+
point = (width_px//2 - int(iy*scale), height_px//2 - int(ix*scale))
35+
color = (0, 255, 0) if not is_far else (120, 120, 120)
36+
cv2.circle(img, point, radius=3, color=color, thickness=-1)
37+
38+
point = (width_px//2, height_px//2)
39+
point2 = (width_px//2, height_px//2-20)
40+
cv2.drawMarker(img, point, color=(0, 0, 255), markerType=cv2.MARKER_DIAMOND, thickness=3, markerSize=10)
41+
cv2.line(img, point, point2, thickness=3, color=(0, 0, 255))
42+
return img

0 commit comments

Comments
 (0)