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 | |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 28 | kCatapultWithGamePiece = angular_system.AngularSystemParams( |
| 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), |
| 32 | 0.03), |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 33 | G=(14.0 / 60.0) * (12.0 / 24.0), |
| 34 | # 208.7328 in^2 lb |
| 35 | J=0.065, |
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, |
| 43 | delayed_u=1) |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 44 | |
| 45 | kCatapultWithoutGamePiece = angular_system.AngularSystemParams( |
| 46 | name='Catapult', |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame^] | 47 | # Add the battery series resistance to make it better match. |
| 48 | motor=AddResistance(control_loop.NMotor(control_loop.KrakenFOC(), 2), |
| 49 | 0.03), |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 50 | G=(14.0 / 60.0) * (12.0 / 24.0), |
| 51 | # 135.2928 in^2 lb |
| 52 | J=0.04, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame^] | 53 | q_pos=0.80, |
| 54 | q_vel=15.0, |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 55 | kalman_q_pos=0.12, |
| 56 | kalman_q_vel=2.0, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame^] | 57 | kalman_q_voltage=0.7, |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 58 | kalman_r_position=0.05, |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame^] | 59 | radius=12 * 0.0254, |
| 60 | delayed_u=1) |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 61 | |
| 62 | |
| 63 | def main(argv): |
| 64 | if FLAGS.plot: |
| 65 | R = numpy.matrix([[numpy.pi / 2.0], [0.0]]) |
Austin Schuh | 087613b | 2024-02-19 12:39:08 -0800 | [diff] [blame^] | 66 | angular_system.PlotKick(kCatapultWithGamePiece, R) |
| 67 | angular_system.PlotMotion(kCatapultWithGamePiece, R) |
Niko Sohmers | 1101711 | 2024-02-18 16:03:58 -0800 | [diff] [blame] | 68 | return |
| 69 | |
| 70 | # Write the generated constants out to a file. |
| 71 | if len(argv) != 7: |
| 72 | glog.fatal( |
| 73 | 'Expected .h file name and .cc file name for the intake and integral intake.' |
| 74 | ) |
| 75 | else: |
| 76 | namespaces = ['y2024', 'control_loops', 'superstructure', 'catapult'] |
| 77 | angular_system.WriteAngularSystem( |
| 78 | [kCatapultWithGamePiece, kCatapultWithoutGamePiece], argv[1:4], |
| 79 | argv[4:7], namespaces) |
| 80 | |
| 81 | |
| 82 | if __name__ == '__main__': |
| 83 | argv = FLAGS(sys.argv) |
| 84 | glog.init() |
| 85 | sys.exit(main(argv)) |