Austin Schuh | 9642a1d | 2019-01-21 16:54:14 -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 | |
Theo Bafrali | 6915f11 | 2019-02-08 22:01:54 -0800 | [diff] [blame] | 17 | kStilts = linear_system.LinearSystemParams( |
| 18 | name='Stilts', |
Austin Schuh | 9642a1d | 2019-01-21 16:54:14 -0800 | [diff] [blame] | 19 | motor=control_loop.Vex775Pro(), |
| 20 | G=(12.0 / 100.0) * (14.0 / 52.0), |
| 21 | # 5mm pitch, 18 tooth |
| 22 | radius=0.005 * 18.0 / (2.0 * numpy.pi), |
| 23 | # Or, 2.34 lb * 2 (2.1 kg) when lifting back up |
suneel | 2bc345d | 2019-02-09 20:00:56 -0800 | [diff] [blame] | 24 | mass=1.175 * 2, # 1 stilt foot = 1.175 kg |
Austin Schuh | 9642a1d | 2019-01-21 16:54:14 -0800 | [diff] [blame] | 25 | q_pos=0.070, |
| 26 | q_vel=1.2, |
| 27 | kalman_q_pos=0.12, |
| 28 | kalman_q_vel=2.00, |
| 29 | kalman_q_voltage=35.0, |
Austin Schuh | 63d095d | 2019-02-23 11:57:12 -0800 | [diff] [blame^] | 30 | kalman_r_position=0.05) |
Austin Schuh | 9642a1d | 2019-01-21 16:54:14 -0800 | [diff] [blame] | 31 | |
| 32 | |
| 33 | def main(argv): |
| 34 | if FLAGS.plot: |
| 35 | R = numpy.matrix([[1.5], [0.0]]) |
Theo Bafrali | 6915f11 | 2019-02-08 22:01:54 -0800 | [diff] [blame] | 36 | linear_system.PlotKick(kStilts, R) |
| 37 | linear_system.PlotMotion(kStilts, R, max_velocity=5.0) |
Austin Schuh | 9642a1d | 2019-01-21 16:54:14 -0800 | [diff] [blame] | 38 | |
| 39 | # Write the generated constants out to a file. |
| 40 | if len(argv) != 5: |
| 41 | glog.fatal( |
| 42 | 'Expected .h file name and .cc file name for the elevator and integral elevator.' |
| 43 | ) |
| 44 | else: |
Theo Bafrali | 6915f11 | 2019-02-08 22:01:54 -0800 | [diff] [blame] | 45 | namespaces = ['y2019', 'control_loops', 'superstructure', 'stilts'] |
| 46 | linear_system.WriteLinearSystem(kStilts, argv[1:3], argv[3:5], |
Austin Schuh | 9642a1d | 2019-01-21 16:54:14 -0800 | [diff] [blame] | 47 | namespaces) |
| 48 | |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | argv = FLAGS(sys.argv) |
| 52 | glog.init() |
| 53 | sys.exit(main(argv)) |