blob: e8f066be6bb7a847759a74441d0e2e1ca033ab6e [file] [log] [blame]
Austin Schuh3db875a2024-02-18 20:02:40 -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 linear_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
22kExtend = linear_system.LinearSystemParams(
23 name='Extend',
24 motor=control_loop.KrakenFOC(),
25 G=(14. / 60.) * (32. / 48.),
26 radius=36 * 0.005 / numpy.pi / 2.0,
27 mass=5.0,
Austin Schuh087613b2024-02-19 12:39:08 -080028 q_pos=0.20,
29 q_vel=80.0,
Austin Schuh3db875a2024-02-18 20:02:40 -080030 kalman_q_pos=0.12,
31 kalman_q_vel=2.0,
Austin Schuh087613b2024-02-19 12:39:08 -080032 kalman_q_voltage=8.0,
Austin Schuh3db875a2024-02-18 20:02:40 -080033 kalman_r_position=0.05,
Austin Schuh65b4f9d2024-03-17 16:03:10 -070034 dt=0.005,
Austin Schuh3db875a2024-02-18 20:02:40 -080035)
36
37
38def main(argv):
39 if FLAGS.plot:
Austin Schuh087613b2024-02-19 12:39:08 -080040 R = numpy.matrix([[0.4], [0.0]])
Austin Schuh3db875a2024-02-18 20:02:40 -080041 linear_system.PlotKick(kExtend, R)
Austin Schuh087613b2024-02-19 12:39:08 -080042 linear_system.PlotMotion(kExtend,
43 R,
44 max_velocity=2.0,
45 max_acceleration=15.0)
Austin Schuh3db875a2024-02-18 20:02:40 -080046 return
47
48 # Write the generated constants out to a file.
49 if len(argv) != 7:
50 glog.fatal(
51 'Expected .h file name and .cc file name for the extend pivot and integral extend pivot.'
52 )
53 else:
54 namespaces = ['y2024', 'control_loops', 'superstructure', 'extend']
55 linear_system.WriteLinearSystem(kExtend, argv[1:4], argv[4:7],
56 namespaces)
57
58
59if __name__ == '__main__':
60 argv = FLAGS(sys.argv)
61 glog.init()
62 sys.exit(main(argv))