blob: 49c6305818add943f04b493bad8c9a83424c10b5 [file] [log] [blame]
Niko Sohmers11017112024-02-18 16:03:58 -08001#!/usr/bin/python3
2
3from aos.util.trapezoid_profile import TrapezoidProfile
4from frc971.control_loops.python import control_loop
5from frc971.control_loops.python import angular_system
6from frc971.control_loops.python import controls
7import numpy
8import sys
9from matplotlib import pylab
10import gflags
11import glog
12
13FLAGS = gflags.FLAGS
14
15try:
16 gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
17except gflags.DuplicateFlagError:
18 pass
19
20gflags.DEFINE_bool('hybrid', False, 'If true, make it hybrid.')
21
Austin Schuh087613b2024-02-19 12:39:08 -080022
23def AddResistance(motor, resistance):
24 motor.resistance += resistance
25 return motor
26
27
Niko Sohmers11017112024-02-18 16:03:58 -080028kCatapultWithGamePiece = angular_system.AngularSystemParams(
29 name='Catapult',
Austin Schuh087613b2024-02-19 12:39:08 -080030 # Add the battery series resistance to make it better match.
31 motor=AddResistance(control_loop.NMotor(control_loop.KrakenFOC(), 2),
Maxwell Henderson6b1be312024-02-28 20:15:06 -080032 0.00),
Niko Sohmers11017112024-02-18 16:03:58 -080033 G=(14.0 / 60.0) * (12.0 / 24.0),
34 # 208.7328 in^2 lb
Maxwell Henderson6b1be312024-02-28 20:15:06 -080035 J=0.065 + 0.04,
Austin Schuh087613b2024-02-19 12:39:08 -080036 q_pos=0.80,
37 q_vel=15.0,
Niko Sohmers11017112024-02-18 16:03:58 -080038 kalman_q_pos=0.12,
39 kalman_q_vel=2.0,
Austin Schuh087613b2024-02-19 12:39:08 -080040 kalman_q_voltage=0.7,
Niko Sohmers11017112024-02-18 16:03:58 -080041 kalman_r_position=0.05,
Austin Schuh087613b2024-02-19 12:39:08 -080042 radius=12 * 0.0254,
43 delayed_u=1)
Niko Sohmers11017112024-02-18 16:03:58 -080044
45kCatapultWithoutGamePiece = angular_system.AngularSystemParams(
46 name='Catapult',
Austin Schuh087613b2024-02-19 12:39:08 -080047 # Add the battery series resistance to make it better match.
48 motor=AddResistance(control_loop.NMotor(control_loop.KrakenFOC(), 2),
Maxwell Henderson6b1be312024-02-28 20:15:06 -080049 0.00),
Niko Sohmers11017112024-02-18 16:03:58 -080050 G=(14.0 / 60.0) * (12.0 / 24.0),
51 # 135.2928 in^2 lb
Maxwell Henderson6b1be312024-02-28 20:15:06 -080052 J=0.06,
Austin Schuh087613b2024-02-19 12:39:08 -080053 q_pos=0.80,
54 q_vel=15.0,
Niko Sohmers11017112024-02-18 16:03:58 -080055 kalman_q_pos=0.12,
56 kalman_q_vel=2.0,
Austin Schuh087613b2024-02-19 12:39:08 -080057 kalman_q_voltage=0.7,
Niko Sohmers11017112024-02-18 16:03:58 -080058 kalman_r_position=0.05,
Austin Schuh087613b2024-02-19 12:39:08 -080059 radius=12 * 0.0254,
60 delayed_u=1)
Niko Sohmers11017112024-02-18 16:03:58 -080061
62
63def main(argv):
64 if FLAGS.plot:
65 R = numpy.matrix([[numpy.pi / 2.0], [0.0]])
Austin Schuh087613b2024-02-19 12:39:08 -080066 angular_system.PlotKick(kCatapultWithGamePiece, R)
67 angular_system.PlotMotion(kCatapultWithGamePiece, R)
Niko Sohmers11017112024-02-18 16:03:58 -080068 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(
Maxwell Henderson6b1be312024-02-28 20:15:06 -080078 [kCatapultWithoutGamePiece, kCatapultWithGamePiece], argv[1:4],
Niko Sohmers11017112024-02-18 16:03:58 -080079 argv[4:7], namespaces)
80
81
82if __name__ == '__main__':
83 argv = FLAGS(sys.argv)
84 glog.init()
85 sys.exit(main(argv))