James Kuszmaul | 998d303 | 2018-09-08 15:41:41 -0700 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | import numpy |
| 4 | import sys |
James Kuszmaul | 7c8aad6 | 2018-09-08 18:16:18 -0700 | [diff] [blame^] | 5 | import calib_sensors |
James Kuszmaul | 998d303 | 2018-09-08 15:41:41 -0700 | [diff] [blame] | 6 | |
James Kuszmaul | 7c8aad6 | 2018-09-08 18:16:18 -0700 | [diff] [blame^] | 7 | def manual_calibrate(): |
James Kuszmaul | 998d303 | 2018-09-08 15:41:41 -0700 | [diff] [blame] | 8 | # 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 Kuszmaul | 7c8aad6 | 2018-09-08 18:16:18 -0700 | [diff] [blame^] | 21 | return transform |
| 22 | |
| 23 | def main(): |
| 24 | transform = manual_calibrate() |
| 25 | |
| 26 | if len(sys.argv) > 1: |
| 27 | transform = calib_sensors.calibrate(sys.argv[1:]) |
James Kuszmaul | 998d303 | 2018-09-08 15:41:41 -0700 | [diff] [blame] | 28 | |
| 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 | |
| 57 | if __name__ == '__main__': |
| 58 | sys.exit(main()) |