blob: c7e13b88c40b6986f47702d626997f9ee439caac [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 Schuh63d095d2019-02-23 11:57:12 -080025 dt=0.00505):
Austin Schuhc1c957a2020-02-20 17:47:58 -080026 """Constructs an AngularSystemParams object.
27
28 Args:
29 motor: Motor object with the motor constants.
30 G: float, Gear ratio. Less than 1 means output moves slower than the
31 input.
32 """
Austin Schuh2e554032019-01-21 15:07:27 -080033 self.name = name
34 self.motor = motor
35 self.G = G
36 self.J = J
37 self.q_pos = q_pos
38 self.q_vel = q_vel
39 self.kalman_q_pos = kalman_q_pos
40 self.kalman_q_vel = kalman_q_vel
41 self.kalman_q_voltage = kalman_q_voltage
42 self.kalman_r_position = kalman_r_position
Milo Lin5d49af02022-02-05 12:50:32 -080043 self.radius = radius
Austin Schuh2e554032019-01-21 15:07:27 -080044 self.dt = dt
45
46
47class AngularSystem(control_loop.ControlLoop):
Ravago Jones5127ccc2022-07-31 16:32:45 -070048
Austin Schuh2e554032019-01-21 15:07:27 -080049 def __init__(self, params, name="AngularSystem"):
50 super(AngularSystem, self).__init__(name)
51 self.params = params
52
53 self.motor = params.motor
54
55 # Gear ratio
56 self.G = params.G
57
58 # Moment of inertia in kg m^2
Austin Schuh2e282d12024-02-19 12:00:58 -080059 self.J_motor = self.motor.motor_inertia / (self.G**2.0)
60 self.J = params.J + self.J_motor
Austin Schuh2e554032019-01-21 15:07:27 -080061
62 # Control loop time step
63 self.dt = params.dt
64
65 # State is [position, velocity]
66 # Input is [Voltage]
Ravago Jones5127ccc2022-07-31 16:32:45 -070067 C1 = self.motor.Kt / (self.G * self.G * self.motor.resistance *
68 self.J * self.motor.Kv)
Austin Schuh2e554032019-01-21 15:07:27 -080069 C2 = self.motor.Kt / (self.G * self.J * self.motor.resistance)
70
71 self.A_continuous = numpy.matrix([[0, 1], [0, -C1]])
72
73 # Start with the unmodified input
74 self.B_continuous = numpy.matrix([[0], [C2]])
75 glog.debug(repr(self.A_continuous))
76 glog.debug(repr(self.B_continuous))
77
78 self.C = numpy.matrix([[1, 0]])
79 self.D = numpy.matrix([[0]])
80
81 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
82 self.B_continuous, self.dt)
83
84 controllability = controls.ctrb(self.A, self.B)
85 glog.debug('Controllability of %d',
86 numpy.linalg.matrix_rank(controllability))
87 glog.debug('J: %f', self.J)
Milo Lin5d49af02022-02-05 12:50:32 -080088 glog.debug('Stall torque: %f (N m)', self.motor.stall_torque / self.G)
89 if self.params.radius is not None:
90 glog.debug('Stall force: %f (N)',
91 self.motor.stall_torque / self.G / self.params.radius)
Ravago Jones5127ccc2022-07-31 16:32:45 -070092 glog.debug(
93 'Stall force: %f (lbf)', self.motor.stall_torque / self.G /
94 self.params.radius * 0.224809)
Milo Lin5d49af02022-02-05 12:50:32 -080095
96 glog.debug('Stall acceleration: %f (rad/s^2)',
Austin Schuh2e554032019-01-21 15:07:27 -080097 self.motor.stall_torque / self.G / self.J)
98
Milo Lin5d49af02022-02-05 12:50:32 -080099 glog.debug('Free speed is %f (rad/s)',
Austin Schuh2e554032019-01-21 15:07:27 -0800100 -self.B_continuous[1, 0] / self.A_continuous[1, 1] * 12.0)
101
102 self.Q = numpy.matrix([[(1.0 / (self.params.q_pos**2.0)), 0.0],
103 [0.0, (1.0 / (self.params.q_vel**2.0))]])
104
105 self.R = numpy.matrix([[(1.0 / (12.0**2.0))]])
106 self.K = controls.dlqr(self.A, self.B, self.Q, self.R)
107
108 q_pos_ff = 0.005
109 q_vel_ff = 1.0
110 self.Qff = numpy.matrix([[(1.0 / (q_pos_ff**2.0)), 0.0],
111 [0.0, (1.0 / (q_vel_ff**2.0))]])
112
113 self.Kff = controls.TwoStateFeedForwards(self.B, self.Qff)
114
115 glog.debug('K %s', repr(self.K))
116 glog.debug('Poles are %s',
117 repr(numpy.linalg.eig(self.A - self.B * self.K)[0]))
118
119 self.Q = numpy.matrix([[(self.params.kalman_q_pos**2.0), 0.0],
120 [0.0, (self.params.kalman_q_vel**2.0)]])
121
122 self.R = numpy.matrix([[(self.params.kalman_r_position**2.0)]])
123
milind-u53ad98a2023-02-20 16:26:09 -0800124 # From testing, these continuous Q and R's appear to be good approximations of Q and R.
125 self.Q_continuous = self.Q / self.dt
126 self.R_continuous = self.R * self.dt
127
128 self.KalmanGain, self.P_steady_state = controls.kalman(A=self.A,
129 B=self.B,
130 C=self.C,
131 Q=self.Q,
132 R=self.R)
Austin Schuh2e554032019-01-21 15:07:27 -0800133
134 glog.debug('Kal %s', repr(self.KalmanGain))
135
136 # The box formed by U_min and U_max must encompass all possible values,
137 # or else Austin's code gets angry.
138 self.U_max = numpy.matrix([[12.0]])
139 self.U_min = numpy.matrix([[-12.0]])
140
141 self.InitializeState()
142
143
144class IntegralAngularSystem(AngularSystem):
Ravago Jones5127ccc2022-07-31 16:32:45 -0700145
Austin Schuh2e554032019-01-21 15:07:27 -0800146 def __init__(self, params, name="IntegralAngularSystem"):
147 super(IntegralAngularSystem, self).__init__(params, name=name)
148
149 self.A_continuous_unaugmented = self.A_continuous
150 self.B_continuous_unaugmented = self.B_continuous
151
152 self.A_continuous = numpy.matrix(numpy.zeros((3, 3)))
153 self.A_continuous[0:2, 0:2] = self.A_continuous_unaugmented
154 self.A_continuous[0:2, 2] = self.B_continuous_unaugmented
155
156 self.B_continuous = numpy.matrix(numpy.zeros((3, 1)))
157 self.B_continuous[0:2, 0] = self.B_continuous_unaugmented
158
159 self.C_unaugmented = self.C
160 self.C = numpy.matrix(numpy.zeros((1, 3)))
161 self.C[0:1, 0:2] = self.C_unaugmented
162
163 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
164 self.B_continuous, self.dt)
165
Tyler Chatow6738c362019-02-16 14:12:30 -0800166 self.Q = numpy.matrix([[(self.params.kalman_q_pos**2.0), 0.0, 0.0],
167 [0.0, (self.params.kalman_q_vel**2.0), 0.0],
Ravago Jones5127ccc2022-07-31 16:32:45 -0700168 [0.0, 0.0,
169 (self.params.kalman_q_voltage**2.0)]])
Austin Schuh2e554032019-01-21 15:07:27 -0800170
171 self.R = numpy.matrix([[(self.params.kalman_r_position**2.0)]])
172
milind-u53ad98a2023-02-20 16:26:09 -0800173 # From testing, these continuous Q and R's appear to be good approximations of Q and R.
174 self.Q_continuous = self.Q / self.dt
175 self.R_continuous = self.R * self.dt
176
177 self.KalmanGain, self.P_steady_state = controls.kalman(A=self.A,
178 B=self.B,
179 C=self.C,
180 Q=self.Q,
181 R=self.R)
Austin Schuh2e554032019-01-21 15:07:27 -0800182
183 self.K_unaugmented = self.K
184 self.K = numpy.matrix(numpy.zeros((1, 3)))
185 self.K[0, 0:2] = self.K_unaugmented
186 self.K[0, 2] = 1
187
188 self.Kff = numpy.concatenate(
189 (self.Kff, numpy.matrix(numpy.zeros((1, 1)))), axis=1)
190
191 self.InitializeState()
192
193
194def RunTest(plant,
195 end_goal,
196 controller,
197 observer=None,
198 duration=1.0,
199 use_profile=True,
200 kick_time=0.5,
Lee Mracek28795ef2019-01-27 05:29:37 -0500201 kick_magnitude=0.0,
202 max_velocity=10.0,
203 max_acceleration=70.0):
Austin Schuh2e554032019-01-21 15:07:27 -0800204 """Runs the plant with an initial condition and goal.
205
206 Args:
207 plant: plant object to use.
208 end_goal: end_goal state.
209 controller: AngularSystem object to get K from, or None if we should
210 use plant.
211 observer: AngularSystem object to use for the observer, or None if we
212 should use the actual state.
213 duration: float, time in seconds to run the simulation for.
214 kick_time: float, time in seconds to kick the robot.
215 kick_magnitude: float, disturbance in volts to apply.
Lee Mracek28795ef2019-01-27 05:29:37 -0500216 max_velocity: float, The maximum velocity for the profile.
217 max_acceleration: float, The maximum acceleration for the profile.
Austin Schuh2e554032019-01-21 15:07:27 -0800218 """
219 t_plot = []
220 x_plot = []
221 v_plot = []
222 a_plot = []
Austin Schuha5aa9362022-02-07 21:26:08 -0800223 motor_current_plot = []
224 battery_current_plot = []
Austin Schuh2e554032019-01-21 15:07:27 -0800225 x_goal_plot = []
226 v_goal_plot = []
227 x_hat_plot = []
228 u_plot = []
Austin Schuh2e282d12024-02-19 12:00:58 -0800229 power_rotor_plot = []
230 power_mechanism_plot = []
231 power_overall_plot = []
232 power_electrical_plot = []
Austin Schuh2e554032019-01-21 15:07:27 -0800233 offset_plot = []
234
235 if controller is None:
236 controller = plant
237
238 vbat = 12.0
239
Tyler Chatow6738c362019-02-16 14:12:30 -0800240 goal = numpy.concatenate((plant.X, numpy.matrix(numpy.zeros((1, 1)))),
241 axis=0)
Austin Schuh2e554032019-01-21 15:07:27 -0800242
243 profile = TrapezoidProfile(plant.dt)
Lee Mracek28795ef2019-01-27 05:29:37 -0500244 profile.set_maximum_acceleration(max_acceleration)
245 profile.set_maximum_velocity(max_velocity)
Austin Schuh2e554032019-01-21 15:07:27 -0800246 profile.SetGoal(goal[0, 0])
247
248 U_last = numpy.matrix(numpy.zeros((1, 1)))
249 iterations = int(duration / plant.dt)
Austin Schuh5ea48472021-02-02 20:46:41 -0800250 for i in range(iterations):
Austin Schuh2e554032019-01-21 15:07:27 -0800251 t = i * plant.dt
252 observer.Y = plant.Y
253 observer.CorrectObserver(U_last)
254
255 offset_plot.append(observer.X_hat[2, 0])
256 x_hat_plot.append(observer.X_hat[0, 0])
257
Ravago Jones5127ccc2022-07-31 16:32:45 -0700258 next_goal = numpy.concatenate((profile.Update(
259 end_goal[0, 0], end_goal[1, 0]), numpy.matrix(numpy.zeros(
260 (1, 1)))),
261 axis=0)
Austin Schuh2e554032019-01-21 15:07:27 -0800262
263 ff_U = controller.Kff * (next_goal - observer.A * goal)
264
265 if use_profile:
266 U_uncapped = controller.K * (goal - observer.X_hat) + ff_U
267 x_goal_plot.append(goal[0, 0])
268 v_goal_plot.append(goal[1, 0])
269 else:
270 U_uncapped = controller.K * (end_goal - observer.X_hat)
271 x_goal_plot.append(end_goal[0, 0])
272 v_goal_plot.append(end_goal[1, 0])
273
274 U = U_uncapped.copy()
Austin Schuha5aa9362022-02-07 21:26:08 -0800275
Austin Schuh2e554032019-01-21 15:07:27 -0800276 U[0, 0] = numpy.clip(U[0, 0], -vbat, vbat)
Austin Schuha5aa9362022-02-07 21:26:08 -0800277
Ravago Jones5127ccc2022-07-31 16:32:45 -0700278 motor_current = (U[0, 0] - plant.X[1, 0] / plant.G /
279 plant.motor.Kv) / plant.motor.resistance
Austin Schuha5aa9362022-02-07 21:26:08 -0800280 motor_current_plot.append(motor_current)
Austin Schuh2e282d12024-02-19 12:00:58 -0800281 battery_current = U[0, 0] * motor_current / vbat
282 power_electrical_plot.append(battery_current * vbat)
Austin Schuha5aa9362022-02-07 21:26:08 -0800283 battery_current_plot.append(battery_current)
Austin Schuh2e282d12024-02-19 12:00:58 -0800284
285 # Instantaneous acceleration.
286 X_dot = plant.A_continuous * plant.X + plant.B_continuous * U
287 # Torque = J * alpha (accel).
288 power_rotor_plot.append(X_dot[1, 0] * plant.J_motor * plant.X[1, 0])
289 power_mechanism_plot.append(X_dot[1, 0] * plant.params.J *
290 plant.X[1, 0])
291 power_overall_plot.append(X_dot[1, 0] * plant.J * plant.X[1, 0])
292
Austin Schuh2e554032019-01-21 15:07:27 -0800293 x_plot.append(plant.X[0, 0])
294
295 if v_plot:
296 last_v = v_plot[-1]
297 else:
298 last_v = 0
299
300 v_plot.append(plant.X[1, 0])
301 a_plot.append((v_plot[-1] - last_v) / plant.dt)
302
303 u_offset = 0.0
304 if t >= kick_time:
305 u_offset = kick_magnitude
306 plant.Update(U + u_offset)
307
308 observer.PredictObserver(U)
309
310 t_plot.append(t)
311 u_plot.append(U[0, 0])
312
313 ff_U -= U_uncapped - U
314 goal = controller.A * goal + controller.B * ff_U
315
316 if U[0, 0] != U_uncapped[0, 0]:
Ravago Jones5127ccc2022-07-31 16:32:45 -0700317 profile.MoveCurrentState(numpy.matrix([[goal[0, 0]], [goal[1,
318 0]]]))
Austin Schuh2e554032019-01-21 15:07:27 -0800319
320 glog.debug('Time: %f', t_plot[-1])
321 glog.debug('goal_error %s', repr(end_goal - goal))
322 glog.debug('error %s', repr(observer.X_hat - end_goal))
323
Austin Schuh2e282d12024-02-19 12:00:58 -0800324 pylab.suptitle(f'Gear ratio {plant.G}')
325 position_ax1 = pylab.subplot(3, 1, 1)
326 position_ax1.plot(t_plot, x_plot, label='x')
327 position_ax1.plot(t_plot, x_hat_plot, label='x_hat')
328 position_ax1.plot(t_plot, x_goal_plot, label='x_goal')
Austin Schuh2e554032019-01-21 15:07:27 -0800329
Austin Schuh2e282d12024-02-19 12:00:58 -0800330 power_ax2 = position_ax1.twinx()
331 power_ax2.set_xlabel("time(s)")
332 power_ax2.set_ylabel("Power (W)")
333 power_ax2.plot(t_plot, power_rotor_plot, label='Rotor power')
334 power_ax2.plot(t_plot, power_mechanism_plot, label='Mechanism power')
335 power_ax2.plot(t_plot,
336 power_overall_plot,
337 label='Overall mechanical power')
338 power_ax2.plot(t_plot, power_electrical_plot, label='Electrical power')
339
340 position_ax1.legend()
341 power_ax2.legend(loc='lower right')
342
343 voltage_ax1 = pylab.subplot(3, 1, 2)
344 voltage_ax1.plot(t_plot, u_plot, label='u')
345 voltage_ax1.plot(t_plot, offset_plot, label='voltage_offset')
346 voltage_ax1.legend()
Austin Schuh2e554032019-01-21 15:07:27 -0800347
Austin Schuha5aa9362022-02-07 21:26:08 -0800348 ax1 = pylab.subplot(3, 1, 3)
349 ax1.set_xlabel("time(s)")
350 ax1.set_ylabel("rad/s^2")
Austin Schuh2e282d12024-02-19 12:00:58 -0800351 ax1.plot(t_plot, a_plot, label='acceleration')
Austin Schuha5aa9362022-02-07 21:26:08 -0800352
353 ax2 = ax1.twinx()
354 ax2.set_xlabel("time(s)")
355 ax2.set_ylabel("Amps")
356 ax2.plot(t_plot, battery_current_plot, 'g', label='battery')
357 ax2.plot(t_plot, motor_current_plot, 'r', label='motor')
Austin Schuh2e554032019-01-21 15:07:27 -0800358 pylab.legend()
359
360 pylab.show()
361
362
Austin Schuh9d9d3742019-02-15 23:00:13 -0800363def PlotStep(params, R, plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800364 """Plots a step move to the goal.
365
366 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800367 params: AngularSystemParams for the controller and observer
368 plant_params: AngularSystemParams for the plant. Defaults to params if
369 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800370 R: numpy.matrix(2, 1), the goal"""
Austin Schuh9d9d3742019-02-15 23:00:13 -0800371 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800372 controller = IntegralAngularSystem(params, params.name)
373 observer = IntegralAngularSystem(params, params.name)
374
375 # Test moving the system.
376 initial_X = numpy.matrix([[0.0], [0.0]])
377 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
378 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700379 RunTest(plant,
380 end_goal=augmented_R,
381 controller=controller,
382 observer=observer,
383 duration=2.0,
384 use_profile=False,
385 kick_time=1.0,
386 kick_magnitude=0.0)
Austin Schuh2e554032019-01-21 15:07:27 -0800387
388
Austin Schuh9d9d3742019-02-15 23:00:13 -0800389def PlotKick(params, R, plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800390 """Plots a step motion with a kick at 1.0 seconds.
391
392 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800393 params: AngularSystemParams for the controller and observer
394 plant_params: AngularSystemParams for the plant. Defaults to params if
395 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800396 R: numpy.matrix(2, 1), the goal"""
Austin Schuh9d9d3742019-02-15 23:00:13 -0800397 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800398 controller = IntegralAngularSystem(params, params.name)
399 observer = IntegralAngularSystem(params, params.name)
400
401 # Test moving the system.
402 initial_X = numpy.matrix([[0.0], [0.0]])
403 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
404 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700405 RunTest(plant,
406 end_goal=augmented_R,
407 controller=controller,
408 observer=observer,
409 duration=2.0,
410 use_profile=False,
411 kick_time=1.0,
412 kick_magnitude=2.0)
Austin Schuh2e554032019-01-21 15:07:27 -0800413
414
Austin Schuh9d9d3742019-02-15 23:00:13 -0800415def PlotMotion(params,
416 R,
417 max_velocity=10.0,
418 max_acceleration=70.0,
419 plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800420 """Plots a trapezoidal motion.
421
422 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800423 params: AngularSystemParams for the controller and observer
424 plant_params: AngularSystemParams for the plant. Defaults to params if
425 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800426 R: numpy.matrix(2, 1), the goal,
Lee Mracek28795ef2019-01-27 05:29:37 -0500427 max_velocity: float, The max velocity of the profile.
428 max_acceleration: float, The max acceleration of the profile.
Austin Schuh2e554032019-01-21 15:07:27 -0800429 """
Austin Schuh9d9d3742019-02-15 23:00:13 -0800430 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800431 controller = IntegralAngularSystem(params, params.name)
432 observer = IntegralAngularSystem(params, params.name)
433
434 # Test moving the system.
435 initial_X = numpy.matrix([[0.0], [0.0]])
436 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
437 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700438 RunTest(plant,
439 end_goal=augmented_R,
440 controller=controller,
441 observer=observer,
442 duration=2.0,
443 use_profile=True,
444 max_velocity=max_velocity,
445 max_acceleration=max_acceleration)
Austin Schuh2e554032019-01-21 15:07:27 -0800446
447
milind-u53ad98a2023-02-20 16:26:09 -0800448def WriteAngularSystem(params,
449 plant_files,
450 controller_files,
451 year_namespaces,
452 plant_type='StateFeedbackPlant',
453 observer_type='StateFeedbackObserver'):
Austin Schuh2e554032019-01-21 15:07:27 -0800454 """Writes out the constants for a angular system to a file.
455
456 Args:
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700457 params: list of AngularSystemParams or AngularSystemParams, the
458 parameters defining the system.
Austin Schuh2e554032019-01-21 15:07:27 -0800459 plant_files: list of strings, the cc and h files for the plant.
460 controller_files: list of strings, the cc and h files for the integral
461 controller.
462 year_namespaces: list of strings, the namespace list to use.
463 """
464 # Write the generated constants out to a file.
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700465 angular_systems = []
466 integral_angular_systems = []
467
468 if type(params) is list:
469 name = params[0].name
470 for index, param in enumerate(params):
471 angular_systems.append(
472 AngularSystem(param, param.name + str(index)))
473 integral_angular_systems.append(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800474 IntegralAngularSystem(param,
475 'Integral' + param.name + str(index)))
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700476 else:
477 name = params.name
478 angular_systems.append(AngularSystem(params, params.name))
479 integral_angular_systems.append(
480 IntegralAngularSystem(params, 'Integral' + params.name))
481
Ravago Jones5127ccc2022-07-31 16:32:45 -0700482 loop_writer = control_loop.ControlLoopWriter(name,
483 angular_systems,
milind-u53ad98a2023-02-20 16:26:09 -0800484 namespaces=year_namespaces,
485 plant_type=plant_type,
486 observer_type=observer_type)
Lee Mracek17cb4892019-02-07 11:24:49 -0500487 loop_writer.AddConstant(
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700488 control_loop.Constant('kOutputRatio', '%f', angular_systems[0].G))
Lee Mracek17cb4892019-02-07 11:24:49 -0500489 loop_writer.AddConstant(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800490 control_loop.Constant('kFreeSpeed', '%f',
491 angular_systems[0].motor.free_speed))
James Kuszmauleeb98e92024-01-14 22:15:32 -0800492 loop_writer.Write(plant_files[0], plant_files[1],
493 None if len(plant_files) < 3 else plant_files[2])
Austin Schuh2e554032019-01-21 15:07:27 -0800494
Austin Schuh2e554032019-01-21 15:07:27 -0800495 integral_loop_writer = control_loop.ControlLoopWriter(
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700496 'Integral' + name,
497 integral_angular_systems,
milind-u53ad98a2023-02-20 16:26:09 -0800498 namespaces=year_namespaces,
499 plant_type=plant_type,
500 observer_type=observer_type)
James Kuszmauleeb98e92024-01-14 22:15:32 -0800501 integral_loop_writer.Write(
502 controller_files[0], controller_files[1],
503 None if len(controller_files) < 3 else controller_files[2])