blob: ea4491630874cdabb01caafaa3d8553fcbbdc276 [file] [log] [blame]
James Kuszmaul998d3032018-09-08 15:41:41 -07001#!/usr/bin/python3
2
3import numpy
4import sys
James Kuszmaul7c8aad62018-09-08 18:16:18 -07005import calib_sensors
James Kuszmaul998d3032018-09-08 15:41:41 -07006
James Kuszmaul7c8aad62018-09-08 18:16:18 -07007def manual_calibrate():
James Kuszmaul998d3032018-09-08 15:41:41 -07008 # 38 27 -84
9 # 36 -64 39
10 # -74 21 35
11 Is0 = numpy.matrix([[38.0, 27.0, -84.0]]).T
12 Is1 = numpy.matrix([[36.0, -64.0, 39.0]]).T
13 Is2 = numpy.matrix([[-74.0, 21.0, 35.0]]).T
14 Is = numpy.matrix(numpy.hstack((Is0, Is1, Is2)))
15
16 current = 46.0
17 I = numpy.matrix([[current, -current / 2.0, -current / 2.0],
18 [-current / 2.0, current, -current / 2.0],
19 [-current / 2.0, -current / 2.0, current]])
20 transform = I * numpy.linalg.inv(Is)
James Kuszmaul7c8aad62018-09-08 18:16:18 -070021 return transform
22
23def main():
24 transform = manual_calibrate()
25
26 if len(sys.argv) > 1:
27 transform = calib_sensors.calibrate(sys.argv[1:])
James Kuszmaul998d3032018-09-08 15:41:41 -070028
29 print("#ifndef MOTORS_FET12_CURRENT_MATRIX_")
30 print("#define MOTORS_FET12_CURRENT_MATRIX_")
31 print("")
32 print("#include <array>")
33 print("")
34 print("namespace frc971 {")
35 print("namespace motors {")
36 print("")
37 print(
38 "inline ::std::array<float, 3> DecoupleCurrents(int16_t currents[3]) {")
39 print(" ::std::array<float, 3> ans;")
40
41 for i in range(3):
42 print(" ans[%d] = %ff * static_cast<float>(currents[0]) +" %
43 (i, transform[i, 0]))
44 print(" %ff * static_cast<float>(currents[1]) +" %
45 transform[i, 1])
46 print(" %ff * static_cast<float>(currents[2]);" % transform[i, 2])
47
48 print(" return ans;")
49 print("}")
50 print("")
51 print("} // namespace motors")
52 print("} // namespace frc971")
53 print("#endif // MOTORS_FET12_CURRENT_MATRIX_")
54
55 return 0
56
57if __name__ == '__main__':
58 sys.exit(main())