Austin Schuh | 085eab9 | 2020-11-26 13:54:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Kai Tinkess | 8a7b8a6 | 2020-02-01 14:38:33 -0800 | [diff] [blame] | 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 copy |
| 8 | import numpy |
| 9 | import sys |
| 10 | from matplotlib import pylab |
| 11 | import gflags |
| 12 | import glog |
| 13 | |
| 14 | FLAGS = gflags.FLAGS |
| 15 | |
| 16 | try: |
| 17 | gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.') |
| 18 | except gflags.DuplicateFlagError: |
| 19 | pass |
| 20 | |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 21 | kTurret = angular_system.AngularSystemParams(name='Turret', |
| 22 | motor=control_loop.MiniCIM(), |
| 23 | G=(26.0 / 150.0) * (14.0 / 60.0) * |
| 24 | (20.0 / 60.0), |
| 25 | J=0.20, |
| 26 | q_pos=0.30, |
| 27 | q_vel=4.5, |
| 28 | kalman_q_pos=0.12, |
| 29 | kalman_q_vel=10.0, |
| 30 | kalman_q_voltage=20.0, |
| 31 | kalman_r_position=0.05) |
| 32 | |
Kai Tinkess | 8a7b8a6 | 2020-02-01 14:38:33 -0800 | [diff] [blame] | 33 | |
| 34 | def main(argv): |
Austin Schuh | 989a313 | 2020-02-20 18:20:06 -0800 | [diff] [blame] | 35 | if FLAGS.plot: |
| 36 | R = numpy.matrix([[numpy.pi], [0.0]]) |
| 37 | angular_system.PlotKick(kTurret, R) |
| 38 | angular_system.PlotMotion(kTurret, R) |
| 39 | |
Kai Tinkess | 8a7b8a6 | 2020-02-01 14:38:33 -0800 | [diff] [blame] | 40 | # Write the generated constants out to a file. |
| 41 | if len(argv) != 5: |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 42 | glog.fatal('Expected .h file name and .cc file name for the turret.') |
Kai Tinkess | 8a7b8a6 | 2020-02-01 14:38:33 -0800 | [diff] [blame] | 43 | else: |
| 44 | namespaces = ['y2020', 'control_loops', 'superstructure', 'turret'] |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 45 | angular_system.WriteAngularSystem([kTurret], argv[1:3], argv[3:5], |
| 46 | namespaces) |
Kai Tinkess | 8a7b8a6 | 2020-02-01 14:38:33 -0800 | [diff] [blame] | 47 | |
| 48 | |
| 49 | if __name__ == '__main__': |
| 50 | argv = FLAGS(sys.argv) |
| 51 | glog.init() |
| 52 | sys.exit(main(argv)) |