Filip Kujawa | 37aa0bc | 2024-01-31 20:59:49 -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 | |
Filip Kujawa | 37aa0bc | 2024-01-31 20:59:49 -0800 | [diff] [blame] | 17 | kClimber = linear_system.LinearSystemParams( |
| 18 | name='Climber', |
Maxwell Henderson | ce232a9 | 2024-02-18 12:17:37 -0800 | [diff] [blame] | 19 | motor=control_loop.KrakenFOC(), |
| 20 | G=(8. / 60.) * (16. / 60.), |
| 21 | radius=16 * 0.25 / numpy.pi / 2.0 * 0.0254, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 22 | mass=2.0, |
| 23 | q_pos=0.03, |
| 24 | q_vel=2., |
Filip Kujawa | 37aa0bc | 2024-01-31 20:59:49 -0800 | [diff] [blame] | 25 | kalman_q_pos=0.12, |
| 26 | kalman_q_vel=2.00, |
| 27 | kalman_q_voltage=35.0, |
Maxwell Henderson | ce232a9 | 2024-02-18 12:17:37 -0800 | [diff] [blame] | 28 | kalman_r_position=0.05, |
Austin Schuh | 65b4f9d | 2024-03-17 16:03:10 -0700 | [diff] [blame] | 29 | dt=0.005, |
Maxwell Henderson | ce232a9 | 2024-02-18 12:17:37 -0800 | [diff] [blame] | 30 | ) |
Filip Kujawa | 37aa0bc | 2024-01-31 20:59:49 -0800 | [diff] [blame] | 31 | |
| 32 | |
| 33 | def main(argv): |
| 34 | if FLAGS.plot: |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 35 | R = numpy.matrix([[0.4], [0.0]]) |
Filip Kujawa | 37aa0bc | 2024-01-31 20:59:49 -0800 | [diff] [blame] | 36 | linear_system.PlotMotion(kClimber, |
| 37 | R, |
| 38 | max_velocity=5.0, |
| 39 | plant_params=kClimber) |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 40 | linear_system.PlotKick(kClimber, R, plant_params=kClimber) |
| 41 | return |
Filip Kujawa | 37aa0bc | 2024-01-31 20:59:49 -0800 | [diff] [blame] | 42 | |
| 43 | # Write the generated constants out to a file. |
| 44 | if len(argv) != 7: |
| 45 | glog.fatal( |
| 46 | 'Expected .h file name and .cc file name for the climber and integral climber.' |
| 47 | ) |
| 48 | else: |
| 49 | namespaces = ['y2024', 'control_loops', 'superstructure', 'climber'] |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 50 | linear_system.WriteLinearSystem(kClimber, argv[1:4], argv[4:7], |
| 51 | namespaces) |
Filip Kujawa | 37aa0bc | 2024-01-31 20:59:49 -0800 | [diff] [blame] | 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | argv = FLAGS(sys.argv) |
| 56 | glog.init() |
| 57 | sys.exit(main(argv)) |