The problem was adapted from Example 4.11 from .
Consider the same system as in Bang-bang control
This time, we will formulate an optimal control problem to find the control input trajectory such that the object follows a sine signal for the position, and a cosine signal for the velocity
with Q identify matrix and R=0.0001 for solution uniqueness. The problem need to be solved subject to dynamics constraints
simple bounds on variables
and boundary conditions
We require the numerical solution to fulfill the following accuracy criteria
We can specify the system dynamics in function DoubleIntegratorTracking_Dynamics_Internal with
For this example problem, we do not have any path constraints, so function DoubleIntegratorTracking_Dynamics_Internal only need to return the value of variable dx .
Similarly, the (optional) simulation dynamics can be specifed in function DoubleIntegratorTracking_Dynamics_Sim.m .
First we provide the function handles for system dynamics with
The optional files providing analytic derivatives can be left empty as we demonstrate the use of finite difference this time
and finally the function handle for the settings file is given as.
Next we define the time variables with
For state variables, we need to provide the initial conditions
bounds on intial conditions
bounds on the absolute local and global (integrated) discretization error of state variables
tolerance for state variable box constraint violation
terminal state bounds
and an initial guess of the state trajectory (optional but recommended)
Lastly for control variables, we need to define simple bounds
bounds on the first control action
tolerance for control variable box constraint violation
as well as an initial guess of the input trajectory (optional but recommended)
Since this problem only has a Lagrange (stage) cost , and no Mayer (boundary) cost ,we simply have
for sub-function L_unscaled and E_unscaled respectively.
For this example problem, we do not have additional boundary constraints (in addition to varialbe simple bounds). Thus we can leave routines b_unscaled as it is.
Now we can fetch the problem and options, solve the resultant NLP, and generate some plots for the solution.
Note the last line of code will generate an open-loop simulation, applying the obtained input trajectory to the dynamics defined in DoubleIntegratorTracking_Dynamics_Sim.m , using the Matlab builtin ode113 ODE solver with a step size of 0.01.
Using the Hermite-Simpson discretization scheme of ICLOCS2, the following state and input trajectories are obtained under a mesh refinement scheme starting with 30 mesh points. The computation time with IPOPT (NLP convergence tol set to 1e-09) is about 0.8 seconds with one mesh refinement iteration, using finite difference derivative calculations on an Intel i7-6700 desktop computer. Subsequent recomputation using the same mesh and warm starting will take on average 0.1 seconds and less than 10 iterations.
 J. Betts, Practical Methods for Optimal Control and Estimation Using Nonlinear Programming: Second Edition, Advances in Design and Control, Society for Industrial and Applied Mathematics, 2010.