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 | |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 22 | |
| 23 | def AddResistance(motor, resistance): |
| 24 | motor.resistance += resistance |
| 25 | return motor |
| 26 | |
| 27 | |
Austin Schuh | 7cea29d | 2024-03-17 18:20:14 -0700 | [diff] [blame] | 28 | kCatapultWithoutGamePiece = angular_system.AngularSystemParams( |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 29 | name='Catapult', |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 30 | # Add the battery series resistance to make it better match. |
| 31 | motor=AddResistance(control_loop.NMotor(control_loop.KrakenFOC(), 2), |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 32 | 0.00), |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 33 | G=(14.0 / 60.0) * (12.0 / 24.0), |
Austin Schuh | 7cea29d | 2024-03-17 18:20:14 -0700 | [diff] [blame] | 34 | # 135.2928 in^2 lb |
| 35 | J=0.06, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 36 | q_pos=0.80, |
| 37 | q_vel=15.0, |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 38 | kalman_q_pos=0.12, |
| 39 | kalman_q_vel=2.0, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 40 | kalman_q_voltage=0.7, |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 41 | kalman_r_position=0.05, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 42 | radius=12 * 0.0254, |
Austin Schuh | 65b4f9d | 2024-03-17 16:03:10 -0700 | [diff] [blame] | 43 | delayed_u=1, |
| 44 | dt=0.005) |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 45 | |
Austin Schuh | 7cea29d | 2024-03-17 18:20:14 -0700 | [diff] [blame] | 46 | kCatapultWithGamePiece = angular_system.AngularSystemParams( |
| 47 | name='CatapultWithPiece', |
| 48 | # Add the battery series resistance to make it better match. |
| 49 | motor=AddResistance(control_loop.NMotor(control_loop.KrakenFOC(), 2), |
| 50 | 0.00), |
| 51 | G=(14.0 / 60.0) * (12.0 / 24.0), |
| 52 | # 208.7328 in^2 lb |
| 53 | J=0.065 + 0.06, |
| 54 | q_pos=0.80, |
| 55 | q_vel=15.0, |
| 56 | kalman_q_pos=0.12, |
| 57 | kalman_q_vel=2.0, |
| 58 | kalman_q_voltage=0.7, |
| 59 | kalman_r_position=0.05, |
| 60 | radius=12 * 0.0254, |
| 61 | delayed_u=1, |
| 62 | dt=0.005) |
| 63 | |
| 64 | kCatapultWithoutGamePieceDecel = angular_system.AngularSystemParams( |
| 65 | name='CatapultWithoutPieceDecel', |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 66 | # Add the battery series resistance to make it better match. |
| 67 | motor=AddResistance(control_loop.NMotor(control_loop.KrakenFOC(), 2), |
Maxwell Henderson | 6b1be31 | 2024-02-28 20:15:06 -0800 | [diff] [blame] | 68 | 0.00), |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 69 | G=(14.0 / 60.0) * (12.0 / 24.0), |
| 70 | # 135.2928 in^2 lb |
Austin Schuh | 7cea29d | 2024-03-17 18:20:14 -0700 | [diff] [blame] | 71 | J=0.04, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 72 | q_pos=0.80, |
| 73 | q_vel=15.0, |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 74 | kalman_q_pos=0.12, |
| 75 | kalman_q_vel=2.0, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 76 | kalman_q_voltage=0.7, |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 77 | kalman_r_position=0.05, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 78 | radius=12 * 0.0254, |
Austin Schuh | 65b4f9d | 2024-03-17 16:03:10 -0700 | [diff] [blame] | 79 | delayed_u=1, |
| 80 | dt=0.005) |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 81 | |
| 82 | |
| 83 | def main(argv): |
| 84 | if FLAGS.plot: |
| 85 | R = numpy.matrix([[numpy.pi / 2.0], [0.0]]) |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame] | 86 | angular_system.PlotKick(kCatapultWithGamePiece, R) |
| 87 | angular_system.PlotMotion(kCatapultWithGamePiece, R) |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 88 | return |
| 89 | |
| 90 | # Write the generated constants out to a file. |
| 91 | if len(argv) != 7: |
| 92 | glog.fatal( |
| 93 | 'Expected .h file name and .cc file name for the intake and integral intake.' |
| 94 | ) |
| 95 | else: |
| 96 | namespaces = ['y2024', 'control_loops', 'superstructure', 'catapult'] |
Austin Schuh | 7cea29d | 2024-03-17 18:20:14 -0700 | [diff] [blame] | 97 | angular_system.WriteAngularSystem([ |
| 98 | kCatapultWithoutGamePiece, kCatapultWithGamePiece, |
| 99 | kCatapultWithoutGamePieceDecel |
| 100 | ], argv[1:4], argv[4:7], namespaces) |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 101 | |
| 102 | |
| 103 | if __name__ == '__main__': |
| 104 | argv = FLAGS(sys.argv) |
| 105 | glog.init() |
| 106 | sys.exit(main(argv)) |