Austin Schuh | 085eab9 | 2020-11-26 13:54:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 2 | |
| 3 | from frc971.control_loops.python import control_loop |
| 4 | from y2020.control_loops.python import flywheel |
| 5 | import numpy |
| 6 | |
| 7 | import sys |
| 8 | |
| 9 | import gflags |
| 10 | import glog |
| 11 | |
| 12 | FLAGS = gflags.FLAGS |
| 13 | |
| 14 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
| 15 | |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 16 | # Gear ratio to the final wheel. |
| 17 | # 40 tooth on the flywheel |
| 18 | # 48 for the falcon. |
| 19 | # 60 tooth on the outer wheel. |
| 20 | G = 48.0 / 40.0 |
| 21 | # Overall flywheel inertia. |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame^] | 22 | J = 0.00507464 |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 23 | |
| 24 | # The position and velocity are measured for the final wheel. |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 25 | kFinisher = flywheel.FlywheelParams( |
| 26 | name='Finisher', |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame^] | 27 | motor=control_loop.NMotor(control_loop.Falcon(), 2), |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 28 | G=G, |
| 29 | J=J, |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 30 | q_pos=0.01, |
| 31 | q_vel=100.0, |
| 32 | q_voltage=6.0, |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 33 | r_pos=0.05, |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame^] | 34 | controller_poles=[.90]) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 35 | |
| 36 | |
| 37 | def main(argv): |
| 38 | if FLAGS.plot: |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 39 | R = numpy.matrix([[0.0], [500.0], [0.0]]) |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 40 | flywheel.PlotSpinup(params=kFinisher, goal=R, iterations=400) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 41 | return 0 |
| 42 | |
| 43 | if len(argv) != 5: |
| 44 | glog.fatal('Expected .h file name and .cc file name') |
| 45 | else: |
| 46 | namespaces = ['y2020', 'control_loops', 'superstructure', 'finisher'] |
| 47 | flywheel.WriteFlywheel(kFinisher, argv[1:3], argv[3:5], namespaces) |
| 48 | |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | argv = FLAGS(sys.argv) |
| 52 | sys.exit(main(argv)) |