Updates to motor controller code
This includes new calibration numbers, and various updates made to
enable gathering those. Also includes updates to the PWM generator.
Change-Id: I2712c04b8427419c318174b6934587a1ea7ff997
diff --git a/motors/fet12/calib_sensors.py b/motors/fet12/calib_sensors.py
index 777ea37..7d882de 100755
--- a/motors/fet12/calib_sensors.py
+++ b/motors/fet12/calib_sensors.py
@@ -4,34 +4,31 @@
# Note on associated data files:
# calib_data_60*.csv has each output channel set at a constant value of 60.
-# calib_data_6030.csv actuates two channels.
+# calib_data_6030*.csv actuates two channels.
def calibrate(fnames):
"""Do fitting to calibrate ADC data given csv files.
CSVs should be of format:
- command_a, command_b, command_c, adc0, adc0, adc1, adc2, adc1, adc2
- Where The adc columns in this case are the 6 samples taken from the
- ADC where each pair of columns with the same name correspond with
- the same measurement (we average samples that are of the same value
- because otherwise the solution matrix can't be solved for in a stable
- manner).
+ command_a, command_b, command_c, reading0, reading1, reading2
+ The command columns are the on-time for each timer in FTM ticks.
+ The reading columns in this case are the 3 samples taken from the
+ ADC (with each pair corresponding to the same measurement pre-averaged). We
+ only care about the averaged samples because otherwise the solution matrix
+ can't be solved for in a stable manner.
"""
- data = np.zeros((1, 9))
+ data = np.zeros((1, 6))
for fname in fnames:
data = np.vstack((data, np.genfromtxt(fname, delimiter=',')))
data = data[1:, :]
- if data.shape[1] == 9:
- data[:, 3] = (data[:, 3] + data[:, 4]) / 2.0
- data[:, 4] = (data[:, 5] + data[:, 7]) / 2.0
- data[:, 5] = (data[:, 6] + data[:, 8]) / 2.0
data = data[:, :6]
b = data[:, 0:3]
b = b - np.tile(np.mean(b, axis=1), (3, 1)).T
# Vcc / 3000 / R
- b *= 30.8 / 3000.0 / 0.0084
+ # 3000 converts duty cycle in FTM ticks to fraction of full.
+ b *= 20.9 / 3000.0 / 0.0079
A = data[:, 3:]
return np.linalg.lstsq(A, b[:])[0].T