blob: 8125f8b5a0d1768055bee310e63e260c7691e787 [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)
Austin Schuh2efe1682021-03-06 22:47:15 -080024# 0.5 inches/turn
Ravago Jones937587c2020-12-26 17:21:09 -080025# 6.7725 inches of travel
Austin Schuh2efe1682021-03-06 22:47:15 -080026turns_of_leadscrew_per_range_of_travel = 6.7725 / 0.5
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
Ravago Jones5127ccc2022-07-31 16:32:45 -070032kHood = angular_system.AngularSystemParams(name='Hood',
33 motor=control_loop.BAG(),
34 G=radians_per_turn_of_motor /
35 (2.0 * numpy.pi),
36 J=0.1,
37 q_pos=0.15,
38 q_vel=10.0,
39 kalman_q_pos=0.12,
40 kalman_q_vel=10.0,
41 kalman_q_voltage=30.0,
42 kalman_r_position=0.02)
Sabina Davis24d94e02020-01-31 21:32:41 -080043
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))