Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -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 | kCatapultWithGamePiece = angular_system.AngularSystemParams( |
| 23 | name='Catapult', |
| 24 | motor=control_loop.KrakenFOC(), |
| 25 | G=(14.0 / 60.0) * (12.0 / 24.0), |
| 26 | # 208.7328 in^2 lb |
| 27 | J=0.065, |
| 28 | q_pos=0.40, |
| 29 | q_vel=3.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=12 * 0.0254) |
| 35 | |
| 36 | kCatapultWithoutGamePiece = angular_system.AngularSystemParams( |
| 37 | name='Catapult', |
| 38 | motor=control_loop.KrakenFOC(), |
| 39 | G=(14.0 / 60.0) * (12.0 / 24.0), |
| 40 | # 135.2928 in^2 lb |
| 41 | J=0.04, |
| 42 | q_pos=0.40, |
| 43 | q_vel=3.0, |
| 44 | kalman_q_pos=0.12, |
| 45 | kalman_q_vel=2.0, |
| 46 | kalman_q_voltage=4.0, |
| 47 | kalman_r_position=0.05, |
| 48 | radius=12 * 0.0254) |
| 49 | |
| 50 | |
| 51 | def main(argv): |
| 52 | if FLAGS.plot: |
| 53 | R = numpy.matrix([[numpy.pi / 2.0], [0.0]]) |
| 54 | angular_system.PlotKick(kCatapult, R) |
| 55 | angular_system.PlotMotion(kCatapult, R) |
| 56 | return |
| 57 | |
| 58 | # Write the generated constants out to a file. |
| 59 | if len(argv) != 7: |
| 60 | glog.fatal( |
| 61 | 'Expected .h file name and .cc file name for the intake and integral intake.' |
| 62 | ) |
| 63 | else: |
| 64 | namespaces = ['y2024', 'control_loops', 'superstructure', 'catapult'] |
| 65 | angular_system.WriteAngularSystem( |
| 66 | [kCatapultWithGamePiece, kCatapultWithoutGamePiece], argv[1:4], |
| 67 | argv[4:7], namespaces) |
| 68 | |
| 69 | |
| 70 | if __name__ == '__main__': |
| 71 | argv = FLAGS(sys.argv) |
| 72 | glog.init() |
| 73 | sys.exit(main(argv)) |