blob: 7573c1684811fcc9ebac70d858d16e35b69c8f99 [file] [log] [blame]
Austin Schuh085eab92020-11-26 13:54:51 -08001#!/usr/bin/python3
Austin Schuh82a66dc2017-03-04 15:06:44 -08002
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
Ravago Jones5127ccc2022-07-31 16:32:45 -070040 self.A_continuous[0, 0] = -(self.indexer.Kt / self.indexer.Kv /
41 (self.indexer.J * self.indexer.resistance *
42 self.indexer.G * self.indexer.G) +
43 self.turret.Kt / self.turret.Kv /
44 (self.indexer.J * self.turret.resistance *
45 self.turret.G * self.turret.G))
Tyler Chatow6738c362019-02-16 14:12:30 -080046 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
Ravago Jones5127ccc2022-07-31 16:32:45 -0700145 self.KalmanGain, self.Q_steady = controls.kalman(A=self.A,
146 B=self.B,
147 C=self.C,
148 Q=self.Q,
149 R=self.R)
Tyler Chatow6738c362019-02-16 14:12:30 -0800150 self.L = self.A * self.KalmanGain
151
152 self.InitializeState()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800153
154
155class IntegralColumn(Column):
Austin Schuh82a66dc2017-03-04 15:06:44 -0800156
Tyler Chatow6738c362019-02-16 14:12:30 -0800157 def __init__(self,
158 name='IntegralColumn',
159 voltage_error_noise=None,
160 disable_indexer=False):
161 super(IntegralColumn, self).__init__(name)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800162
Tyler Chatow6738c362019-02-16 14:12:30 -0800163 A_continuous = numpy.matrix(numpy.zeros((6, 6)))
164 A_continuous[0:4, 0:4] = self.A_continuous
165 A_continuous[0:4:, 4:6] = self.B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800166
Tyler Chatow6738c362019-02-16 14:12:30 -0800167 B_continuous = numpy.matrix(numpy.zeros((6, 2)))
168 B_continuous[0:4, :] = self.B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800169
Tyler Chatow6738c362019-02-16 14:12:30 -0800170 self.A_continuous = A_continuous
171 self.B_continuous = B_continuous
Austin Schuh82a66dc2017-03-04 15:06:44 -0800172
Tyler Chatow6738c362019-02-16 14:12:30 -0800173 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
174 self.B_continuous, self.dt)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800175
Tyler Chatow6738c362019-02-16 14:12:30 -0800176 C = numpy.matrix(numpy.zeros((2, 6)))
177 C[0:2, 0:4] = self.C
178 self.C = C
Austin Schuh82a66dc2017-03-04 15:06:44 -0800179
Tyler Chatow6738c362019-02-16 14:12:30 -0800180 self.D = numpy.matrix([[0, 0], [0, 0]])
Austin Schuhd5ccb862017-03-11 22:06:36 -0800181
Tyler Chatow6738c362019-02-16 14:12:30 -0800182 orig_K = self.K
183 self.K = numpy.matrix(numpy.zeros((2, 6)))
184 self.K[:, 0:4] = orig_K
Austin Schuh82a66dc2017-03-04 15:06:44 -0800185
Tyler Chatow6738c362019-02-16 14:12:30 -0800186 # TODO(austin): I'm not certain this is ideal. If someone spins the bottom
187 # at a constant rate, we'll learn a voltage offset. That should translate
188 # directly to a voltage on the turret to hold it steady. I'm also not
189 # convinced we care that much. If the indexer is off, it'll stop rather
190 # quickly anyways, so this is mostly a moot point.
191 if not disable_indexer:
192 self.K[0, 4] = 1
193 self.K[1, 5] = 1
Austin Schuh82a66dc2017-03-04 15:06:44 -0800194
Tyler Chatow6738c362019-02-16 14:12:30 -0800195 orig_Kff = self.Kff
196 self.Kff = numpy.matrix(numpy.zeros((2, 6)))
197 self.Kff[:, 0:4] = orig_Kff
Austin Schuh82a66dc2017-03-04 15:06:44 -0800198
Tyler Chatow6738c362019-02-16 14:12:30 -0800199 q_pos = 0.40
200 q_vel = 2.00
201 q_voltage = 8.0
202 if voltage_error_noise is not None:
203 q_voltage = voltage_error_noise
Austin Schuh82a66dc2017-03-04 15:06:44 -0800204
Tyler Chatow6738c362019-02-16 14:12:30 -0800205 self.Q = numpy.matrix([[(q_pos**2.0), 0.0, 0.0, 0.0, 0.0, 0.0],
206 [0.0, (q_vel**2.0), 0.0, 0.0, 0.0, 0.0],
207 [0.0, 0.0, (q_pos**2.0), 0.0, 0.0, 0.0],
208 [0.0, 0.0, 0.0, (q_vel**2.0), 0.0, 0.0],
209 [0.0, 0.0, 0.0, 0.0, (q_voltage**2.0), 0.0],
210 [0.0, 0.0, 0.0, 0.0, 0.0, (q_voltage**2.0)]])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800211
Tyler Chatow6738c362019-02-16 14:12:30 -0800212 r_pos = 0.05
213 self.R = numpy.matrix([[(r_pos**2.0), 0.0], [0.0, (r_pos**2.0)]])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800214
Ravago Jones5127ccc2022-07-31 16:32:45 -0700215 self.KalmanGain, self.Q_steady = controls.kalman(A=self.A,
216 B=self.B,
217 C=self.C,
218 Q=self.Q,
219 R=self.R)
Tyler Chatow6738c362019-02-16 14:12:30 -0800220 self.L = self.A * self.KalmanGain
221
222 self.InitializeState()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800223
224
225class ScenarioPlotter(object):
Austin Schuh82a66dc2017-03-04 15:06:44 -0800226
Tyler Chatow6738c362019-02-16 14:12:30 -0800227 def __init__(self):
228 # Various lists for graphing things.
229 self.t = []
230 self.xi = []
231 self.xt = []
232 self.vi = []
233 self.vt = []
234 self.ai = []
235 self.at = []
236 self.x_hat = []
237 self.ui = []
238 self.ut = []
239 self.ui_fb = []
240 self.ut_fb = []
241 self.offseti = []
242 self.offsett = []
243 self.turret_error = []
Austin Schuh82a66dc2017-03-04 15:06:44 -0800244
Tyler Chatow6738c362019-02-16 14:12:30 -0800245 def run_test(self,
246 column,
247 end_goal,
248 controller_column,
249 observer_column=None,
250 iterations=200):
251 """Runs the column plant with an initial condition and goal.
Austin Schuh82a66dc2017-03-04 15:06:44 -0800252
Tyler Chatow6738c362019-02-16 14:12:30 -0800253 Args:
254 column: column object to use.
255 end_goal: end_goal state.
256 controller_column: Intake object to get K from, or None if we should
257 use column.
258 observer_column: Intake object to use for the observer, or None if we should
259 use the actual state.
260 iterations: Number of timesteps to run the model for.
261 """
Austin Schuh82a66dc2017-03-04 15:06:44 -0800262
Tyler Chatow6738c362019-02-16 14:12:30 -0800263 if controller_column is None:
264 controller_column = column
Austin Schuh82a66dc2017-03-04 15:06:44 -0800265
Tyler Chatow6738c362019-02-16 14:12:30 -0800266 vbat = 12.0
Austin Schuh82a66dc2017-03-04 15:06:44 -0800267
Tyler Chatow6738c362019-02-16 14:12:30 -0800268 if self.t:
269 initial_t = self.t[-1] + column.dt
270 else:
271 initial_t = 0
Austin Schuh82a66dc2017-03-04 15:06:44 -0800272
Tyler Chatow6738c362019-02-16 14:12:30 -0800273 goal = numpy.concatenate((column.X, numpy.matrix(numpy.zeros((2, 1)))),
274 axis=0)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800275
Tyler Chatow6738c362019-02-16 14:12:30 -0800276 profile = TrapezoidProfile(column.dt)
277 profile.set_maximum_acceleration(10.0)
278 profile.set_maximum_velocity(3.0)
279 profile.SetGoal(goal[2, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800280
Tyler Chatow6738c362019-02-16 14:12:30 -0800281 U_last = numpy.matrix(numpy.zeros((2, 1)))
Austin Schuh5ea48472021-02-02 20:46:41 -0800282 for i in range(iterations):
Tyler Chatow6738c362019-02-16 14:12:30 -0800283 observer_column.Y = column.Y
284 observer_column.CorrectObserver(U_last)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800285
Tyler Chatow6738c362019-02-16 14:12:30 -0800286 self.offseti.append(observer_column.X_hat[4, 0])
287 self.offsett.append(observer_column.X_hat[5, 0])
288 self.x_hat.append(observer_column.X_hat[0, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800289
Tyler Chatow6738c362019-02-16 14:12:30 -0800290 next_goal = numpy.concatenate(
Ravago Jones5127ccc2022-07-31 16:32:45 -0700291 (end_goal[0:2, :],
292 profile.Update(end_goal[2, 0],
293 end_goal[3, 0]), end_goal[4:6, :]),
Tyler Chatow6738c362019-02-16 14:12:30 -0800294 axis=0)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800295
Ravago Jones5127ccc2022-07-31 16:32:45 -0700296 ff_U = controller_column.Kff * (next_goal -
297 observer_column.A * goal)
Tyler Chatow6738c362019-02-16 14:12:30 -0800298 fb_U = controller_column.K * (goal - observer_column.X_hat)
299 self.turret_error.append((goal[2, 0] - column.X[2, 0]) * 100.0)
300 self.ui_fb.append(fb_U[0, 0])
301 self.ut_fb.append(fb_U[1, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800302
Tyler Chatow6738c362019-02-16 14:12:30 -0800303 U_uncapped = ff_U + fb_U
Austin Schuh82a66dc2017-03-04 15:06:44 -0800304
Tyler Chatow6738c362019-02-16 14:12:30 -0800305 U = U_uncapped.copy()
306 U[0, 0] = numpy.clip(U[0, 0], -vbat, vbat)
307 U[1, 0] = numpy.clip(U[1, 0], -vbat, vbat)
308 self.xi.append(column.X[0, 0])
309 self.xt.append(column.X[2, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800310
Tyler Chatow6738c362019-02-16 14:12:30 -0800311 if self.vi:
312 last_vi = self.vi[-1]
313 else:
314 last_vi = 0
315 if self.vt:
316 last_vt = self.vt[-1]
317 else:
318 last_vt = 0
Austin Schuh82a66dc2017-03-04 15:06:44 -0800319
Tyler Chatow6738c362019-02-16 14:12:30 -0800320 self.vi.append(column.X[1, 0])
321 self.vt.append(column.X[3, 0])
322 self.ai.append((self.vi[-1] - last_vi) / column.dt)
323 self.at.append((self.vt[-1] - last_vt) / column.dt)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800324
Tyler Chatow6738c362019-02-16 14:12:30 -0800325 offset = 0.0
326 if i > 100:
327 offset = 1.0
328 column.Update(U + numpy.matrix([[0.0], [offset]]))
Austin Schuh82a66dc2017-03-04 15:06:44 -0800329
Tyler Chatow6738c362019-02-16 14:12:30 -0800330 observer_column.PredictObserver(U)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800331
Tyler Chatow6738c362019-02-16 14:12:30 -0800332 self.t.append(initial_t + i * column.dt)
333 self.ui.append(U[0, 0])
334 self.ut.append(U[1, 0])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800335
Tyler Chatow6738c362019-02-16 14:12:30 -0800336 ff_U -= U_uncapped - U
337 goal = controller_column.A * goal + controller_column.B * ff_U
Austin Schuh82a66dc2017-03-04 15:06:44 -0800338
Tyler Chatow6738c362019-02-16 14:12:30 -0800339 if U[1, 0] != U_uncapped[1, 0]:
340 profile.MoveCurrentState(
341 numpy.matrix([[goal[2, 0]], [goal[3, 0]]]))
Austin Schuh82a66dc2017-03-04 15:06:44 -0800342
Tyler Chatow6738c362019-02-16 14:12:30 -0800343 glog.debug('Time: %f', self.t[-1])
344 glog.debug('goal_error %s', repr((end_goal - goal).T))
345 glog.debug('error %s', repr((observer_column.X_hat - end_goal).T))
Austin Schuh82a66dc2017-03-04 15:06:44 -0800346
Tyler Chatow6738c362019-02-16 14:12:30 -0800347 def Plot(self):
348 pylab.subplot(3, 1, 1)
349 pylab.plot(self.t, self.xi, label='x_indexer')
350 pylab.plot(self.t, self.xt, label='x_turret')
351 pylab.plot(self.t, self.x_hat, label='x_hat')
352 pylab.plot(self.t, self.turret_error, label='turret_error * 100')
353 pylab.legend()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800354
Tyler Chatow6738c362019-02-16 14:12:30 -0800355 pylab.subplot(3, 1, 2)
356 pylab.plot(self.t, self.ui, label='u_indexer')
357 pylab.plot(self.t, self.ui_fb, label='u_indexer_fb')
358 pylab.plot(self.t, self.ut, label='u_turret')
359 pylab.plot(self.t, self.ut_fb, label='u_turret_fb')
360 pylab.plot(self.t, self.offseti, label='voltage_offset_indexer')
361 pylab.plot(self.t, self.offsett, label='voltage_offset_turret')
362 pylab.legend()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800363
Tyler Chatow6738c362019-02-16 14:12:30 -0800364 pylab.subplot(3, 1, 3)
365 pylab.plot(self.t, self.ai, label='a_indexer')
366 pylab.plot(self.t, self.at, label='a_turret')
367 pylab.plot(self.t, self.vi, label='v_indexer')
368 pylab.plot(self.t, self.vt, label='v_turret')
369 pylab.legend()
370
371 pylab.show()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800372
373
374def main(argv):
Tyler Chatow6738c362019-02-16 14:12:30 -0800375 scenario_plotter = ScenarioPlotter()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800376
Tyler Chatow6738c362019-02-16 14:12:30 -0800377 column = Column()
378 column_controller = IntegralColumn()
379 observer_column = IntegralColumn()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800380
Tyler Chatow6738c362019-02-16 14:12:30 -0800381 initial_X = numpy.matrix([[0.0], [0.0], [0.0], [0.0]])
382 R = numpy.matrix([[0.0], [10.0], [5.0], [0.0], [0.0], [0.0]])
Ravago Jones5127ccc2022-07-31 16:32:45 -0700383 scenario_plotter.run_test(column,
384 end_goal=R,
385 controller_column=column_controller,
386 observer_column=observer_column,
387 iterations=400)
Austin Schuh82a66dc2017-03-04 15:06:44 -0800388
Tyler Chatow6738c362019-02-16 14:12:30 -0800389 if FLAGS.plot:
390 scenario_plotter.Plot()
Austin Schuh82a66dc2017-03-04 15:06:44 -0800391
Tyler Chatow6738c362019-02-16 14:12:30 -0800392 if len(argv) != 7:
393 glog.fatal('Expected .h file name and .cc file names')
394 else:
395 namespaces = ['y2017', 'control_loops', 'superstructure', 'column']
396 column = Column('Column')
Ravago Jones5127ccc2022-07-31 16:32:45 -0700397 loop_writer = control_loop.ControlLoopWriter('Column', [column],
398 namespaces=namespaces)
Tyler Chatow6738c362019-02-16 14:12:30 -0800399 loop_writer.AddConstant(
400 control_loop.Constant('kIndexerFreeSpeed', '%f',
401 column.indexer.free_speed))
402 loop_writer.AddConstant(
403 control_loop.Constant('kIndexerOutputRatio', '%f',
404 column.indexer.G))
405 loop_writer.AddConstant(
406 control_loop.Constant('kTurretFreeSpeed', '%f',
407 column.turret.free_speed))
408 loop_writer.AddConstant(
409 control_loop.Constant('kTurretOutputRatio', '%f', column.turret.G))
410 loop_writer.Write(argv[1], argv[2])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800411
Tyler Chatow6738c362019-02-16 14:12:30 -0800412 # IntegralColumn controller 1 will disable the indexer.
413 integral_column = IntegralColumn('IntegralColumn')
Ravago Jones5127ccc2022-07-31 16:32:45 -0700414 disabled_integral_column = IntegralColumn('DisabledIntegralColumn',
415 disable_indexer=True)
Tyler Chatow6738c362019-02-16 14:12:30 -0800416 integral_loop_writer = control_loop.ControlLoopWriter(
417 'IntegralColumn', [integral_column, disabled_integral_column],
418 namespaces=namespaces)
419 integral_loop_writer.Write(argv[3], argv[4])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800420
Ravago Jones5127ccc2022-07-31 16:32:45 -0700421 stuck_integral_column = IntegralColumn('StuckIntegralColumn',
422 voltage_error_noise=8.0)
Tyler Chatow6738c362019-02-16 14:12:30 -0800423 stuck_integral_loop_writer = control_loop.ControlLoopWriter(
424 'StuckIntegralColumn', [stuck_integral_column],
425 namespaces=namespaces)
426 stuck_integral_loop_writer.Write(argv[5], argv[6])
Austin Schuh82a66dc2017-03-04 15:06:44 -0800427
428
429if __name__ == '__main__':
Tyler Chatow6738c362019-02-16 14:12:30 -0800430 argv = FLAGS(sys.argv)
431 glog.init()
432 sys.exit(main(argv))