blob: 7e703fce586ec05dac1cda1fe182907ea58b6aa0 [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 Schuheb240f62021-11-07 19:57:06 -080023J = 0.0035
Austin Schuh80476772021-03-06 20:17:36 -080024
Ravago Jones5127ccc2022-07-31 16:32:45 -070025
Austin Schuh80476772021-03-06 20:17:36 -080026def AddResistance(motor, resistance):
27 motor.resistance += resistance
28 return motor
29
Ravago Jones5127ccc2022-07-31 16:32:45 -070030
Austin Schuh80476772021-03-06 20:17:36 -080031def ScaleKv(motor, scale):
32 motor.Kv *= scale
33 return motor
Austin Schuhc1c957a2020-02-20 17:47:58 -080034
Ravago Jones5127ccc2022-07-31 16:32:45 -070035
Austin Schuhc1c957a2020-02-20 17:47:58 -080036# The position and velocity are measured for the final wheel.
Sabina Davisedf89472020-02-17 15:27:37 -080037kFinisher = flywheel.FlywheelParams(
38 name='Finisher',
Austin Schuh5c40ea42021-09-26 13:28:03 -070039 motor=AddResistance(control_loop.NMotor(control_loop.Falcon(), 2), 0.03),
Austin Schuhc1c957a2020-02-20 17:47:58 -080040 G=G,
41 J=J,
Austin Schuh43b9ae92020-02-29 23:08:38 -080042 q_pos=0.01,
Austin Schuh80476772021-03-06 20:17:36 -080043 q_vel=10.0,
44 q_voltage=4.0,
45 r_pos=0.01,
Austin Schuheb240f62021-11-07 19:57:06 -080046 controller_poles=[.93])
Sabina Davisedf89472020-02-17 15:27:37 -080047
48
49def main(argv):
50 if FLAGS.plot:
Austin Schuhc1c957a2020-02-20 17:47:58 -080051 R = numpy.matrix([[0.0], [500.0], [0.0]])
Austin Schuh43b9ae92020-02-29 23:08:38 -080052 flywheel.PlotSpinup(params=kFinisher, goal=R, iterations=400)
Sabina Davisedf89472020-02-17 15:27:37 -080053 return 0
54
55 if len(argv) != 5:
56 glog.fatal('Expected .h file name and .cc file name')
57 else:
58 namespaces = ['y2020', 'control_loops', 'superstructure', 'finisher']
59 flywheel.WriteFlywheel(kFinisher, argv[1:3], argv[3:5], namespaces)
60
61
62if __name__ == '__main__':
63 argv = FLAGS(sys.argv)
Austin Schuheb240f62021-11-07 19:57:06 -080064 glog.init()
Sabina Davisedf89472020-02-17 15:27:37 -080065 sys.exit(main(argv))