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. |
Austin Schuh | 8047677 | 2021-03-06 20:17:36 -0800 | [diff] [blame^] | 20 | G = 44.0 / 40.0 |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 21 | # Overall flywheel inertia. |
Austin Schuh | 0ad31d7 | 2021-03-06 17:07:04 -0800 | [diff] [blame] | 22 | J = 0.00507464 |
Austin Schuh | 8047677 | 2021-03-06 20:17:36 -0800 | [diff] [blame^] | 23 | J = 0.008 |
| 24 | |
| 25 | def AddResistance(motor, resistance): |
| 26 | motor.resistance += resistance |
| 27 | return motor |
| 28 | |
| 29 | def ScaleKv(motor, scale): |
| 30 | motor.Kv *= scale |
| 31 | return motor |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 32 | |
| 33 | # The position and velocity are measured for the final wheel. |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 34 | kFinisher = flywheel.FlywheelParams( |
| 35 | name='Finisher', |
Austin Schuh | 8047677 | 2021-03-06 20:17:36 -0800 | [diff] [blame^] | 36 | motor=AddResistance(control_loop.NMotor(control_loop.Falcon(), 2), 0.01), |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 37 | G=G, |
| 38 | J=J, |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 39 | q_pos=0.01, |
Austin Schuh | 8047677 | 2021-03-06 20:17:36 -0800 | [diff] [blame^] | 40 | q_vel=10.0, |
| 41 | q_voltage=4.0, |
| 42 | r_pos=0.01, |
| 43 | controller_poles=[.89]) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 44 | |
| 45 | |
| 46 | def main(argv): |
| 47 | if FLAGS.plot: |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 48 | R = numpy.matrix([[0.0], [500.0], [0.0]]) |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 49 | flywheel.PlotSpinup(params=kFinisher, goal=R, iterations=400) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 50 | return 0 |
| 51 | |
| 52 | if len(argv) != 5: |
| 53 | glog.fatal('Expected .h file name and .cc file name') |
| 54 | else: |
| 55 | namespaces = ['y2020', 'control_loops', 'superstructure', 'finisher'] |
| 56 | flywheel.WriteFlywheel(kFinisher, argv[1:3], argv[3:5], namespaces) |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | argv = FLAGS(sys.argv) |
| 61 | sys.exit(main(argv)) |