blob: db6b72733c07105bc278b6401f316139bbc4b918 [file] [log] [blame]
Austin Schuh085eab92020-11-26 13:54:51 -08001#!/usr/bin/python3
Sabina Davis24d94e02020-01-31 21:32:41 -08002
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
Austin Schuhc1c957a2020-02-20 17:47:58 -080020# Hood is an angular subsystem due to the mounting of the encoder on the hood
21# joint. We are currently electing to ignore potential non-linearity.
22
Ravago Jones937587c2020-12-26 17:21:09 -080023range_of_travel_radians = (38.0 * numpy.pi / 180.0)
24# 0.472441 inches/turn (12 mm)
25# 6.7725 inches of travel
26turns_of_leadscrew_per_range_of_travel = 6.7725 / 0.472441
Austin Schuhc1c957a2020-02-20 17:47:58 -080027
28radians_per_turn = range_of_travel_radians / turns_of_leadscrew_per_range_of_travel
29
Ravago Jones937587c2020-12-26 17:21:09 -080030radians_per_turn_of_motor = 12.0 / 60.0 * radians_per_turn
31
Sabina Davis24d94e02020-01-31 21:32:41 -080032kHood = angular_system.AngularSystemParams(
33 name='Hood',
34 motor=control_loop.BAG(),
Ravago Jones937587c2020-12-26 17:21:09 -080035 G=radians_per_turn_of_motor / (2.0 * numpy.pi),
Austin Schuh78f0bfd2020-02-29 23:04:21 -080036 J=4.0,
37 q_pos=0.15,
38 q_vel=5.0,
Sabina Davis24d94e02020-01-31 21:32:41 -080039 kalman_q_pos=0.12,
Austin Schuh78f0bfd2020-02-29 23:04:21 -080040 kalman_q_vel=10.0,
41 kalman_q_voltage=15.0,
Sabina Davis24d94e02020-01-31 21:32:41 -080042 kalman_r_position=0.05)
43
44
45def main(argv):
46 if FLAGS.plot:
Austin Schuhc1c957a2020-02-20 17:47:58 -080047 R = numpy.matrix([[numpy.pi / 4.0], [0.0]])
Sabina Davis24d94e02020-01-31 21:32:41 -080048 angular_system.PlotKick(kHood, R)
49 angular_system.PlotMotion(kHood, R)
50
Austin Schuh085eab92020-11-26 13:54:51 -080051 glog.debug("Radians per turn: %f\n", radians_per_turn)
Austin Schuh43b9ae92020-02-29 23:08:38 -080052
Sabina Davis24d94e02020-01-31 21:32:41 -080053 # Write the generated constants out to a file.
54 if len(argv) != 5:
55 glog.fatal(
56 'Expected .h file name and .cc file name for the hood and integral hood.'
57 )
58 else:
59 namespaces = ['y2020', 'control_loops', 'superstructure', 'hood']
60 angular_system.WriteAngularSystem(kHood, argv[1:3], argv[3:5],
61 namespaces)
62
63
64if __name__ == '__main__':
65 argv = FLAGS(sys.argv)
66 glog.init()
67 sys.exit(main(argv))