-
Notifications
You must be signed in to change notification settings - Fork 1
/
s_rviz.py
69 lines (47 loc) · 1.36 KB
/
s_rviz.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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#/*
# @year: 2020/2021
# @author: Sekomer
# @touch: [email protected]
#*/
import numpy as np
import math
import cv2
import sys
import time
import rospy
import os
from sensor_msgs.msg import LaserScan
center_x, center_y = 400, 400
desired_fps = 15
laser = None
FI = 360/1440
def sin(angle):
return math.sin(math.radians(angle))
def cos(angle):
return math.cos(math.radians(angle))
def lidar_data(data):
global laser
laser = np.array(data.ranges[-1:0:-1])
#laser = np.array(data.ranges)
laser[laser > 25] = 0
if len(sys.argv) > 1:
laser *= int(sys.argv[1])
else:
laser *= 50
d = np.zeros((center_x * 2, center_y * 2))
d = cv2.circle(d, (center_x,center_y), 7, 255, 1)
for index, item in enumerate(laser):
x = int(sin(index * FI - 90) * item) + center_x
y = int(cos(index * FI - 90) * item) + center_y
if (0 <= x < (center_x*2)) and (0 <= y < (center_y*2)):
d[x][y] = 255
cv2.imshow("LIDAR", d)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
rospy.signal_shutdown("TERMINATING FAKE RVIZ")
if __name__ == "__main__":
rospy.init_node('fake_rviz', anonymous=True)
rospy.Subscriber('/scan', LaserScan, lidar_data)
rospy.spin()