James (Peilun) Li | e9ee3e6 | 2024-11-03 21:24:21 -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 linear_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 | kArm = linear_system.LinearSystemParams( |
| 23 | name='Arm', |
| 24 | motor=control_loop.KrakenFOC(), |
| 25 | G=(14. / 60.) * (32. / 48.), |
| 26 | radius=36 * 0.005 / numpy.pi / 2.0, |
| 27 | mass=5.0, |
| 28 | q_pos=0.20, |
| 29 | q_vel=80.0, |
| 30 | kalman_q_pos=0.12, |
| 31 | kalman_q_vel=2.0, |
| 32 | kalman_q_voltage=8.0, |
| 33 | kalman_r_position=0.05, |
| 34 | dt=0.005, |
| 35 | ) |
| 36 | |
| 37 | |
| 38 | def main(argv): |
| 39 | if FLAGS.plot: |
| 40 | R = numpy.matrix([[0.4], [0.0]]) |
| 41 | linear_system.PlotKick(kArm, R) |
| 42 | linear_system.PlotMotion(kArm, |
| 43 | R, |
| 44 | max_velocity=2.0, |
| 45 | max_acceleration=15.0) |
| 46 | 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 arm pivot and integral arm pivot.' |
| 52 | ) |
| 53 | else: |
| 54 | namespaces = ['y2024_bot3', 'control_loops', 'superstructure', 'arm'] |
| 55 | linear_system.WriteLinearSystem(kArm, argv[1:4], argv[4:7], namespaces) |
| 56 | |
| 57 | |
| 58 | if __name__ == '__main__': |
| 59 | argv = FLAGS(sys.argv) |
| 60 | glog.init() |
| 61 | sys.exit(main(argv)) |