blob: 16773fa14b936c744bc17892f14dad63a469fe78 [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,
James Kuszmaula4226f52024-03-01 21:29:12 -080026 enable_voltage_error=True,
Austin Schuh087613b2024-02-19 12:39:08 -080027 delayed_u=0):
Austin Schuhc1c957a2020-02-20 17:47:58 -080028 """Constructs an AngularSystemParams object.
29
30 Args:
31 motor: Motor object with the motor constants.
32 G: float, Gear ratio. Less than 1 means output moves slower than the
33 input.
34 """
Austin Schuh2e554032019-01-21 15:07:27 -080035 self.name = name
36 self.motor = motor
37 self.G = G
38 self.J = J
39 self.q_pos = q_pos
40 self.q_vel = q_vel
41 self.kalman_q_pos = kalman_q_pos
42 self.kalman_q_vel = kalman_q_vel
43 self.kalman_q_voltage = kalman_q_voltage
44 self.kalman_r_position = kalman_r_position
Milo Lin5d49af02022-02-05 12:50:32 -080045 self.radius = radius
Austin Schuh2e554032019-01-21 15:07:27 -080046 self.dt = dt
James Kuszmaula4226f52024-03-01 21:29:12 -080047 self.enable_voltage_error = enable_voltage_error
Austin Schuh087613b2024-02-19 12:39:08 -080048 self.delayed_u = delayed_u
Austin Schuh2e554032019-01-21 15:07:27 -080049
50
51class AngularSystem(control_loop.ControlLoop):
Ravago Jones5127ccc2022-07-31 16:32:45 -070052
Austin Schuh2e554032019-01-21 15:07:27 -080053 def __init__(self, params, name="AngularSystem"):
54 super(AngularSystem, self).__init__(name)
55 self.params = params
56
57 self.motor = params.motor
58
59 # Gear ratio
60 self.G = params.G
61
62 # Moment of inertia in kg m^2
Austin Schuh2e282d12024-02-19 12:00:58 -080063 self.J_motor = self.motor.motor_inertia / (self.G**2.0)
64 self.J = params.J + self.J_motor
Austin Schuh2e554032019-01-21 15:07:27 -080065
66 # Control loop time step
67 self.dt = params.dt
68
69 # State is [position, velocity]
70 # Input is [Voltage]
Ravago Jones5127ccc2022-07-31 16:32:45 -070071 C1 = self.motor.Kt / (self.G * self.G * self.motor.resistance *
72 self.J * self.motor.Kv)
Austin Schuh2e554032019-01-21 15:07:27 -080073 C2 = self.motor.Kt / (self.G * self.J * self.motor.resistance)
74
75 self.A_continuous = numpy.matrix([[0, 1], [0, -C1]])
76
77 # Start with the unmodified input
78 self.B_continuous = numpy.matrix([[0], [C2]])
79 glog.debug(repr(self.A_continuous))
80 glog.debug(repr(self.B_continuous))
81
82 self.C = numpy.matrix([[1, 0]])
83 self.D = numpy.matrix([[0]])
84
85 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
86 self.B_continuous, self.dt)
87
88 controllability = controls.ctrb(self.A, self.B)
89 glog.debug('Controllability of %d',
90 numpy.linalg.matrix_rank(controllability))
91 glog.debug('J: %f', self.J)
Milo Lin5d49af02022-02-05 12:50:32 -080092 glog.debug('Stall torque: %f (N m)', self.motor.stall_torque / self.G)
93 if self.params.radius is not None:
94 glog.debug('Stall force: %f (N)',
95 self.motor.stall_torque / self.G / self.params.radius)
Ravago Jones5127ccc2022-07-31 16:32:45 -070096 glog.debug(
97 'Stall force: %f (lbf)', self.motor.stall_torque / self.G /
98 self.params.radius * 0.224809)
Milo Lin5d49af02022-02-05 12:50:32 -080099
100 glog.debug('Stall acceleration: %f (rad/s^2)',
Austin Schuh2e554032019-01-21 15:07:27 -0800101 self.motor.stall_torque / self.G / self.J)
102
Milo Lin5d49af02022-02-05 12:50:32 -0800103 glog.debug('Free speed is %f (rad/s)',
Austin Schuh2e554032019-01-21 15:07:27 -0800104 -self.B_continuous[1, 0] / self.A_continuous[1, 1] * 12.0)
105
106 self.Q = numpy.matrix([[(1.0 / (self.params.q_pos**2.0)), 0.0],
107 [0.0, (1.0 / (self.params.q_vel**2.0))]])
108
109 self.R = numpy.matrix([[(1.0 / (12.0**2.0))]])
110 self.K = controls.dlqr(self.A, self.B, self.Q, self.R)
111
112 q_pos_ff = 0.005
113 q_vel_ff = 1.0
114 self.Qff = numpy.matrix([[(1.0 / (q_pos_ff**2.0)), 0.0],
115 [0.0, (1.0 / (q_vel_ff**2.0))]])
116
117 self.Kff = controls.TwoStateFeedForwards(self.B, self.Qff)
118
119 glog.debug('K %s', repr(self.K))
120 glog.debug('Poles are %s',
121 repr(numpy.linalg.eig(self.A - self.B * self.K)[0]))
122
123 self.Q = numpy.matrix([[(self.params.kalman_q_pos**2.0), 0.0],
124 [0.0, (self.params.kalman_q_vel**2.0)]])
125
126 self.R = numpy.matrix([[(self.params.kalman_r_position**2.0)]])
127
milind-u53ad98a2023-02-20 16:26:09 -0800128 # From testing, these continuous Q and R's appear to be good approximations of Q and R.
129 self.Q_continuous = self.Q / self.dt
130 self.R_continuous = self.R * self.dt
131
132 self.KalmanGain, self.P_steady_state = controls.kalman(A=self.A,
133 B=self.B,
134 C=self.C,
135 Q=self.Q,
136 R=self.R)
Austin Schuh2e554032019-01-21 15:07:27 -0800137
138 glog.debug('Kal %s', repr(self.KalmanGain))
139
140 # The box formed by U_min and U_max must encompass all possible values,
141 # or else Austin's code gets angry.
142 self.U_max = numpy.matrix([[12.0]])
143 self.U_min = numpy.matrix([[-12.0]])
144
145 self.InitializeState()
146
147
148class IntegralAngularSystem(AngularSystem):
Ravago Jones5127ccc2022-07-31 16:32:45 -0700149
Austin Schuh2e554032019-01-21 15:07:27 -0800150 def __init__(self, params, name="IntegralAngularSystem"):
151 super(IntegralAngularSystem, self).__init__(params, name=name)
152
153 self.A_continuous_unaugmented = self.A_continuous
154 self.B_continuous_unaugmented = self.B_continuous
155
156 self.A_continuous = numpy.matrix(numpy.zeros((3, 3)))
157 self.A_continuous[0:2, 0:2] = self.A_continuous_unaugmented
158 self.A_continuous[0:2, 2] = self.B_continuous_unaugmented
159
160 self.B_continuous = numpy.matrix(numpy.zeros((3, 1)))
161 self.B_continuous[0:2, 0] = self.B_continuous_unaugmented
162
163 self.C_unaugmented = self.C
164 self.C = numpy.matrix(numpy.zeros((1, 3)))
165 self.C[0:1, 0:2] = self.C_unaugmented
166
167 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
168 self.B_continuous, self.dt)
169
Tyler Chatow6738c362019-02-16 14:12:30 -0800170 self.Q = numpy.matrix([[(self.params.kalman_q_pos**2.0), 0.0, 0.0],
171 [0.0, (self.params.kalman_q_vel**2.0), 0.0],
Ravago Jones5127ccc2022-07-31 16:32:45 -0700172 [0.0, 0.0,
173 (self.params.kalman_q_voltage**2.0)]])
Austin Schuh2e554032019-01-21 15:07:27 -0800174
175 self.R = numpy.matrix([[(self.params.kalman_r_position**2.0)]])
176
milind-u53ad98a2023-02-20 16:26:09 -0800177 # From testing, these continuous Q and R's appear to be good approximations of Q and R.
178 self.Q_continuous = self.Q / self.dt
179 self.R_continuous = self.R * self.dt
180
181 self.KalmanGain, self.P_steady_state = controls.kalman(A=self.A,
182 B=self.B,
183 C=self.C,
184 Q=self.Q,
185 R=self.R)
Austin Schuh2e554032019-01-21 15:07:27 -0800186
187 self.K_unaugmented = self.K
188 self.K = numpy.matrix(numpy.zeros((1, 3)))
189 self.K[0, 0:2] = self.K_unaugmented
James Kuszmaula4226f52024-03-01 21:29:12 -0800190 if params.enable_voltage_error:
191 self.K[0, 2] = 1
Austin Schuh2e554032019-01-21 15:07:27 -0800192
193 self.Kff = numpy.concatenate(
194 (self.Kff, numpy.matrix(numpy.zeros((1, 1)))), axis=1)
195
196 self.InitializeState()
197
198
199def RunTest(plant,
200 end_goal,
201 controller,
202 observer=None,
203 duration=1.0,
204 use_profile=True,
205 kick_time=0.5,
Lee Mracek28795ef2019-01-27 05:29:37 -0500206 kick_magnitude=0.0,
207 max_velocity=10.0,
208 max_acceleration=70.0):
Austin Schuh2e554032019-01-21 15:07:27 -0800209 """Runs the plant with an initial condition and goal.
210
211 Args:
212 plant: plant object to use.
213 end_goal: end_goal state.
214 controller: AngularSystem object to get K from, or None if we should
215 use plant.
216 observer: AngularSystem object to use for the observer, or None if we
217 should use the actual state.
218 duration: float, time in seconds to run the simulation for.
219 kick_time: float, time in seconds to kick the robot.
220 kick_magnitude: float, disturbance in volts to apply.
Lee Mracek28795ef2019-01-27 05:29:37 -0500221 max_velocity: float, The maximum velocity for the profile.
222 max_acceleration: float, The maximum acceleration for the profile.
Austin Schuh2e554032019-01-21 15:07:27 -0800223 """
224 t_plot = []
225 x_plot = []
226 v_plot = []
227 a_plot = []
Austin Schuha5aa9362022-02-07 21:26:08 -0800228 motor_current_plot = []
229 battery_current_plot = []
Austin Schuh2e554032019-01-21 15:07:27 -0800230 x_goal_plot = []
231 v_goal_plot = []
232 x_hat_plot = []
233 u_plot = []
Austin Schuh2e282d12024-02-19 12:00:58 -0800234 power_rotor_plot = []
235 power_mechanism_plot = []
236 power_overall_plot = []
237 power_electrical_plot = []
Austin Schuh2e554032019-01-21 15:07:27 -0800238 offset_plot = []
239
240 if controller is None:
241 controller = plant
242
243 vbat = 12.0
244
Tyler Chatow6738c362019-02-16 14:12:30 -0800245 goal = numpy.concatenate((plant.X, numpy.matrix(numpy.zeros((1, 1)))),
246 axis=0)
Austin Schuh2e554032019-01-21 15:07:27 -0800247
248 profile = TrapezoidProfile(plant.dt)
Lee Mracek28795ef2019-01-27 05:29:37 -0500249 profile.set_maximum_acceleration(max_acceleration)
250 profile.set_maximum_velocity(max_velocity)
Austin Schuh2e554032019-01-21 15:07:27 -0800251 profile.SetGoal(goal[0, 0])
252
253 U_last = numpy.matrix(numpy.zeros((1, 1)))
254 iterations = int(duration / plant.dt)
Austin Schuh5ea48472021-02-02 20:46:41 -0800255 for i in range(iterations):
Austin Schuh2e554032019-01-21 15:07:27 -0800256 t = i * plant.dt
257 observer.Y = plant.Y
258 observer.CorrectObserver(U_last)
259
260 offset_plot.append(observer.X_hat[2, 0])
261 x_hat_plot.append(observer.X_hat[0, 0])
262
Ravago Jones5127ccc2022-07-31 16:32:45 -0700263 next_goal = numpy.concatenate((profile.Update(
264 end_goal[0, 0], end_goal[1, 0]), numpy.matrix(numpy.zeros(
265 (1, 1)))),
266 axis=0)
Austin Schuh2e554032019-01-21 15:07:27 -0800267
268 ff_U = controller.Kff * (next_goal - observer.A * goal)
269
270 if use_profile:
271 U_uncapped = controller.K * (goal - observer.X_hat) + ff_U
272 x_goal_plot.append(goal[0, 0])
273 v_goal_plot.append(goal[1, 0])
274 else:
275 U_uncapped = controller.K * (end_goal - observer.X_hat)
276 x_goal_plot.append(end_goal[0, 0])
277 v_goal_plot.append(end_goal[1, 0])
278
279 U = U_uncapped.copy()
Austin Schuha5aa9362022-02-07 21:26:08 -0800280
Austin Schuh2e554032019-01-21 15:07:27 -0800281 U[0, 0] = numpy.clip(U[0, 0], -vbat, vbat)
Austin Schuha5aa9362022-02-07 21:26:08 -0800282
Ravago Jones5127ccc2022-07-31 16:32:45 -0700283 motor_current = (U[0, 0] - plant.X[1, 0] / plant.G /
284 plant.motor.Kv) / plant.motor.resistance
Austin Schuha5aa9362022-02-07 21:26:08 -0800285 motor_current_plot.append(motor_current)
Austin Schuh2e282d12024-02-19 12:00:58 -0800286 battery_current = U[0, 0] * motor_current / vbat
287 power_electrical_plot.append(battery_current * vbat)
Austin Schuha5aa9362022-02-07 21:26:08 -0800288 battery_current_plot.append(battery_current)
Austin Schuh2e282d12024-02-19 12:00:58 -0800289
290 # Instantaneous acceleration.
291 X_dot = plant.A_continuous * plant.X + plant.B_continuous * U
292 # Torque = J * alpha (accel).
293 power_rotor_plot.append(X_dot[1, 0] * plant.J_motor * plant.X[1, 0])
294 power_mechanism_plot.append(X_dot[1, 0] * plant.params.J *
295 plant.X[1, 0])
296 power_overall_plot.append(X_dot[1, 0] * plant.J * plant.X[1, 0])
297
Austin Schuh2e554032019-01-21 15:07:27 -0800298 x_plot.append(plant.X[0, 0])
299
300 if v_plot:
301 last_v = v_plot[-1]
302 else:
303 last_v = 0
304
305 v_plot.append(plant.X[1, 0])
306 a_plot.append((v_plot[-1] - last_v) / plant.dt)
307
308 u_offset = 0.0
309 if t >= kick_time:
310 u_offset = kick_magnitude
311 plant.Update(U + u_offset)
312
313 observer.PredictObserver(U)
314
315 t_plot.append(t)
316 u_plot.append(U[0, 0])
317
318 ff_U -= U_uncapped - U
319 goal = controller.A * goal + controller.B * ff_U
320
321 if U[0, 0] != U_uncapped[0, 0]:
Ravago Jones5127ccc2022-07-31 16:32:45 -0700322 profile.MoveCurrentState(numpy.matrix([[goal[0, 0]], [goal[1,
323 0]]]))
Austin Schuh2e554032019-01-21 15:07:27 -0800324
325 glog.debug('Time: %f', t_plot[-1])
326 glog.debug('goal_error %s', repr(end_goal - goal))
327 glog.debug('error %s', repr(observer.X_hat - end_goal))
328
Austin Schuh2e282d12024-02-19 12:00:58 -0800329 pylab.suptitle(f'Gear ratio {plant.G}')
330 position_ax1 = pylab.subplot(3, 1, 1)
331 position_ax1.plot(t_plot, x_plot, label='x')
332 position_ax1.plot(t_plot, x_hat_plot, label='x_hat')
333 position_ax1.plot(t_plot, x_goal_plot, label='x_goal')
Austin Schuh2e554032019-01-21 15:07:27 -0800334
Austin Schuh2e282d12024-02-19 12:00:58 -0800335 power_ax2 = position_ax1.twinx()
336 power_ax2.set_xlabel("time(s)")
337 power_ax2.set_ylabel("Power (W)")
338 power_ax2.plot(t_plot, power_rotor_plot, label='Rotor power')
339 power_ax2.plot(t_plot, power_mechanism_plot, label='Mechanism power')
340 power_ax2.plot(t_plot,
341 power_overall_plot,
342 label='Overall mechanical power')
343 power_ax2.plot(t_plot, power_electrical_plot, label='Electrical power')
344
345 position_ax1.legend()
346 power_ax2.legend(loc='lower right')
347
348 voltage_ax1 = pylab.subplot(3, 1, 2)
349 voltage_ax1.plot(t_plot, u_plot, label='u')
350 voltage_ax1.plot(t_plot, offset_plot, label='voltage_offset')
351 voltage_ax1.legend()
Austin Schuh2e554032019-01-21 15:07:27 -0800352
Austin Schuha5aa9362022-02-07 21:26:08 -0800353 ax1 = pylab.subplot(3, 1, 3)
354 ax1.set_xlabel("time(s)")
355 ax1.set_ylabel("rad/s^2")
Austin Schuh2e282d12024-02-19 12:00:58 -0800356 ax1.plot(t_plot, a_plot, label='acceleration')
Austin Schuha5aa9362022-02-07 21:26:08 -0800357
358 ax2 = ax1.twinx()
359 ax2.set_xlabel("time(s)")
360 ax2.set_ylabel("Amps")
361 ax2.plot(t_plot, battery_current_plot, 'g', label='battery')
362 ax2.plot(t_plot, motor_current_plot, 'r', label='motor')
Austin Schuh2e554032019-01-21 15:07:27 -0800363 pylab.legend()
364
365 pylab.show()
366
367
Austin Schuh9d9d3742019-02-15 23:00:13 -0800368def PlotStep(params, R, plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800369 """Plots a step move to the goal.
370
371 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800372 params: AngularSystemParams for the controller and observer
373 plant_params: AngularSystemParams for the plant. Defaults to params if
374 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800375 R: numpy.matrix(2, 1), the goal"""
Austin Schuh9d9d3742019-02-15 23:00:13 -0800376 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800377 controller = IntegralAngularSystem(params, params.name)
378 observer = IntegralAngularSystem(params, params.name)
379
380 # Test moving the system.
381 initial_X = numpy.matrix([[0.0], [0.0]])
382 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
383 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700384 RunTest(plant,
385 end_goal=augmented_R,
386 controller=controller,
387 observer=observer,
388 duration=2.0,
389 use_profile=False,
390 kick_time=1.0,
391 kick_magnitude=0.0)
Austin Schuh2e554032019-01-21 15:07:27 -0800392
393
Austin Schuh9d9d3742019-02-15 23:00:13 -0800394def PlotKick(params, R, plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800395 """Plots a step motion with a kick at 1.0 seconds.
396
397 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800398 params: AngularSystemParams for the controller and observer
399 plant_params: AngularSystemParams for the plant. Defaults to params if
400 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800401 R: numpy.matrix(2, 1), the goal"""
Austin Schuh9d9d3742019-02-15 23:00:13 -0800402 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800403 controller = IntegralAngularSystem(params, params.name)
404 observer = IntegralAngularSystem(params, params.name)
405
406 # Test moving the system.
407 initial_X = numpy.matrix([[0.0], [0.0]])
408 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
409 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700410 RunTest(plant,
411 end_goal=augmented_R,
412 controller=controller,
413 observer=observer,
414 duration=2.0,
415 use_profile=False,
416 kick_time=1.0,
417 kick_magnitude=2.0)
Austin Schuh2e554032019-01-21 15:07:27 -0800418
419
Austin Schuh9d9d3742019-02-15 23:00:13 -0800420def PlotMotion(params,
421 R,
422 max_velocity=10.0,
423 max_acceleration=70.0,
424 plant_params=None):
Austin Schuh2e554032019-01-21 15:07:27 -0800425 """Plots a trapezoidal motion.
426
427 Args:
Austin Schuh9d9d3742019-02-15 23:00:13 -0800428 params: AngularSystemParams for the controller and observer
429 plant_params: AngularSystemParams for the plant. Defaults to params if
430 plant_params is None.
Austin Schuh2e554032019-01-21 15:07:27 -0800431 R: numpy.matrix(2, 1), the goal,
Lee Mracek28795ef2019-01-27 05:29:37 -0500432 max_velocity: float, The max velocity of the profile.
433 max_acceleration: float, The max acceleration of the profile.
Austin Schuh2e554032019-01-21 15:07:27 -0800434 """
Austin Schuh9d9d3742019-02-15 23:00:13 -0800435 plant = AngularSystem(plant_params or params, params.name)
Austin Schuh2e554032019-01-21 15:07:27 -0800436 controller = IntegralAngularSystem(params, params.name)
437 observer = IntegralAngularSystem(params, params.name)
438
439 # Test moving the system.
440 initial_X = numpy.matrix([[0.0], [0.0]])
441 augmented_R = numpy.matrix(numpy.zeros((3, 1)))
442 augmented_R[0:2, :] = R
Ravago Jones5127ccc2022-07-31 16:32:45 -0700443 RunTest(plant,
444 end_goal=augmented_R,
445 controller=controller,
446 observer=observer,
447 duration=2.0,
448 use_profile=True,
449 max_velocity=max_velocity,
450 max_acceleration=max_acceleration)
Austin Schuh2e554032019-01-21 15:07:27 -0800451
452
milind-u53ad98a2023-02-20 16:26:09 -0800453def WriteAngularSystem(params,
454 plant_files,
455 controller_files,
456 year_namespaces,
457 plant_type='StateFeedbackPlant',
458 observer_type='StateFeedbackObserver'):
Austin Schuh2e554032019-01-21 15:07:27 -0800459 """Writes out the constants for a angular system to a file.
460
461 Args:
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700462 params: list of AngularSystemParams or AngularSystemParams, the
463 parameters defining the system.
Austin Schuh2e554032019-01-21 15:07:27 -0800464 plant_files: list of strings, the cc and h files for the plant.
465 controller_files: list of strings, the cc and h files for the integral
466 controller.
467 year_namespaces: list of strings, the namespace list to use.
468 """
469 # Write the generated constants out to a file.
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700470 angular_systems = []
471 integral_angular_systems = []
472
473 if type(params) is list:
474 name = params[0].name
475 for index, param in enumerate(params):
476 angular_systems.append(
477 AngularSystem(param, param.name + str(index)))
478 integral_angular_systems.append(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800479 IntegralAngularSystem(param,
480 'Integral' + param.name + str(index)))
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700481 else:
482 name = params.name
483 angular_systems.append(AngularSystem(params, params.name))
484 integral_angular_systems.append(
485 IntegralAngularSystem(params, 'Integral' + params.name))
486
Ravago Jones5127ccc2022-07-31 16:32:45 -0700487 loop_writer = control_loop.ControlLoopWriter(name,
488 angular_systems,
milind-u53ad98a2023-02-20 16:26:09 -0800489 namespaces=year_namespaces,
490 plant_type=plant_type,
491 observer_type=observer_type)
Lee Mracek17cb4892019-02-07 11:24:49 -0500492 loop_writer.AddConstant(
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700493 control_loop.Constant('kOutputRatio', '%f', angular_systems[0].G))
Lee Mracek17cb4892019-02-07 11:24:49 -0500494 loop_writer.AddConstant(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800495 control_loop.Constant('kFreeSpeed', '%f',
496 angular_systems[0].motor.free_speed))
James Kuszmauleeb98e92024-01-14 22:15:32 -0800497 loop_writer.Write(plant_files[0], plant_files[1],
498 None if len(plant_files) < 3 else plant_files[2])
Austin Schuh2e554032019-01-21 15:07:27 -0800499
Austin Schuh2e554032019-01-21 15:07:27 -0800500 integral_loop_writer = control_loop.ControlLoopWriter(
Tyler Chatowd3afdef2019-04-06 22:15:26 -0700501 'Integral' + name,
502 integral_angular_systems,
milind-u53ad98a2023-02-20 16:26:09 -0800503 namespaces=year_namespaces,
504 plant_type=plant_type,
505 observer_type=observer_type)
James Kuszmauleeb98e92024-01-14 22:15:32 -0800506 integral_loop_writer.Write(
507 controller_files[0], controller_files[1],
508 None if len(controller_files) < 3 else controller_files[2])