James Kuszmaul | bfdd256 | 2024-07-06 14:18:53 -0700 | [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_current |
| 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 | import matplotlib |
| 13 | |
| 14 | FLAGS = gflags.FLAGS |
| 15 | |
| 16 | try: |
| 17 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
| 18 | except gflags.DuplicateFlagError: |
| 19 | pass |
| 20 | |
| 21 | kRotation = angular_system_current.AngularSystemCurrentParams( |
| 22 | name='Rotation', |
| 23 | motor=control_loop.KrakenFOC(), |
| 24 | G=9.0 / 24.0 * 14.0 / 72.0, |
| 25 | J=3.1 / 1000.0, |
| 26 | q_pos=0.05, |
| 27 | q_vel=20.0, |
| 28 | kalman_q_pos=0.12, |
| 29 | kalman_q_vel=2.0, |
| 30 | kalman_q_voltage=4.0, |
| 31 | kalman_r_position=0.05, |
| 32 | radius=25 * 0.0254, |
| 33 | wrap_point=2.0 * numpy.pi) |
| 34 | |
| 35 | |
| 36 | def main(argv): |
| 37 | if FLAGS.plot: |
| 38 | R = numpy.matrix([[numpy.pi / 2.0], [0.0]]) |
| 39 | angular_system_current.PlotKick(kRotation, R) |
| 40 | angular_system_current.PlotMotion(kRotation, R) |
| 41 | return |
| 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 wrist and integral wrist.' |
| 47 | ) |
| 48 | else: |
| 49 | namespaces = ['y2024_swerve', 'control_loops', 'drivetrain'] |
| 50 | angular_system_current.WriteAngularSystemCurrent( |
| 51 | kRotation, argv[1:4], argv[4:7], namespaces) |
| 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | argv = FLAGS(sys.argv) |
| 56 | glog.init() |
| 57 | sys.exit(main(argv)) |