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