blob: bb6871c311a079a43d95a3287b5e2058322c2657 [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# Inertia for a single 4" diameter, 1" wide neopreme wheel.
17J_wheel = 0.000319
18# Gear ratio between wheels (speed up!)
19G_per_wheel = 1.2
20# Gear ratio to the final wheel.
21G = (30.0 / 40.0) * numpy.power(G_per_wheel, 3.0)
22# Overall flywheel inertia.
23J = J_wheel * (
Austin Schuh80476772021-03-06 20:17:36 -080024 1.0 + numpy.power(G_per_wheel, -2.0) + numpy.power(G_per_wheel, -4.0) + numpy.power(G_per_wheel, -6.0))
Austin Schuhc1c957a2020-02-20 17:47:58 -080025
26# The position and velocity are measured for the final wheel.
Sabina Davisedf89472020-02-17 15:27:37 -080027kAccelerator = flywheel.FlywheelParams(
28 name='Accelerator',
29 motor=control_loop.Falcon(),
Austin Schuhc1c957a2020-02-20 17:47:58 -080030 G=G,
Austin Schuh80476772021-03-06 20:17:36 -080031 J=J * 1.3,
Austin Schuh43b9ae92020-02-29 23:08:38 -080032 q_pos=0.01,
33 q_vel=40.0,
Austin Schuh80476772021-03-06 20:17:36 -080034 q_voltage=1.0,
35 r_pos=0.03,
36 controller_poles=[.89])
Sabina Davisedf89472020-02-17 15:27:37 -080037
38
39def main(argv):
40 if FLAGS.plot:
Austin Schuh989a3132020-02-20 18:20:06 -080041 R = numpy.matrix([[0.0], [500.0], [0.0]])
Austin Schuh43b9ae92020-02-29 23:08:38 -080042 flywheel.PlotSpinup(kAccelerator, goal=R, iterations=400)
Sabina Davisedf89472020-02-17 15:27:37 -080043 return 0
44
Austin Schuh43b9ae92020-02-29 23:08:38 -080045 glog.debug("J is %f" % J)
46
Sabina Davisedf89472020-02-17 15:27:37 -080047 if len(argv) != 5:
48 glog.fatal('Expected .h file name and .cc file name')
49 else:
50 namespaces = [
51 'y2020', 'control_loops', 'superstructure', 'accelerator'
52 ]
53 flywheel.WriteFlywheel(kAccelerator, argv[1:3], argv[3:5], namespaces)
54
55
56if __name__ == '__main__':
57 argv = FLAGS(sys.argv)
Austin Schuh43b9ae92020-02-29 23:08:38 -080058 glog.init()
Sabina Davisedf89472020-02-17 15:27:37 -080059 sys.exit(main(argv))