Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 1 | import controls |
| 2 | import numpy |
Austin Schuh | 572ff40 | 2015-11-08 12:17:50 -0800 | [diff] [blame] | 3 | import os |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 4 | |
Ben Fredrickson | 1b45f78 | 2014-02-23 07:44:36 +0000 | [diff] [blame] | 5 | class Constant(object): |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 6 | def __init__ (self, name, formatt, value): |
| 7 | self.name = name |
| 8 | self.formatt = formatt |
| 9 | self.value = value |
| 10 | self.formatToType = {} |
Brian Silverman | 4e55e58 | 2015-11-10 14:16:37 -0500 | [diff] [blame] | 11 | self.formatToType['%f'] = "double" |
| 12 | self.formatToType['%d'] = "int" |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 13 | def __str__ (self): |
| 14 | return str("\nstatic constexpr %s %s = "+ self.formatt +";\n") % \ |
| 15 | (self.formatToType[self.formatt], self.name, self.value) |
Ben Fredrickson | 1b45f78 | 2014-02-23 07:44:36 +0000 | [diff] [blame] | 16 | |
| 17 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 18 | class ControlLoopWriter(object): |
Ben Fredrickson | 1b45f78 | 2014-02-23 07:44:36 +0000 | [diff] [blame] | 19 | def __init__(self, gain_schedule_name, loops, namespaces=None, write_constants=False): |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 20 | """Constructs a control loop writer. |
| 21 | |
| 22 | Args: |
| 23 | gain_schedule_name: string, Name of the overall controller. |
| 24 | loops: array[ControlLoop], a list of control loops to gain schedule |
| 25 | in order. |
| 26 | namespaces: array[string], a list of names of namespaces to nest in |
| 27 | order. If None, the default will be used. |
| 28 | """ |
| 29 | self._gain_schedule_name = gain_schedule_name |
| 30 | self._loops = loops |
| 31 | if namespaces: |
| 32 | self._namespaces = namespaces |
| 33 | else: |
| 34 | self._namespaces = ['frc971', 'control_loops'] |
| 35 | |
| 36 | self._namespace_start = '\n'.join( |
| 37 | ['namespace %s {' % name for name in self._namespaces]) |
| 38 | |
| 39 | self._namespace_end = '\n'.join( |
| 40 | ['} // namespace %s' % name for name in reversed(self._namespaces)]) |
Ben Fredrickson | 1b45f78 | 2014-02-23 07:44:36 +0000 | [diff] [blame] | 41 | |
| 42 | self._constant_list = [] |
Austin Schuh | 2593385 | 2014-02-23 02:04:13 -0800 | [diff] [blame] | 43 | |
| 44 | def AddConstant(self, constant): |
| 45 | """Adds a constant to write. |
| 46 | |
| 47 | Args: |
| 48 | constant: Constant, the constant to add to the header. |
| 49 | """ |
| 50 | self._constant_list.append(constant) |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 51 | |
Brian Silverman | e51ad63 | 2014-01-08 15:12:29 -0800 | [diff] [blame] | 52 | def _TopDirectory(self): |
| 53 | return self._namespaces[0] |
| 54 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 55 | def _HeaderGuard(self, header_file): |
Austin Schuh | 572ff40 | 2015-11-08 12:17:50 -0800 | [diff] [blame] | 56 | return ('_'.join([namespace.upper() for namespace in self._namespaces]) + |
| 57 | os.path.basename(header_file).upper() |
| 58 | .replace('.', '_').replace('/', '_') + '_') |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 59 | |
| 60 | def Write(self, header_file, cc_file): |
| 61 | """Writes the loops to the specified files.""" |
| 62 | self.WriteHeader(header_file) |
Austin Schuh | 572ff40 | 2015-11-08 12:17:50 -0800 | [diff] [blame] | 63 | self.WriteCC(os.path.basename(header_file), cc_file) |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 64 | |
| 65 | def _GenericType(self, typename): |
| 66 | """Returns a loop template using typename for the type.""" |
| 67 | num_states = self._loops[0].A.shape[0] |
| 68 | num_inputs = self._loops[0].B.shape[1] |
| 69 | num_outputs = self._loops[0].C.shape[0] |
| 70 | return '%s<%d, %d, %d>' % ( |
| 71 | typename, num_states, num_inputs, num_outputs) |
| 72 | |
| 73 | def _ControllerType(self): |
| 74 | """Returns a template name for StateFeedbackController.""" |
| 75 | return self._GenericType('StateFeedbackController') |
| 76 | |
| 77 | def _LoopType(self): |
| 78 | """Returns a template name for StateFeedbackLoop.""" |
| 79 | return self._GenericType('StateFeedbackLoop') |
| 80 | |
| 81 | def _PlantType(self): |
| 82 | """Returns a template name for StateFeedbackPlant.""" |
| 83 | return self._GenericType('StateFeedbackPlant') |
| 84 | |
| 85 | def _CoeffType(self): |
| 86 | """Returns a template name for StateFeedbackPlantCoefficients.""" |
| 87 | return self._GenericType('StateFeedbackPlantCoefficients') |
| 88 | |
James Kuszmaul | 0e86651 | 2014-02-21 13:12:52 -0800 | [diff] [blame] | 89 | def WriteHeader(self, header_file, double_appendage=False, MoI_ratio=0.0): |
| 90 | """Writes the header file to the file named header_file. |
| 91 | Set double_appendage to true in order to include a ratio of |
| 92 | moments of inertia constant. Currently, only used for 2014 claw.""" |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 93 | with open(header_file, 'w') as fd: |
| 94 | header_guard = self._HeaderGuard(header_file) |
| 95 | fd.write('#ifndef %s\n' |
| 96 | '#define %s\n\n' % (header_guard, header_guard)) |
| 97 | fd.write('#include \"frc971/control_loops/state_feedback_loop.h\"\n') |
| 98 | fd.write('\n') |
| 99 | |
| 100 | fd.write(self._namespace_start) |
Ben Fredrickson | 1b45f78 | 2014-02-23 07:44:36 +0000 | [diff] [blame] | 101 | |
| 102 | for const in self._constant_list: |
| 103 | fd.write(str(const)) |
| 104 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 105 | fd.write('\n\n') |
| 106 | for loop in self._loops: |
| 107 | fd.write(loop.DumpPlantHeader()) |
| 108 | fd.write('\n') |
| 109 | fd.write(loop.DumpControllerHeader()) |
| 110 | fd.write('\n') |
| 111 | |
| 112 | fd.write('%s Make%sPlant();\n\n' % |
| 113 | (self._PlantType(), self._gain_schedule_name)) |
| 114 | |
| 115 | fd.write('%s Make%sLoop();\n\n' % |
| 116 | (self._LoopType(), self._gain_schedule_name)) |
| 117 | |
| 118 | fd.write(self._namespace_end) |
| 119 | fd.write('\n\n') |
| 120 | fd.write("#endif // %s\n" % header_guard) |
| 121 | |
| 122 | def WriteCC(self, header_file_name, cc_file): |
| 123 | """Writes the cc file to the file named cc_file.""" |
| 124 | with open(cc_file, 'w') as fd: |
Austin Schuh | 572ff40 | 2015-11-08 12:17:50 -0800 | [diff] [blame] | 125 | fd.write('#include \"%s/%s\"\n' % |
| 126 | (os.path.join(*self._namespaces), header_file_name)) |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 127 | fd.write('\n') |
| 128 | fd.write('#include <vector>\n') |
| 129 | fd.write('\n') |
| 130 | fd.write('#include \"frc971/control_loops/state_feedback_loop.h\"\n') |
| 131 | fd.write('\n') |
| 132 | fd.write(self._namespace_start) |
| 133 | fd.write('\n\n') |
| 134 | for loop in self._loops: |
| 135 | fd.write(loop.DumpPlant()) |
| 136 | fd.write('\n') |
| 137 | |
| 138 | for loop in self._loops: |
| 139 | fd.write(loop.DumpController()) |
| 140 | fd.write('\n') |
| 141 | |
| 142 | fd.write('%s Make%sPlant() {\n' % |
| 143 | (self._PlantType(), self._gain_schedule_name)) |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 144 | fd.write(' ::std::vector< ::std::unique_ptr<%s>> plants(%d);\n' % ( |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 145 | self._CoeffType(), len(self._loops))) |
| 146 | for index, loop in enumerate(self._loops): |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 147 | fd.write(' plants[%d] = ::std::unique_ptr<%s>(new %s(%s));\n' % |
| 148 | (index, self._CoeffType(), self._CoeffType(), |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 149 | loop.PlantFunction())) |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 150 | fd.write(' return %s(&plants);\n' % self._PlantType()) |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 151 | fd.write('}\n\n') |
| 152 | |
| 153 | fd.write('%s Make%sLoop() {\n' % |
| 154 | (self._LoopType(), self._gain_schedule_name)) |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 155 | fd.write(' ::std::vector< ::std::unique_ptr<%s>> controllers(%d);\n' % ( |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 156 | self._ControllerType(), len(self._loops))) |
| 157 | for index, loop in enumerate(self._loops): |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 158 | fd.write(' controllers[%d] = ::std::unique_ptr<%s>(new %s(%s));\n' % |
| 159 | (index, self._ControllerType(), self._ControllerType(), |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 160 | loop.ControllerFunction())) |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 161 | fd.write(' return %s(&controllers);\n' % self._LoopType()) |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 162 | fd.write('}\n\n') |
| 163 | |
| 164 | fd.write(self._namespace_end) |
| 165 | fd.write('\n') |
| 166 | |
| 167 | |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 168 | class ControlLoop(object): |
| 169 | def __init__(self, name): |
| 170 | """Constructs a control loop object. |
| 171 | |
| 172 | Args: |
| 173 | name: string, The name of the loop to use when writing the C++ files. |
| 174 | """ |
| 175 | self._name = name |
| 176 | |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 177 | def ContinuousToDiscrete(self, A_continuous, B_continuous, dt): |
| 178 | """Calculates the discrete time values for A and B. |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 179 | |
| 180 | Args: |
| 181 | A_continuous: numpy.matrix, The continuous time A matrix |
| 182 | B_continuous: numpy.matrix, The continuous time B matrix |
| 183 | dt: float, The time step of the control loop |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 184 | |
| 185 | Returns: |
| 186 | (A, B), numpy.matrix, the control matricies. |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 187 | """ |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 188 | return controls.c2d(A_continuous, B_continuous, dt) |
| 189 | |
| 190 | def InitializeState(self): |
| 191 | """Sets X, Y, and X_hat to zero defaults.""" |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 192 | self.X = numpy.zeros((self.A.shape[0], 1)) |
Austin Schuh | c1f6889 | 2013-03-16 17:06:27 -0700 | [diff] [blame] | 193 | self.Y = self.C * self.X |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 194 | self.X_hat = numpy.zeros((self.A.shape[0], 1)) |
| 195 | |
| 196 | def PlaceControllerPoles(self, poles): |
| 197 | """Places the controller poles. |
| 198 | |
| 199 | Args: |
| 200 | poles: array, An array of poles. Must be complex conjegates if they have |
| 201 | any imaginary portions. |
| 202 | """ |
| 203 | self.K = controls.dplace(self.A, self.B, poles) |
| 204 | |
| 205 | def PlaceObserverPoles(self, poles): |
| 206 | """Places the observer poles. |
| 207 | |
| 208 | Args: |
| 209 | poles: array, An array of poles. Must be complex conjegates if they have |
| 210 | any imaginary portions. |
| 211 | """ |
| 212 | self.L = controls.dplace(self.A.T, self.C.T, poles).T |
| 213 | |
| 214 | def Update(self, U): |
| 215 | """Simulates one time step with the provided U.""" |
Austin Schuh | 1d00573 | 2015-03-01 00:10:20 -0800 | [diff] [blame] | 216 | #U = numpy.clip(U, self.U_min, self.U_max) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 217 | self.X = self.A * self.X + self.B * U |
| 218 | self.Y = self.C * self.X + self.D * U |
| 219 | |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 220 | def PredictObserver(self, U): |
| 221 | """Runs the predict step of the observer update.""" |
| 222 | self.X_hat = (self.A * self.X_hat + self.B * U) |
| 223 | |
| 224 | def CorrectObserver(self, U): |
| 225 | """Runs the correct step of the observer update.""" |
| 226 | self.X_hat += numpy.linalg.inv(self.A) * self.L * ( |
| 227 | self.Y - self.C * self.X_hat - self.D * U) |
| 228 | |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 229 | def UpdateObserver(self, U): |
| 230 | """Updates the observer given the provided U.""" |
| 231 | self.X_hat = (self.A * self.X_hat + self.B * U + |
| 232 | self.L * (self.Y - self.C * self.X_hat - self.D * U)) |
| 233 | |
| 234 | def _DumpMatrix(self, matrix_name, matrix): |
| 235 | """Dumps the provided matrix into a variable called matrix_name. |
| 236 | |
| 237 | Args: |
| 238 | matrix_name: string, The variable name to save the matrix to. |
| 239 | matrix: The matrix to dump. |
| 240 | |
| 241 | Returns: |
| 242 | string, The C++ commands required to populate a variable named matrix_name |
| 243 | with the contents of matrix. |
| 244 | """ |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 245 | ans = [' Eigen::Matrix<double, %d, %d> %s;\n' % ( |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 246 | matrix.shape[0], matrix.shape[1], matrix_name)] |
| 247 | first = True |
Brian Silverman | 0f63738 | 2013-03-03 17:44:46 -0800 | [diff] [blame] | 248 | for x in xrange(matrix.shape[0]): |
| 249 | for y in xrange(matrix.shape[1]): |
Austin Schuh | 7ec34fd | 2014-02-15 22:27:46 -0800 | [diff] [blame] | 250 | element = matrix[x, y] |
Brian Silverman | 0f63738 | 2013-03-03 17:44:46 -0800 | [diff] [blame] | 251 | if first: |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 252 | ans.append(' %s << ' % matrix_name) |
Brian Silverman | 0f63738 | 2013-03-03 17:44:46 -0800 | [diff] [blame] | 253 | first = False |
| 254 | else: |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 255 | ans.append(', ') |
Brian Silverman | 0f63738 | 2013-03-03 17:44:46 -0800 | [diff] [blame] | 256 | ans.append(str(element)) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 257 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 258 | ans.append(';\n') |
| 259 | return ''.join(ans) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 260 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 261 | def DumpPlantHeader(self): |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 262 | """Writes out a c++ header declaration which will create a Plant object. |
| 263 | |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 264 | Returns: |
| 265 | string, The header declaration for the function. |
| 266 | """ |
| 267 | num_states = self.A.shape[0] |
| 268 | num_inputs = self.B.shape[1] |
| 269 | num_outputs = self.C.shape[0] |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 270 | return 'StateFeedbackPlantCoefficients<%d, %d, %d> Make%sPlantCoefficients();\n' % ( |
| 271 | num_states, num_inputs, num_outputs, self._name) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 272 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 273 | def DumpPlant(self): |
| 274 | """Writes out a c++ function which will create a PlantCoefficients object. |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 275 | |
| 276 | Returns: |
| 277 | string, The function which will create the object. |
| 278 | """ |
| 279 | num_states = self.A.shape[0] |
| 280 | num_inputs = self.B.shape[1] |
| 281 | num_outputs = self.C.shape[0] |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 282 | ans = ['StateFeedbackPlantCoefficients<%d, %d, %d>' |
| 283 | ' Make%sPlantCoefficients() {\n' % ( |
| 284 | num_states, num_inputs, num_outputs, self._name)] |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 285 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 286 | ans.append(self._DumpMatrix('A', self.A)) |
| 287 | ans.append(self._DumpMatrix('B', self.B)) |
| 288 | ans.append(self._DumpMatrix('C', self.C)) |
| 289 | ans.append(self._DumpMatrix('D', self.D)) |
| 290 | ans.append(self._DumpMatrix('U_max', self.U_max)) |
| 291 | ans.append(self._DumpMatrix('U_min', self.U_min)) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 292 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 293 | ans.append(' return StateFeedbackPlantCoefficients<%d, %d, %d>' |
| 294 | '(A, B, C, D, U_max, U_min);\n' % (num_states, num_inputs, |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 295 | num_outputs)) |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 296 | ans.append('}\n') |
| 297 | return ''.join(ans) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 298 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 299 | def PlantFunction(self): |
| 300 | """Returns the name of the plant coefficient function.""" |
| 301 | return 'Make%sPlantCoefficients()' % self._name |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 302 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 303 | def ControllerFunction(self): |
| 304 | """Returns the name of the controller function.""" |
| 305 | return 'Make%sController()' % self._name |
| 306 | |
| 307 | def DumpControllerHeader(self): |
| 308 | """Writes out a c++ header declaration which will create a Controller object. |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 309 | |
| 310 | Returns: |
| 311 | string, The header declaration for the function. |
| 312 | """ |
| 313 | num_states = self.A.shape[0] |
| 314 | num_inputs = self.B.shape[1] |
| 315 | num_outputs = self.C.shape[0] |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 316 | return 'StateFeedbackController<%d, %d, %d> %s;\n' % ( |
| 317 | num_states, num_inputs, num_outputs, self.ControllerFunction()) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 318 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 319 | def DumpController(self): |
| 320 | """Returns a c++ function which will create a Controller object. |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 321 | |
| 322 | Returns: |
| 323 | string, The function which will create the object. |
| 324 | """ |
| 325 | num_states = self.A.shape[0] |
| 326 | num_inputs = self.B.shape[1] |
| 327 | num_outputs = self.C.shape[0] |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 328 | ans = ['StateFeedbackController<%d, %d, %d> %s {\n' % ( |
| 329 | num_states, num_inputs, num_outputs, self.ControllerFunction())] |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 330 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 331 | ans.append(self._DumpMatrix('L', self.L)) |
| 332 | ans.append(self._DumpMatrix('K', self.K)) |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 333 | ans.append(self._DumpMatrix('A_inv', numpy.linalg.inv(self.A))) |
Austin Schuh | 3c54231 | 2013-02-24 01:53:50 -0800 | [diff] [blame] | 334 | |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 335 | ans.append(' return StateFeedbackController<%d, %d, %d>' |
Austin Schuh | 1a38796 | 2015-01-31 16:36:20 -0800 | [diff] [blame] | 336 | '(L, K, A_inv, Make%sPlantCoefficients());\n' % ( |
| 337 | num_states, num_inputs, num_outputs, self._name)) |
Austin Schuh | e349062 | 2013-03-13 01:24:30 -0700 | [diff] [blame] | 338 | ans.append('}\n') |
| 339 | return ''.join(ans) |