Austin Schuh | 085eab9 | 2020-11-26 13:54:51 -0800 | [diff] [blame^] | 1 | #!/usr/bin/python3 |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 2 | |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 3 | from frc971.control_loops.python import control_loop |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 4 | from frc971.control_loops.python import linear_system |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 5 | import numpy |
| 6 | import sys |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 7 | import gflags |
| 8 | import glog |
| 9 | |
| 10 | FLAGS = gflags.FLAGS |
| 11 | |
| 12 | try: |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 13 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 14 | except gflags.DuplicateFlagError: |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 15 | pass |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 16 | |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 17 | kIntake = linear_system.LinearSystemParams( |
| 18 | name='Intake', |
| 19 | motor=control_loop.Vex775Pro(), |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 20 | # (1 / 35.0) * (20.0 / 40.0) -> 16 tooth sprocket on #25 chain |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 21 | G=(1.0 / 35.0) * (20.0 / 40.0), |
| 22 | radius=16.0 * 0.25 / (2.0 * numpy.pi) * 0.0254, |
| 23 | mass=5.4, |
| 24 | q_pos=0.015, |
| 25 | q_vel=0.3, |
| 26 | kalman_q_pos=0.12, |
| 27 | kalman_q_vel=2.00, |
| 28 | kalman_q_voltage=40.0, |
| 29 | kalman_r_position=0.05) |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 30 | |
| 31 | |
| 32 | def main(argv): |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 33 | if FLAGS.plot: |
| 34 | R = numpy.matrix([[0.1], [0.0]]) |
| 35 | linear_system.PlotMotion(kIntake, R) |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 36 | |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 37 | # Write the generated constants out to a file. |
| 38 | if len(argv) != 5: |
| 39 | glog.fatal( |
| 40 | 'Expected .h file name and .cc file name for the intake and integral intake.' |
| 41 | ) |
| 42 | else: |
| 43 | namespaces = ['y2017', 'control_loops', 'superstructure', 'intake'] |
| 44 | linear_system.WriteLinearSystem(kIntake, argv[1:3], argv[3:5], |
| 45 | namespaces) |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 46 | |
Austin Schuh | 48d60c1 | 2017-02-04 21:58:58 -0800 | [diff] [blame] | 47 | |
| 48 | if __name__ == '__main__': |
Austin Schuh | b5d302f | 2019-01-20 20:51:19 -0800 | [diff] [blame] | 49 | argv = FLAGS(sys.argv) |
| 50 | glog.init() |
| 51 | sys.exit(main(argv)) |