milind-u | f8bd177 | 2023-02-20 16:27:25 -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 | kWrist = angular_system.AngularSystemParams( |
| 21 | name='Wrist', |
| 22 | motor=control_loop.BAG(), |
Austin Schuh | e5248cd | 2023-03-05 12:46:16 -0800 | [diff] [blame] | 23 | G=(6.0 / 48.0) * (20.0 / 100.0) * (18.0 / 24.0) * (24.0 / 44.0), |
milind-u | f8bd177 | 2023-02-20 16:27:25 -0800 | [diff] [blame] | 24 | # Use parallel axis theorem to get the moment of inertia around |
| 25 | # the joint (I = I_cm + mh^2 = 0.001877 + 0.8332 * 0.0407162^2) |
| 26 | J=0.003258, |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 27 | q_pos=0.80, |
| 28 | q_vel=80.0, |
milind-u | f8bd177 | 2023-02-20 16:27:25 -0800 | [diff] [blame] | 29 | kalman_q_pos=0.12, |
| 30 | kalman_q_vel=2.0, |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 31 | kalman_q_voltage=0.5, |
milind-u | f8bd177 | 2023-02-20 16:27:25 -0800 | [diff] [blame] | 32 | kalman_r_position=0.05, |
| 33 | radius=5.71 * 0.0254) |
| 34 | |
| 35 | |
| 36 | def main(argv): |
| 37 | if FLAGS.plot: |
| 38 | R = numpy.matrix([[numpy.pi / 2.0], [0.0]]) |
Austin Schuh | a32a189 | 2023-02-21 14:04:07 -0800 | [diff] [blame] | 39 | angular_system.PlotKick(kWrist, R) |
| 40 | angular_system.PlotMotion(kWrist, R) |
| 41 | return |
milind-u | f8bd177 | 2023-02-20 16:27:25 -0800 | [diff] [blame] | 42 | |
| 43 | # Write the generated constants out to a file. |
| 44 | if len(argv) != 5: |
| 45 | glog.fatal( |
| 46 | 'Expected .h file name and .cc file name for the wrist and integral wrist.' |
| 47 | ) |
| 48 | else: |
| 49 | namespaces = ['y2023', 'control_loops', 'superstructure', 'wrist'] |
| 50 | angular_system.WriteAngularSystem(kWrist, argv[1:3], argv[3:5], |
| 51 | namespaces) |
| 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | argv = FLAGS(sys.argv) |
| 56 | glog.init() |
| 57 | sys.exit(main(argv)) |