Optimal control module by murrayrm · Pull Request #549 · python-control/python-control
This PR adds a new optimal control module, control.optimal, that implements finite horizon optimal control problems with constraints, including rudimentary model predictive control (MPC). The underlying algorithms are not super-efficient, so this is more of a "reference implementation" than something that you could use on a large problem, but it does allow you to explore ideas around tradeoffs in various types of cost functions, constraints, and other concepts. The PR includes unit tests and documentation on the use of the module.
(The motivation for this PR is that I'll be teaching an optimal control class next year, and I'd like to have some tools around that students can use to get a feel for the concepts. The hope is to implement most of the concepts that are in my (very incomplete) notes on "Optimization-Based Control".)
A few notes (for feedback):
- I have called the module
control.optimaland it is not loaded by default. So, like thescipy.optimizepackage, you have to load the module separately if you want to use it (control.flatsysis also like this, so there is a precedent). I'm initially called the moduleobc(for optimization-based control, but decided thatoptimalwas probably better (and matchedoptimize`, used in SciPy). - The module is basically just a wrapper around the
scipy.optimize.minimizefunction: it essentially takes the element of an optimal control problem and creates an optimization problem for SciPy to solve. For this reason I have tried to make things consistent withscipy.optimizewhen possible (eg, the form of constraints, the way results are returned). - The unit tests are a bit finicky and seem to depend on what system they are tested on. Everything is working in GitHub Actions, but you'll see some conditional checks in the code for things that work differently there versus my local machine. For this reason, it would be useful if people can try things out on other platforms and let me know what happens.
- Finally, as noted already above, the code is not super efficient, particularly for continuous time systems. You'll see this if you run the
examples/steering-optimal.pyscript, which takes about 30 seconds to do solve some pretty straightforward problems.It also takes about 15 seconds forcontrol/tests/optimal_test.pyto run on my Mac, which can get annoying (a fullpytestrun takes about a 45 seconds, so this is 30% for just one module).
Other changes along the way:
- Added in some functionality to check for unrecognized keywords in the
config.pyparsing function_get_param. - 28 Feb 2021: Added a new 'bezier' basis function in
flatsys, though only a partial implementation (needed for examples of optimizing over a set of basis functions). - 28 Feb 2021: Added a
benchmarkdirectory with some airspeed velocity (asv) benchmarks for optimal control. These are mainly for development purposes, but might be something we use more generally at a future date.
Comments and advice welcome!