The problem was adapted from Example 2, Section 12.4.2 of .
Consider the system illustrated below
consisting of two identical beams with the same property (mass, length and moment of inerita), connected at two actuated joints. The objective is to formulate an optimal control problem to reposition the payload M using minimum time:
With the following assumptions and nondimensionalizations,
the system dynamics can then be expressed as
Additionally, we need 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 TwoLinkRobotArm_Dynamics_Internal with
For this example problem, we do not have any path constraints, so function TwoLinkRobotArm_Dynamics_Internal only need to return the value of variable dx .
Similarly, the (optional) simulation dynamics can be specifed in function TwoLinkRobotArm_Dynamics_Sim .
First we provide the function handles for system dynamics with,
the optional files providing analytic derivatives can be left empty as we use finite difference this time
and the function handle for the settings file.
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)
This problem has both Lagrange (stage) cost and Mayer (boundary) cost , thus we specify
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 sub-routine 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 TwoLinkRobotArm_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 20 mesh points. The computation time with IPOPT (NLP convergence tol set to 1e-09) is about 2 seconds for 4 mesh refinement iterations together, 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.3 seconds and about 10 iterations.
 R. Luus, Iterative Dynamic Programming, Chapman and Hall/CRC Monographs and Surveys in Pure and Applied Mathematics, 2000.