Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 3 | import control_loop |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 4 | import controls |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 5 | import numpy |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 6 | import sys |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 7 | from matplotlib import pylab |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 8 | |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 9 | class Claw(control_loop.ControlLoop): |
| 10 | def __init__(self, name="RawClaw"): |
| 11 | super(Claw, self).__init__(name) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 12 | # Stall Torque in N m |
James Kuszmaul | e1755b3 | 2014-02-13 06:27:48 -0800 | [diff] [blame] | 13 | self.stall_torque = 2.42 |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 14 | # Stall Current in Amps |
James Kuszmaul | e1755b3 | 2014-02-13 06:27:48 -0800 | [diff] [blame] | 15 | self.stall_current = 133 |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 16 | # Free Speed in RPM |
| 17 | self.free_speed = 5500.0 |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 18 | # Free Current in Amps |
James Kuszmaul | e1755b3 | 2014-02-13 06:27:48 -0800 | [diff] [blame] | 19 | self.free_current = 2.7 |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 20 | # Moment of inertia of the claw in kg m^2 |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 21 | # measured from CAD |
| 22 | self.J_top = 0.3 |
| 23 | self.J_bottom = 0.9 |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 24 | # Resistance of the motor |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 25 | self.R = 12.0 / self.stall_current |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 26 | # Motor velocity constant |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 27 | self.Kv = ((self.free_speed / 60.0 * 2.0 * numpy.pi) / |
| 28 | (13.5 - self.R * self.free_current)) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 29 | # Torque constant |
| 30 | self.Kt = self.stall_torque / self.stall_current |
| 31 | # Gear ratio |
James Kuszmaul | e1755b3 | 2014-02-13 06:27:48 -0800 | [diff] [blame] | 32 | self.G = 14.0 / 48.0 * 18.0 / 32.0 * 18.0 / 66.0 * 12.0 / 60.0 |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 33 | # Control loop time step |
| 34 | self.dt = 0.01 |
| 35 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 36 | # State is [bottom position, top - bottom position, |
| 37 | # bottom velocity, top - bottom velocity] |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 38 | # Input is [bottom power, top - bottom power] |
| 39 | # Motor time constants. difference_bottom refers to the constant for how the |
| 40 | # bottom velocity affects the difference of the top and bottom velocities. |
| 41 | self.common_motor_constant = -self.Kt / self.Kv / (self.G * self.G * self.R) |
| 42 | self.bottom_bottom = self.common_motor_constant / self.J_bottom |
| 43 | self.difference_bottom = self.common_motor_constant * (1 / self.J_bottom |
| 44 | - 1 / self.J_top) |
| 45 | self.difference_difference = self.common_motor_constant / self.J_top |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 46 | # State feedback matrices |
| 47 | self.A_continuous = numpy.matrix( |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 48 | [[0, 0, 1, 0], |
| 49 | [0, 0, 0, 1], |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 50 | [0, 0, self.bottom_bottom, 0], |
| 51 | [0, 0, self.difference_bottom, self.difference_difference]]) |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 52 | |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 53 | self.motor_feedforward = self.Kt / (self.G * self.R) |
| 54 | self.motor_feedforward_bottom = self.motor_feedforward / self.J_top |
| 55 | self.motor_feedforward_difference = self.motor_feedforward / self.J_bottom |
| 56 | self.motor_feedforward_difference_bottom = ( |
| 57 | self.motor_feedforward * (1 / self.J_bottom - 1 / self.J_top)) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 58 | self.B_continuous = numpy.matrix( |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 59 | [[0, 0], |
| 60 | [0, 0], |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 61 | [self.motor_feedforward_bottom, 0], |
| 62 | [self.motor_feedforward_difference_bottom, |
| 63 | self.motor_feedforward_difference]]) |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 64 | self.C = numpy.matrix([[1, 0, 0, 0], |
| 65 | [1, 1, 0, 0]]) |
| 66 | self.D = numpy.matrix([[0, 0], |
| 67 | [0, 0]]) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 68 | |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 69 | self.A, self.B = self.ContinuousToDiscrete( |
| 70 | self.A_continuous, self.B_continuous, self.dt) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 71 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 72 | #controlability = controls.ctrb(self.A, self.B); |
| 73 | #print "Rank of controlability matrix.", numpy.linalg.matrix_rank(controlability) |
| 74 | |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 75 | self.Q = numpy.matrix([[(1.0 / (0.10 ** 2.0)), 0.0, 0.0, 0.0], |
| 76 | [0.0, (1.0 / (0.03 ** 2.0)), 0.0, 0.0], |
| 77 | [0.0, 0.0, 0.2, 0.0], |
| 78 | [0.0, 0.0, 0.0, 2.00]]) |
| 79 | |
| 80 | self.R = numpy.matrix([[(1.0 / (20.0 ** 2.0)), 0.0], |
| 81 | [0.0, (1.0 / (20.0 ** 2.0))]]) |
| 82 | self.K = controls.dlqr(self.A, self.B, self.Q, self.R) |
| 83 | |
| 84 | print "K unaugmented" |
| 85 | print self.K |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 86 | |
| 87 | self.rpl = .05 |
| 88 | self.ipl = 0.008 |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 89 | self.PlaceObserverPoles([self.rpl + 1j * self.ipl, |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 90 | self.rpl - 1j * self.ipl, |
| 91 | self.rpl + 1j * self.ipl, |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 92 | self.rpl - 1j * self.ipl]) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 93 | |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 94 | # The box formed by U_min and U_max must encompass all possible values, |
| 95 | # or else Austin's code gets angry. |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 96 | self.U_max = numpy.matrix([[12.0], [24.0]]) |
| 97 | self.U_min = numpy.matrix([[-12.0], [-24.0]]) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 98 | |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 99 | self.InitializeState() |
| 100 | |
| 101 | |
Austin Schuh | 3bb9a44 | 2014-02-02 16:01:45 -0800 | [diff] [blame] | 102 | class ClawDeltaU(Claw): |
| 103 | def __init__(self, name="Claw"): |
| 104 | super(ClawDeltaU, self).__init__(name) |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 105 | A_unaugmented = self.A |
| 106 | B_unaugmented = self.B |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 107 | C_unaugmented = self.C |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 108 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 109 | self.A = numpy.matrix([[0.0, 0.0, 0.0, 0.0, 0.0], |
| 110 | [0.0, 0.0, 0.0, 0.0, 0.0], |
| 111 | [0.0, 0.0, 0.0, 0.0, 0.0], |
| 112 | [0.0, 0.0, 0.0, 0.0, 0.0], |
| 113 | [0.0, 0.0, 0.0, 0.0, 1.0]]) |
| 114 | self.A[0:4, 0:4] = A_unaugmented |
| 115 | self.A[0:4, 4] = B_unaugmented[0:4, 0] |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 116 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 117 | self.B = numpy.matrix([[0.0, 0.0], |
| 118 | [0.0, 0.0], |
| 119 | [0.0, 0.0], |
| 120 | [0.0, 0.0], |
| 121 | [1.0, 0.0]]) |
| 122 | self.B[0:4, 1] = B_unaugmented[0:4, 1] |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 123 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 124 | self.C = numpy.concatenate((C_unaugmented, numpy.matrix([[0.0], [0.0]])), |
| 125 | axis=1) |
| 126 | self.D = numpy.matrix([[0.0, 0.0], |
| 127 | [0.0, 0.0]]) |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 128 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 129 | #self.PlaceControllerPoles([0.55, 0.35, 0.55, 0.35, 0.80]) |
| 130 | self.Q = numpy.matrix([[(1.0 / (0.04 ** 2.0)), 0.0, 0.0, 0.0, 0.0], |
| 131 | [0.0, (1.0 / (0.01 ** 2)), 0.0, 0.0, 0.0], |
| 132 | [0.0, 0.0, 0.01, 0.0, 0.0], |
| 133 | [0.0, 0.0, 0.0, 0.08, 0.0], |
| 134 | [0.0, 0.0, 0.0, 0.0, (1.0 / (10.0 ** 2))]]) |
| 135 | |
| 136 | self.R = numpy.matrix([[0.000001, 0.0], |
| 137 | [0.0, 1.0 / (10.0 ** 2.0)]]) |
| 138 | self.K = controls.dlqr(self.A, self.B, self.Q, self.R) |
| 139 | |
| 140 | self.K = numpy.matrix([[50.0, 0.0, 10.0, 0.0, 1.0], |
| 141 | [50.0, 0.0, 10.0, 0.0, 1.0]]) |
| 142 | #self.K = numpy.matrix([[50.0, -100.0, 0, -10, 0], |
| 143 | # [50.0, 100.0, 0, 10, 0]]) |
| 144 | |
| 145 | controlability = controls.ctrb(self.A, self.B); |
| 146 | print "Rank of augmented controlability matrix.", numpy.linalg.matrix_rank(controlability) |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 147 | |
| 148 | print "K" |
| 149 | print self.K |
| 150 | print "Placed controller poles are" |
| 151 | print numpy.linalg.eig(self.A - self.B * self.K)[0] |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 152 | print [numpy.abs(x) for x in numpy.linalg.eig(self.A - self.B * self.K)[0]] |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 153 | |
| 154 | self.rpl = .05 |
| 155 | self.ipl = 0.008 |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 156 | self.PlaceObserverPoles([self.rpl + 1j * self.ipl, 0.10, 0.09, |
Brian Silverman | 23a67ca | 2013-03-16 23:48:50 -0700 | [diff] [blame] | 157 | self.rpl - 1j * self.ipl, 0.90]) |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 158 | #print "A is" |
| 159 | #print self.A |
| 160 | #print "L is" |
| 161 | #print self.L |
| 162 | #print "C is" |
| 163 | #print self.C |
| 164 | #print "A - LC is" |
| 165 | #print self.A - self.L * self.C |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 166 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 167 | #print "Placed observer poles are" |
| 168 | #print numpy.linalg.eig(self.A - self.L * self.C)[0] |
| 169 | |
| 170 | self.U_max = numpy.matrix([[12.0], [12.0]]) |
| 171 | self.U_min = numpy.matrix([[-12.0], [-12.0]]) |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 172 | |
| 173 | self.InitializeState() |
| 174 | |
| 175 | |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 176 | def FullSeparationPriority(claw, U): |
| 177 | bottom_u = U[0, 0] |
| 178 | top_u = U[1, 0] + bottom_u |
| 179 | |
| 180 | #print "Bottom is", new_unclipped_bottom_u, "Top is", top_u |
| 181 | if bottom_u > claw.U_max[0, 0]: |
| 182 | #print "Bottom is too big. Was", new_unclipped_bottom_u, "changing top by", new_unclipped_bottom_u - claw.U_max[0, 0] |
| 183 | top_u -= bottom_u - claw.U_max[0, 0] |
| 184 | if top_u < claw.U_min[1, 0]: |
| 185 | top_u = claw.U_min[1, 0] |
| 186 | |
| 187 | bottom_u = claw.U_max[0, 0] |
| 188 | if top_u > claw.U_max[1, 0]: |
| 189 | bottom_u -= top_u - claw.U_max[1, 0] |
| 190 | if bottom_u < claw.U_min[0, 0]: |
| 191 | bottom_u = claw.U_min[0, 0] |
| 192 | |
| 193 | top_u = claw.U_max[1, 0] |
| 194 | if top_u < claw.U_min[1, 0]: |
| 195 | bottom_u -= top_u - claw.U_min[1, 0] |
| 196 | if bottom_u > claw.U_max[0, 0]: |
| 197 | bottom_u = claw.U_max[0, 0] |
| 198 | |
| 199 | top_u = claw.U_min[1, 0] |
| 200 | if bottom_u < claw.U_min[0, 0]: |
| 201 | top_u -= bottom_u - claw.U_min[0, 0] |
| 202 | if top_u > claw.U_max[1, 0]: |
| 203 | top_u = claw.U_max[1, 0] |
| 204 | |
| 205 | bottom_u = claw.U_min[0, 0] |
| 206 | |
| 207 | return numpy.matrix([[bottom_u], [top_u - bottom_u]]) |
| 208 | |
| 209 | def AverageUFix(claw, U): |
| 210 | bottom_u = U[0, 0] |
| 211 | top_u = U[1, 0] + bottom_u |
| 212 | |
| 213 | #print "Bottom is", new_unclipped_bottom_u, "Top is", top_u |
James Kuszmaul | 9279740 | 2014-02-17 14:08:49 -0800 | [diff] [blame^] | 214 | if (bottom_u > claw.U_max[0, 0] or top_u > claw.U_max[0, 0] or |
| 215 | top_u < claw.U_min[0, 0] or bottom_u < claw.U_min[0, 0]): |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 216 | scalar = 12.0 / max(numpy.abs(top_u), numpy.abs(bottom_u)) |
| 217 | top_u *= scalar |
| 218 | bottom_u *= scalar |
| 219 | |
| 220 | return numpy.matrix([[bottom_u], [top_u - bottom_u]]) |
| 221 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 222 | def ClipDeltaU(claw, U): |
| 223 | delta_u = U[0, 0] |
| 224 | top_u = U[1, 0] |
| 225 | old_bottom_u = claw.X[4, 0] |
| 226 | |
| 227 | # TODO(austin): Preserve the difference between the top and bottom power. |
| 228 | new_unclipped_bottom_u = old_bottom_u + delta_u |
| 229 | |
| 230 | #print "Bottom is", new_unclipped_bottom_u, "Top is", top_u |
| 231 | if new_unclipped_bottom_u > claw.U_max[0, 0]: |
| 232 | #print "Bottom is too big. Was", new_unclipped_bottom_u, "changing top by", new_unclipped_bottom_u - claw.U_max[0, 0] |
| 233 | top_u -= new_unclipped_bottom_u - claw.U_max[0, 0] |
| 234 | new_unclipped_bottom_u = claw.U_max[0, 0] |
| 235 | if top_u > claw.U_max[1, 0]: |
| 236 | new_unclipped_bottom_u -= top_u - claw.U_max[1, 0] |
| 237 | top_u = claw.U_max[1, 0] |
| 238 | if top_u < claw.U_min[1, 0]: |
| 239 | new_unclipped_bottom_u -= top_u - claw.U_min[1, 0] |
| 240 | top_u = claw.U_min[1, 0] |
| 241 | if new_unclipped_bottom_u < claw.U_min[0, 0]: |
| 242 | top_u -= new_unclipped_bottom_u - claw.U_min[0, 0] |
| 243 | new_unclipped_bottom_u = claw.U_min[0, 0] |
| 244 | |
| 245 | new_bottom_u = numpy.clip(new_unclipped_bottom_u, claw.U_min[0, 0], claw.U_max[0, 0]) |
| 246 | new_top_u = numpy.clip(top_u, claw.U_min[1, 0], claw.U_max[1, 0]) |
| 247 | |
| 248 | return numpy.matrix([[new_bottom_u - old_bottom_u], [new_top_u]]) |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 249 | |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 250 | def main(argv): |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 251 | # Simulate the response of the system to a step input. |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 252 | #claw = ClawDeltaU() |
| 253 | #simulated_x = [] |
| 254 | #for _ in xrange(100): |
| 255 | # claw.Update(numpy.matrix([[12.0]])) |
| 256 | # simulated_x.append(claw.X[0, 0]) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 257 | |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 258 | #pylab.plot(range(100), simulated_x) |
| 259 | #pylab.show() |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 260 | |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 261 | # Simulate the closed loop response of the system to a step input. |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 262 | claw = Claw("TopClaw") |
| 263 | t = [] |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 264 | close_loop_x_bottom = [] |
| 265 | close_loop_x_sep = [] |
| 266 | close_loop_u_bottom = [] |
| 267 | close_loop_u_top = [] |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 268 | R = numpy.matrix([[1.0], [1.0], [0.0], [0.0]]) |
| 269 | claw.X[0, 0] = 0 |
| 270 | for i in xrange(100): |
| 271 | #print "Error is", (R - claw.X_hat) |
| 272 | U = claw.K * (R - claw.X_hat) |
| 273 | #U = numpy.clip(claw.K * (R - claw.X_hat), claw.U_min, claw.U_max) |
| 274 | #U = FullSeparationPriority(claw, U) |
| 275 | U = AverageUFix(claw, U) |
| 276 | #U = claw.K * (R - claw.X_hat) |
| 277 | #U = ClipDeltaU(claw, U) |
| 278 | claw.UpdateObserver(U) |
| 279 | claw.Update(U) |
| 280 | close_loop_x_bottom.append(claw.X[0, 0] * 10) |
| 281 | close_loop_u_bottom.append(U[0, 0]) |
| 282 | close_loop_x_sep.append(claw.X[1, 0] * 10) |
| 283 | close_loop_u_top.append(U[1, 0] + U[0, 0]) |
| 284 | t.append(0.01 * i) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 285 | |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 286 | pylab.plot(t, close_loop_x_bottom, label='x bottom') |
| 287 | pylab.plot(t, close_loop_x_sep, label='seperation') |
| 288 | pylab.plot(t, close_loop_u_bottom, label='u bottom') |
| 289 | pylab.plot(t, close_loop_u_top, label='u top') |
Austin Schuh | 0d9467a | 2014-02-15 22:36:45 -0800 | [diff] [blame] | 290 | pylab.legend() |
Austin Schuh | fa03369 | 2013-02-24 01:00:55 -0800 | [diff] [blame] | 291 | pylab.show() |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 292 | |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 293 | # Write the generated constants out to a file. |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 294 | if len(argv) != 3: |
| 295 | print "Expected .h file name and .cc file name for the claw." |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 296 | else: |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 297 | claw = Claw("Claw") |
| 298 | loop_writer = control_loop.ControlLoopWriter("Claw", [claw]) |
Austin Schuh | 683a0d0 | 2013-03-02 01:51:31 -0800 | [diff] [blame] | 299 | if argv[1][-3:] == '.cc': |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 300 | loop_writer.Write(argv[2], argv[1]) |
Austin Schuh | 683a0d0 | 2013-03-02 01:51:31 -0800 | [diff] [blame] | 301 | else: |
Austin Schuh | cda86af | 2014-02-16 16:16:39 -0800 | [diff] [blame] | 302 | loop_writer.Write(argv[1], argv[2]) |
Austin Schuh | c8ca244 | 2013-02-23 12:29:33 -0800 | [diff] [blame] | 303 | |
| 304 | if __name__ == '__main__': |
| 305 | sys.exit(main(sys.argv)) |