blob: d8118a1a9ffa2a3e1f84b9bd057c6199ef930ed7 [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
23range_of_travel_radians = (37.0 * numpy.pi / 180.0)
24# 0.083 inches/turn
25# 6.38 inches of travel
26turns_of_leadscrew_per_range_of_travel = 6.38 / 0.083
27
28radians_per_turn = range_of_travel_radians / turns_of_leadscrew_per_range_of_travel
29
Sabina Davis24d94e02020-01-31 21:32:41 -080030kHood = angular_system.AngularSystemParams(
31 name='Hood',
32 motor=control_loop.BAG(),
Austin Schuh78f0bfd2020-02-29 23:04:21 -080033 G=radians_per_turn / (2.0 * numpy.pi),
34 J=4.0,
35 q_pos=0.15,
36 q_vel=5.0,
Sabina Davis24d94e02020-01-31 21:32:41 -080037 kalman_q_pos=0.12,
Austin Schuh78f0bfd2020-02-29 23:04:21 -080038 kalman_q_vel=10.0,
39 kalman_q_voltage=15.0,
Sabina Davis24d94e02020-01-31 21:32:41 -080040 kalman_r_position=0.05)
41
42
43def main(argv):
44 if FLAGS.plot:
Austin Schuhc1c957a2020-02-20 17:47:58 -080045 R = numpy.matrix([[numpy.pi / 4.0], [0.0]])
Sabina Davis24d94e02020-01-31 21:32:41 -080046 angular_system.PlotKick(kHood, R)
47 angular_system.PlotMotion(kHood, R)
48
Austin Schuh085eab92020-11-26 13:54:51 -080049 glog.debug("Radians per turn: %f\n", radians_per_turn)
Austin Schuh43b9ae92020-02-29 23:08:38 -080050
Sabina Davis24d94e02020-01-31 21:32:41 -080051 # Write the generated constants out to a file.
52 if len(argv) != 5:
53 glog.fatal(
54 'Expected .h file name and .cc file name for the hood and integral hood.'
55 )
56 else:
57 namespaces = ['y2020', 'control_loops', 'superstructure', 'hood']
58 angular_system.WriteAngularSystem(kHood, argv[1:3], argv[3:5],
59 namespaces)
60
61
62if __name__ == '__main__':
63 argv = FLAGS(sys.argv)
64 glog.init()
65 sys.exit(main(argv))