blob: b7fc74b0ae06129b6973263894405e5d6c3e187e [file] [log] [blame]
Austin Schuh085eab92020-11-26 13:54:51 -08001#!/usr/bin/python3
Austin Schuhb0b6ccb2019-01-20 21:56:33 -08002
3from frc971.control_loops.python import control_loop
4from frc971.control_loops.python import linear_system
Austin Schuhba23ba92019-02-15 23:03:10 -08005import copy
Austin Schuhb0b6ccb2019-01-20 21:56:33 -08006import numpy
7import sys
8import gflags
9import glog
10
11FLAGS = gflags.FLAGS
12
13try:
14 gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
15except gflags.DuplicateFlagError:
16 pass
17
suneel2bc345d2019-02-09 20:00:56 -080018first_stage_mass = 0.7957
19carriage_mass = 2.754
20
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080021kElevator = linear_system.LinearSystemParams(
22 name='Elevator',
23 motor=control_loop.Vex775Pro(),
24 G=(8.0 / 82.0),
25 radius=2.25 * 0.0254 / 2.0,
suneel2bc345d2019-02-09 20:00:56 -080026 mass=first_stage_mass + carriage_mass,
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080027 q_pos=0.070,
Austin Schuhba23ba92019-02-15 23:03:10 -080028 q_vel=1.35,
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080029 kalman_q_pos=0.12,
30 kalman_q_vel=2.00,
31 kalman_q_voltage=35.0,
Austin Schuh63d095d2019-02-23 11:57:12 -080032 kalman_r_position=0.05)
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080033
Tyler Chatow993fe282019-04-06 22:24:36 -070034kElevatorBall = copy.copy(kElevator)
35kElevatorBall.q_pos = 0.15
36kElevatorBall.q_vel = 1.5
37
Austin Schuhba23ba92019-02-15 23:03:10 -080038kElevatorModel = copy.copy(kElevator)
39kElevatorModel.mass = carriage_mass + first_stage_mass + 1.0
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080040
Tyler Chatow993fe282019-04-06 22:24:36 -070041
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080042def main(argv):
43 if FLAGS.plot:
44 R = numpy.matrix([[1.5], [0.0]])
Tyler Chatow993fe282019-04-06 22:24:36 -070045 linear_system.PlotKick(kElevatorBall, R, plant_params=kElevatorModel)
Austin Schuhba23ba92019-02-15 23:03:10 -080046 linear_system.PlotMotion(
Tyler Chatow993fe282019-04-06 22:24:36 -070047 kElevatorBall, R, max_velocity=5.0, plant_params=kElevatorModel)
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080048
49 # Write the generated constants out to a file.
50 if len(argv) != 5:
51 glog.fatal(
52 'Expected .h file name and .cc file name for the elevator and integral elevator.'
53 )
54 else:
55 namespaces = ['y2019', 'control_loops', 'superstructure', 'elevator']
Tyler Chatow993fe282019-04-06 22:24:36 -070056 linear_system.WriteLinearSystem([kElevator, kElevatorBall, kElevator],
57 argv[1:3], argv[3:5], namespaces)
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080058
59
60if __name__ == '__main__':
61 argv = FLAGS(sys.argv)
62 glog.init()
63 sys.exit(main(argv))