blob: c81d597b43608bfd4b42e09b78805e6340bfcdd6 [file] [log] [blame]
Comran Morshed2a97bc82016-01-16 17:27:01 +00001#!/usr/bin/python
2
3from frc971.control_loops.python import control_loop
4import numpy
5import sys
6from matplotlib import pylab
7
8class Shooter(control_loop.ControlLoop):
9 def __init__(self):
10 super(Shooter, self).__init__("Shooter")
11 # Stall Torque in N m
Austin Schuhd9e55782016-01-31 00:30:05 -080012 self.stall_torque = 0.71
Comran Morshed2a97bc82016-01-16 17:27:01 +000013 # Stall Current in Amps
Austin Schuhd9e55782016-01-31 00:30:05 -080014 self.stall_current = 134
Comran Morshed2a97bc82016-01-16 17:27:01 +000015 # Free Speed in RPM
Austin Schuhd9e55782016-01-31 00:30:05 -080016 self.free_speed = 18730.0
Comran Morshed2a97bc82016-01-16 17:27:01 +000017 # Free Current in Amps
Austin Schuhd9e55782016-01-31 00:30:05 -080018 self.free_current = 0.7
Comran Morshed2a97bc82016-01-16 17:27:01 +000019 # Moment of inertia of the shooter wheel in kg m^2
Austin Schuhd9e55782016-01-31 00:30:05 -080020 self.J = 0.00032
Comran Morshed2a97bc82016-01-16 17:27:01 +000021 # Resistance of the motor, divided by 2 to account for the 2 motors
Austin Schuhd9e55782016-01-31 00:30:05 -080022 self.R = 12.0 / self.stall_current
Comran Morshed2a97bc82016-01-16 17:27:01 +000023 # Motor velocity constant
24 self.Kv = ((self.free_speed / 60.0 * 2.0 * numpy.pi) /
25 (12.0 - self.R * self.free_current))
26 # Torque constant
27 self.Kt = self.stall_torque / self.stall_current
28 # Gear ratio
Austin Schuhd9e55782016-01-31 00:30:05 -080029 self.G = 12.0 / 18.0
Comran Morshed2a97bc82016-01-16 17:27:01 +000030 # Control loop time step
31 self.dt = 0.005
32
33 # State feedback matrices
Comran Morshedcde50322016-01-18 15:10:36 +000034 # [position, angular velocity]
Comran Morshed2a97bc82016-01-16 17:27:01 +000035 self.A_continuous = numpy.matrix(
36 [[0, 1],
37 [0, -self.Kt / self.Kv / (self.J * self.G * self.G * self.R)]])
38 self.B_continuous = numpy.matrix(
39 [[0],
40 [self.Kt / (self.J * self.G * self.R)]])
41 self.C = numpy.matrix([[1, 0]])
42 self.D = numpy.matrix([[0]])
43
44 self.A, self.B = self.ContinuousToDiscrete(
45 self.A_continuous, self.B_continuous, self.dt)
46
47 self.PlaceControllerPoles([.6, .981])
48
49 self.rpl = .45
50 self.ipl = 0.07
51 self.PlaceObserverPoles([self.rpl + 1j * self.ipl,
52 self.rpl - 1j * self.ipl])
53
54 self.U_max = numpy.matrix([[12.0]])
55 self.U_min = numpy.matrix([[-12.0]])
56
57
58def main(argv):
59 if len(argv) != 3:
60 print "Expected .h file name and .cc file name"
61 else:
62 namespaces = ['y2016', 'control_loops', 'shooter']
63 shooter = Shooter()
64 loop_writer = control_loop.ControlLoopWriter("Shooter", [shooter],
65 namespaces=namespaces)
66 if argv[1][-3:] == '.cc':
67 loop_writer.Write(argv[2], argv[1])
68 else:
69 loop_writer.Write(argv[1], argv[2])
70
71
72if __name__ == '__main__':
73 sys.exit(main(sys.argv))