blob: 98ddfe450e1ae8bc24dd5dd3fdbea75d2fe89874 [file] [log] [blame]
Sabina Davis24d94e02020-01-31 21:32:41 -08001#!/usr/bin/python
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
Sabina Davis24d94e02020-01-31 21:32:41 -080020
Austin Schuhc1c957a2020-02-20 17:47:58 -080021# Hood is an angular subsystem due to the mounting of the encoder on the hood
22# joint. We are currently electing to ignore potential non-linearity.
23
24range_of_travel_radians = (37.0 * numpy.pi / 180.0)
25# 0.083 inches/turn
26# 6.38 inches of travel
27turns_of_leadscrew_per_range_of_travel = 6.38 / 0.083
28
29radians_per_turn = range_of_travel_radians / turns_of_leadscrew_per_range_of_travel
30
Sabina Davis24d94e02020-01-31 21:32:41 -080031kHood = angular_system.AngularSystemParams(
32 name='Hood',
33 motor=control_loop.BAG(),
Austin Schuh78f0bfd2020-02-29 23:04:21 -080034 G=radians_per_turn / (2.0 * numpy.pi),
35 J=4.0,
36 q_pos=0.15,
37 q_vel=5.0,
Sabina Davis24d94e02020-01-31 21:32:41 -080038 kalman_q_pos=0.12,
Austin Schuh78f0bfd2020-02-29 23:04:21 -080039 kalman_q_vel=10.0,
40 kalman_q_voltage=15.0,
Sabina Davis24d94e02020-01-31 21:32:41 -080041 kalman_r_position=0.05)
42
43
44def main(argv):
45 if FLAGS.plot:
Austin Schuhc1c957a2020-02-20 17:47:58 -080046 R = numpy.matrix([[numpy.pi / 4.0], [0.0]])
Sabina Davis24d94e02020-01-31 21:32:41 -080047 angular_system.PlotKick(kHood, R)
48 angular_system.PlotMotion(kHood, R)
49
50 # Write the generated constants out to a file.
51 if len(argv) != 5:
52 glog.fatal(
53 'Expected .h file name and .cc file name for the hood and integral hood.'
54 )
55 else:
56 namespaces = ['y2020', 'control_loops', 'superstructure', 'hood']
57 angular_system.WriteAngularSystem(kHood, argv[1:3], argv[3:5],
58 namespaces)
59
60
61if __name__ == '__main__':
62 argv = FLAGS(sys.argv)
63 glog.init()
64 sys.exit(main(argv))