milind-u | 53ad98a | 2023-02-20 16:26:09 -0800 | [diff] [blame^] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | from aos.util.trapezoid_profile import TrapezoidProfile |
| 4 | from frc971.control_loops.python import control_loop |
| 5 | from frc971.control_loops.python import angular_system |
| 6 | from frc971.control_loops.python import controls |
| 7 | import numpy |
| 8 | import sys |
| 9 | from matplotlib import pylab |
| 10 | import gflags |
| 11 | import glog |
| 12 | |
| 13 | FLAGS = gflags.FLAGS |
| 14 | |
| 15 | try: |
| 16 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
| 17 | except gflags.DuplicateFlagError: |
| 18 | pass |
| 19 | |
| 20 | gflags.DEFINE_bool('hybrid', False, 'If true, make it hybrid.') |
| 21 | |
| 22 | kRoll = angular_system.AngularSystemParams( |
| 23 | name='Roll', |
| 24 | motor=control_loop.BAG(), |
| 25 | G=18.0 / 48.0 * 1.0 / 36.0, |
| 26 | # 598.006 in^2 lb |
| 27 | J=0.175, |
| 28 | q_pos=0.40, |
| 29 | q_vel=20.0, |
| 30 | kalman_q_pos=0.12, |
| 31 | kalman_q_vel=2.0, |
| 32 | kalman_q_voltage=4.0, |
| 33 | kalman_r_position=0.05, |
| 34 | radius=13 * 0.0254) |
| 35 | |
| 36 | |
| 37 | def main(argv): |
| 38 | if FLAGS.plot: |
| 39 | R = numpy.matrix([[numpy.pi / 2.0], [0.0]]) |
| 40 | angular_system.PlotKick(kRoll, R) |
| 41 | angular_system.PlotMotion(kRoll, R) |
| 42 | |
| 43 | # Write the generated constants out to a file. |
| 44 | if len(argv) != 5: |
| 45 | glog.fatal( |
| 46 | 'Expected .h file name and .cc file name for the intake and integral intake.' |
| 47 | ) |
| 48 | else: |
| 49 | namespaces = ['y2023', 'control_loops', 'superstructure', 'roll'] |
| 50 | if FLAGS.hybrid: |
| 51 | kRoll.name = 'HybridRoll' |
| 52 | angular_system.WriteAngularSystem( |
| 53 | kRoll, |
| 54 | argv[1:3], |
| 55 | argv[3:5], |
| 56 | namespaces, |
| 57 | plant_type='StateFeedbackHybridPlant', |
| 58 | observer_type='HybridKalman') |
| 59 | else: |
| 60 | angular_system.WriteAngularSystem(kRoll, argv[1:3], argv[3:5], |
| 61 | namespaces) |
| 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |
| 65 | argv = FLAGS(sys.argv) |
| 66 | glog.init() |
| 67 | sys.exit(main(argv)) |