Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 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 | # Inertia for a single 4" diameter, 2" wide neopreme wheel. |
| 17 | J_wheel = 0.000319 * 2.0 |
| 18 | # Gear ratio to the final wheel. |
| 19 | # 40 tooth on the flywheel |
| 20 | # 48 for the falcon. |
| 21 | # 60 tooth on the outer wheel. |
| 22 | G = 48.0 / 40.0 |
| 23 | # Overall flywheel inertia. |
| 24 | J = J_wheel * (1.0 + (40.0 / 60.0)**2.0) |
| 25 | |
| 26 | # The position and velocity are measured for the final wheel. |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 27 | kFinisher = flywheel.FlywheelParams( |
| 28 | name='Finisher', |
| 29 | motor=control_loop.Falcon(), |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 30 | G=G, |
| 31 | J=J, |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 32 | q_pos=0.08, |
| 33 | q_vel=4.00, |
Austin Schuh | 989a313 | 2020-02-20 18:20:06 -0800 | [diff] [blame] | 34 | q_voltage=0.4, |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 35 | r_pos=0.05, |
Austin Schuh | 989a313 | 2020-02-20 18:20:06 -0800 | [diff] [blame] | 36 | controller_poles=[.80]) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 37 | |
| 38 | |
| 39 | def main(argv): |
| 40 | if FLAGS.plot: |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 41 | R = numpy.matrix([[0.0], [500.0], [0.0]]) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 42 | flywheel.PlotSpinup(params=kFinisher, goal=R, iterations=200) |
| 43 | return 0 |
| 44 | |
| 45 | if len(argv) != 5: |
| 46 | glog.fatal('Expected .h file name and .cc file name') |
| 47 | else: |
| 48 | namespaces = ['y2020', 'control_loops', 'superstructure', 'finisher'] |
| 49 | flywheel.WriteFlywheel(kFinisher, argv[1:3], argv[3:5], namespaces) |
| 50 | |
| 51 | |
| 52 | if __name__ == '__main__': |
| 53 | argv = FLAGS(sys.argv) |
| 54 | sys.exit(main(argv)) |