17 def botturn(name, r, theta):
19 odleft = (r-CoR) * theta
20 odright = (r+CoR) * theta
22 odleft = (r+CoR) * -theta
23 odright = (r-CoR) * -theta
24 return name, odleft, odright
29 (
"up", 100, 100), botturn(
"left90", 0, m.pi/2), (
"left", 100, 100)],
32 'spinleft': [botturn(
"spin360_left", 0, Tau)],
35 'spinright': [botturn(
"spin360_right", 0, -Tau)],
38 'path2': [botturn(
"right45", 0, -m.pi/4), (
"up_right", 100, 100)],
42 botturn(
"right45", 0, -m.pi/4),
43 (
"up_right", 100, 100),
44 botturn(
"right90", 0, -m.pi/2),
45 (
"dn_right", 100, 100),
46 botturn(
"right90", 0, -m.pi/2),
47 (
"dn_left", 100, 100),
48 botturn(
"right90", 0, -m.pi/2),
49 (
"up_left", 100, 100)],
52 'ccw 8th-circle': [botturn(
"circle(pi/4)", 100.0 * CoR, m.pi/4)],
55 'ccw qtr-circle': [botturn(
"circle(pi/2)", 100.0 * CoR, m.pi/2)],
58 'ccw half-circle': [botturn(
"circle(pi)", 100.0 * CoR, m.pi)],
61 'ccw full-circle': [botturn(
"circle(2*pi)", 100.0 * CoR, Tau)],
64 'ccw two-circles': [botturn(
"circle(4*pi)", 100.0 * CoR, 2.0*Tau)],
67 'cw qtr-circle': [botturn(
"circle(pi/2)", 100.0 * CoR, -m.pi/2)],
76 pose[
'od_right'] = 0.0
84 def printpose(name, pose):
85 print "%s: (x,y,theta)=(%.3f, %.3f, %.3f), " \
86 "s=%.3f, r=%.3f, c=%.3f, " \
88 (name, pose[
'x'], pose[
'y'], m.degrees(pose[
'theta']),
89 pose[
's'], pose[
'r'], m.degrees(pose['c']),
90 pose[
'od_left'], pose[
'od_right'])
92 def theta(od_left, od_right):
93 theta = (od_right - od_left) / Wheelbase
98 global cur_pose, prev_pose
100 dleft = cur_pose[
'od_left'] - prev_pose[
'od_left']
101 dright = cur_pose[
'od_right'] - prev_pose[
'od_right']
102 s = (dright + dleft)/2.0
104 theta_j = cur_pose[
'theta']
105 theta_i = prev_pose[
'theta']
106 c = theta_j - theta_i
109 if m.fabs(s) <= 1e-4:
115 elif m.fabs(c) > 1e-4:
129 dx = r * (m.sin(theta_j) - m.sin(theta_i))
130 dy = r * (m.cos(theta_i) - m.cos(theta_j))
132 x = prev_pose[
'x'] + dx
133 y = prev_pose[
'y'] + dy
138 x = prev_pose[
'x'] + r * m.cos(theta_j)
139 y = prev_pose[
'y'] + r * m.sin(theta_j)
148 global cur_pose, prev_pose
153 for desc, odl, odr
in path:
156 print "%d. %s: [%.2f, %.2f]" % (n, desc, od[0], od[1])
158 prev_pose = cur_pose.copy()
159 printpose(
" prev_pose", prev_pose)
161 cur_pose[
'od_left'] = od[0]
162 cur_pose[
'od_right'] = od[1]
164 cur_pose[
'theta'] = theta(od[0], od[1])
166 cur_pose[
'x'], cur_pose[
'y'] = pose()
167 cur_pose[
'theta'] = m.fmod(cur_pose[
'theta'], Tau)
168 printpose(
" cur_pose", cur_pose)
173 for key, path
in paths.iteritems():
174 print "\n------------------------------------------------------------------" 176 print "------------------------------------------------------------------"