Austin Schuh | 085eab9 | 2020-11-26 13:54:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 2 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 3 | from aos.util.trapezoid_profile import TrapezoidProfile |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 4 | from frc971.control_loops.python import control_loop |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 5 | from frc971.control_loops.python import angular_system |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 6 | from frc971.control_loops.python import controls |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 7 | import numpy |
| 8 | import sys |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 9 | from matplotlib import pylab |
| 10 | import gflags |
| 11 | import glog |
| 12 | |
| 13 | FLAGS = gflags.FLAGS |
| 14 | |
| 15 | try: |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 16 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 17 | except gflags.DuplicateFlagError: |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 18 | pass |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 19 | |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 20 | kIntake = angular_system.AngularSystemParams( |
| 21 | name='Intake', |
| 22 | motor=control_loop.Vex775Pro(), |
| 23 | # (1 / 35.0) * (20.0 / 40.0) -> 16 tooth sprocket on #25 chain |
| 24 | G=(12.0 / 56.0) * (14.0 / 54.0) * (18.0 / 64.0) * (16.0 / 48.0), |
| 25 | J=0.34 - 0.03757568, |
| 26 | q_pos=0.20, |
| 27 | q_vel=5.0, |
Austin Schuh | 63d095d | 2019-02-23 11:57:12 -0800 | [diff] [blame] | 28 | dt=0.005, |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 29 | kalman_q_pos=0.12, |
| 30 | kalman_q_vel=2.0, |
| 31 | kalman_q_voltage=4.0, |
| 32 | kalman_r_position=0.05) |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | def main(argv): |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 36 | if FLAGS.plot: |
| 37 | R = numpy.matrix([[numpy.pi / 2.0], [0.0]]) |
| 38 | angular_system.PlotMotion(kIntake, R) |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 39 | |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 40 | # Write the generated constants out to a file. |
| 41 | if len(argv) != 5: |
| 42 | glog.fatal( |
| 43 | 'Expected .h file name and .cc file name for the intake and integral intake.' |
| 44 | ) |
| 45 | else: |
| 46 | namespaces = ['y2016', 'control_loops', 'superstructure'] |
| 47 | angular_system.WriteAngularSystem(kIntake, argv[1:3], argv[3:5], |
| 48 | namespaces) |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 49 | |
Comran Morshed | 2ae094e | 2016-01-23 20:43:20 +0000 | [diff] [blame] | 50 | |
| 51 | if __name__ == '__main__': |
Austin Schuh | 2e55403 | 2019-01-21 15:07:27 -0800 | [diff] [blame] | 52 | argv = FLAGS(sys.argv) |
| 53 | glog.init() |
| 54 | sys.exit(main(argv)) |