Austin Schuh | 085eab9 | 2020-11-26 13:54:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Sabina Davis | 24d94e0 | 2020-01-31 21:32:41 -0800 | [diff] [blame] | 2 | |
| 3 | from aos.util.trapezoid_profile import TrapezoidProfile |
| 4 | from frc971.control_loops.python import control_loop |
| 5 | from frc971.control_loops.python import angular_system |
| 6 | from frc971.control_loops.python import controls |
| 7 | import numpy |
| 8 | import sys |
| 9 | from matplotlib import pylab |
| 10 | import gflags |
| 11 | import glog |
| 12 | |
| 13 | FLAGS = gflags.FLAGS |
| 14 | |
| 15 | try: |
| 16 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
| 17 | except gflags.DuplicateFlagError: |
| 18 | pass |
| 19 | |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 20 | # Hood is an angular subsystem due to the mounting of the encoder on the hood |
| 21 | # joint. We are currently electing to ignore potential non-linearity. |
| 22 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 23 | range_of_travel_radians = (38.0 * numpy.pi / 180.0) |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 24 | # 0.5 inches/turn |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 25 | # 6.7725 inches of travel |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 26 | turns_of_leadscrew_per_range_of_travel = 6.7725 / 0.5 |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 27 | |
| 28 | radians_per_turn = range_of_travel_radians / turns_of_leadscrew_per_range_of_travel |
| 29 | |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 30 | radians_per_turn_of_motor = 12.0 / 60.0 * radians_per_turn |
| 31 | |
Sabina Davis | 24d94e0 | 2020-01-31 21:32:41 -0800 | [diff] [blame] | 32 | kHood = angular_system.AngularSystemParams( |
| 33 | name='Hood', |
| 34 | motor=control_loop.BAG(), |
Ravago Jones | 937587c | 2020-12-26 17:21:09 -0800 | [diff] [blame] | 35 | G=radians_per_turn_of_motor / (2.0 * numpy.pi), |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 36 | J=0.1, |
Austin Schuh | 78f0bfd | 2020-02-29 23:04:21 -0800 | [diff] [blame] | 37 | q_pos=0.15, |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 38 | q_vel=10.0, |
Sabina Davis | 24d94e0 | 2020-01-31 21:32:41 -0800 | [diff] [blame] | 39 | kalman_q_pos=0.12, |
Austin Schuh | 78f0bfd | 2020-02-29 23:04:21 -0800 | [diff] [blame] | 40 | kalman_q_vel=10.0, |
Austin Schuh | 2efe168 | 2021-03-06 22:47:15 -0800 | [diff] [blame] | 41 | kalman_q_voltage=30.0, |
| 42 | kalman_r_position=0.02) |
Sabina Davis | 24d94e0 | 2020-01-31 21:32:41 -0800 | [diff] [blame] | 43 | |
| 44 | |
| 45 | def main(argv): |
| 46 | if FLAGS.plot: |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 47 | R = numpy.matrix([[numpy.pi / 4.0], [0.0]]) |
Sabina Davis | 24d94e0 | 2020-01-31 21:32:41 -0800 | [diff] [blame] | 48 | angular_system.PlotKick(kHood, R) |
| 49 | angular_system.PlotMotion(kHood, R) |
| 50 | |
Austin Schuh | 085eab9 | 2020-11-26 13:54:51 -0800 | [diff] [blame] | 51 | glog.debug("Radians per turn: %f\n", radians_per_turn) |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 52 | |
Sabina Davis | 24d94e0 | 2020-01-31 21:32:41 -0800 | [diff] [blame] | 53 | # Write the generated constants out to a file. |
| 54 | if len(argv) != 5: |
| 55 | glog.fatal( |
| 56 | 'Expected .h file name and .cc file name for the hood and integral hood.' |
| 57 | ) |
| 58 | else: |
| 59 | namespaces = ['y2020', 'control_loops', 'superstructure', 'hood'] |
| 60 | angular_system.WriteAngularSystem(kHood, argv[1:3], argv[3:5], |
| 61 | namespaces) |
| 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |
| 65 | argv = FLAGS(sys.argv) |
| 66 | glog.init() |
| 67 | sys.exit(main(argv)) |