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 | |
suneel | 2bc345d | 2019-02-09 20:00:56 -0800 | [diff] [blame] | 17 | first_stage_mass = 0.7957 |
| 18 | carriage_mass = 2.754 |
| 19 | |
Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 20 | kElevator = linear_system.LinearSystemParams( |
| 21 | name='Elevator', |
| 22 | motor=control_loop.Vex775Pro(), |
| 23 | G=(8.0 / 82.0), |
| 24 | radius=2.25 * 0.0254 / 2.0, |
suneel | 2bc345d | 2019-02-09 20:00:56 -0800 | [diff] [blame] | 25 | mass=first_stage_mass + carriage_mass, |
Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 26 | q_pos=0.070, |
| 27 | q_vel=1.2, |
| 28 | kalman_q_pos=0.12, |
| 29 | kalman_q_vel=2.00, |
| 30 | kalman_q_voltage=35.0, |
| 31 | kalman_r_position=0.05, |
| 32 | dt=0.00505) |
| 33 | |
| 34 | |
| 35 | def main(argv): |
| 36 | if FLAGS.plot: |
| 37 | R = numpy.matrix([[1.5], [0.0]]) |
| 38 | linear_system.PlotKick(kElevator, R) |
| 39 | linear_system.PlotMotion(kElevator, R, max_velocity=5.0) |
| 40 | |
| 41 | # Write the generated constants out to a file. |
| 42 | if len(argv) != 5: |
| 43 | glog.fatal( |
| 44 | 'Expected .h file name and .cc file name for the elevator and integral elevator.' |
| 45 | ) |
| 46 | else: |
| 47 | namespaces = ['y2019', 'control_loops', 'superstructure', 'elevator'] |
| 48 | linear_system.WriteLinearSystem(kElevator, argv[1:3], argv[3:5], |
| 49 | namespaces) |
| 50 | |
| 51 | |
| 52 | if __name__ == '__main__': |
| 53 | argv = FLAGS(sys.argv) |
| 54 | glog.init() |
| 55 | sys.exit(main(argv)) |