blob: 91dba3c1e12eb574d1023a9eee9d2bd06820f875 [file] [log] [blame]
Campbell Crowley33e0e3d2017-12-27 17:55:40 -08001#!/usr/bin/python
2
3import numpy
4from frc971.control_loops.python import polytope
5import frc971.control_loops.python.drivetrain
6from frc971.control_loops.python import control_loop
7from frc971.control_loops.python import controls
8from frc971.control_loops.python.cim import CIM
9from matplotlib import pylab
10
11import glog
12
13def CoerceGoal(region, K, w, R):
14 """Intersects a line with a region, and finds the closest point to R.
15
16 Finds a point that is closest to R inside the region, and on the line
17 defined by K X = w. If it is not possible to find a point on the line,
18 finds a point that is inside the region and closest to the line. This
19 function assumes that
20
21 Args:
22 region: HPolytope, the valid goal region.
23 K: numpy.matrix (2 x 1), the matrix for the equation [K1, K2] [x1; x2] = w
24 w: float, the offset in the equation above.
25 R: numpy.matrix (2 x 1), the point to be closest to.
26
27 Returns:
28 numpy.matrix (2 x 1), the point.
29 """
30 return DoCoerceGoal(region, K, w, R)[0]
31
32def DoCoerceGoal(region, K, w, R):
33 if region.IsInside(R):
34 return (R, True)
35
36 perpendicular_vector = K.T / numpy.linalg.norm(K)
37 parallel_vector = numpy.matrix([[perpendicular_vector[1, 0]],
38 [-perpendicular_vector[0, 0]]])
39
40 # We want to impose the constraint K * X = w on the polytope H * X <= k.
41 # We do this by breaking X up into parallel and perpendicular components to
42 # the half plane. This gives us the following equation.
43 #
44 # parallel * (parallel.T \dot X) + perpendicular * (perpendicular \dot X)) = X
45 #
46 # Then, substitute this into the polytope.
47 #
48 # H * (parallel * (parallel.T \dot X) + perpendicular * (perpendicular \dot X)) <= k
49 #
50 # Substitute K * X = w
51 #
52 # H * parallel * (parallel.T \dot X) + H * perpendicular * w <= k
53 #
54 # Move all the knowns to the right side.
55 #
56 # H * parallel * ([parallel1 parallel2] * X) <= k - H * perpendicular * w
57 #
58 # Let t = parallel.T \dot X, the component parallel to the surface.
59 #
60 # H * parallel * t <= k - H * perpendicular * w
61 #
62 # This is a polytope which we can solve, and use to figure out the range of X
63 # that we care about!
64
65 t_poly = polytope.HPolytope(
66 region.H * parallel_vector,
67 region.k - region.H * perpendicular_vector * w)
68
69 vertices = t_poly.Vertices()
70
71 if vertices.shape[0]:
72 # The region exists!
73 # Find the closest vertex
74 min_distance = numpy.infty
75 closest_point = None
76 for vertex in vertices:
77 point = parallel_vector * vertex + perpendicular_vector * w
78 length = numpy.linalg.norm(R - point)
79 if length < min_distance:
80 min_distance = length
81 closest_point = point
82
83 return (closest_point, True)
84 else:
85 # Find the vertex of the space that is closest to the line.
86 region_vertices = region.Vertices()
87 min_distance = numpy.infty
88 closest_point = None
89 for vertex in region_vertices:
90 point = vertex.T
91 length = numpy.abs((perpendicular_vector.T * point)[0, 0])
92 if length < min_distance:
93 min_distance = length
94 closest_point = point
95
96 return (closest_point, False)
97
98class VelocityDrivetrainModel(control_loop.ControlLoop):
99 def __init__(self, drivetrain_params, left_low=True, right_low=True,
100 name="VelocityDrivetrainModel"):
101 super(VelocityDrivetrainModel, self).__init__(name)
102 self._drivetrain = frc971.control_loops.python.drivetrain.Drivetrain(
103 left_low=left_low, right_low=right_low,
104 drivetrain_params=drivetrain_params)
105 self.dt = drivetrain_params.dt
106 self.A_continuous = numpy.matrix(
107 [[self._drivetrain.A_continuous[1, 1], self._drivetrain.A_continuous[1, 3]],
108 [self._drivetrain.A_continuous[3, 1], self._drivetrain.A_continuous[3, 3]]])
109
110 self.B_continuous = numpy.matrix(
111 [[self._drivetrain.B_continuous[1, 0], self._drivetrain.B_continuous[1, 1]],
112 [self._drivetrain.B_continuous[3, 0], self._drivetrain.B_continuous[3, 1]]])
113 self.C = numpy.matrix(numpy.eye(2))
114 self.D = numpy.matrix(numpy.zeros((2, 2)))
115
116 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
117 self.B_continuous, self.dt)
118
119 # FF * X = U (steady state)
120 self.FF = self.B.I * (numpy.eye(2) - self.A)
121
122 self.PlaceControllerPoles(drivetrain_params.controller_poles)
Austin Schuh74425152018-12-21 11:37:14 +1100123 # Build a kalman filter for the velocity. We don't care what the gains
124 # are, but the hybrid kalman filter that we want to write to disk to get
125 # access to A_continuous and B_continuous needs this for completeness.
126 self.Q_continuous = numpy.matrix([[(0.5 ** 2.0), 0.0], [0.0, (0.5 ** 2.0)]])
127 self.R_continuous = numpy.matrix([[(0.1 ** 2.0), 0.0], [0.0, (0.1 ** 2.0)]])
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800128 self.PlaceObserverPoles(drivetrain_params.observer_poles)
Austin Schuh74425152018-12-21 11:37:14 +1100129 _, _, self.Q, self.R = controls.kalmd(
130 A_continuous=self.A_continuous, B_continuous=self.B_continuous,
131 Q_continuous=self.Q_continuous, R_continuous=self.R_continuous,
132 dt=self.dt)
133
134 self.KalmanGain, self.P_steady_state = controls.kalman(
135 A=self.A, B=self.B, C=self.C, Q=self.Q, R=self.R)
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800136
137 self.G_high = self._drivetrain.G_high
138 self.G_low = self._drivetrain.G_low
139 self.resistance = self._drivetrain.resistance
140 self.r = self._drivetrain.r
141 self.Kv = self._drivetrain.Kv
142 self.Kt = self._drivetrain.Kt
143
144 self.U_max = self._drivetrain.U_max
145 self.U_min = self._drivetrain.U_min
146
Austin Schuh44aa9142018-12-03 21:07:23 +1100147 @property
148 def robot_radius_l(self):
149 return self._drivetrain.robot_radius_l
150 @property
151 def robot_radius_r(self):
152 return self._drivetrain.robot_radius_r
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800153
154class VelocityDrivetrain(object):
155 HIGH = 'high'
156 LOW = 'low'
157 SHIFTING_UP = 'up'
158 SHIFTING_DOWN = 'down'
159
Austin Schuh74425152018-12-21 11:37:14 +1100160 def __init__(self, drivetrain_params, name='VelocityDrivetrain'):
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800161 self.drivetrain_low_low = VelocityDrivetrainModel(
Austin Schuh74425152018-12-21 11:37:14 +1100162 left_low=True, right_low=True, name=name + 'LowLow',
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800163 drivetrain_params=drivetrain_params)
164 self.drivetrain_low_high = VelocityDrivetrainModel(
Austin Schuh74425152018-12-21 11:37:14 +1100165 left_low=True, right_low=False, name=name + 'LowHigh',
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800166 drivetrain_params=drivetrain_params)
167 self.drivetrain_high_low = VelocityDrivetrainModel(
Austin Schuh74425152018-12-21 11:37:14 +1100168 left_low=False, right_low=True, name = name + 'HighLow',
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800169 drivetrain_params=drivetrain_params)
170 self.drivetrain_high_high = VelocityDrivetrainModel(
Austin Schuh74425152018-12-21 11:37:14 +1100171 left_low=False, right_low=False, name = name + 'HighHigh',
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800172 drivetrain_params=drivetrain_params)
173
174 # X is [lvel, rvel]
175 self.X = numpy.matrix(
176 [[0.0],
177 [0.0]])
178
179 self.U_poly = polytope.HPolytope(
180 numpy.matrix([[1, 0],
181 [-1, 0],
182 [0, 1],
183 [0, -1]]),
184 numpy.matrix([[12],
185 [12],
186 [12],
187 [12]]))
188
189 self.U_max = numpy.matrix(
190 [[12.0],
191 [12.0]])
192 self.U_min = numpy.matrix(
193 [[-12.0000000000],
194 [-12.0000000000]])
195
196 self.dt = 0.00505
197
198 self.R = numpy.matrix(
199 [[0.0],
200 [0.0]])
201
202 self.U_ideal = numpy.matrix(
203 [[0.0],
204 [0.0]])
205
206 # ttrust is the comprimise between having full throttle negative inertia,
207 # and having no throttle negative inertia. A value of 0 is full throttle
208 # inertia. A value of 1 is no throttle negative inertia.
209 self.ttrust = 1.0
210
211 self.left_gear = VelocityDrivetrain.LOW
212 self.right_gear = VelocityDrivetrain.LOW
213 self.left_shifter_position = 0.0
214 self.right_shifter_position = 0.0
215 self.left_cim = CIM()
216 self.right_cim = CIM()
217
218 def IsInGear(self, gear):
219 return gear is VelocityDrivetrain.HIGH or gear is VelocityDrivetrain.LOW
220
221 def MotorRPM(self, shifter_position, velocity):
222 if shifter_position > 0.5:
223 return (velocity / self.CurrentDrivetrain().G_high /
224 self.CurrentDrivetrain().r)
225 else:
226 return (velocity / self.CurrentDrivetrain().G_low /
227 self.CurrentDrivetrain().r)
228
229 def CurrentDrivetrain(self):
230 if self.left_shifter_position > 0.5:
231 if self.right_shifter_position > 0.5:
232 return self.drivetrain_high_high
233 else:
234 return self.drivetrain_high_low
235 else:
236 if self.right_shifter_position > 0.5:
237 return self.drivetrain_low_high
238 else:
239 return self.drivetrain_low_low
240
241 def SimShifter(self, gear, shifter_position):
242 if gear is VelocityDrivetrain.HIGH or gear is VelocityDrivetrain.SHIFTING_UP:
243 shifter_position = min(shifter_position + 0.5, 1.0)
244 else:
245 shifter_position = max(shifter_position - 0.5, 0.0)
246
247 if shifter_position == 1.0:
248 gear = VelocityDrivetrain.HIGH
249 elif shifter_position == 0.0:
250 gear = VelocityDrivetrain.LOW
251
252 return gear, shifter_position
253
254 def ComputeGear(self, wheel_velocity, should_print=False, current_gear=False, gear_name=None):
255 high_omega = (wheel_velocity / self.CurrentDrivetrain().G_high /
256 self.CurrentDrivetrain().r)
257 low_omega = (wheel_velocity / self.CurrentDrivetrain().G_low /
258 self.CurrentDrivetrain().r)
259 #print gear_name, "Motor Energy Difference.", 0.5 * 0.000140032647 * (low_omega * low_omega - high_omega * high_omega), "joules"
260 high_torque = ((12.0 - high_omega / self.CurrentDrivetrain().Kv) *
261 self.CurrentDrivetrain().Kt / self.CurrentDrivetrain().resistance)
262 low_torque = ((12.0 - low_omega / self.CurrentDrivetrain().Kv) *
263 self.CurrentDrivetrain().Kt / self.CurrentDrivetrain().resistance)
264 high_power = high_torque * high_omega
265 low_power = low_torque * low_omega
266 #if should_print:
267 # print gear_name, "High omega", high_omega, "Low omega", low_omega
268 # print gear_name, "High torque", high_torque, "Low torque", low_torque
269 # print gear_name, "High power", high_power, "Low power", low_power
270
271 # Shift algorithm improvements.
272 # TODO(aschuh):
273 # It takes time to shift. Shifting down for 1 cycle doesn't make sense
274 # because you will end up slower than without shifting. Figure out how
275 # to include that info.
276 # If the driver is still in high gear, but isn't asking for the extra power
277 # from low gear, don't shift until he asks for it.
278 goal_gear_is_high = high_power > low_power
279 #goal_gear_is_high = True
280
281 if not self.IsInGear(current_gear):
282 glog.debug('%s Not in gear.', gear_name)
283 return current_gear
284 else:
285 is_high = current_gear is VelocityDrivetrain.HIGH
286 if is_high != goal_gear_is_high:
287 if goal_gear_is_high:
288 glog.debug('%s Shifting up.', gear_name)
289 return VelocityDrivetrain.SHIFTING_UP
290 else:
291 glog.debug('%s Shifting down.', gear_name)
292 return VelocityDrivetrain.SHIFTING_DOWN
293 else:
294 return current_gear
295
296 def FilterVelocity(self, throttle):
297 # Invert the plant to figure out how the velocity filter would have to work
298 # out in order to filter out the forwards negative inertia.
299 # This math assumes that the left and right power and velocity are equal.
300
301 # The throttle filter should filter such that the motor in the highest gear
302 # should be controlling the time constant.
303 # Do this by finding the index of FF that has the lowest value, and computing
304 # the sums using that index.
305 FF_sum = self.CurrentDrivetrain().FF.sum(axis=1)
306 min_FF_sum_index = numpy.argmin(FF_sum)
307 min_FF_sum = FF_sum[min_FF_sum_index, 0]
308 min_K_sum = self.CurrentDrivetrain().K[min_FF_sum_index, :].sum()
309 # Compute the FF sum for high gear.
310 high_min_FF_sum = self.drivetrain_high_high.FF[0, :].sum()
311
312 # U = self.K[0, :].sum() * (R - x_avg) + self.FF[0, :].sum() * R
313 # throttle * 12.0 = (self.K[0, :].sum() + self.FF[0, :].sum()) * R
314 # - self.K[0, :].sum() * x_avg
315
316 # R = (throttle * 12.0 + self.K[0, :].sum() * x_avg) /
317 # (self.K[0, :].sum() + self.FF[0, :].sum())
318
319 # U = (K + FF) * R - K * X
320 # (K + FF) ^-1 * (U + K * X) = R
321
322 # Scale throttle by min_FF_sum / high_min_FF_sum. This will make low gear
323 # have the same velocity goal as high gear, and so that the robot will hold
324 # the same speed for the same throttle for all gears.
325 adjusted_ff_voltage = numpy.clip(throttle * 12.0 * min_FF_sum / high_min_FF_sum, -12.0, 12.0)
326 return ((adjusted_ff_voltage + self.ttrust * min_K_sum * (self.X[0, 0] + self.X[1, 0]) / 2.0)
327 / (self.ttrust * min_K_sum + min_FF_sum))
328
329 def Update(self, throttle, steering):
330 # Shift into the gear which sends the most power to the floor.
331 # This is the same as sending the most torque down to the floor at the
332 # wheel.
333
334 self.left_gear = self.right_gear = True
335 if True:
336 self.left_gear = self.ComputeGear(self.X[0, 0], should_print=True,
337 current_gear=self.left_gear,
338 gear_name="left")
339 self.right_gear = self.ComputeGear(self.X[1, 0], should_print=True,
340 current_gear=self.right_gear,
341 gear_name="right")
342 if self.IsInGear(self.left_gear):
343 self.left_cim.X[0, 0] = self.MotorRPM(self.left_shifter_position, self.X[0, 0])
344
345 if self.IsInGear(self.right_gear):
346 self.right_cim.X[0, 0] = self.MotorRPM(self.right_shifter_position, self.X[0, 0])
347
348 if self.IsInGear(self.left_gear) and self.IsInGear(self.right_gear):
349 # Filter the throttle to provide a nicer response.
350 fvel = self.FilterVelocity(throttle)
351
352 # Constant radius means that angualar_velocity / linear_velocity = constant.
353 # Compute the left and right velocities.
354 steering_velocity = numpy.abs(fvel) * steering
355 left_velocity = fvel - steering_velocity
356 right_velocity = fvel + steering_velocity
357
358 # Write this constraint in the form of K * R = w
359 # angular velocity / linear velocity = constant
360 # (left - right) / (left + right) = constant
361 # left - right = constant * left + constant * right
362
363 # (fvel - steering * numpy.abs(fvel) - fvel - steering * numpy.abs(fvel)) /
364 # (fvel - steering * numpy.abs(fvel) + fvel + steering * numpy.abs(fvel)) =
365 # constant
366 # (- 2 * steering * numpy.abs(fvel)) / (2 * fvel) = constant
367 # (-steering * sign(fvel)) = constant
368 # (-steering * sign(fvel)) * (left + right) = left - right
369 # (steering * sign(fvel) + 1) * left + (steering * sign(fvel) - 1) * right = 0
370
371 equality_k = numpy.matrix(
372 [[1 + steering * numpy.sign(fvel), -(1 - steering * numpy.sign(fvel))]])
373 equality_w = 0.0
374
375 self.R[0, 0] = left_velocity
376 self.R[1, 0] = right_velocity
377
378 # Construct a constraint on R by manipulating the constraint on U
379 # Start out with H * U <= k
380 # U = FF * R + K * (R - X)
381 # H * (FF * R + K * R - K * X) <= k
382 # H * (FF + K) * R <= k + H * K * X
383 R_poly = polytope.HPolytope(
384 self.U_poly.H * (self.CurrentDrivetrain().K + self.CurrentDrivetrain().FF),
385 self.U_poly.k + self.U_poly.H * self.CurrentDrivetrain().K * self.X)
386
387 # Limit R back inside the box.
388 self.boxed_R = CoerceGoal(R_poly, equality_k, equality_w, self.R)
389
390 FF_volts = self.CurrentDrivetrain().FF * self.boxed_R
391 self.U_ideal = self.CurrentDrivetrain().K * (self.boxed_R - self.X) + FF_volts
392 else:
393 glog.debug('Not all in gear')
394 if not self.IsInGear(self.left_gear) and not self.IsInGear(self.right_gear):
395 # TODO(austin): Use battery volts here.
396 R_left = self.MotorRPM(self.left_shifter_position, self.X[0, 0])
397 self.U_ideal[0, 0] = numpy.clip(
398 self.left_cim.K * (R_left - self.left_cim.X) + R_left / self.left_cim.Kv,
399 self.left_cim.U_min, self.left_cim.U_max)
400 self.left_cim.Update(self.U_ideal[0, 0])
401
402 R_right = self.MotorRPM(self.right_shifter_position, self.X[1, 0])
403 self.U_ideal[1, 0] = numpy.clip(
404 self.right_cim.K * (R_right - self.right_cim.X) + R_right / self.right_cim.Kv,
405 self.right_cim.U_min, self.right_cim.U_max)
406 self.right_cim.Update(self.U_ideal[1, 0])
407 else:
408 assert False
409
410 self.U = numpy.clip(self.U_ideal, self.U_min, self.U_max)
411
412 # TODO(austin): Model the robot as not accelerating when you shift...
413 # This hack only works when you shift at the same time.
414 if self.IsInGear(self.left_gear) and self.IsInGear(self.right_gear):
415 self.X = self.CurrentDrivetrain().A * self.X + self.CurrentDrivetrain().B * self.U
416
417 self.left_gear, self.left_shifter_position = self.SimShifter(
418 self.left_gear, self.left_shifter_position)
419 self.right_gear, self.right_shifter_position = self.SimShifter(
420 self.right_gear, self.right_shifter_position)
421
422 glog.debug('U is %s %s', str(self.U[0, 0]), str(self.U[1, 0]))
423 glog.debug('Left shifter %s %d Right shifter %s %d',
424 self.left_gear, self.left_shifter_position,
425 self.right_gear, self.right_shifter_position)
426
Austin Schuh74425152018-12-21 11:37:14 +1100427def WritePolyDrivetrain(drivetrain_files, motor_files, hybrid_files,
428 year_namespace, drivetrain_params,
429 scalar_type='double'):
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800430 vdrivetrain = VelocityDrivetrain(drivetrain_params)
Austin Schuh74425152018-12-21 11:37:14 +1100431 hybrid_vdrivetrain = VelocityDrivetrain(drivetrain_params,
432 name="HybridVelocityDrivetrain")
Austin Schuhbcce26a2018-03-26 23:41:24 -0700433 if isinstance(year_namespace, list):
434 namespaces = year_namespace
435 else:
436 namespaces = [year_namespace, 'control_loops', 'drivetrain']
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800437 dog_loop_writer = control_loop.ControlLoopWriter(
438 "VelocityDrivetrain", [vdrivetrain.drivetrain_low_low,
439 vdrivetrain.drivetrain_low_high,
440 vdrivetrain.drivetrain_high_low,
441 vdrivetrain.drivetrain_high_high],
Austin Schuhbcce26a2018-03-26 23:41:24 -0700442 namespaces=namespaces,
443 scalar_type=scalar_type)
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800444
445 dog_loop_writer.Write(drivetrain_files[0], drivetrain_files[1])
446
Austin Schuh74425152018-12-21 11:37:14 +1100447 hybrid_loop_writer = control_loop.ControlLoopWriter(
448 "HybridVelocityDrivetrain", [hybrid_vdrivetrain.drivetrain_low_low,
449 hybrid_vdrivetrain.drivetrain_low_high,
450 hybrid_vdrivetrain.drivetrain_high_low,
451 hybrid_vdrivetrain.drivetrain_high_high],
452 namespaces=namespaces,
453 scalar_type=scalar_type,
454 plant_type='StateFeedbackHybridPlant',
455 observer_type='HybridKalman')
456
457 hybrid_loop_writer.Write(hybrid_files[0], hybrid_files[1])
458
Austin Schuhbcce26a2018-03-26 23:41:24 -0700459 cim_writer = control_loop.ControlLoopWriter("CIM", [CIM()], scalar_type=scalar_type)
Campbell Crowley33e0e3d2017-12-27 17:55:40 -0800460
461 cim_writer.Write(motor_files[0], motor_files[1])
462
463def PlotPolyDrivetrainMotions(drivetrain_params):
464 vdrivetrain = VelocityDrivetrain(drivetrain_params)
465 vl_plot = []
466 vr_plot = []
467 ul_plot = []
468 ur_plot = []
469 radius_plot = []
470 t_plot = []
471 left_gear_plot = []
472 right_gear_plot = []
473 vdrivetrain.left_shifter_position = 0.0
474 vdrivetrain.right_shifter_position = 0.0
475 vdrivetrain.left_gear = VelocityDrivetrain.LOW
476 vdrivetrain.right_gear = VelocityDrivetrain.LOW
477
478 glog.debug('K is %s', str(vdrivetrain.CurrentDrivetrain().K))
479
480 if vdrivetrain.left_gear is VelocityDrivetrain.HIGH:
481 glog.debug('Left is high')
482 else:
483 glog.debug('Left is low')
484 if vdrivetrain.right_gear is VelocityDrivetrain.HIGH:
485 glog.debug('Right is high')
486 else:
487 glog.debug('Right is low')
488
489 for t in numpy.arange(0, 1.7, vdrivetrain.dt):
490 if t < 0.5:
491 vdrivetrain.Update(throttle=0.00, steering=1.0)
492 elif t < 1.2:
493 vdrivetrain.Update(throttle=0.5, steering=1.0)
494 else:
495 vdrivetrain.Update(throttle=0.00, steering=1.0)
496 t_plot.append(t)
497 vl_plot.append(vdrivetrain.X[0, 0])
498 vr_plot.append(vdrivetrain.X[1, 0])
499 ul_plot.append(vdrivetrain.U[0, 0])
500 ur_plot.append(vdrivetrain.U[1, 0])
501 left_gear_plot.append((vdrivetrain.left_gear is VelocityDrivetrain.HIGH) * 2.0 - 10.0)
502 right_gear_plot.append((vdrivetrain.right_gear is VelocityDrivetrain.HIGH) * 2.0 - 10.0)
503
504 fwd_velocity = (vdrivetrain.X[1, 0] + vdrivetrain.X[0, 0]) / 2
505 turn_velocity = (vdrivetrain.X[1, 0] - vdrivetrain.X[0, 0])
506 if abs(fwd_velocity) < 0.0000001:
507 radius_plot.append(turn_velocity)
508 else:
509 radius_plot.append(turn_velocity / fwd_velocity)
510
511 # TODO(austin):
512 # Shifting compensation.
513
514 # Tighten the turn.
515 # Closed loop drive.
516
517 pylab.plot(t_plot, vl_plot, label='left velocity')
518 pylab.plot(t_plot, vr_plot, label='right velocity')
519 pylab.plot(t_plot, ul_plot, label='left voltage')
520 pylab.plot(t_plot, ur_plot, label='right voltage')
521 pylab.plot(t_plot, radius_plot, label='radius')
522 pylab.plot(t_plot, left_gear_plot, label='left gear high')
523 pylab.plot(t_plot, right_gear_plot, label='right gear high')
524 pylab.legend()
525 pylab.show()