-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.py
162 lines (126 loc) · 3.36 KB
/
path.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
from math import pi, cos, sin
from utils import draw_sphere_marker
import numpy as np
def draw_path(path: list, radius=0.1, color=(0, 0, 0, 1)) -> None:
for pt in path:
draw_sphere_marker((pt[0], pt[1], 1), radius, color)
def gen_path(param: dict) -> list:
if param['type'] == 'circle':
return gen_path_circle(param['radius'], param['step'])
if param['type'] == 'L-turn':
return gen_path_lturn(param['step'])
if param['type'] == 'eecs':
return gen_path_eecs(param['step'])
def gen_path_circle(r: float, step: float) -> list:
angle = 0
path = []
while angle < 2 * pi:
path.append((r * sin(angle), -r * cos(angle) + r, angle))
angle += step
return path
def move(x: float, y: float, angle: float, dx: float, dy: float, dangle: float,
step: float) -> list:
path = []
while dx != 0 or dy != 0 or dangle != 0:
path.append((x, y, angle))
if abs(dx) < step:
x += dx
dx = 0
elif abs(dx) == dx:
x += step
dx -= step
else:
x -= step
dx += step
if abs(dy) < step:
y += dy
dy = 0
elif abs(dy) == dy:
y += step
dy -= step
else:
y -= step
dy += step
if abs(dangle) < step:
angle += dangle
dangle = 0
elif abs(dangle) == dangle:
angle += pi / 4
dangle -= pi / 4
else:
angle -= pi / 4
dangle += pi / 4
path.append(np.array([x, y, angle]))
return path
def gen_path_lturn(step: float) -> list:
x = 0
y = 0
angle = 0
path = []
#move +x
path.extend(move(x, y, angle, 13, 0, 0, step))
x += 13
#turn
path.extend(move(x, y, angle, 0, 0, pi / 2, step))
angle += pi / 2
#move +y
path.extend(move(x, y, angle, 0, 13, 0, step))
y += 13
return path
def gen_path_eecs(step: float) -> list:
x = 0
y = 0
angle = 0
path = []
#move x+7
path.extend(move(x, y, angle, 7, 0, 0, step))
x += 7
#turn +pi/2
path.extend(move(x, y, angle, 0, 0, pi / 2, step))
angle += pi / 2
#move y+3
path.extend(move(x, y, angle, 0, 3, 0, step))
y += 3
#move x-3
path.extend(move(x, y, angle, -3, 0, 0, step))
x -= 3
#move y+1
path.extend(move(x, y, angle, 0, 1, 0, step))
y += 1
#move x+3
path.extend(move(x, y, angle, 3, 0, 0, step))
x += 3
#move y+7
path.extend(move(x, y, angle, 0, 7, 0, step))
y += 7
#turn -pi/2
path.extend(move(x, y, angle, 0, 0, -pi / 2, step))
angle -= pi / 2
#move x+12
path.extend(move(x, y, angle, 12, 0, 0, step))
x += 12
#turn -pi/2
path.extend(move(x, y, angle, 0, 0, -pi / 2, step))
angle -= pi / 2
#move y-3
path.extend(move(x, y, angle, 0, -3, 0, step))
y -= 3
#move x-3, y-3
path.extend(move(x, y, angle, -3, -3, 0, step))
x -= 3
y -= 3
#move x+3, y-3
path.extend(move(x, y, angle, 3, -3, 0, step))
x += 3
y -= 3
#move y-2
path.extend(move(x, y, angle, 0, -2, 0, step))
y -= 2
#turn +pi/2
path.extend(move(x, y, angle, 0, 0, pi / 2, step))
angle += pi / 2
#move x+7
path.extend(move(x, y, angle, 7, 0, 0, step))
x += 7
return path