-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.py
141 lines (132 loc) · 4.61 KB
/
debug.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import socket
import sys
import time
from zss_debug_pb2 import Debug_Msgs, Debug_Msg, Debug_Arc
class Debugger(object):
def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.debug_address = ('localhost', 20001)
def draw_circle(self, package, x, y, radius=300):
msg = package.msgs.add()
msg.type = Debug_Msg.ARC
msg.color = Debug_Msg.WHITE
arc = msg.arc
arc.rectangle.point1.x = x - radius
arc.rectangle.point1.y = y - radius
arc.rectangle.point2.x = x + radius
arc.rectangle.point2.y = y + radius
arc.start = 0
arc.end = 360
arc.FILL = True
def draw_line(self, package, x1, y1, x2, y2):
msg = package.msgs.add()
msg.type = Debug_Msg.LINE
msg.color = Debug_Msg.WHITE
line = msg.line
line.start.x = x1
line.start.y = y1
line.end.x = x2
line.end.y = y2
line.FORWARD = True
line.BACK = True
def draw_lines(self, package, x1, y1, x2, y2,color='w'):
idx=['w','bk','r','g','b'].index(color)
COLOR = [Debug_Msg.WHITE,Debug_Msg.BLACK,Debug_Msg.RED,Debug_Msg.GREEN,Debug_Msg.BLUE][idx]
for i in range(len(x1)):
msg = package.msgs.add()
msg.type = Debug_Msg.LINE
msg.color = COLOR
line = msg.line
line.start.x = x1[i]
line.start.y = y1[i]
line.end.x = x2[i]
line.end.y = y2[i]
line.FORWARD = True
line.BACK = True
def draw_point(self, package, x, y,color='w'):
msg = package.msgs.add()
idx=['w','bk','r','g','b'].index(color)
COLOR = [Debug_Msg.WHITE,Debug_Msg.BLACK,Debug_Msg.RED,Debug_Msg.GREEN,Debug_Msg.BLUE][idx]
# line 1
msg.type = Debug_Msg.LINE
msg.color = COLOR
# msg.color = Debug_Msg.WHITE
line = msg.line
line.start.x = x + 50
line.start.y = y + 50
line.end.x = x - 50
line.end.y = y - 50
line.FORWARD = True
line.BACK = True
# line 2
msg = package.msgs.add()
msg.type = Debug_Msg.LINE
msg.color = COLOR
line = msg.line
line.start.x = x - 50
line.start.y = y + 50
line.end.x = x + 50
line.end.y = y - 50
line.FORWARD = True
line.BACK = True
def draw_points(self, package, x, y):
for i in range(len(x)):
# line 1
msg = package.msgs.add()
msg.type = Debug_Msg.LINE
msg.color = Debug_Msg.WHITE
line = msg.line
line.start.x = x[i] + 50
line.start.y = y[i] + 50
line.end.x = x[i] - 50
line.end.y = y[i] - 50
line.FORWARD = True
line.BACK = True
# line 2
msg = package.msgs.add()
msg.type = Debug_Msg.LINE
msg.color = Debug_Msg.WHITE
line = msg.line
line.start.x = x[i] - 50
line.start.y = y[i] + 50
line.end.x = x[i] + 50
line.end.y = y[i] - 50
line.FORWARD = True
line.BACK = True
def draw_points_numpy(self, package, x, y,color='w'):
idx=['w','bk','r','g','b'].index(color)
COLOR = [Debug_Msg.WHITE,Debug_Msg.BLACK,Debug_Msg.RED,Debug_Msg.GREEN,Debug_Msg.BLUE][idx]
for i in range(x.shape[0]):
# line 1
msg = package.msgs.add()
msg.type = Debug_Msg.LINE
msg.color = COLOR
line = msg.line
line.start.x = x[i] + 50
line.start.y = y[i] + 50
line.end.x = x[i] - 50
line.end.y = y[i] - 50
line.FORWARD = True
line.BACK = True
# line 2
msg = package.msgs.add()
msg.type = Debug_Msg.LINE
msg.color = COLOR
line = msg.line
line.start.x = x[i] - 50
line.start.y = y[i] + 50
line.end.x = x[i] + 50
line.end.y = y[i] - 50
line.FORWARD = True
line.BACK = True
def send(self, package):
self.sock.sendto(package.SerializeToString(), self.debug_address)
if __name__ == '__main__':
debugger = Debugger()
package = Debug_Msgs()
debugger.draw_circle(package, x=0, y=500)
debugger.draw_line(package, x1=0, y1=2500, x2=600, y2=2500)
debugger.draw_lines(package, x1=[0,0], y1=[0,2000], x2=[2000,2000], y2=[0,2000])
debugger.draw_point(package, x=500, y=500)
debugger.draw_points(package, x=[1000, 2000], y=[3000, 3000])
debugger.send(package)