blob: 0807c796f1695b0023ac3dbfdfd0fe1e0f9056a0 [file] [log] [blame]
Parker Schuh19b93b12018-03-02 23:26:58 -08001import numpy
2
3# joint_center in x-y space.
Parker Schuhdc682952018-03-03 18:24:01 -08004joint_center = (-0.299, 0.299)
Parker Schuh19b93b12018-03-02 23:26:58 -08005
6# Joint distances (l1 = "proximal", l2 = "distal")
Parker Schuhdc682952018-03-03 18:24:01 -08007l1 = 46.25 * 0.0254
8l2 = 43.75 * 0.0254
9
Parker Schuh19b93b12018-03-02 23:26:58 -080010
11# Convert from x-y coordinates to theta coordinates.
Parker Schuhdc682952018-03-03 18:24:01 -080012# orientation is a bool. This orientation is circular_index mod 2.
13# where circular_index is the circular index, or the position in the
Parker Schuh19b93b12018-03-02 23:26:58 -080014# "hyperextension" zones. "cross_point" allows shifting the place where
15# it rounds the result so that it draws nicer (no other functional differences).
Parker Schuhdc682952018-03-03 18:24:01 -080016def to_theta(pt, circular_index, cross_point=-numpy.pi):
17 orient = (circular_index % 2) == 0
18 x = pt[0]
19 y = pt[1]
20 x -= joint_center[0]
21 y -= joint_center[1]
22 l3 = numpy.hypot(x, y)
23 t3 = numpy.arctan2(y, x)
24 theta1 = numpy.arccos((l1**2 + l3**2 - l2**2) / (2 * l1 * l3))
Parker Schuh19b93b12018-03-02 23:26:58 -080025
Parker Schuhdc682952018-03-03 18:24:01 -080026 if orient:
27 theta1 = -theta1
28 theta1 += t3
29 theta1 = (theta1 - cross_point) % (2 * numpy.pi) + cross_point
30 theta2 = numpy.arctan2(y - l1 * numpy.sin(theta1),
31 x - l1 * numpy.cos(theta1))
32 return numpy.array((theta1, theta2))
33
Parker Schuh19b93b12018-03-02 23:26:58 -080034
35# Simple trig to go back from theta1, theta2 to x-y
Parker Schuhdc682952018-03-03 18:24:01 -080036def to_xy(theta1, theta2):
37 x = numpy.cos(theta1) * l1 + numpy.cos(theta2) * l2 + joint_center[0]
38 y = numpy.sin(theta1) * l1 + numpy.sin(theta2) * l2 + joint_center[1]
39 orient = ((theta2 - theta1) % (2.0 * numpy.pi)) < numpy.pi
40 return (x, y, orient)
41
42
43def get_circular_index(theta):
44 return int(numpy.floor((theta[1] - theta[0]) / numpy.pi))
45
46
47def get_xy(theta):
48 theta1 = theta[0]
49 theta2 = theta[1]
50 x = numpy.cos(theta1) * l1 + numpy.cos(theta2) * l2 + joint_center[0]
51 y = numpy.sin(theta1) * l1 + numpy.sin(theta2) * l2 + joint_center[1]
52 return numpy.array((x, y))
53
Parker Schuh19b93b12018-03-02 23:26:58 -080054
55# Draw a list of lines to a cairo context.
56def draw_lines(cr, lines):
Parker Schuhdc682952018-03-03 18:24:01 -080057 cr.move_to(lines[0][0], lines[0][1])
58 for pt in lines[1:]:
59 cr.line_to(pt[0], pt[1])
Parker Schuh19b93b12018-03-02 23:26:58 -080060
Parker Schuhdc682952018-03-03 18:24:01 -080061
62max_dist = 0.01
Parker Schuh19b93b12018-03-02 23:26:58 -080063max_dist_theta = numpy.pi / 64
Parker Schuhdc682952018-03-03 18:24:01 -080064xy_end_circle_size = 0.01
65theta_end_circle_size = 0.07
66
Parker Schuh19b93b12018-03-02 23:26:58 -080067
68# Subdivide in theta space.
69def subdivide_theta(lines):
Parker Schuhdc682952018-03-03 18:24:01 -080070 out = []
71 last_pt = lines[0]
72 out.append(last_pt)
73 for n_pt in lines[1:]:
74 for pt in subdivide(last_pt, n_pt, max_dist_theta):
75 out.append(pt)
76 last_pt = n_pt
Parker Schuh19b93b12018-03-02 23:26:58 -080077
Parker Schuhdc682952018-03-03 18:24:01 -080078 return out
79
Parker Schuh19b93b12018-03-02 23:26:58 -080080
81# subdivide in xy space.
Parker Schuhdc682952018-03-03 18:24:01 -080082def subdivide_xy(lines, max_dist=max_dist):
83 out = []
84 last_pt = lines[0]
85 out.append(last_pt)
86 for n_pt in lines[1:]:
87 for pt in subdivide(last_pt, n_pt, max_dist):
88 out.append(pt)
89 last_pt = n_pt
Parker Schuh19b93b12018-03-02 23:26:58 -080090
Parker Schuhdc682952018-03-03 18:24:01 -080091 return out
92
93
94def to_theta_with_ci(pt, circular_index):
95 return to_theta_with_circular_index(pt[0], pt[1], circular_index)
96
Parker Schuh19b93b12018-03-02 23:26:58 -080097
98# to_theta, but distinguishes between
Parker Schuhdc682952018-03-03 18:24:01 -080099def to_theta_with_circular_index(x, y, circular_index):
100 theta1, theta2 = to_theta((x, y), circular_index)
101 n_circular_index = int(numpy.floor((theta2 - theta1) / numpy.pi))
102 theta2 = theta2 + ((circular_index - n_circular_index)) * numpy.pi
103 return numpy.array((theta1, theta2))
104
Parker Schuh19b93b12018-03-02 23:26:58 -0800105
106# alpha is in [0, 1] and is the weight to merge a and b.
107def alpha_blend(a, b, alpha):
Parker Schuhdc682952018-03-03 18:24:01 -0800108 """Blends a and b.
Parker Schuh19b93b12018-03-02 23:26:58 -0800109
Parker Schuhdc682952018-03-03 18:24:01 -0800110 Args:
111 alpha: double, Ratio. Needs to be in [0, 1] and is the weight to blend a
112 and b.
113 """
114 return b * alpha + (1.0 - alpha) * a
115
116
Parker Schuh19b93b12018-03-02 23:26:58 -0800117def normalize(v):
Parker Schuhdc682952018-03-03 18:24:01 -0800118 """Normalize a vector while handling 0 length vectors."""
119 norm = numpy.linalg.norm(v)
120 if norm == 0:
121 return v
122 return v / norm
123
Parker Schuh19b93b12018-03-02 23:26:58 -0800124
125# CI is circular index and allows selecting between all the stats that map
126# to the same x-y state (by giving them an integer index).
127# This will compute approximate first and second derivatives with respect
128# to path length.
Parker Schuhdc682952018-03-03 18:24:01 -0800129def to_theta_with_circular_index_and_derivs(x, y, dx, dy,
130 circular_index_select):
131 a = to_theta_with_circular_index(x, y, circular_index_select)
132 b = to_theta_with_circular_index(x + dx * 0.0001, y + dy * 0.0001,
133 circular_index_select)
134 c = to_theta_with_circular_index(x - dx * 0.0001, y - dy * 0.0001,
135 circular_index_select)
136 d1 = normalize(b - a)
137 d2 = normalize(c - a)
138 accel = (d1 + d2) / numpy.linalg.norm(a - b)
139 return (a[0], a[1], d1[0], d1[1], accel[0], accel[1])
140
141
142def to_theta_with_ci_and_derivs(p_prev, p, p_next, c_i_select):
143 a = to_theta(p, c_i_select)
144 b = to_theta(p_next, c_i_select)
145 c = to_theta(p_prev, c_i_select)
146 d1 = normalize(b - a)
147 d2 = normalize(c - a)
148 accel = (d1 + d2) / numpy.linalg.norm(a - b)
149 return (a[0], a[1], d1[0], d1[1], accel[0], accel[1])
150
Parker Schuh19b93b12018-03-02 23:26:58 -0800151
152# Generic subdivision algorithm.
153def subdivide(p1, p2, max_dist):
Parker Schuhdc682952018-03-03 18:24:01 -0800154 dx = p2[0] - p1[0]
155 dy = p2[1] - p1[1]
156 dist = numpy.sqrt(dx**2 + dy**2)
157 n = int(numpy.ceil(dist / max_dist))
158 return [(alpha_blend(p1[0], p2[0],
159 float(i) / n), alpha_blend(p1[1], p2[1],
160 float(i) / n))
161 for i in range(1, n + 1)]
Parker Schuh19b93b12018-03-02 23:26:58 -0800162
Parker Schuh19b93b12018-03-02 23:26:58 -0800163
164# convert from an xy space loop into a theta loop.
165# All segements are expected go from one "hyper-extension" boundary
166# to another, thus we must go backwards over the "loop" to get a loop in
167# x-y space.
Parker Schuhdc682952018-03-03 18:24:01 -0800168def to_theta_loop(lines, cross_point=-numpy.pi):
169 out = []
170 last_pt = lines[0]
171 for n_pt in lines[1:]:
172 for pt in subdivide(last_pt, n_pt, max_dist):
173 out.append(to_theta(pt, 0, cross_point))
174 last_pt = n_pt
175 for n_pt in reversed(lines[:-1]):
176 for pt in subdivide(last_pt, n_pt, max_dist):
177 out.append(to_theta(pt, 1, cross_point))
178 last_pt = n_pt
179 return out
180
Parker Schuh19b93b12018-03-02 23:26:58 -0800181
182# Convert a loop (list of line segments) into
183# The name incorrectly suggests that it is cyclic.
184def back_to_xy_loop(lines):
Parker Schuhdc682952018-03-03 18:24:01 -0800185 out = []
186 last_pt = lines[0]
187 out.append(to_xy(last_pt[0], last_pt[1]))
188 for n_pt in lines[1:]:
189 for pt in subdivide(last_pt, n_pt, max_dist_theta):
190 out.append(to_xy(pt[0], pt[1]))
191 last_pt = n_pt
Parker Schuh19b93b12018-03-02 23:26:58 -0800192
Parker Schuhdc682952018-03-03 18:24:01 -0800193 return out
Parker Schuh19b93b12018-03-02 23:26:58 -0800194
Parker Schuh19b93b12018-03-02 23:26:58 -0800195
196# Segment in angle space.
197class AngleSegment:
Austin Schuh41c71e42018-04-04 20:11:20 -0700198 def __init__(self, start, end, name=None, alpha_unitizer=None, vmax=None):
Parker Schuhdc682952018-03-03 18:24:01 -0800199 """Creates an angle segment.
Parker Schuh19b93b12018-03-02 23:26:58 -0800200
Parker Schuhdc682952018-03-03 18:24:01 -0800201 Args:
202 start: (double, double), The start of the segment in theta1, theta2
203 coordinates in radians
204 end: (double, double), The end of the segment in theta1, theta2
205 coordinates in radians
206 """
207 self.start = start
208 self.end = end
209 self.name = name
Austin Schuh41c71e42018-04-04 20:11:20 -0700210 self.alpha_unitizer = alpha_unitizer
211 self.vmax = vmax
Parker Schuh19b93b12018-03-02 23:26:58 -0800212
Parker Schuhdc682952018-03-03 18:24:01 -0800213 def __repr__(self):
214 return "AngleSegment(%s, %s)" % (repr(self.start), repr(self.end))
Parker Schuh19b93b12018-03-02 23:26:58 -0800215
Parker Schuhdc682952018-03-03 18:24:01 -0800216 def DrawTo(self, cr, theta_version):
217 if theta_version:
218 cr.move_to(self.start[0], self.start[1] + theta_end_circle_size)
219 cr.arc(self.start[0], self.start[1], theta_end_circle_size, 0,
220 2.0 * numpy.pi)
221 cr.move_to(self.end[0], self.end[1] + theta_end_circle_size)
222 cr.arc(self.end[0], self.end[1], theta_end_circle_size, 0,
223 2.0 * numpy.pi)
224 cr.move_to(self.start[0], self.start[1])
225 cr.line_to(self.end[0], self.end[1])
226 else:
227 start_xy = to_xy(self.start[0], self.start[1])
228 end_xy = to_xy(self.end[0], self.end[1])
229 draw_lines(cr, back_to_xy_loop([self.start, self.end]))
230 cr.move_to(start_xy[0] + xy_end_circle_size, start_xy[1])
231 cr.arc(start_xy[0], start_xy[1], xy_end_circle_size, 0,
232 2.0 * numpy.pi)
233 cr.move_to(end_xy[0] + xy_end_circle_size, end_xy[1])
234 cr.arc(end_xy[0], end_xy[1], xy_end_circle_size, 0, 2.0 * numpy.pi)
235
236 def ToThetaPoints(self):
237 dx = self.end[0] - self.start[0]
238 dy = self.end[1] - self.start[1]
239 mag = numpy.hypot(dx, dy)
240 dx /= mag
241 dy /= mag
242
243 return [(self.start[0], self.start[1], dx, dy, 0.0, 0.0),
244 (self.end[0], self.end[1], dx, dy, 0.0, 0.0)]
245
246
Parker Schuh19b93b12018-03-02 23:26:58 -0800247class XYSegment:
Parker Schuhdc682952018-03-03 18:24:01 -0800248 """Straight line in XY space."""
Parker Schuh19b93b12018-03-02 23:26:58 -0800249
Austin Schuh41c71e42018-04-04 20:11:20 -0700250 def __init__(self, start, end, name=None, alpha_unitizer=None, vmax=None):
Parker Schuhdc682952018-03-03 18:24:01 -0800251 """Creates an XY segment.
Parker Schuh19b93b12018-03-02 23:26:58 -0800252
Parker Schuhdc682952018-03-03 18:24:01 -0800253 Args:
254 start: (double, double), The start of the segment in theta1, theta2
255 coordinates in radians
256 end: (double, double), The end of the segment in theta1, theta2
257 coordinates in radians
258 """
259 self.start = start
260 self.end = end
261 self.name = name
Austin Schuh41c71e42018-04-04 20:11:20 -0700262 self.alpha_unitizer = alpha_unitizer
263 self.vmax = vmax
Parker Schuh19b93b12018-03-02 23:26:58 -0800264
Parker Schuhdc682952018-03-03 18:24:01 -0800265 def __repr__(self):
266 return "XYSegment(%s, %s)" % (repr(self.start), repr(self.end))
Parker Schuh19b93b12018-03-02 23:26:58 -0800267
Parker Schuhdc682952018-03-03 18:24:01 -0800268 def DrawTo(self, cr, theta_version):
269 if theta_version:
270 theta1, theta2 = self.start
271 circular_index_select = int(
272 numpy.floor((self.start[1] - self.start[0]) / numpy.pi))
273 start = get_xy(self.start)
274 end = get_xy(self.end)
Parker Schuh19b93b12018-03-02 23:26:58 -0800275
Parker Schuhdc682952018-03-03 18:24:01 -0800276 ln = [(start[0], start[1]), (end[0], end[1])]
277 draw_lines(cr, [
278 to_theta_with_circular_index(x, y, circular_index_select)
279 for x, y in subdivide_xy(ln)
280 ])
281 cr.move_to(self.start[0] + theta_end_circle_size, self.start[1])
282 cr.arc(self.start[0], self.start[1], theta_end_circle_size, 0,
283 2.0 * numpy.pi)
284 cr.move_to(self.end[0] + theta_end_circle_size, self.end[1])
285 cr.arc(self.end[0], self.end[1], theta_end_circle_size, 0,
286 2.0 * numpy.pi)
287 else:
288 start = get_xy(self.start)
289 end = get_xy(self.end)
290 cr.move_to(start[0], start[1])
291 cr.line_to(end[0], end[1])
292 cr.move_to(start[0] + xy_end_circle_size, start[1])
293 cr.arc(start[0], start[1], xy_end_circle_size, 0, 2.0 * numpy.pi)
294 cr.move_to(end[0] + xy_end_circle_size, end[1])
295 cr.arc(end[0], end[1], xy_end_circle_size, 0, 2.0 * numpy.pi)
Parker Schuh19b93b12018-03-02 23:26:58 -0800296
Parker Schuhdc682952018-03-03 18:24:01 -0800297 def ToThetaPoints(self):
298 """ Converts to points in theta space via to_theta_with_circular_index_and_derivs"""
299 theta1, theta2 = self.start
300 circular_index_select = int(
301 numpy.floor((self.start[1] - self.start[0]) / numpy.pi))
302 start = get_xy(self.start)
303 end = get_xy(self.end)
304
305 ln = [(start[0], start[1]), (end[0], end[1])]
306
307 dx = end[0] - start[0]
308 dy = end[1] - start[1]
309 mag = numpy.hypot(dx, dy)
310 dx /= mag
311 dy /= mag
312
313 return [
314 to_theta_with_circular_index_and_derivs(x, y, dx, dy,
315 circular_index_select)
316 for x, y in subdivide_xy(ln, 0.01)
317 ]
318
319
320def spline_eval(start, control1, control2, end, alpha):
321 a = alpha_blend(start, control1, alpha)
322 b = alpha_blend(control1, control2, alpha)
323 c = alpha_blend(control2, end, alpha)
324 return alpha_blend(
325 alpha_blend(a, b, alpha), alpha_blend(b, c, alpha), alpha)
326
327
328def subdivide_spline(start, control1, control2, end):
329 # TODO: pick N based on spline parameters? or otherwise change it to be more evenly spaced?
330 n = 100
331 for i in range(0, n + 1):
332 yield i / float(n)
333
334
335class SplineSegment:
Austin Schuh41c71e42018-04-04 20:11:20 -0700336 def __init__(self,
337 start,
338 control1,
339 control2,
340 end,
341 name=None,
342 alpha_unitizer=None,
343 vmax=None):
Parker Schuhdc682952018-03-03 18:24:01 -0800344 self.start = start
345 self.control1 = control1
346 self.control2 = control2
347 self.end = end
348 self.name = name
Austin Schuh41c71e42018-04-04 20:11:20 -0700349 self.alpha_unitizer = alpha_unitizer
350 self.vmax = vmax
Parker Schuhdc682952018-03-03 18:24:01 -0800351
352 def __repr__(self):
Austin Schuh41c71e42018-04-04 20:11:20 -0700353 return "SplineSegment(%s, %s, %s, %s)" % (repr(self.start),
354 repr(self.control1),
355 repr(self.control2),
356 repr(self.end))
Parker Schuhdc682952018-03-03 18:24:01 -0800357
358 def DrawTo(self, cr, theta_version):
Austin Schuh41c71e42018-04-04 20:11:20 -0700359 if theta_version:
Parker Schuhdc682952018-03-03 18:24:01 -0800360 c_i_select = get_circular_index(self.start)
361 start = get_xy(self.start)
362 control1 = get_xy(self.control1)
363 control2 = get_xy(self.control2)
364 end = get_xy(self.end)
365
366 draw_lines(cr, [
367 to_theta(
368 spline_eval(start, control1, control2, end, alpha),
369 c_i_select)
370 for alpha in subdivide_spline(start, control1, control2, end)
371 ])
Austin Schuh41c71e42018-04-04 20:11:20 -0700372 cr.move_to(self.start[0] + theta_end_circle_size, self.start[1])
373 cr.arc(self.start[0], self.start[1], theta_end_circle_size, 0,
374 2.0 * numpy.pi)
375 cr.move_to(self.end[0] + theta_end_circle_size, self.end[1])
376 cr.arc(self.end[0], self.end[1], theta_end_circle_size, 0,
377 2.0 * numpy.pi)
Parker Schuhdc682952018-03-03 18:24:01 -0800378 else:
379 start = get_xy(self.start)
380 control1 = get_xy(self.control1)
381 control2 = get_xy(self.control2)
382 end = get_xy(self.end)
Austin Schuh41c71e42018-04-04 20:11:20 -0700383
Parker Schuhdc682952018-03-03 18:24:01 -0800384 draw_lines(cr, [
385 spline_eval(start, control1, control2, end, alpha)
386 for alpha in subdivide_spline(start, control1, control2, end)
387 ])
Austin Schuh41c71e42018-04-04 20:11:20 -0700388
389 cr.move_to(self.start[0] + xy_end_circle_size, start[1])
390 cr.arc(start[0], start[1], xy_end_circle_size, 0, 2.0 * numpy.pi)
391 cr.move_to(end[0] + xy_end_circle_size, end[1])
392 cr.arc(end[0], end[1], xy_end_circle_size, 0, 2.0 * numpy.pi)
Parker Schuhdc682952018-03-03 18:24:01 -0800393
394 def ToThetaPoints(self):
395 t1, t2 = self.start
396 c_i_select = get_circular_index(self.start)
397 start = get_xy(self.start)
398 control1 = get_xy(self.control1)
399 control2 = get_xy(self.control2)
400 end = get_xy(self.end)
401
402 return [
403 to_theta_with_ci_and_derivs(
404 spline_eval(start, control1, control2, end, alpha - 0.00001),
405 spline_eval(start, control1, control2, end, alpha),
406 spline_eval(start, control1, control2, end, alpha + 0.00001),
407 c_i_select)
408 for alpha in subdivide_spline(start, control1, control2, end)
409 ]
410
411
Austin Schuh41c71e42018-04-04 20:11:20 -0700412def get_derivs(t_prev, t, t_next):
413 c, a, b = t_prev, t, t_next
414 d1 = normalize(b - a)
415 d2 = normalize(c - a)
416 accel = (d1 + d2) / numpy.linalg.norm(a - b)
417 return (a[0], a[1], d1[0], d1[1], accel[0], accel[1])
418
419
420class ThetaSplineSegment:
421 def __init__(self,
422 start,
423 control1,
424 control2,
425 end,
426 name=None,
427 alpha_unitizer=None,
428 vmax=None):
429 self.start = start
430 self.control1 = control1
431 self.control2 = control2
432 self.end = end
433 self.name = name
434 self.alpha_unitizer = alpha_unitizer
435 self.vmax = vmax
436
437 def __repr__(self):
438 return "ThetaSplineSegment(%s, %s, &s, %s)" % (repr(self.start),
439 repr(self.control1),
440 repr(self.control2),
441 repr(self.end))
442
443 def DrawTo(self, cr, theta_version):
444 if (theta_version):
445 draw_lines(cr, [
446 spline_eval(self.start, self.control1, self.control2, self.end,
447 alpha)
448 for alpha in subdivide_spline(self.start, self.control1,
449 self.control2, self.end)
450 ])
451 else:
452 start = get_xy(self.start)
453 end = get_xy(self.end)
454
455 draw_lines(cr, [
456 get_xy(
457 spline_eval(self.start, self.control1, self.control2,
458 self.end, alpha))
459 for alpha in subdivide_spline(self.start, self.control1,
460 self.control2, self.end)
461 ])
462
463 cr.move_to(start[0] + xy_end_circle_size, start[1])
464 cr.arc(start[0], start[1], xy_end_circle_size, 0, 2.0 * numpy.pi)
465 cr.move_to(end[0] + xy_end_circle_size, end[1])
466 cr.arc(end[0], end[1], xy_end_circle_size, 0, 2.0 * numpy.pi)
467
468 def ToThetaPoints(self):
469 return [
470 get_derivs(
471 spline_eval(self.start, self.control1, self.control2, self.end,
472 alpha - 0.00001),
473 spline_eval(self.start, self.control1, self.control2, self.end,
474 alpha),
475 spline_eval(self.start, self.control1, self.control2, self.end,
476 alpha + 0.00001))
477 for alpha in subdivide_spline(self.start, self.control1,
478 self.control2, self.end)
479 ]
480
481
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700482tall_box_x = 0.411
483tall_box_y = 0.125
Parker Schuhdc682952018-03-03 18:24:01 -0800484
485short_box_x = 0.431
486short_box_y = 0.082
487
488ready_above_box = to_theta_with_circular_index(
489 tall_box_x, tall_box_y + 0.08, circular_index=-1)
490tall_box_grab = to_theta_with_circular_index(
491 tall_box_x, tall_box_y, circular_index=-1)
492short_box_grab = to_theta_with_circular_index(
493 short_box_x, short_box_y, circular_index=-1)
494
495# TODO(austin): Drive the front/back off the same numbers a bit better.
496front_high_box = to_theta_with_circular_index(0.378, 2.46, circular_index=-1)
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700497front_middle3_box = to_theta_with_circular_index(
498 0.700, 2.125, circular_index=-1.000000)
Parker Schuhdc682952018-03-03 18:24:01 -0800499front_middle2_box = to_theta_with_circular_index(
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700500 0.700, 2.268, circular_index=-1)
Parker Schuhdc682952018-03-03 18:24:01 -0800501front_middle1_box = to_theta_with_circular_index(
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700502 0.800, 1.915, circular_index=-1)
503front_low_box = to_theta_with_circular_index(0.87, 1.572, circular_index=-1)
Parker Schuhdc682952018-03-03 18:24:01 -0800504back_high_box = to_theta_with_circular_index(-0.75, 2.48, circular_index=0)
505back_middle2_box = to_theta_with_circular_index(
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700506 -0.700, 2.268, circular_index=0)
Parker Schuhdc682952018-03-03 18:24:01 -0800507back_middle1_box = to_theta_with_circular_index(
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700508 -0.800, 1.915, circular_index=0)
509back_low_box = to_theta_with_circular_index(-0.87, 1.572, circular_index=0)
Parker Schuhdc682952018-03-03 18:24:01 -0800510
511front_switch = to_theta_with_circular_index(0.88, 0.967, circular_index=-1)
512back_switch = to_theta_with_circular_index(-0.88, 0.967, circular_index=-2)
513
514neutral = to_theta_with_circular_index(0.0, 0.33, circular_index=-1)
515
516up = to_theta_with_circular_index(0.0, 2.547, circular_index=-1)
517
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700518front_switch_auto = to_theta_with_circular_index(
519 0.750, 2.20, circular_index=-1.000000)
520
Austin Schuhccf56632018-04-04 20:14:44 -0700521duck = numpy.array(
522 [numpy.pi / 2.0 - 0.92, numpy.pi / 2.0 - 4.26])
523
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700524starting = numpy.array(
525 [numpy.pi / 2.0 - 0.593329, numpy.pi / 2.0 - 3.749631])
526vertical_starting = numpy.array(
527 [numpy.pi / 2.0, -numpy.pi / 2.0])
528
Austin Schuh17e484e2018-03-11 01:11:36 -0800529self_hang = numpy.array(
530 [numpy.pi / 2.0 - 0.191611, numpy.pi / 2.0])
531partner_hang = numpy.array(
532 [numpy.pi / 2.0 - (-0.25), numpy.pi / 2.0])
533
534above_hang = numpy.array(
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700535 [numpy.pi / 2.0 - 0.14, numpy.pi / 2.0 - (-0.165)])
Austin Schuh17e484e2018-03-11 01:11:36 -0800536below_hang = numpy.array(
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700537 [numpy.pi / 2.0 - 0.39, numpy.pi / 2.0 - (-0.517)])
Austin Schuh17e484e2018-03-11 01:11:36 -0800538
Parker Schuhdc682952018-03-03 18:24:01 -0800539up_c1 = to_theta((0.63, 1.17), circular_index=-1)
540up_c2 = to_theta((0.65, 1.62), circular_index=-1)
541
542front_high_box_c1 = to_theta((0.63, 1.04), circular_index=-1)
543front_high_box_c2 = to_theta((0.50, 1.60), circular_index=-1)
544
545front_middle2_box_c1 = to_theta((0.41, 0.83), circular_index=-1)
546front_middle2_box_c2 = to_theta((0.52, 1.30), circular_index=-1)
547
548front_middle1_box_c1 = to_theta((0.34, 0.82), circular_index=-1)
549front_middle1_box_c2 = to_theta((0.48, 1.15), circular_index=-1)
550
Austin Schuhccf56632018-04-04 20:14:44 -0700551#c1: (1.421433, -1.070254)
552#c2: (1.434384, -1.057803
553ready_above_box_c1 = numpy.array([1.480802, -1.081218])
554ready_above_box_c2 = numpy.array([1.391449, -1.060331])
Parker Schuhdc682952018-03-03 18:24:01 -0800555
Austin Schuh214b91c2018-03-10 19:25:23 -0800556front_switch_c1 = numpy.array([1.903841, -0.622351])
557front_switch_c2 = numpy.array([1.903841, -0.622351])
558
Parker Schuhdc682952018-03-03 18:24:01 -0800559points = [(ready_above_box, "ReadyAboveBox"),
560 (tall_box_grab, "TallBoxGrab"),
561 (short_box_grab, "ShortBoxGrab"),
562 (front_high_box, "FrontHighBox"),
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700563 (front_middle3_box, "FrontMiddle3Box"),
Parker Schuhdc682952018-03-03 18:24:01 -0800564 (front_middle2_box, "FrontMiddle2Box"),
565 (front_middle1_box, "FrontMiddle1Box"),
566 (front_low_box, "FrontLowBox"),
567 (back_high_box, "BackHighBox"),
568 (back_middle2_box, "BackMiddle2Box"),
569 (back_middle1_box, "BackMiddle1Box"),
570 (back_low_box, "BackLowBox"),
571 (front_switch, "FrontSwitch"),
572 (back_switch, "BackSwitch"),
573 (neutral, "Neutral"),
Austin Schuh17e484e2018-03-11 01:11:36 -0800574 (up, "Up"),
575 (above_hang, "AboveHang"),
576 (below_hang, "BelowHang"),
577 (self_hang, "SelfHang"),
578 (partner_hang, "PartnerHang"),
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700579 (front_switch_auto, "FrontSwitchAuto"),
580 (starting, "Starting"),
Austin Schuhccf56632018-04-04 20:14:44 -0700581 (duck, "Duck"),
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700582 (vertical_starting, "VerticalStarting"),
Austin Schuh17e484e2018-03-11 01:11:36 -0800583] # yapf: disable
Parker Schuhdc682952018-03-03 18:24:01 -0800584
Austin Schuhccf56632018-04-04 20:14:44 -0700585duck_c1 = numpy.array([1.337111, -1.721008])
586duck_c2 = numpy.array([1.283701, -1.795519])
587
588ready_to_up_c1 = numpy.array([1.792962, 0.198329])
589ready_to_up_c2 = numpy.array([1.792962, 0.198329])
590
591
Parker Schuhdc682952018-03-03 18:24:01 -0800592# We need to define critical points so we can create paths connecting them.
593# TODO(austin): Attach velocities to the slow ones.
594named_segments = [
Parker Schuhdc682952018-03-03 18:24:01 -0800595 SplineSegment(neutral, ready_above_box_c1, ready_above_box_c2,
596 ready_above_box, "ReadyToNeutral"),
Austin Schuh41c71e42018-04-04 20:11:20 -0700597 XYSegment(ready_above_box, tall_box_grab, "ReadyToTallBox", vmax=6.0),
598 XYSegment(ready_above_box, short_box_grab, "ReadyToShortBox", vmax=6.0),
599 XYSegment(tall_box_grab, short_box_grab, "TallToShortBox", vmax=6.0),
Austin Schuhb874fd32018-03-05 00:27:10 -0800600 SplineSegment(neutral, ready_above_box_c1, ready_above_box_c2,
601 tall_box_grab, "TallToNeutral"),
602 SplineSegment(neutral, ready_above_box_c1, ready_above_box_c2,
603 short_box_grab, "ShortToNeutral"),
Parker Schuhdc682952018-03-03 18:24:01 -0800604 SplineSegment(neutral, up_c1, up_c2, up, "NeutralToUp"),
605 SplineSegment(neutral, front_high_box_c1, front_high_box_c2,
606 front_high_box, "NeutralToFrontHigh"),
607 SplineSegment(neutral, front_middle2_box_c1, front_middle2_box_c2,
Austin Schuh7dfccf62018-03-03 21:28:14 -0800608 front_middle2_box, "NeutralToFrontMiddle2"),
Parker Schuhdc682952018-03-03 18:24:01 -0800609 SplineSegment(neutral, front_middle1_box_c1, front_middle1_box_c2,
Austin Schuh7dfccf62018-03-03 21:28:14 -0800610 front_middle1_box, "NeutralToFrontMiddle1"),
Parker Schuhdc682952018-03-03 18:24:01 -0800611]
612
613unnamed_segments = [
Austin Schuhccf56632018-04-04 20:14:44 -0700614 SplineSegment(tall_box_grab, ready_to_up_c1, ready_to_up_c2, up),
615 SplineSegment(short_box_grab, ready_to_up_c1, ready_to_up_c2, up),
616 SplineSegment(ready_above_box, ready_to_up_c1, ready_to_up_c2, up),
617 ThetaSplineSegment(duck, duck_c1, duck_c2, neutral),
Austin Schuh214b91c2018-03-10 19:25:23 -0800618 SplineSegment(neutral, front_switch_c1, front_switch_c2, front_switch),
Austin Schuhccf56632018-04-04 20:14:44 -0700619 AngleSegment(neutral, back_switch),
620
621 XYSegment(ready_above_box, front_low_box),
622 XYSegment(ready_above_box, front_switch),
623 XYSegment(ready_above_box, front_middle1_box),
624 XYSegment(ready_above_box, front_middle2_box),
625 XYSegment(ready_above_box, front_middle3_box),
626 XYSegment(ready_above_box, front_high_box),
627 #XYSegment(ready_above_box, up),
Parker Schuhdc682952018-03-03 18:24:01 -0800628
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700629 AngleSegment(starting, vertical_starting),
630 AngleSegment(vertical_starting, neutral),
631
Austin Schuhccf56632018-04-04 20:14:44 -0700632 # TODO(austin): Duck -> neutral with a theta spline.
633 #AngleSegment(duck, vertical_starting),
634
Austin Schuh214b91c2018-03-10 19:25:23 -0800635 XYSegment(neutral, front_low_box),
Parker Schuhdc682952018-03-03 18:24:01 -0800636 XYSegment(up, front_high_box),
637 XYSegment(up, front_middle2_box),
Austin Schuh83cdd8a2018-03-21 20:49:02 -0700638
639 XYSegment(front_middle3_box, up),
640 XYSegment(front_middle3_box, front_high_box),
641 XYSegment(front_middle3_box, front_middle2_box),
642 XYSegment(front_middle3_box, front_middle1_box),
643
644 XYSegment(neutral, front_switch_auto),
645
Parker Schuhdc682952018-03-03 18:24:01 -0800646 XYSegment(up, front_middle1_box),
647 XYSegment(up, front_low_box),
648 XYSegment(front_high_box, front_middle2_box),
649 XYSegment(front_high_box, front_middle1_box),
650 XYSegment(front_high_box, front_low_box),
651 XYSegment(front_middle2_box, front_middle1_box),
652 XYSegment(front_middle2_box, front_low_box),
653 XYSegment(front_middle1_box, front_low_box),
654 XYSegment(front_switch, front_low_box),
655 XYSegment(front_switch, up),
656 XYSegment(front_switch, front_high_box),
657 AngleSegment(up, back_high_box),
658 AngleSegment(up, back_middle2_box),
659 AngleSegment(up, back_middle1_box),
660 XYSegment(back_high_box, back_middle2_box),
661 XYSegment(back_high_box, back_middle1_box),
662 XYSegment(back_high_box, back_low_box),
663 XYSegment(back_middle2_box, back_middle1_box),
664 XYSegment(back_middle2_box, back_low_box),
665 XYSegment(back_middle1_box, back_low_box),
Austin Schuh17e484e2018-03-11 01:11:36 -0800666
667 AngleSegment(up, above_hang),
668 AngleSegment(above_hang, below_hang),
669 AngleSegment(up, below_hang),
670 AngleSegment(up, self_hang),
671 AngleSegment(up, partner_hang),
Parker Schuhdc682952018-03-03 18:24:01 -0800672]
673
674segments = named_segments + unnamed_segments