This is an optimal control solving algorithm using MATLAB's function handle and optimization toolbox. Basic direct shooting algorithm is reformulated, its main idea to discrete control (DSS), or control and state (DMS) to get global optimal input of dynamical system. These code could work on low-dimension simple OCP, with free terminal time
Git link
A simulation tool that uses direct single shooting and direct multiple shooting state control systems.
-
$u\in\Reals^q,x\in\Reals^n$ -
dynamical equation constraint: $$ \dot x=f(x,u,t) $$
-
path constraint in inequality $$ g(x,u,t)\le 0 $$
-
boundary constraint as equality $$ c(x(t_0),x(t_f),u(t_0),u(t_f))=0 $$
-
mixed performance index OR Bolza's objective $$ min_{u(t)}J:=\phi(x,t)+\int_{t_0}^{t_f}L(x,u,t)\text d t $$
-
terminal time
$t_f$ free or pre-defined, the latter is transformed into terminal constraint
DSS algorithm solves a problem in this form:
- discrete
$u(t)$ , into column vector$(p*N)$ by 1, control is assumed constant in each segment - in each segment,
$x(t)=\Phi(x,u,t)$ are solved by RK4 integration - no gradient info needed
DMS algorithm solves a problem in this form:
-
$N$ segment to discrete control-state variables - discrete
$u(t)$ , into column vector$(p*N)$ by 1, control is assumed constant in each segment -
$x(t)$ are also discretized in each segment, and dynamical constraint is emphasized by constraint and solving$x(k+1)-\Phi(x(k),u_k,t)=0$ this equation by RK4 integration - gradient info needed or not, but if provided, better convergence will be when used to highly nonlinear system
initial state known$x_0=[\theta,\omega]^{\mathrm T}=[\pi,0]$,terminal state constraint$[\theta_f,\omega_f]^{\mathrm T}=[0,0]$,terminal time $t_f$free ,and a quadratic criterion $$ \min_{u(t)}=\frac1 2\mathbf x_f^{\mathrm T}\text Q\mathbf x_f+\frac1 2\int_0^{t_f}\text R\mathbf u^2\ \text{s.t.} \begin{bmatrix}\dot\theta\\dot\omega\end{bmatrix}=\begin{bmatrix}\omega\1/I(-mgl\sin\theta+b\omega+u)\end{bmatrix} $$
a moon lander pinpoint landing problem, terminal time
This is a simple problem and you can test your algorithm. DSS and DMS are all well suited.
To find the control angle
As the convergence problem is a little poor, DSS algorithm has to be set with initial value very close to optimal, while DMS is suited to solve it.