blob: 99a2d606c56be4e460c669ef35f20981ebac4f68 [file] [log] [blame]
Austin Schuh085eab92020-11-26 13:54:51 -08001#!/usr/bin/python3
Brian Silverman6260c092018-01-14 15:21:36 -08002
3from frc971.control_loops.python import control_loop
4from frc971.control_loops.python import controls
5import numpy
6import sys
7import copy
8import scipy.interpolate
9from matplotlib import pylab
10
11import gflags
12import glog
13
14FLAGS = gflags.FLAGS
15
16gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
17gflags.DEFINE_string('data', None, 'If defined, plot the provided CAN data')
Tyler Chatow6738c362019-02-16 14:12:30 -080018gflags.DEFINE_bool(
19 'rerun_kf', False,
20 'If true, rerun the KF. The torque in the data file will be interpreted as the commanded current.'
21)
22
Brian Silverman6260c092018-01-14 15:21:36 -080023
24class SystemParams(object):
Ravago Jones5127ccc2022-07-31 16:32:45 -070025
Tyler Chatow6738c362019-02-16 14:12:30 -080026 def __init__(self, J, G, kP, kD, kCompensationTimeconstant, q_pos, q_vel,
27 q_torque, current_limit):
28 self.J = J
29 self.G = G
30 self.q_pos = q_pos
31 self.q_vel = q_vel
32 self.q_torque = q_torque
33 self.kP = kP
34 self.kD = kD
35 self.kCompensationTimeconstant = kCompensationTimeconstant
36 self.r_pos = 0.001
37 self.current_limit = current_limit
Brian Silverman6260c092018-01-14 15:21:36 -080038
Tyler Chatow6738c362019-02-16 14:12:30 -080039 #[15.0, 0.25],
40 #[10.0, 0.2],
41 #[5.0, 0.13],
42 #[3.0, 0.10],
43 #[2.0, 0.08],
44 #[1.0, 0.06],
45 #[0.5, 0.05],
46 #[0.25, 0.025],
47
48
Ravago Jones5127ccc2022-07-31 16:32:45 -070049kWheel = SystemParams(J=0.0008,
50 G=(1.25 + 0.02) / 0.35,
51 q_pos=0.001,
52 q_vel=0.20,
53 q_torque=0.005,
54 kP=7.0,
55 kD=0.0,
56 kCompensationTimeconstant=0.95,
57 current_limit=4.5)
58kTrigger = SystemParams(J=0.00025,
59 G=(0.925 * 2.0 + 0.02) / 0.35,
60 q_pos=0.001,
61 q_vel=0.1,
62 q_torque=0.005,
63 kP=120.0,
64 kD=1.8,
65 kCompensationTimeconstant=0.95,
66 current_limit=3.0)
Tyler Chatow6738c362019-02-16 14:12:30 -080067
Brian Silverman6260c092018-01-14 15:21:36 -080068
69class HapticInput(control_loop.ControlLoop):
Ravago Jones5127ccc2022-07-31 16:32:45 -070070
Tyler Chatow6738c362019-02-16 14:12:30 -080071 def __init__(self, params=None, name='HapticInput'):
72 # The defaults are for the steering wheel.
73 super(HapticInput, self).__init__(name)
74 motor = self.motor = control_loop.MN3510()
Brian Silverman6260c092018-01-14 15:21:36 -080075
Tyler Chatow6738c362019-02-16 14:12:30 -080076 # Moment of inertia of the wheel in kg m^2
77 self.J = params.J
Brian Silverman6260c092018-01-14 15:21:36 -080078
Tyler Chatow6738c362019-02-16 14:12:30 -080079 # Control loop time step
80 self.dt = 0.001
Brian Silverman6260c092018-01-14 15:21:36 -080081
Tyler Chatow6738c362019-02-16 14:12:30 -080082 # Gear ratio from the motor to the input.
83 self.G = params.G
Brian Silverman6260c092018-01-14 15:21:36 -080084
Tyler Chatow6738c362019-02-16 14:12:30 -080085 self.A_continuous = numpy.matrix(numpy.zeros((2, 2)))
86 self.A_continuous[1, 1] = 0
87 self.A_continuous[0, 1] = 1
Brian Silverman6260c092018-01-14 15:21:36 -080088
Tyler Chatow6738c362019-02-16 14:12:30 -080089 self.B_continuous = numpy.matrix(numpy.zeros((2, 1)))
90 self.B_continuous[1, 0] = motor.Kt * self.G / self.J
Brian Silverman6260c092018-01-14 15:21:36 -080091
Tyler Chatow6738c362019-02-16 14:12:30 -080092 # State feedback matrices
93 # [position, angular velocity]
94 self.C = numpy.matrix([[1.0, 0.0]])
95 self.D = numpy.matrix([[0.0]])
Brian Silverman6260c092018-01-14 15:21:36 -080096
Tyler Chatow6738c362019-02-16 14:12:30 -080097 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
98 self.B_continuous, self.dt)
Brian Silverman6260c092018-01-14 15:21:36 -080099
Tyler Chatow6738c362019-02-16 14:12:30 -0800100 self.U_max = numpy.matrix([[2.5]])
101 self.U_min = numpy.matrix([[-2.5]])
Brian Silverman6260c092018-01-14 15:21:36 -0800102
Tyler Chatow6738c362019-02-16 14:12:30 -0800103 self.L = numpy.matrix([[0.0], [0.0]])
104 self.K = numpy.matrix([[0.0, 0.0]])
105
106 self.InitializeState()
Brian Silverman6260c092018-01-14 15:21:36 -0800107
108
109class IntegralHapticInput(HapticInput):
Ravago Jones5127ccc2022-07-31 16:32:45 -0700110
Tyler Chatow6738c362019-02-16 14:12:30 -0800111 def __init__(self, params=None, name="IntegralHapticInput"):
112 super(IntegralHapticInput, self).__init__(name=name, params=params)
Brian Silverman6260c092018-01-14 15:21:36 -0800113
Tyler Chatow6738c362019-02-16 14:12:30 -0800114 self.A_continuous_unaugmented = self.A_continuous
115 self.B_continuous_unaugmented = self.B_continuous
Brian Silverman6260c092018-01-14 15:21:36 -0800116
Tyler Chatow6738c362019-02-16 14:12:30 -0800117 self.A_continuous = numpy.matrix(numpy.zeros((3, 3)))
118 self.A_continuous[0:2, 0:2] = self.A_continuous_unaugmented
119 self.A_continuous[1, 2] = (1 / self.J)
Brian Silverman6260c092018-01-14 15:21:36 -0800120
Tyler Chatow6738c362019-02-16 14:12:30 -0800121 self.B_continuous = numpy.matrix(numpy.zeros((3, 1)))
122 self.B_continuous[0:2, 0] = self.B_continuous_unaugmented
Brian Silverman6260c092018-01-14 15:21:36 -0800123
Tyler Chatow6738c362019-02-16 14:12:30 -0800124 self.C_unaugmented = self.C
125 self.C = numpy.matrix(numpy.zeros((1, 3)))
126 self.C[0:1, 0:2] = self.C_unaugmented
Brian Silverman6260c092018-01-14 15:21:36 -0800127
Tyler Chatow6738c362019-02-16 14:12:30 -0800128 self.A, self.B = self.ContinuousToDiscrete(self.A_continuous,
129 self.B_continuous, self.dt)
Brian Silverman6260c092018-01-14 15:21:36 -0800130
Tyler Chatow6738c362019-02-16 14:12:30 -0800131 self.Q = numpy.matrix([[(params.q_pos**2.0), 0.0, 0.0],
132 [0.0, (params.q_vel**2.0), 0.0],
133 [0.0, 0.0, (params.q_torque**2.0)]])
Brian Silverman6260c092018-01-14 15:21:36 -0800134
Tyler Chatow6738c362019-02-16 14:12:30 -0800135 self.R = numpy.matrix([[(params.r_pos**2.0)]])
Brian Silverman6260c092018-01-14 15:21:36 -0800136
Ravago Jones5127ccc2022-07-31 16:32:45 -0700137 self.KalmanGain, self.Q_steady = controls.kalman(A=self.A,
138 B=self.B,
139 C=self.C,
140 Q=self.Q,
141 R=self.R)
Tyler Chatow6738c362019-02-16 14:12:30 -0800142 self.L = self.A * self.KalmanGain
Brian Silverman6260c092018-01-14 15:21:36 -0800143
Tyler Chatow6738c362019-02-16 14:12:30 -0800144 self.K_unaugmented = self.K
145 self.K = numpy.matrix(numpy.zeros((1, 3)))
146 self.K[0, 0:2] = self.K_unaugmented
147 self.K[0, 2] = 1.0 / (self.motor.Kt / (self.motor.resistance))
148
149 self.InitializeState()
150
Brian Silverman6260c092018-01-14 15:21:36 -0800151
152def ReadCan(filename):
Tyler Chatow6738c362019-02-16 14:12:30 -0800153 """Reads the candump in filename and returns the 4 fields."""
154 trigger = []
155 trigger_velocity = []
156 trigger_torque = []
157 trigger_current = []
158 wheel = []
159 wheel_velocity = []
160 wheel_torque = []
161 wheel_current = []
Brian Silverman6260c092018-01-14 15:21:36 -0800162
Tyler Chatow6738c362019-02-16 14:12:30 -0800163 trigger_request_time = [0.0]
164 trigger_request_current = [0.0]
165 wheel_request_time = [0.0]
166 wheel_request_current = [0.0]
Brian Silverman6260c092018-01-14 15:21:36 -0800167
Tyler Chatow6738c362019-02-16 14:12:30 -0800168 with open(filename, 'r') as fd:
169 for line in fd:
170 data = line.split()
171 can_id = int(data[1], 16)
172 if can_id == 0:
173 data = [int(d, 16) for d in data[3:]]
174 trigger.append(((data[0] + (data[1] << 8)) - 32768) / 32768.0)
175 trigger_velocity.append(
176 ((data[2] + (data[3] << 8)) - 32768) / 32768.0)
177 trigger_torque.append(
178 ((data[4] + (data[5] << 8)) - 32768) / 32768.0)
179 trigger_current.append(
180 ((data[6] + ((data[7] & 0x3f) << 8)) - 8192) / 8192.0)
181 elif can_id == 1:
182 data = [int(d, 16) for d in data[3:]]
183 wheel.append(((data[0] + (data[1] << 8)) - 32768) / 32768.0)
184 wheel_velocity.append(
185 ((data[2] + (data[3] << 8)) - 32768) / 32768.0)
186 wheel_torque.append(
187 ((data[4] + (data[5] << 8)) - 32768) / 32768.0)
188 wheel_current.append(
189 ((data[6] + ((data[7] & 0x3f) << 8)) - 8192) / 8192.0)
190 elif can_id == 2:
191 data = [int(d, 16) for d in data[3:]]
192 trigger_request_current.append(
193 ((data[4] + (data[5] << 8)) - 32768) / 32768.0)
194 trigger_request_time.append(len(trigger) * 0.001)
195 elif can_id == 3:
196 data = [int(d, 16) for d in data[3:]]
197 wheel_request_current.append(
198 ((data[4] + (data[5] << 8)) - 32768) / 32768.0)
199 wheel_request_time.append(len(wheel) * 0.001)
Brian Silverman6260c092018-01-14 15:21:36 -0800200
Tyler Chatow6738c362019-02-16 14:12:30 -0800201 trigger_data_time = numpy.arange(0, len(trigger)) * 0.001
202 wheel_data_time = numpy.arange(0, len(wheel)) * 0.001
Brian Silverman6260c092018-01-14 15:21:36 -0800203
Tyler Chatow6738c362019-02-16 14:12:30 -0800204 # Extend out the data in the interpolation table.
205 trigger_request_time.append(trigger_data_time[-1])
206 trigger_request_current.append(trigger_request_current[-1])
207 wheel_request_time.append(wheel_data_time[-1])
208 wheel_request_current.append(wheel_request_current[-1])
Brian Silverman6260c092018-01-14 15:21:36 -0800209
Tyler Chatow6738c362019-02-16 14:12:30 -0800210 return (trigger_data_time, wheel_data_time, trigger, wheel,
211 trigger_velocity, wheel_velocity, trigger_torque, wheel_torque,
212 trigger_current, wheel_current, trigger_request_time,
213 trigger_request_current, wheel_request_time, wheel_request_current)
Brian Silverman6260c092018-01-14 15:21:36 -0800214
Brian Silverman6260c092018-01-14 15:21:36 -0800215
Tyler Chatow6738c362019-02-16 14:12:30 -0800216def rerun_and_plot_kf(data_time,
217 data_radians,
218 data_current,
219 data_request_current,
220 params,
221 run_correct=True):
222 kf_velocity = []
223 dt_velocity = []
224 kf_position = []
225 adjusted_position = []
226 last_angle = None
227 haptic_observer = IntegralHapticInput(params=params)
Brian Silverman6260c092018-01-14 15:21:36 -0800228
Tyler Chatow6738c362019-02-16 14:12:30 -0800229 # Parameter sweep J.
230 num_kf = 1
231 min_J = max_J = params.J
Brian Silverman6260c092018-01-14 15:21:36 -0800232
Tyler Chatow6738c362019-02-16 14:12:30 -0800233 # J = 0.0022
234 #num_kf = 15
235 #min_J = min_J / 2.0
236 #max_J = max_J * 2.0
237 initial_velocity = (data_radians[1] - data_radians[0]) * 1000.0
Brian Silverman6260c092018-01-14 15:21:36 -0800238
Tyler Chatow6738c362019-02-16 14:12:30 -0800239 def DupParamsWithJ(params, J):
240 p = copy.copy(params)
241 p.J = J
242 return p
Brian Silverman6260c092018-01-14 15:21:36 -0800243
Tyler Chatow6738c362019-02-16 14:12:30 -0800244 haptic_observers = [
Ravago Jones5127ccc2022-07-31 16:32:45 -0700245 IntegralHapticInput(params=DupParamsWithJ(params, j)) for j in
246 numpy.logspace(numpy.log10(min_J), numpy.log10(max_J), num=num_kf)
Tyler Chatow6738c362019-02-16 14:12:30 -0800247 ]
248 # Initialize all the KF's.
249 haptic_observer.X_hat[1, 0] = initial_velocity
250 haptic_observer.X_hat[0, 0] = data_radians[0]
251 for observer in haptic_observers:
252 observer.X_hat[1, 0] = initial_velocity
253 observer.X_hat[0, 0] = data_radians[0]
Brian Silverman6260c092018-01-14 15:21:36 -0800254
Tyler Chatow6738c362019-02-16 14:12:30 -0800255 last_request_current = data_request_current[0]
Austin Schuh5ea48472021-02-02 20:46:41 -0800256 kf_torques = [[] for i in range(num_kf)]
Tyler Chatow6738c362019-02-16 14:12:30 -0800257 for angle, current, request_current in zip(data_radians, data_current,
258 data_request_current):
259 # Predict and correct all the parameter swept observers.
260 for i, observer in enumerate(haptic_observers):
261 observer.Y = numpy.matrix([[angle]])
262 if run_correct:
263 observer.CorrectObserver(numpy.matrix([[current]]))
264 kf_torques[i].append(-observer.X_hat[2, 0])
265 observer.PredictObserver(numpy.matrix([[current]]))
266 observer.PredictObserver(numpy.matrix([[current]]))
Brian Silverman6260c092018-01-14 15:21:36 -0800267
Tyler Chatow6738c362019-02-16 14:12:30 -0800268 # Predict and correct the main observer.
269 haptic_observer.Y = numpy.matrix([[angle]])
270 if run_correct:
271 haptic_observer.CorrectObserver(numpy.matrix([[current]]))
272 kf_position.append(haptic_observer.X_hat[0, 0])
273 adjusted_position.append(kf_position[-1] -
274 last_request_current / params.kP)
275 last_request_current = last_request_current * params.kCompensationTimeconstant + request_current * (
276 1.0 - params.kCompensationTimeconstant)
277 kf_velocity.append(haptic_observer.X_hat[1, 0])
278 if last_angle is None:
279 last_angle = angle
280 dt_velocity.append((angle - last_angle) / 0.001)
Brian Silverman6260c092018-01-14 15:21:36 -0800281
Tyler Chatow6738c362019-02-16 14:12:30 -0800282 haptic_observer.PredictObserver(numpy.matrix([[current]]))
283 last_angle = angle
Brian Silverman6260c092018-01-14 15:21:36 -0800284
Tyler Chatow6738c362019-02-16 14:12:30 -0800285 # Plot the wheel observers.
286 fig, ax1 = pylab.subplots()
287 ax1.plot(data_time, data_radians, '.', label='wheel')
288 ax1.plot(data_time, dt_velocity, '.', label='dt_velocity')
289 ax1.plot(data_time, kf_velocity, '.', label='kf_velocity')
290 ax1.plot(data_time, kf_position, '.', label='kf_position')
291 ax1.plot(data_time, adjusted_position, '.', label='adjusted_position')
Brian Silverman6260c092018-01-14 15:21:36 -0800292
Tyler Chatow6738c362019-02-16 14:12:30 -0800293 ax2 = ax1.twinx()
294 ax2.plot(data_time, data_current, label='data_current')
295 ax2.plot(data_time, data_request_current, label='request_current')
Brian Silverman6260c092018-01-14 15:21:36 -0800296
Tyler Chatow6738c362019-02-16 14:12:30 -0800297 for i, kf_torque in enumerate(kf_torques):
Ravago Jones5127ccc2022-07-31 16:32:45 -0700298 ax2.plot(data_time,
299 kf_torque,
300 label='-kf_torque[%f]' % haptic_observers[i].J)
Tyler Chatow6738c362019-02-16 14:12:30 -0800301 fig.tight_layout()
302 ax1.legend(loc=3)
303 ax2.legend(loc=4)
Brian Silverman6260c092018-01-14 15:21:36 -0800304
Brian Silverman6260c092018-01-14 15:21:36 -0800305
Tyler Chatow6738c362019-02-16 14:12:30 -0800306def plot_input(data_time,
307 data_radians,
308 data_velocity,
309 data_torque,
310 data_current,
311 params,
312 run_correct=True):
313 dt_velocity = []
314 last_angle = None
315 initial_velocity = (data_radians[1] - data_radians[0]) * 1000.0
Brian Silverman6260c092018-01-14 15:21:36 -0800316
Tyler Chatow6738c362019-02-16 14:12:30 -0800317 for angle in data_radians:
318 if last_angle is None:
319 last_angle = angle
320 dt_velocity.append((angle - last_angle) / 0.001)
321
322 last_angle = angle
323
324 # Plot the wheel observers.
325 fig, ax1 = pylab.subplots()
326 ax1.plot(data_time, data_radians, '.', label='angle')
327 ax1.plot(data_time, data_velocity, '-', label='velocity')
328 ax1.plot(data_time, dt_velocity, '.', label='dt_velocity')
329
330 ax2 = ax1.twinx()
331 ax2.plot(data_time, data_torque, label='data_torque')
332 ax2.plot(data_time, data_current, label='data_current')
333 fig.tight_layout()
334 ax1.legend(loc=3)
335 ax2.legend(loc=4)
336
Brian Silverman6260c092018-01-14 15:21:36 -0800337
338def main(argv):
Tyler Chatow6738c362019-02-16 14:12:30 -0800339 if FLAGS.plot:
340 if FLAGS.data is None:
341 haptic_wheel = HapticInput()
342 haptic_wheel_controller = IntegralHapticInput()
343 observer_haptic_wheel = IntegralHapticInput()
344 observer_haptic_wheel.X_hat[2, 0] = 0.01
Brian Silverman6260c092018-01-14 15:21:36 -0800345
Tyler Chatow6738c362019-02-16 14:12:30 -0800346 R = numpy.matrix([[0.0], [0.0], [0.0]])
Brian Silverman6260c092018-01-14 15:21:36 -0800347
Tyler Chatow6738c362019-02-16 14:12:30 -0800348 control_loop.TestSingleIntegralAxisSquareWave(
349 R, 1.0, haptic_wheel, haptic_wheel_controller,
350 observer_haptic_wheel)
351 else:
352 # Read the CAN trace in.
353 trigger_data_time, wheel_data_time, trigger, wheel, trigger_velocity, \
354 wheel_velocity, trigger_torque, wheel_torque, trigger_current, \
355 wheel_current, trigger_request_time, trigger_request_current, \
356 wheel_request_time, wheel_request_current = ReadCan(FLAGS.data)
357
358 wheel_radians = [w * numpy.pi * (338.16 / 360.0) for w in wheel]
359 wheel_velocity = [w * 50.0 for w in wheel_velocity]
360 wheel_torque = [w / 2.0 for w in wheel_torque]
361 wheel_current = [w * 10.0 for w in wheel_current]
362 wheel_request_current = [w * 2.0 for w in wheel_request_current]
363 resampled_wheel_request_current = scipy.interpolate.interp1d(
364 wheel_request_time, wheel_request_current,
365 kind="zero")(wheel_data_time)
366
367 trigger_radians = [t * numpy.pi * (45.0 / 360.0) for t in trigger]
368 trigger_velocity = [t * 50.0 for t in trigger_velocity]
369 trigger_torque = [t / 2.0 for t in trigger_torque]
370 trigger_current = [t * 10.0 for t in trigger_current]
Ravago Jones26f7ad02021-02-05 15:45:59 -0800371 trigger_request_current = [
372 t * 2.0 for t in trigger_request_current
373 ]
Tyler Chatow6738c362019-02-16 14:12:30 -0800374 resampled_trigger_request_current = scipy.interpolate.interp1d(
375 trigger_request_time, trigger_request_current,
376 kind="zero")(trigger_data_time)
377
378 if FLAGS.rerun_kf:
Ravago Jones5127ccc2022-07-31 16:32:45 -0700379 rerun_and_plot_kf(trigger_data_time,
380 trigger_radians,
381 trigger_current,
382 resampled_trigger_request_current,
383 kTrigger,
384 run_correct=True)
385 rerun_and_plot_kf(wheel_data_time,
386 wheel_radians,
387 wheel_current,
388 resampled_wheel_request_current,
389 kWheel,
390 run_correct=True)
Tyler Chatow6738c362019-02-16 14:12:30 -0800391 else:
Ravago Jones26f7ad02021-02-05 15:45:59 -0800392 plot_input(trigger_data_time, trigger_radians,
393 trigger_velocity, trigger_torque, trigger_current,
394 kTrigger)
Tyler Chatow6738c362019-02-16 14:12:30 -0800395 plot_input(wheel_data_time, wheel_radians, wheel_velocity,
396 wheel_torque, wheel_current, kWheel)
397 pylab.show()
398
399 return
400
401 if len(argv) != 9:
402 glog.fatal('Expected .h file name and .cc file name')
Brian Silverman6260c092018-01-14 15:21:36 -0800403 else:
Tyler Chatow6738c362019-02-16 14:12:30 -0800404 namespaces = ['frc971', 'control_loops', 'drivetrain']
405 for name, params, filenames in [('HapticWheel', kWheel, argv[1:5]),
Ravago Jones5127ccc2022-07-31 16:32:45 -0700406 ('HapticTrigger', kTrigger, argv[5:9])
407 ]:
Tyler Chatow6738c362019-02-16 14:12:30 -0800408 haptic_input = HapticInput(params=params, name=name)
Ravago Jones5127ccc2022-07-31 16:32:45 -0700409 loop_writer = control_loop.ControlLoopWriter(name, [haptic_input],
410 namespaces=namespaces,
411 scalar_type='float')
Tyler Chatow6738c362019-02-16 14:12:30 -0800412 loop_writer.Write(filenames[0], filenames[1])
Brian Silverman6260c092018-01-14 15:21:36 -0800413
Ravago Jones5127ccc2022-07-31 16:32:45 -0700414 integral_haptic_input = IntegralHapticInput(params=params,
415 name='Integral' + name)
Tyler Chatow6738c362019-02-16 14:12:30 -0800416 integral_loop_writer = control_loop.ControlLoopWriter(
417 'Integral' + name, [integral_haptic_input],
418 namespaces=namespaces,
419 scalar_type='float')
Brian Silverman6260c092018-01-14 15:21:36 -0800420
Tyler Chatow6738c362019-02-16 14:12:30 -0800421 integral_loop_writer.AddConstant(
422 control_loop.Constant("k" + name + "Dt", "%f",
423 integral_haptic_input.dt))
424 integral_loop_writer.AddConstant(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800425 control_loop.Constant(
426 "k" + name + "FreeCurrent", "%f",
427 integral_haptic_input.motor.free_current))
Tyler Chatow6738c362019-02-16 14:12:30 -0800428 integral_loop_writer.AddConstant(
Ravago Jones26f7ad02021-02-05 15:45:59 -0800429 control_loop.Constant(
430 "k" + name + "StallTorque", "%f",
431 integral_haptic_input.motor.stall_torque))
Tyler Chatow6738c362019-02-16 14:12:30 -0800432 integral_loop_writer.AddConstant(
433 control_loop.Constant("k" + name + "J", "%f",
434 integral_haptic_input.J))
435 integral_loop_writer.AddConstant(
436 control_loop.Constant("k" + name + "R", "%f",
437 integral_haptic_input.motor.resistance))
438 integral_loop_writer.AddConstant(
439 control_loop.Constant("k" + name + "T", "%f",
440 integral_haptic_input.motor.Kt))
441 integral_loop_writer.AddConstant(
442 control_loop.Constant("k" + name + "V", "%f",
443 integral_haptic_input.motor.Kv))
444 integral_loop_writer.AddConstant(
445 control_loop.Constant("k" + name + "P", "%f", params.kP))
446 integral_loop_writer.AddConstant(
447 control_loop.Constant("k" + name + "D", "%f", params.kD))
448 integral_loop_writer.AddConstant(
449 control_loop.Constant("k" + name + "G", "%f", params.G))
450 integral_loop_writer.AddConstant(
451 control_loop.Constant("k" + name + "CurrentLimit", "%f",
452 params.current_limit))
Brian Silverman6260c092018-01-14 15:21:36 -0800453
Tyler Chatow6738c362019-02-16 14:12:30 -0800454 integral_loop_writer.Write(filenames[2], filenames[3])
Brian Silverman6260c092018-01-14 15:21:36 -0800455
456
457if __name__ == '__main__':
Tyler Chatow6738c362019-02-16 14:12:30 -0800458 argv = FLAGS(sys.argv)
459 sys.exit(main(argv))