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 | # Inertia for a single 4" diameter, 1" wide neopreme wheel. |
| 17 | J_wheel = 0.000319 |
| 18 | # Gear ratio between wheels (speed up!) |
| 19 | G_per_wheel = 1.2 |
| 20 | # Gear ratio to the final wheel. |
| 21 | G = (30.0 / 40.0) * numpy.power(G_per_wheel, 3.0) |
| 22 | # Overall flywheel inertia. |
| 23 | J = J_wheel * ( |
Austin Schuh | 8047677 | 2021-03-06 20:17:36 -0800 | [diff] [blame] | 24 | 1.0 + numpy.power(G_per_wheel, -2.0) + numpy.power(G_per_wheel, -4.0) + numpy.power(G_per_wheel, -6.0)) |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 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 | kAccelerator = flywheel.FlywheelParams( |
| 28 | name='Accelerator', |
| 29 | motor=control_loop.Falcon(), |
Austin Schuh | c1c957a | 2020-02-20 17:47:58 -0800 | [diff] [blame] | 30 | G=G, |
Austin Schuh | 8047677 | 2021-03-06 20:17:36 -0800 | [diff] [blame] | 31 | J=J * 1.3, |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 32 | q_pos=0.01, |
| 33 | q_vel=40.0, |
Austin Schuh | 8047677 | 2021-03-06 20:17:36 -0800 | [diff] [blame] | 34 | q_voltage=1.0, |
| 35 | r_pos=0.03, |
| 36 | controller_poles=[.89]) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 37 | |
| 38 | |
| 39 | def main(argv): |
| 40 | if FLAGS.plot: |
Austin Schuh | 989a313 | 2020-02-20 18:20:06 -0800 | [diff] [blame] | 41 | R = numpy.matrix([[0.0], [500.0], [0.0]]) |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 42 | flywheel.PlotSpinup(kAccelerator, goal=R, iterations=400) |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 43 | return 0 |
| 44 | |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 45 | glog.debug("J is %f" % J) |
| 46 | |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 47 | if len(argv) != 5: |
| 48 | glog.fatal('Expected .h file name and .cc file name') |
| 49 | else: |
| 50 | namespaces = [ |
| 51 | 'y2020', 'control_loops', 'superstructure', 'accelerator' |
| 52 | ] |
| 53 | flywheel.WriteFlywheel(kAccelerator, argv[1:3], argv[3:5], namespaces) |
| 54 | |
| 55 | |
| 56 | if __name__ == '__main__': |
| 57 | argv = FLAGS(sys.argv) |
Austin Schuh | 43b9ae9 | 2020-02-29 23:08:38 -0800 | [diff] [blame] | 58 | glog.init() |
Sabina Davis | edf8947 | 2020-02-17 15:27:37 -0800 | [diff] [blame] | 59 | sys.exit(main(argv)) |