Skip to content

An optimal control software which returns the optimal control law for an arbitrary system when provided with a set of governing equations and user-defined cost functional.

License

Notifications You must be signed in to change notification settings

nicholashirsch/universal-optimal-control-software

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Universal Optimal Control Software (UOCS)

The software functions as a numerical solver for optimal control problems in MATLAB. Given an arbitrary system's dynamic equations as well as any constraints it solves for the optimal control law and corresponding state trajectory as a function of an independent variable and then returns the results to the user.

What is optimal control?

Optimal control is a method of computing the control law of a system which minimizes a scalar value known as a Bolza cost. UOCS computes said law numerically using a technique known as direct hp-LGR colloction. Rather the reutrn an equation for said control law, UOCS simply computes the value of the optimal control exactly (to a specified tolerance) at a series of time points and then returns these to the user. This discrete control can then simply be thought of as a list of commands for the system to follow. One of the great strengths of optimal control is that it can handle highly nonlinear, coupled, and boundary/path constrained systems with far more accuracy than other control techniques. In addition, it is also flexible enough that a single software is able to compute the optimal control for an arbitrary system given its governing equations and a cost functional. See the MIT course on optimal control or Applied Optimal Control by Dr. Arthur E. Bryson Jr and Dr. Yu-Chi-Ho for more information.

How do I use UOCS?

To begin, go to ../UOCS/Example NLPs and create a copy of NLPTemplate.m. Think of this file as a form to fill out which describes your optimal control problem (OCP). Once it's complete, simply run the UOCS.m executive file and when prompted for an NLP paste in the file path of your NLP. Make sure to format it as "/filepath" as UOCS requires the file path to be passed as a string. At the bottom of UOCS.m there is a variable known as plotSettings that can be used to select which plots UOCS should automatically generate. Additionally, the optimal state and controls as a function of the independent variable (denoted "time" in the code) as well as the solver error are all returned.

How do I go about setting up an NLP file?

UOCS is based on the work of Dr. Anil V. Rao at the University of Florida, primarily the contents of a paper titled "Direct Trajectory Optimization and Costate Estimation via an Orthogonal Collocation Method" as well as a course in optimal control which he teaches. A robust knowledge of the theory of numerical methods in optimal control is NOT REQURIED to use UOCS however, once the NLP file is constructed all of that occurs under the hood. The structure of the NLP file (found in NLPTemplate.m) is as follows:

  1. Define any constant system variables.
  2. The dimensions of the state and control. For scalars, put 1, for vectors this corresponds to the number of components in each.
  3. The number of intervals to perform collocation at. When solving for the optimal trajectory, UOCS splits the time interval into several smaller intervals and solves each seperately. The more intervals, the more accurate the final trajectory is. In addition, UOCS must discretize each interval into a series of points. The trajectory is only gauranteed to be within the specified error tolerance (1e-8 by default) at these points. It is recommended to keep the number of points low (3-5 per interval) to avoid Runge phenomenon.
  4. The collocated vector of all terms to optimize (state, control, time, boundaries, etc;) is referred to as the decision vector. UOCS requires a guess from the user as to what the true values of these quantities are to use to begin optimization. This guess does affect convergence but does not have to be anywhere close to exact. The initial and final boundaries refer to the values of the state at the initial and final times. The interior state and control guess represents the value of these quantities at every point along the trajectory within the boundaries. Note that the guess need only be a vector (MATLAB double) of as many components as the state and control have. For the interior trajectories UOCS automatically propagates it to every discrete time point. If the boundary values of the state or time are known in advance, simple input these values.
  5. Path (interior) and boundary constraints on the state and control. These restrict the domain of the optimal values. Path constraints hold along the entirety of the trajectory except at the boundaries where the boundary constraints instead hold. Note that boundary constraints can not be specified on the control. If there are no constraints just input +/- infinity. If the path constraints are equality constraints - that is, the maximum and minimum values are the same, simply input the same value for both. NOTE: THE INITIAL GUESSES FOR ALL FREE VARAIBLES MUST LIE WITHIN THE PATH CONSTRAINTS OR UOCS WILL FAIL.
  6. Define the problem's dynamics as a series of anynomous functions of the state, time, and control. If either are vectors, reference the components using state(:, componentDimension).
  7. Specify the Mayor and Lagrange portions of the Bolza cost functional, also as anonymous functions. If either does not exist, simply input a 0 after the anonymous function handle.
  8. Specify any nonlinear path constraints as an anonymous function as well.

There are a set of example NLP files in ../UOCS/Example NLPs for reference. hyperSensitiveNLP has scalar state and controls while moonLanderNLP has vector state and controls. There are no examples of NLPs with nonlinear constraints at this time, apologies.

How do I create a cost functional?

The only thing besides an initial guess which the user must create themselves is a Bolza cost functional. This can be thought of as the goal of the system. If the user does not have experience with optimal control, one of the following is suggested:

  1. Mayor cost = time(end), no Lagrange cost - optimal control which minimizes final time.
  2. No Mayor cost, Lagrange cost = (state^transposed)(state) - optimal control which the square of the state, thus keeping the state as close to zero at all times within the system's constraints. Given in quadratic form in case the state is a vector.
  3. No Mayor cost, Lagrange cost = (control^transposed)(control) - optimal control which the square of the control, thus keeping the control effort as close to zero at all times within the system's constraints. Given in quadratic form in case the control is a vector.
  4. No Mayor cost, Lagrange cost = (state^transposed)(state) + (control^transposed)(control) - optimal control which the square of the state and control control, thus keeping the state and the control effort as close to zero at all times within the system's constraints. Given in quadratic form in case the state or control are vectors.
  5. No Mayor cost, Lagrange cost = (state^transposed)(state) + 2(state^transposed)(control) + (control^transposed)(control) - optimal control which the square of the state and control control, thus keeping the state and the control effort as close to zero at all times within the system's constraints. Also considers coupling between the state and control my multiplying the two together. Given in quadratic form in case the state or control are vectors.

The 2nd, through 5th cost functionals are all forms of the LQR cost functional without weighting. See the provided Mathworks link if information on including weight matrices is desired. They are useful for states and controls with multiple components where it is more important to keep some components close to zero than others.

Are there any alternatives to UOCS?

Yes! UOCS has many limitations, primarily the inability to handle event constraints, inaccuracy on bang-bang control probelms, and the fact that it's optimizer - Mathworks' fmincon - is not the most robust. If UOCS ever falls short of user need, or a more professional optimal control software is desied, Dr. Anil V. Rao's GPOPS-II can be acquired at a reasonable price.

Can I use UOCS in my project?

UOCS is under the GNU LGPLv3 license. This means that any changes made to UOCS exclusively must be made public, but if UOCS is used within a larger code base (ex. proprietary research or control software) it need not be publicized. However, a nod to this repository would still be appreciated as it would bring it to more peoples' attention. Note that UOCS uses Dirl Haehnel's collocD function to compute it's differentiation matrices under its MIT license.

About

An optimal control software which returns the optimal control law for an arbitrary system when provided with a set of governing equations and user-defined cost functional.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages