Austin Schuh | 085eab9 | 2020-11-26 13:54:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 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 | |
Tyler Chatow | 993fe28 | 2019-04-06 22:24:36 -0700 | [diff] [blame] | 34 | kElevatorBall = copy.copy(kElevator) |
| 35 | kElevatorBall.q_pos = 0.15 |
| 36 | kElevatorBall.q_vel = 1.5 |
| 37 | |
Austin Schuh | ba23ba9 | 2019-02-15 23:03:10 -0800 | [diff] [blame] | 38 | kElevatorModel = copy.copy(kElevator) |
| 39 | kElevatorModel.mass = carriage_mass + first_stage_mass + 1.0 |
Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 40 | |
Tyler Chatow | 993fe28 | 2019-04-06 22:24:36 -0700 | [diff] [blame] | 41 | |
Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 42 | def main(argv): |
| 43 | if FLAGS.plot: |
| 44 | R = numpy.matrix([[1.5], [0.0]]) |
Tyler Chatow | 993fe28 | 2019-04-06 22:24:36 -0700 | [diff] [blame] | 45 | linear_system.PlotKick(kElevatorBall, R, plant_params=kElevatorModel) |
Austin Schuh | ba23ba9 | 2019-02-15 23:03:10 -0800 | [diff] [blame] | 46 | linear_system.PlotMotion( |
Tyler Chatow | 993fe28 | 2019-04-06 22:24:36 -0700 | [diff] [blame] | 47 | kElevatorBall, R, max_velocity=5.0, plant_params=kElevatorModel) |
Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 48 | |
| 49 | # Write the generated constants out to a file. |
| 50 | if len(argv) != 5: |
| 51 | glog.fatal( |
| 52 | 'Expected .h file name and .cc file name for the elevator and integral elevator.' |
| 53 | ) |
| 54 | else: |
| 55 | namespaces = ['y2019', 'control_loops', 'superstructure', 'elevator'] |
Tyler Chatow | 993fe28 | 2019-04-06 22:24:36 -0700 | [diff] [blame] | 56 | linear_system.WriteLinearSystem([kElevator, kElevatorBall, kElevator], |
| 57 | argv[1:3], argv[3:5], namespaces) |
Austin Schuh | b0b6ccb | 2019-01-20 21:56:33 -0800 | [diff] [blame] | 58 | |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 | argv = FLAGS(sys.argv) |
| 62 | glog.init() |
| 63 | sys.exit(main(argv)) |