blob: 70cd64961bb3870a9185864c919884d42c455005 [file] [log] [blame]
Austin Schuh82a66dc2017-03-04 15:06:44 -08001#!/usr/bin/python
2
John Park33858a32018-09-28 23:05:48 -07003from aos.util.trapezoid_profile import TrapezoidProfile
Austin Schuh82a66dc2017-03-04 15:06:44 -08004from frc971.control_loops.python import control_loop
5from frc971.control_loops.python import controls
6from y2017.control_loops.python import turret
7from y2017.control_loops.python import indexer
8import numpy
9import sys
Austin Schuh82a66dc2017-03-04 15:06:44 -080010from matplotlib import pylab
11import gflags
12import glog
13
14FLAGS = gflags.FLAGS
15
16try:
Tyler Chatow6738c362019-02-16 14:12:30 -080017 gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
Austin Schuh82a66dc2017-03-04 15:06:44 -080018except gflags.DuplicateFlagError:
Tyler Chatow6738c362019-02-16 14:12:30 -080019 pass
Austin Schuh82a66dc2017-03-04 15:06:44 -080020
21
Austin Schuh82a66dc2017-03-04 15:06:44 -080022class ColumnController(control_loop.ControlLoop):
Austin Schuh82a66dc2017-03-04 15:06:44 -080023
Tyler Chatow6738c362019-02-16 14:12:30 -080024 def __init__(self, name='Column'):
25 super(ColumnController, self).__init__(name)
26 self.turret = turret.Turret(name + 'Turret')
27 self.indexer = indexer.Indexer(name + 'Indexer')
Austin Schuh82a66dc2017-03-04 15:06:44 -080028
Tyler Chatow6738c362019-02-16 14:12:30 -080029 # Control loop time step
30 self.dt = 0.005
Austin Schuh82a66dc2017-03-04 15:06:44 -080031
Tyler Chatow6738c362019-02-16 14:12:30 -080032 # State is [position_indexer,
33 # velocity_indexer,
34 # position_shooter,
35 # velocity_shooter]
36 # Input is [volts_indexer, volts_shooter]
37 self.A_continuous = numpy.matrix(numpy.zeros((3, 3)))
38 self.B_continuous = numpy.matrix(numpy.zeros((3, 2)))
Austin Schuh82a66dc2017-03-04 15:06:44 -080039
Tyler Chatow6738c362019-02-16 14:12:30 -080040 self.A_continuous[0, 0] = -(
41 self.indexer.Kt / self.indexer.Kv /
42 (self.indexer.J * self.indexer.resistance * self.indexer.G *
43 self.indexer.G) + self.turret.Kt / self.turret.Kv /
44 (self.indexer.J * self.turret.resistance * self.turret.G *
45 self.turret.G))
46 self.A_continuous[0, 2] = self.turret.Kt / self.turret.Kv / (
47 self.indexer.J * self.turret.resistance * self.turret.G *
48 self.turret.G)
49 self.B_continuous[0, 0] = self.indexer.Kt / (
50 self.indexer.J * self.indexer.resistance * self.indexer.G)
51 self.B_continuous[0, 1] = -self.turret.Kt / (
52 self.indexer.J * self.turret.resistance * self.turret.G)
Austin Schuh82a66dc2017-03-04 15:06:44 -080053
Tyler Chatow6738c362019-02-16 14:12:30 -080054 self.A_continuous[1, 2] = 1
Austin Schuh82a66dc2017-03-04 15:06:44 -080055
Tyler Chatow6738c362019-02-16 14:12:30 -080056 self.A_continuous[2, 0] = self.turret.Kt / self.turret.Kv / (
57 self.turret.J * self.turret.resistance * self.turret.G *
58 self.turret.G)
59 self.A_continuous[2, 2] = -self.turret.Kt / self.turret.Kv / (
60 self.turret.J * self.turret.resistance * self.turret.G *
61 self.turret.G)
Austin Schuh82a66dc2017-03-04 15:06:44 -080062
Tyler Chatow6738c362019-02-16 14:12:30 -080063 self.B_continuous[2, 1] = self.turret.Kt / (
64 self.turret.J * self.turret.resistance * self.turret.G)
Austin Schuh82a66dc2017-03-04 15:06:44 -080065
Tyler Chatow6738c362019-02-16 14:12:30 -080066 self.C = numpy.matrix([[1, 0, 0], [0, 1, 0]])
67 self.D = numpy.matrix([[0, 0], [0, 0]])
Austin Schuh82a66dc2017-03-04 15:06:44 -080068
Tyler Chatow6738c362019-02-16 14:12:30 -080069 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
70 self.B_continuous, self.dt)
Austin Schuh82a66dc2017-03-04 15:06:44 -080071
Tyler Chatow6738c362019-02-16 14:12:30 -080072 q_indexer_vel = 13.0
73 q_pos = 0.05
74 q_vel = 0.8
75 self.Q = numpy.matrix([[(1.0 / (q_indexer_vel**2.0)), 0.0, 0.0],
76 [0.0, (1.0 / (q_pos**2.0)), 0.0],
77 [0.0, 0.0, (1.0 / (q_vel**2.0))]])
Austin Schuh82a66dc2017-03-04 15:06:44 -080078
Tyler Chatow6738c362019-02-16 14:12:30 -080079 self.R = numpy.matrix([[(1.0 / (12.0**2.0)), 0.0],
80 [0.0, (1.0 / (12.0**2.0))]])
81 self.K = controls.dlqr(self.A, self.B, self.Q, self.R)
Austin Schuhd5ccb862017-03-11 22:06:36 -080082
Tyler Chatow6738c362019-02-16 14:12:30 -080083 glog.debug('Controller poles are ' +
84 repr(numpy.linalg.eig(self.A - self.B * self.K)[0]))
Austin Schuh82a66dc2017-03-04 15:06:44 -080085
Tyler Chatow6738c362019-02-16 14:12:30 -080086 q_vel_indexer_ff = 0.000005
87 q_pos_ff = 0.0000005
88 q_vel_ff = 0.00008
89 self.Qff = numpy.matrix([[(1.0 / (q_vel_indexer_ff**2.0)), 0.0, 0.0],
90 [0.0, (1.0 / (q_pos_ff**2.0)), 0.0],
91 [0.0, 0.0, (1.0 / (q_vel_ff**2.0))]])
Austin Schuh82a66dc2017-03-04 15:06:44 -080092
Tyler Chatow6738c362019-02-16 14:12:30 -080093 self.Kff = controls.TwoStateFeedForwards(self.B, self.Qff)
Austin Schuh82a66dc2017-03-04 15:06:44 -080094
Tyler Chatow6738c362019-02-16 14:12:30 -080095 self.U_max = numpy.matrix([[12.0], [12.0]])
96 self.U_min = numpy.matrix([[-12.0], [-12.0]])
97
98 self.InitializeState()
Austin Schuh82a66dc2017-03-04 15:06:44 -080099
100
101class Column(ColumnController):
Austin Schuh82a66dc2017-03-04 15:06:44 -0800102
Tyler Chatow6738c362019-02-16 14:12:30 -0800103 def __init__(self, name='Column', disable_indexer=False):
104 super(Column, self).__init__(name)
105 A_continuous = numpy.matrix(numpy.zeros((4, 4)))
106 B_continuous = numpy.matrix(numpy.zeros((4, 2)))
Austin Schuh82a66dc2017-03-04 15:06:44 -0800107
Tyler Chatow6738c362019-02-16 14:12:30 -0800108 A_continuous[0, 1] = 1
109 A_continuous[1:, 1:] = self.A_continuous
110 B_continuous[1:, :] = self.B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800111
Tyler Chatow6738c362019-02-16 14:12:30 -0800112 self.A_continuous = A_continuous
113 self.B_continuous = B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800114
Tyler Chatow6738c362019-02-16 14:12:30 -0800115 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
116 self.B_continuous, self.dt)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800117
Tyler Chatow6738c362019-02-16 14:12:30 -0800118 self.C = numpy.matrix([[1, 0, 0, 0], [-1, 0, 1, 0]])
119 self.D = numpy.matrix([[0, 0], [0, 0]])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800120
Tyler Chatow6738c362019-02-16 14:12:30 -0800121 orig_K = self.K
122 self.K = numpy.matrix(numpy.zeros((2, 4)))
123 self.K[:, 1:] = orig_K
Austin Schuhd5ccb862017-03-11 22:06:36 -0800124
Tyler Chatow6738c362019-02-16 14:12:30 -0800125 glog.debug('K is ' + repr(self.K))
126 # TODO(austin): Do we want to damp velocity out or not when disabled?
127 #if disable_indexer:
128 # self.K[0, 1] = 0.0
129 # self.K[1, 1] = 0.0
Austin Schuh82a66dc2017-03-04 15:06:44 -0800130
Tyler Chatow6738c362019-02-16 14:12:30 -0800131 orig_Kff = self.Kff
132 self.Kff = numpy.matrix(numpy.zeros((2, 4)))
133 self.Kff[:, 1:] = orig_Kff
Austin Schuh82a66dc2017-03-04 15:06:44 -0800134
Tyler Chatow6738c362019-02-16 14:12:30 -0800135 q_pos = 0.12
136 q_vel = 2.00
137 self.Q = numpy.matrix([[(q_pos**2.0), 0.0, 0.0, 0.0],
138 [0.0, (q_vel**2.0), 0.0, 0.0],
139 [0.0, 0.0, (q_pos**2.0), 0.0],
140 [0.0, 0.0, 0.0, (q_vel**2.0)]])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800141
Tyler Chatow6738c362019-02-16 14:12:30 -0800142 r_pos = 0.05
143 self.R = numpy.matrix([[(r_pos**2.0), 0.0], [0.0, (r_pos**2.0)]])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800144
Tyler Chatow6738c362019-02-16 14:12:30 -0800145 self.KalmanGain, self.Q_steady = controls.kalman(
146 A=self.A, B=self.B, C=self.C, Q=self.Q, R=self.R)
147 self.L = self.A * self.KalmanGain
148
149 self.InitializeState()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800150
151
152class IntegralColumn(Column):
Austin Schuh82a66dc2017-03-04 15:06:44 -0800153
Tyler Chatow6738c362019-02-16 14:12:30 -0800154 def __init__(self,
155 name='IntegralColumn',
156 voltage_error_noise=None,
157 disable_indexer=False):
158 super(IntegralColumn, self).__init__(name)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800159
Tyler Chatow6738c362019-02-16 14:12:30 -0800160 A_continuous = numpy.matrix(numpy.zeros((6, 6)))
161 A_continuous[0:4, 0:4] = self.A_continuous
162 A_continuous[0:4:, 4:6] = self.B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800163
Tyler Chatow6738c362019-02-16 14:12:30 -0800164 B_continuous = numpy.matrix(numpy.zeros((6, 2)))
165 B_continuous[0:4, :] = self.B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800166
Tyler Chatow6738c362019-02-16 14:12:30 -0800167 self.A_continuous = A_continuous
168 self.B_continuous = B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800169
Tyler Chatow6738c362019-02-16 14:12:30 -0800170 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
171 self.B_continuous, self.dt)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800172
Tyler Chatow6738c362019-02-16 14:12:30 -0800173 C = numpy.matrix(numpy.zeros((2, 6)))
174 C[0:2, 0:4] = self.C
175 self.C = C
Austin Schuh82a66dc2017-03-04 15:06:44 -0800176
Tyler Chatow6738c362019-02-16 14:12:30 -0800177 self.D = numpy.matrix([[0, 0], [0, 0]])
Austin Schuhd5ccb862017-03-11 22:06:36 -0800178
Tyler Chatow6738c362019-02-16 14:12:30 -0800179 orig_K = self.K
180 self.K = numpy.matrix(numpy.zeros((2, 6)))
181 self.K[:, 0:4] = orig_K
Austin Schuh82a66dc2017-03-04 15:06:44 -0800182
Tyler Chatow6738c362019-02-16 14:12:30 -0800183 # TODO(austin): I'm not certain this is ideal. If someone spins the bottom
184 # at a constant rate, we'll learn a voltage offset. That should translate
185 # directly to a voltage on the turret to hold it steady. I'm also not
186 # convinced we care that much. If the indexer is off, it'll stop rather
187 # quickly anyways, so this is mostly a moot point.
188 if not disable_indexer:
189 self.K[0, 4] = 1
190 self.K[1, 5] = 1
Austin Schuh82a66dc2017-03-04 15:06:44 -0800191
Tyler Chatow6738c362019-02-16 14:12:30 -0800192 orig_Kff = self.Kff
193 self.Kff = numpy.matrix(numpy.zeros((2, 6)))
194 self.Kff[:, 0:4] = orig_Kff
Austin Schuh82a66dc2017-03-04 15:06:44 -0800195
Tyler Chatow6738c362019-02-16 14:12:30 -0800196 q_pos = 0.40
197 q_vel = 2.00
198 q_voltage = 8.0
199 if voltage_error_noise is not None:
200 q_voltage = voltage_error_noise
Austin Schuh82a66dc2017-03-04 15:06:44 -0800201
Tyler Chatow6738c362019-02-16 14:12:30 -0800202 self.Q = numpy.matrix([[(q_pos**2.0), 0.0, 0.0, 0.0, 0.0, 0.0],
203 [0.0, (q_vel**2.0), 0.0, 0.0, 0.0, 0.0],
204 [0.0, 0.0, (q_pos**2.0), 0.0, 0.0, 0.0],
205 [0.0, 0.0, 0.0, (q_vel**2.0), 0.0, 0.0],
206 [0.0, 0.0, 0.0, 0.0, (q_voltage**2.0), 0.0],
207 [0.0, 0.0, 0.0, 0.0, 0.0, (q_voltage**2.0)]])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800208
Tyler Chatow6738c362019-02-16 14:12:30 -0800209 r_pos = 0.05
210 self.R = numpy.matrix([[(r_pos**2.0), 0.0], [0.0, (r_pos**2.0)]])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800211
Tyler Chatow6738c362019-02-16 14:12:30 -0800212 self.KalmanGain, self.Q_steady = controls.kalman(
213 A=self.A, B=self.B, C=self.C, Q=self.Q, R=self.R)
214 self.L = self.A * self.KalmanGain
215
216 self.InitializeState()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800217
218
219class ScenarioPlotter(object):
Austin Schuh82a66dc2017-03-04 15:06:44 -0800220
Tyler Chatow6738c362019-02-16 14:12:30 -0800221 def __init__(self):
222 # Various lists for graphing things.
223 self.t = []
224 self.xi = []
225 self.xt = []
226 self.vi = []
227 self.vt = []
228 self.ai = []
229 self.at = []
230 self.x_hat = []
231 self.ui = []
232 self.ut = []
233 self.ui_fb = []
234 self.ut_fb = []
235 self.offseti = []
236 self.offsett = []
237 self.turret_error = []
Austin Schuh82a66dc2017-03-04 15:06:44 -0800238
Tyler Chatow6738c362019-02-16 14:12:30 -0800239 def run_test(self,
240 column,
241 end_goal,
242 controller_column,
243 observer_column=None,
244 iterations=200):
245 """Runs the column plant with an initial condition and goal.
Austin Schuh82a66dc2017-03-04 15:06:44 -0800246
Tyler Chatow6738c362019-02-16 14:12:30 -0800247 Args:
248 column: column object to use.
249 end_goal: end_goal state.
250 controller_column: Intake object to get K from, or None if we should
251 use column.
252 observer_column: Intake object to use for the observer, or None if we should
253 use the actual state.
254 iterations: Number of timesteps to run the model for.
255 """
Austin Schuh82a66dc2017-03-04 15:06:44 -0800256
Tyler Chatow6738c362019-02-16 14:12:30 -0800257 if controller_column is None:
258 controller_column = column
Austin Schuh82a66dc2017-03-04 15:06:44 -0800259
Tyler Chatow6738c362019-02-16 14:12:30 -0800260 vbat = 12.0
Austin Schuh82a66dc2017-03-04 15:06:44 -0800261
Tyler Chatow6738c362019-02-16 14:12:30 -0800262 if self.t:
263 initial_t = self.t[-1] + column.dt
264 else:
265 initial_t = 0
Austin Schuh82a66dc2017-03-04 15:06:44 -0800266
Tyler Chatow6738c362019-02-16 14:12:30 -0800267 goal = numpy.concatenate((column.X, numpy.matrix(numpy.zeros((2, 1)))),
268 axis=0)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800269
Tyler Chatow6738c362019-02-16 14:12:30 -0800270 profile = TrapezoidProfile(column.dt)
271 profile.set_maximum_acceleration(10.0)
272 profile.set_maximum_velocity(3.0)
273 profile.SetGoal(goal[2, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800274
Tyler Chatow6738c362019-02-16 14:12:30 -0800275 U_last = numpy.matrix(numpy.zeros((2, 1)))
276 for i in xrange(iterations):
277 observer_column.Y = column.Y
278 observer_column.CorrectObserver(U_last)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800279
Tyler Chatow6738c362019-02-16 14:12:30 -0800280 self.offseti.append(observer_column.X_hat[4, 0])
281 self.offsett.append(observer_column.X_hat[5, 0])
282 self.x_hat.append(observer_column.X_hat[0, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800283
Tyler Chatow6738c362019-02-16 14:12:30 -0800284 next_goal = numpy.concatenate(
285 (end_goal[0:2, :], profile.Update(
286 end_goal[2, 0], end_goal[3, 0]), end_goal[4:6, :]),
287 axis=0)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800288
Tyler Chatow6738c362019-02-16 14:12:30 -0800289 ff_U = controller_column.Kff * (
290 next_goal - observer_column.A * goal)
291 fb_U = controller_column.K * (goal - observer_column.X_hat)
292 self.turret_error.append((goal[2, 0] - column.X[2, 0]) * 100.0)
293 self.ui_fb.append(fb_U[0, 0])
294 self.ut_fb.append(fb_U[1, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800295
Tyler Chatow6738c362019-02-16 14:12:30 -0800296 U_uncapped = ff_U + fb_U
Austin Schuh82a66dc2017-03-04 15:06:44 -0800297
Tyler Chatow6738c362019-02-16 14:12:30 -0800298 U = U_uncapped.copy()
299 U[0, 0] = numpy.clip(U[0, 0], -vbat, vbat)
300 U[1, 0] = numpy.clip(U[1, 0], -vbat, vbat)
301 self.xi.append(column.X[0, 0])
302 self.xt.append(column.X[2, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800303
Tyler Chatow6738c362019-02-16 14:12:30 -0800304 if self.vi:
305 last_vi = self.vi[-1]
306 else:
307 last_vi = 0
308 if self.vt:
309 last_vt = self.vt[-1]
310 else:
311 last_vt = 0
Austin Schuh82a66dc2017-03-04 15:06:44 -0800312
Tyler Chatow6738c362019-02-16 14:12:30 -0800313 self.vi.append(column.X[1, 0])
314 self.vt.append(column.X[3, 0])
315 self.ai.append((self.vi[-1] - last_vi) / column.dt)
316 self.at.append((self.vt[-1] - last_vt) / column.dt)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800317
Tyler Chatow6738c362019-02-16 14:12:30 -0800318 offset = 0.0
319 if i > 100:
320 offset = 1.0
321 column.Update(U + numpy.matrix([[0.0], [offset]]))
Austin Schuh82a66dc2017-03-04 15:06:44 -0800322
Tyler Chatow6738c362019-02-16 14:12:30 -0800323 observer_column.PredictObserver(U)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800324
Tyler Chatow6738c362019-02-16 14:12:30 -0800325 self.t.append(initial_t + i * column.dt)
326 self.ui.append(U[0, 0])
327 self.ut.append(U[1, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800328
Tyler Chatow6738c362019-02-16 14:12:30 -0800329 ff_U -= U_uncapped - U
330 goal = controller_column.A * goal + controller_column.B * ff_U
Austin Schuh82a66dc2017-03-04 15:06:44 -0800331
Tyler Chatow6738c362019-02-16 14:12:30 -0800332 if U[1, 0] != U_uncapped[1, 0]:
333 profile.MoveCurrentState(
334 numpy.matrix([[goal[2, 0]], [goal[3, 0]]]))
Austin Schuh82a66dc2017-03-04 15:06:44 -0800335
Tyler Chatow6738c362019-02-16 14:12:30 -0800336 glog.debug('Time: %f', self.t[-1])
337 glog.debug('goal_error %s', repr((end_goal - goal).T))
338 glog.debug('error %s', repr((observer_column.X_hat - end_goal).T))
Austin Schuh82a66dc2017-03-04 15:06:44 -0800339
Tyler Chatow6738c362019-02-16 14:12:30 -0800340 def Plot(self):
341 pylab.subplot(3, 1, 1)
342 pylab.plot(self.t, self.xi, label='x_indexer')
343 pylab.plot(self.t, self.xt, label='x_turret')
344 pylab.plot(self.t, self.x_hat, label='x_hat')
345 pylab.plot(self.t, self.turret_error, label='turret_error * 100')
346 pylab.legend()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800347
Tyler Chatow6738c362019-02-16 14:12:30 -0800348 pylab.subplot(3, 1, 2)
349 pylab.plot(self.t, self.ui, label='u_indexer')
350 pylab.plot(self.t, self.ui_fb, label='u_indexer_fb')
351 pylab.plot(self.t, self.ut, label='u_turret')
352 pylab.plot(self.t, self.ut_fb, label='u_turret_fb')
353 pylab.plot(self.t, self.offseti, label='voltage_offset_indexer')
354 pylab.plot(self.t, self.offsett, label='voltage_offset_turret')
355 pylab.legend()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800356
Tyler Chatow6738c362019-02-16 14:12:30 -0800357 pylab.subplot(3, 1, 3)
358 pylab.plot(self.t, self.ai, label='a_indexer')
359 pylab.plot(self.t, self.at, label='a_turret')
360 pylab.plot(self.t, self.vi, label='v_indexer')
361 pylab.plot(self.t, self.vt, label='v_turret')
362 pylab.legend()
363
364 pylab.show()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800365
366
367def main(argv):
Tyler Chatow6738c362019-02-16 14:12:30 -0800368 scenario_plotter = ScenarioPlotter()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800369
Tyler Chatow6738c362019-02-16 14:12:30 -0800370 column = Column()
371 column_controller = IntegralColumn()
372 observer_column = IntegralColumn()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800373
Tyler Chatow6738c362019-02-16 14:12:30 -0800374 initial_X = numpy.matrix([[0.0], [0.0], [0.0], [0.0]])
375 R = numpy.matrix([[0.0], [10.0], [5.0], [0.0], [0.0], [0.0]])
376 scenario_plotter.run_test(
377 column,
378 end_goal=R,
379 controller_column=column_controller,
380 observer_column=observer_column,
381 iterations=400)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800382
Tyler Chatow6738c362019-02-16 14:12:30 -0800383 if FLAGS.plot:
384 scenario_plotter.Plot()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800385
Tyler Chatow6738c362019-02-16 14:12:30 -0800386 if len(argv) != 7:
387 glog.fatal('Expected .h file name and .cc file names')
388 else:
389 namespaces = ['y2017', 'control_loops', 'superstructure', 'column']
390 column = Column('Column')
391 loop_writer = control_loop.ControlLoopWriter(
392 'Column', [column], namespaces=namespaces)
393 loop_writer.AddConstant(
394 control_loop.Constant('kIndexerFreeSpeed', '%f',
395 column.indexer.free_speed))
396 loop_writer.AddConstant(
397 control_loop.Constant('kIndexerOutputRatio', '%f',
398 column.indexer.G))
399 loop_writer.AddConstant(
400 control_loop.Constant('kTurretFreeSpeed', '%f',
401 column.turret.free_speed))
402 loop_writer.AddConstant(
403 control_loop.Constant('kTurretOutputRatio', '%f', column.turret.G))
404 loop_writer.Write(argv[1], argv[2])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800405
Tyler Chatow6738c362019-02-16 14:12:30 -0800406 # IntegralColumn controller 1 will disable the indexer.
407 integral_column = IntegralColumn('IntegralColumn')
408 disabled_integral_column = IntegralColumn(
409 'DisabledIntegralColumn', disable_indexer=True)
410 integral_loop_writer = control_loop.ControlLoopWriter(
411 'IntegralColumn', [integral_column, disabled_integral_column],
412 namespaces=namespaces)
413 integral_loop_writer.Write(argv[3], argv[4])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800414
Tyler Chatow6738c362019-02-16 14:12:30 -0800415 stuck_integral_column = IntegralColumn(
416 'StuckIntegralColumn', voltage_error_noise=8.0)
417 stuck_integral_loop_writer = control_loop.ControlLoopWriter(
418 'StuckIntegralColumn', [stuck_integral_column],
419 namespaces=namespaces)
420 stuck_integral_loop_writer.Write(argv[5], argv[6])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800421
422
423if __name__ == '__main__':
Tyler Chatow6738c362019-02-16 14:12:30 -0800424 argv = FLAGS(sys.argv)
425 glog.init()
426 sys.exit(main(argv))