blob: 546ead5d696686ee9c939777f05dfa7f127dbc06 [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
Ravago Jones5127ccc2022-07-31 16:32:45 -070021kElevator = linear_system.LinearSystemParams(name='Elevator',
22 motor=control_loop.Vex775Pro(),
23 G=(8.0 / 82.0),
24 radius=2.25 * 0.0254 / 2.0,
25 mass=first_stage_mass +
26 carriage_mass,
27 q_pos=0.070,
28 q_vel=1.35,
29 kalman_q_pos=0.12,
30 kalman_q_vel=2.00,
31 kalman_q_voltage=35.0,
32 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)
Ravago Jones5127ccc2022-07-31 16:32:45 -070046 linear_system.PlotMotion(kElevatorBall,
47 R,
48 max_velocity=5.0,
49 plant_params=kElevatorModel)
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080050
51 # 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 elevator and integral elevator.'
55 )
56 else:
57 namespaces = ['y2019', 'control_loops', 'superstructure', 'elevator']
Tyler Chatow993fe282019-04-06 22:24:36 -070058 linear_system.WriteLinearSystem([kElevator, kElevatorBall, kElevator],
59 argv[1:3], argv[3:5], namespaces)
Austin Schuhb0b6ccb2019-01-20 21:56:33 -080060
61
62if __name__ == '__main__':
63 argv = FLAGS(sys.argv)
64 glog.init()
65 sys.exit(main(argv))