blob: beade857ffc75418a4fa4e9fbc6da4a6c44e41f4 [file] [log] [blame]
Austin Schuh085eab92020-11-26 13:54:51 -08001#!/usr/bin/python3
Austin Schuh2e554032019-01-21 15:07:27 -08002
3from aos.util.trapezoid_profile import TrapezoidProfile
4from frc971.control_loops.python import control_loop
5from frc971.control_loops.python import controls
6import numpy
7from matplotlib import pylab
8import glog
9
10
11class AngularSystemParams(object):
Ravago Jones5127ccc2022-07-31 16:32:45 -070012
Austin Schuh2e554032019-01-21 15:07:27 -080013 def __init__(self,
14 name,
15 motor,
16 G,
17 J,
18 q_pos,
19 q_vel,
20 kalman_q_pos,
21 kalman_q_vel,
22 kalman_q_voltage,
23 kalman_r_position,
Ravago Jones5127ccc2022-07-31 16:32:45 -070024 radius=None,
Austin Schuh087613b2024-02-19 12:39:08 -080025 dt=0.00505,
26 delayed_u=0):
Austin Schuhc1c957a2020-02-20 17:47:58 -080027 """Constructs an AngularSystemParams object.
28
29 Args:
30 motor: Motor object with the motor constants.
31 G: float, Gear ratio. Less than 1 means output moves slower than the
32 input.
33 """
Austin Schuh2e554032019-01-21 15:07:27 -080034 self.name = name
35 self.motor = motor
36 self.G = G
37 self.J = J
38 self.q_pos = q_pos
39 self.q_vel = q_vel
40 self.kalman_q_pos = kalman_q_pos
41 self.kalman_q_vel = kalman_q_vel
42 self.kalman_q_voltage = kalman_q_voltage
43 self.kalman_r_position = kalman_r_position
Milo Lin5d49af02022-02-05 12:50:32 -080044 self.radius = radius
Austin Schuh2e554032019-01-21 15:07:27 -080045 self.dt = dt
Austin Schuh087613b2024-02-19 12:39:08 -080046 self.delayed_u = delayed_u
Austin Schuh2e554032019-01-21 15:07:27 -080047
48
49class AngularSystem(control_loop.ControlLoop):
Ravago Jones5127ccc2022-07-31 16:32:45 -070050
Austin Schuh2e554032019-01-21 15:07:27 -080051 def __init__(self, params, name="AngularSystem"):
52 super(AngularSystem, self).__init__(name)
53 self.params = params
54
55 self.motor = params.motor
56
57 # Gear ratio
58 self.G = params.G
59
60 # Moment of inertia in kg m^2
Austin Schuh2e282d12024-02-19 12:00:58 -080061 self.J_motor = self.motor.motor_inertia / (self.G**2.0)
62 self.J = params.J + self.J_motor
Austin Schuh2e554032019-01-21 15:07:27 -080063
64 # Control loop time step
65 self.dt = params.dt
66
67 # State is [position, velocity]
68 # Input is [Voltage]
Ravago Jones5127ccc2022-07-31 16:32:45 -070069 C1 = self.motor.Kt / (self.G * self.G * self.motor.resistance *
70 self.J * self.motor.Kv)
Austin Schuh2e554032019-01-21 15:07:27 -080071 C2 = self.motor.Kt / (self.G * self.J * self.motor.resistance)
72
73 self.A_continuous = numpy.matrix([[0, 1], [0, -C1]])
74
75 # Start with the unmodified input
76 self.B_continuous = numpy.matrix([[0], [C2]])
77 glog.debug(repr(self.A_continuous))
78 glog.debug(repr(self.B_continuous))
79
80 self.C = numpy.matrix([[1, 0]])
81 self.D = numpy.matrix([[0]])
82
83 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
84 self.B_continuous, self.dt)
85
86 controllability = controls.ctrb(self.A, self.B)
87 glog.debug('Controllability of %d',
88 numpy.linalg.matrix_rank(controllability))
89 glog.debug('J: %f', self.J)
Milo Lin5d49af02022-02-05 12:50:32 -080090 glog.debug('Stall torque: %f (N m)', self.motor.stall_torque / self.G)
91 if self.params.radius is not None:
92 glog.debug('Stall force: %f (N)',
93 self.motor.stall_torque / self.G / self.params.radius)
Ravago Jones5127ccc2022-07-31 16:32:45 -070094 glog.debug(
95 'Stall force: %f (lbf)', self.motor.stall_torque / self.G /
96 self.params.radius * 0.224809)
Milo Lin5d49af02022-02-05 12:50:32 -080097
98 glog.debug('Stall acceleration: %f (rad/s^2)',
Austin Schuh2e554032019-01-21 15:07:27 -080099 self.motor.stall_torque / self.G / self.J)
100
Milo Lin5d49af02022-02-05 12:50:32 -0800101 glog.debug('Free speed is %f (rad/s)',
Austin Schuh2e554032019-01-21 15:07:27 -0800102 -self.B_continuous[1, 0] / self.A_continuous[1, 1] * 12.0)
103
104 self.Q = numpy.matrix([[(1.0 / (self.params.q_pos**2.0)), 0.0],
105 [0.0, (1.0 / (self.params.q_vel**2.0))]])
106
107 self.R = numpy.matrix([[(1.0 / (12.0**2.0))]])
108 self.K = controls.dlqr(self.A, self.B, self.Q, self.R)
109
110 q_pos_ff = 0.005
111 q_vel_ff = 1.0
112 self.Qff = numpy.matrix([[(1.0 / (q_pos_ff**2.0)), 0.0],
113 [0.0, (1.0 / (q_vel_ff**2.0))]])
114
115 self.Kff = controls.TwoStateFeedForwards(self.B, self.Qff)
116
117 glog.debug('K %s', repr(self.K))
118 glog.debug('Poles are %s',
119 repr(numpy.linalg.eig(self.A - self.B * self.K)[0]))
120
121 self.Q = numpy.matrix([[(self.params.kalman_q_pos**2.0), 0.0],
122 [0.0, (self.params.kalman_q_vel**2.0)]])
123
124 self.R = numpy.matrix([[(self.params.kalman_r_position**2.0)]])
125
milind-u53ad98a2023-02-20 16:26:09 -0800126 # From testing, these continuous Q and R's appear to be good approximations of Q and R.
127 self.Q_continuous = self.Q / self.dt
128 self.R_continuous = self.R * self.dt
129
130 self.KalmanGain, self.P_steady_state = controls.kalman(A=self.A,
131 B=self.B,
132 C=self.C,
133 Q=self.Q,
134 R=self.R)
Austin Schuh2e554032019-01-21 15:07:27 -0800135
136 glog.debug('Kal %s', repr(self.KalmanGain))
137
138 # The box formed by U_min and U_max must encompass all possible values,
139 # or else Austin's code gets angry.
140 self.U_max = numpy.matrix([[12.0]])
141 self.U_min = numpy.matrix([[-12.0]])
142
143 self.InitializeState()
144
145
146class IntegralAngularSystem(AngularSystem):
Ravago Jones5127ccc2022-07-31 16:32:45 -0700147
Austin Schuh2e554032019-01-21 15:07:27 -0800148 def __init__(self, params, name="IntegralAngularSystem"):
149 super(IntegralAngularSystem, self).__init__(params, name=name)
150
151 self.A_continuous_unaugmented = self.A_continuous
152 self.B_continuous_unaugmented = self.B_continuous
153
154 self.A_continuous = numpy.matrix(numpy.zeros((3, 3)))
155 self.A_continuous[0:2, 0:2] = self.A_continuous_unaugmented
156 self.A_continuous[0:2, 2] = self.B_continuous_unaugmented
157
158 self.B_continuous = numpy.matrix(numpy.zeros((3, 1)))
159 self.B_continuous[0:2, 0] = self.B_continuous_unaugmented
160
161 self.C_unaugmented = self.C
162 self.C = numpy.matrix(numpy.zeros((1, 3)))
163 self.C[0:1, 0:2] = self.C_unaugmented
164
165 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
166 self.B_continuous, self.dt)
167
Tyler Chatow6738c362019-02-16 14:12:30 -0800168 self.Q = numpy.matrix([[(self.params.kalman_q_pos**2.0), 0.0, 0.0],
169 [0.0, (self.params.kalman_q_vel**2.0), 0.0],
Ravago Jones5127ccc2022-07-31 16:32:45 -0700170 [0.0, 0.0,
171 (self.params.kalman_q_voltage**2.0)]])
Austin Schuh2e554032019-01-21 15:07:27 -0800172
173 self.R = numpy.matrix([[(self.params.kalman_r_position**2.0)]])
174
milind-u53ad98a2023-02-20 16:26:09 -0800175 # From testing, these continuous Q and R's appear to be good approximations of Q and R.
176 self.Q_continuous = self.Q / self.dt
177 self.R_continuous = self.R * self.dt
178
179 self.KalmanGain, self.P_steady_state = controls.kalman(A=self.A,
180 B=self.B,
181 C=self.C,
182 Q=self.Q,
183 R=self.R)
Austin Schuh2e554032019-01-21 15:07:27 -0800184
185 self.K_unaugmented = self.K
186 self.K = numpy.matrix(numpy.zeros((1, 3)))
187 self.K[0, 0:2] = self.K_unaugmented
188 self.K[0, 2] = 1
189
190 self.Kff = numpy.concatenate(
191 (self.Kff, numpy.matrix(numpy.zeros((1, 1)))), axis=1)
192
193 self.InitializeState()
194
195
196def RunTest(plant,
197 end_goal,
198 controller,
199 observer=None,
200 duration=1.0,
201 use_profile=True,
202 kick_time=0.5,
Lee Mracek28795ef2019-01-27 05:29:37 -0500203 kick_magnitude=0.0,
204 max_velocity=10.0,
205 max_acceleration=70.0):
Austin Schuh2e554032019-01-21 15:07:27 -0800206 """Runs the plant with an initial condition and goal.
207
208 Args:
209 plant: plant object to use.
210 end_goal: end_goal state.
211 controller: AngularSystem object to get K from, or None if we should
212 use plant.
213 observer: AngularSystem object to use for the observer, or None if we
214 should use the actual state.
215 duration: float, time in seconds to run the simulation for.
216 kick_time: float, time in seconds to kick the robot.
217 kick_magnitude: float, disturbance in volts to apply.
Lee Mracek28795ef2019-01-27 05:29:37 -0500218 max_velocity: float, The maximum velocity for the profile.
219 max_acceleration: float, The maximum acceleration for the profile.
Austin Schuh2e554032019-01-21 15:07:27 -0800220 """
221 t_plot = []
222 x_plot = []
223 v_plot = []
224 a_plot = []
Austin Schuha5aa9362022-02-07 21:26:08 -0800225 motor_current_plot = []
226 battery_current_plot = []
Austin Schuh2e554032019-01-21 15:07:27 -0800227 x_goal_plot = []
228 v_goal_plot = []
229 x_hat_plot = []
230 u_plot = []
Austin Schuh2e282d12024-02-19 12:00:58 -0800231 power_rotor_plot = []
232 power_mechanism_plot = []
233 power_overall_plot = []
234 power_electrical_plot = []
Austin Schuh2e554032019-01-21 15:07:27 -0800235 offset_plot = []
236
237 if controller is None:
238 controller = plant
239
240 vbat = 12.0
241
Tyler Chatow6738c362019-02-16 14:12:30 -0800242 goal = numpy.concatenate((plant.X, numpy.matrix(numpy.zeros((1, 1)))),
243 axis=0)
Austin Schuh2e554032019-01-21 15:07:27 -0800244
245 profile = TrapezoidProfile(plant.dt)
Lee Mracek28795ef2019-01-27 05:29:37 -0500246 profile.set_maximum_acceleration(max_acceleration)
247 profile.set_maximum_velocity(max_velocity)
Austin Schuh2e554032019-01-21 15:07:27 -0800248 profile.SetGoal(goal[0, 0])
249
250 U_last = numpy.matrix(numpy.zeros((1, 1)))
251 iterations = int(duration / plant.dt)
Austin Schuh5ea48472021-02-02 20:46:41 -0800252 for i in range(iterations):
Austin Schuh2e554032019-01-21 15:07:27 -0800253 t = i * plant.dt
254 observer.Y = plant.Y
255 observer.CorrectObserver(U_last)
256
257 offset_plot.append(observer.X_hat[2, 0])
258 x_hat_plot.append(observer.X_hat[0, 0])
259
Ravago Jones5127ccc2022-07-31 16:32:45 -0700260 next_goal = numpy.concatenate((profile.Update(
261 end_goal[0, 0], end_goal[1, 0]), numpy.matrix(numpy.zeros(
262 (1, 1)))),
263 axis=0)
Austin Schuh2e554032019-01-21 15:07:27 -0800264
265 ff_U = controller.Kff * (next_goal - observer.A * goal)
266
267 if use_profile:
268 U_uncapped = controller.K * (goal - observer.X_hat) + ff_U
269 x_goal_plot.append(goal[0, 0])
270 v_goal_plot.append(goal[1, 0])
271 else:
272 U_uncapped = controller.K * (end_goal - observer.X_hat)
273 x_goal_plot.append(end_goal[0, 0])
274 v_goal_plot.append(end_goal[1, 0])
275
276 U = U_uncapped.copy()
Austin Schuha5aa9362022-02-07 21:26:08 -0800277
Austin Schuh2e554032019-01-21 15:07:27 -0800278 U[0, 0] = numpy.clip(U[0, 0], -vbat, vbat)
Austin Schuha5aa9362022-02-07 21:26:08 -0800279
Ravago Jones5127ccc2022-07-31 16:32:45 -0700280 motor_current = (U[0, 0] - plant.X[1, 0] / plant.G /
281 plant.motor.Kv) / plant.motor.resistance
Austin Schuha5aa9362022-02-07 21:26:08 -0800282 motor_current_plot.append(motor_current)
Austin Schuh2e282d12024-02-19 12:00:58 -0800283 battery_current = U[0, 0] * motor_current / vbat
284 power_electrical_plot.append(battery_current * vbat)
Austin Schuha5aa9362022-02-07 21:26:08 -0800285 battery_current_plot.append(battery_current)
Austin Schuh2e282d12024-02-19 12:00:58 -0800286
287 # Instantaneous acceleration.
288 X_dot = plant.A_continuous * plant.X + plant.B_continuous * U
289 # Torque = J * alpha (accel).
290 power_rotor_plot.append(X_dot[1, 0] * plant.J_motor * plant.X[1, 0])
291 power_mechanism_plot.append(X_dot[1, 0] * plant.params.J *
292 plant.X[1, 0])
293 power_overall_plot.append(X_dot[1, 0] * plant.J * plant.X[1, 0])
294
Austin Schuh2e554032019-01-21 15:07:27 -0800295 x_plot.append(plant.X[0, 0])
296
297 if v_plot:
298 last_v = v_plot[-1]
299 else:
300 last_v = 0
301
302 v_plot.append(plant.X[1, 0])
303 a_plot.append((v_plot[-1] - last_v) / plant.dt)
304
305 u_offset = 0.0
306 if t >= kick_time:
307 u_offset = kick_magnitude
308 plant.Update(U + u_offset)
309
310 observer.PredictObserver(U)
311
312 t_plot.append(t)
313 u_plot.append(U[0, 0])
314
315 ff_U -= U_uncapped - U
316 goal = controller.A * goal + controller.B * ff_U
317
318 if U[0, 0] != U_uncapped[0, 0]:
Ravago Jones5127ccc2022-07-31 16:32:45 -0700319 profile.MoveCurrentState(numpy.matrix([[goal[0, 0]], [goal[1,
320 0]]]))
Austin Schuh2e554032019-01-21 15:07:27 -0800321
322 glog.debug('Time: %f', t_plot[-1])
323 glog.debug('goal_error %s', repr(end_goal - goal))
324 glog.debug('error %s', repr(observer.X_hat - end_goal))
325
Austin Schuh2e282d12024-02-19 12:00:58 -0800326 pylab.suptitle(f'Gear ratio {plant.G}')
327 position_ax1 = pylab.subplot(3, 1, 1)
328 position_ax1.plot(t_plot, x_plot, label='x')
329 position_ax1.plot(t_plot, x_hat_plot, label='x_hat')
330 position_ax1.plot(t_plot, x_goal_plot, label='x_goal')
Austin Schuh2e554032019-01-21 15:07:27 -0800331
Austin Schuh2e282d12024-02-19 12:00:58 -0800332 power_ax2 = position_ax1.twinx()
333 power_ax2.set_xlabel("time(s)")
334 power_ax2.set_ylabel("Power (W)")
335 power_ax2.plot(t_plot, power_rotor_plot, label='Rotor power')
336 power_ax2.plot(t_plot, power_mechanism_plot, label='Mechanism power')
337 power_ax2.plot(t_plot,
338 power_overall_plot,
339 label='Overall mechanical power')
340 power_ax2.plot(t_plot, power_electrical_plot, label='Electrical power')
341
342 position_ax1.legend()
343 power_ax2.legend(loc='lower right')
344
345 voltage_ax1 = pylab.subplot(3, 1, 2)
346 voltage_ax1.plot(t_plot, u_plot, label='u')
347 voltage_ax1.plot(t_plot, offset_plot, label='voltage_offset')
348 voltage_ax1.legend()
Austin Schuh2e554032019-01-21 15:07:27 -0800349
Austin Schuha5aa9362022-02-07 21:26:08 -0800350 ax1 = pylab.subplot(3, 1, 3)
351 ax1.set_xlabel("time(s)")
352 ax1.set_ylabel("rad/s^2")
Austin Schuh2e282d12024-02-19 12:00:58 -0800353 ax1.plot(t_plot, a_plot, label='acceleration')
Austin Schuha5aa9362022-02-07 21:26:08 -0800354
355 ax2 = ax1.twinx()
356 ax2.set_xlabel("time(s)")
357 ax2.set_ylabel("Amps")
358 ax2.plot(t_plot, battery_current_plot, 'g', label='battery')
359 ax2.plot(t_plot, motor_current_plot, 'r', label='motor')
Austin Schuh2e554032019-01-21 15:07:27 -0800360 pylab.legend()
361
362 pylab.show()
363
364
Austin Schuh9d9d3742019-02-15 23:00:13 -0800365def PlotStep(params, R, plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800366 """Plots a step move to the goal.
367
368 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800369 params: AngularSystemParams for the controller and observer
370 plant_params: AngularSystemParams for the plant. Defaults to params if
371 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800372 R: numpy.matrix(2, 1), the goal"""
Austin Schuh9d9d3742019-02-15 23:00:13 -0800373 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800374 controller = IntegralAngularSystem(params, params.name)
375 observer = IntegralAngularSystem(params, params.name)
376
377 # Test moving the system.
378 initial_X = numpy.matrix([[0.0], [0.0]])
379 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
380 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700381 RunTest(plant,
382 end_goal=augmented_R,
383 controller=controller,
384 observer=observer,
385 duration=2.0,
386 use_profile=False,
387 kick_time=1.0,
388 kick_magnitude=0.0)
Austin Schuh2e554032019-01-21 15:07:27 -0800389
390
Austin Schuh9d9d3742019-02-15 23:00:13 -0800391def PlotKick(params, R, plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800392 """Plots a step motion with a kick at 1.0 seconds.
393
394 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800395 params: AngularSystemParams for the controller and observer
396 plant_params: AngularSystemParams for the plant. Defaults to params if
397 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800398 R: numpy.matrix(2, 1), the goal"""
Austin Schuh9d9d3742019-02-15 23:00:13 -0800399 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800400 controller = IntegralAngularSystem(params, params.name)
401 observer = IntegralAngularSystem(params, params.name)
402
403 # Test moving the system.
404 initial_X = numpy.matrix([[0.0], [0.0]])
405 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
406 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700407 RunTest(plant,
408 end_goal=augmented_R,
409 controller=controller,
410 observer=observer,
411 duration=2.0,
412 use_profile=False,
413 kick_time=1.0,
414 kick_magnitude=2.0)
Austin Schuh2e554032019-01-21 15:07:27 -0800415
416
Austin Schuh9d9d3742019-02-15 23:00:13 -0800417def PlotMotion(params,
418 R,
419 max_velocity=10.0,
420 max_acceleration=70.0,
421 plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800422 """Plots a trapezoidal motion.
423
424 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800425 params: AngularSystemParams for the controller and observer
426 plant_params: AngularSystemParams for the plant. Defaults to params if
427 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800428 R: numpy.matrix(2, 1), the goal,
Lee Mracek28795ef2019-01-27 05:29:37 -0500429 max_velocity: float, The max velocity of the profile.
430 max_acceleration: float, The max acceleration of the profile.
Austin Schuh2e554032019-01-21 15:07:27 -0800431 """
Austin Schuh9d9d3742019-02-15 23:00:13 -0800432 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800433 controller = IntegralAngularSystem(params, params.name)
434 observer = IntegralAngularSystem(params, params.name)
435
436 # Test moving the system.
437 initial_X = numpy.matrix([[0.0], [0.0]])
438 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
439 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700440 RunTest(plant,
441 end_goal=augmented_R,
442 controller=controller,
443 observer=observer,
444 duration=2.0,
445 use_profile=True,
446 max_velocity=max_velocity,
447 max_acceleration=max_acceleration)
Austin Schuh2e554032019-01-21 15:07:27 -0800448
449
milind-u53ad98a2023-02-20 16:26:09 -0800450def WriteAngularSystem(params,
451 plant_files,
452 controller_files,
453 year_namespaces,
454 plant_type='StateFeedbackPlant',
455 observer_type='StateFeedbackObserver'):
Austin Schuh2e554032019-01-21 15:07:27 -0800456 """Writes out the constants for a angular system to a file.
457
458 Args:
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700459 params: list of AngularSystemParams or AngularSystemParams, the
460 parameters defining the system.
Austin Schuh2e554032019-01-21 15:07:27 -0800461 plant_files: list of strings, the cc and h files for the plant.
462 controller_files: list of strings, the cc and h files for the integral
463 controller.
464 year_namespaces: list of strings, the namespace list to use.
465 """
466 # Write the generated constants out to a file.
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700467 angular_systems = []
468 integral_angular_systems = []
469
470 if type(params) is list:
471 name = params[0].name
472 for index, param in enumerate(params):
473 angular_systems.append(
474 AngularSystem(param, param.name + str(index)))
475 integral_angular_systems.append(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800476 IntegralAngularSystem(param,
477 'Integral' + param.name + str(index)))
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700478 else:
479 name = params.name
480 angular_systems.append(AngularSystem(params, params.name))
481 integral_angular_systems.append(
482 IntegralAngularSystem(params, 'Integral' + params.name))
483
Ravago Jones5127ccc2022-07-31 16:32:45 -0700484 loop_writer = control_loop.ControlLoopWriter(name,
485 angular_systems,
milind-u53ad98a2023-02-20 16:26:09 -0800486 namespaces=year_namespaces,
487 plant_type=plant_type,
488 observer_type=observer_type)
Lee Mracek17cb4892019-02-07 11:24:49 -0500489 loop_writer.AddConstant(
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700490 control_loop.Constant('kOutputRatio', '%f', angular_systems[0].G))
Lee Mracek17cb4892019-02-07 11:24:49 -0500491 loop_writer.AddConstant(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800492 control_loop.Constant('kFreeSpeed', '%f',
493 angular_systems[0].motor.free_speed))
James Kuszmauleeb98e92024-01-14 22:15:32 -0800494 loop_writer.Write(plant_files[0], plant_files[1],
495 None if len(plant_files) < 3 else plant_files[2])
Austin Schuh2e554032019-01-21 15:07:27 -0800496
Austin Schuh2e554032019-01-21 15:07:27 -0800497 integral_loop_writer = control_loop.ControlLoopWriter(
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700498 'Integral' + name,
499 integral_angular_systems,
milind-u53ad98a2023-02-20 16:26:09 -0800500 namespaces=year_namespaces,
501 plant_type=plant_type,
502 observer_type=observer_type)
James Kuszmauleeb98e92024-01-14 22:15:32 -0800503 integral_loop_writer.Write(
504 controller_files[0], controller_files[1],
505 None if len(controller_files) < 3 else controller_files[2])