Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 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 | kClimber = linear_system.LinearSystemParams( |
| 18 | name='Climber', |
| 19 | motor=control_loop.Falcon(), |
milind-u | 6e7d8d4 | 2022-04-06 18:30:43 -0700 | [diff] [blame] | 20 | G=(1.0 / 4.0) * (1.0 / 3.0) * (1.0 / 3.0), |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 21 | radius=22 * 0.25 / numpy.pi / 2.0 * 0.0254, |
| 22 | mass=2.0, |
| 23 | q_pos=0.10, |
| 24 | q_vel=1.35, |
| 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 | |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 30 | |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 31 | def main(argv): |
| 32 | if FLAGS.plot: |
| 33 | R = numpy.matrix([[0.2], [0.0]]) |
| 34 | linear_system.PlotKick(kClimber, R, plant_params=kClimber) |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 35 | linear_system.PlotMotion(kClimber, |
| 36 | R, |
| 37 | max_velocity=5.0, |
| 38 | plant_params=kClimber) |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 39 | |
| 40 | # Write the generated constants out to a file. |
| 41 | if len(argv) != 5: |
| 42 | glog.fatal( |
| 43 | 'Expected .h file name and .cc file name for the climber and integral climber.' |
| 44 | ) |
| 45 | else: |
| 46 | namespaces = ['y2022', 'control_loops', 'superstructure', 'climber'] |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 47 | linear_system.WriteLinearSystem(kClimber, argv[1:3], argv[3:5], |
| 48 | namespaces) |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame] | 49 | |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | argv = FLAGS(sys.argv) |
| 53 | glog.init() |
| 54 | sys.exit(main(argv)) |