blob: 35ff48fa8b4e4cc77349d72a5a2c969b09eae47d [file] [log] [blame]
Austin Schuh085eab92020-11-26 13:54:51 -08001#!/usr/bin/python3
Sabina Davisedf89472020-02-17 15:27:37 -08002
3from frc971.control_loops.python import control_loop
4from y2020.control_loops.python import flywheel
5import numpy
6
7import sys
8
9import gflags
10import glog
11
12FLAGS = gflags.FLAGS
13
14gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
15
Austin Schuhc1c957a2020-02-20 17:47:58 -080016# Gear ratio to the final wheel.
17# 40 tooth on the flywheel
18# 48 for the falcon.
19# 60 tooth on the outer wheel.
Austin Schuh80476772021-03-06 20:17:36 -080020G = 44.0 / 40.0
Austin Schuhc1c957a2020-02-20 17:47:58 -080021# Overall flywheel inertia.
Austin Schuh0ad31d72021-03-06 17:07:04 -080022J = 0.00507464
Austin Schuh80476772021-03-06 20:17:36 -080023J = 0.008
24
25def AddResistance(motor, resistance):
26 motor.resistance += resistance
27 return motor
28
29def ScaleKv(motor, scale):
30 motor.Kv *= scale
31 return motor
Austin Schuhc1c957a2020-02-20 17:47:58 -080032
33# The position and velocity are measured for the final wheel.
Sabina Davisedf89472020-02-17 15:27:37 -080034kFinisher = flywheel.FlywheelParams(
35 name='Finisher',
Austin Schuh80476772021-03-06 20:17:36 -080036 motor=AddResistance(control_loop.NMotor(control_loop.Falcon(), 2), 0.01),
Austin Schuhc1c957a2020-02-20 17:47:58 -080037 G=G,
38 J=J,
Austin Schuh43b9ae92020-02-29 23:08:38 -080039 q_pos=0.01,
Austin Schuh80476772021-03-06 20:17:36 -080040 q_vel=10.0,
41 q_voltage=4.0,
42 r_pos=0.01,
43 controller_poles=[.89])
Sabina Davisedf89472020-02-17 15:27:37 -080044
45
46def main(argv):
47 if FLAGS.plot:
Austin Schuhc1c957a2020-02-20 17:47:58 -080048 R = numpy.matrix([[0.0], [500.0], [0.0]])
Austin Schuh43b9ae92020-02-29 23:08:38 -080049 flywheel.PlotSpinup(params=kFinisher, goal=R, iterations=400)
Sabina Davisedf89472020-02-17 15:27:37 -080050 return 0
51
52 if len(argv) != 5:
53 glog.fatal('Expected .h file name and .cc file name')
54 else:
55 namespaces = ['y2020', 'control_loops', 'superstructure', 'finisher']
56 flywheel.WriteFlywheel(kFinisher, argv[1:3], argv[3:5], namespaces)
57
58
59if __name__ == '__main__':
60 argv = FLAGS(sys.argv)
61 sys.exit(main(argv))