Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | from frc971.control_loops.python import control_loop |
| 4 | from frc971.control_loops.python import linear_system |
| 5 | import numpy |
| 6 | import sys |
| 7 | import gflags |
| 8 | import glog |
| 9 | |
| 10 | FLAGS = gflags.FLAGS |
| 11 | |
| 12 | try: |
| 13 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
| 14 | except gflags.DuplicateFlagError: |
| 15 | pass |
| 16 | |
| 17 | kElevator = linear_system.LinearSystemParams( |
| 18 | name='Elevator', |
| 19 | motor=control_loop.Vex775Pro(), |
| 20 | G=(8.0 / 82.0), |
| 21 | radius=2.25 * 0.0254 / 2.0, |
| 22 | mass=4.0, |
| 23 | q_pos=0.070, |
| 24 | q_vel=1.2, |
| 25 | kalman_q_pos=0.12, |
| 26 | kalman_q_vel=2.00, |
| 27 | kalman_q_voltage=35.0, |
| 28 | kalman_r_position=0.05, |
| 29 | dt=0.00505) |
| 30 | |
| 31 | |
| 32 | def main(argv): |
| 33 | if FLAGS.plot: |
| 34 | R = numpy.matrix([[1.5], [0.0]]) |
| 35 | linear_system.PlotKick(kElevator, R) |
| 36 | linear_system.PlotMotion(kElevator, R, max_velocity=5.0) |
| 37 | |
| 38 | # Write the generated constants out to a file. |
| 39 | if len(argv) != 5: |
| 40 | glog.fatal( |
| 41 | 'Expected .h file name and .cc file name for the elevator and integral elevator.' |
| 42 | ) |
| 43 | else: |
| 44 | namespaces = ['y2019', 'control_loops', 'superstructure', 'elevator'] |
| 45 | linear_system.WriteLinearSystem(kElevator, argv[1:3], argv[3:5], |
| 46 | namespaces) |
| 47 | |
| 48 | |
| 49 | if __name__ == '__main__': |
| 50 | argv = FLAGS(sys.argv) |
| 51 | glog.init() |
| 52 | sys.exit(main(argv)) |