function [t, x, u] = NMPC_mWithaddition(runningcosts, terminalcosts, ...
constraints, terminalconstraints, ...
linearconstraints, system, ...
mpciterations, N, T, tmeasure, xmeasure, u0, yref, varargin)
% nmpc(runningcosts, terminalcosts, constraints, ...
% terminalconstraints, linearconstraints, system, ...
% mpciterations, N, T, tmeasure, xmeasure, u0, ...
% tol_opt, opt_option, ...
% type, atol_ode_real, rtol_ode_real, atol_ode_sim, rtol_ode_sim, ...
% iprint, printHeader, printClosedloopData, plotTrajectories)
% Computes the closed loop solution for the NMPC problem defined by
% the functions
% runningcosts: evaluates the running costs for state and control
% at one sampling instant.
% The function returns the running costs for one
% sampling instant.
% Usage: [cost] = runningcosts(t, x, u)
% with time t, state x and control u
% terminalcosts: evaluates the terminal costs for state at the end
% of the open loop horizon.
% The function returns value of the terminal costs.
% Usage: cost = terminalcosts(t, x)
% with time t and state x
% constraints: computes the value of the restrictions for a
% sampling instance provided the data t, x and u
% given by the optimization method.
% The function returns the value of the
% restrictions for a sampling instance separated
% for inequality restrictions c and equality
% restrictions ceq.
% Usage: [c,ceq] = constraints(t, x, u)
% with time t, state x and control u
% terminalconstraints: computes the value of the terminal restrictions
% provided the data t, x and u given by the
% optimization method.
% The function returns the value of the
% terminal restriction for inequality restrictions
% c and equality restrictions ceq.
% Usage: [c,ceq] = terminalconstraints(t, x)
% with time t and state x
% linearconstraints: sets the linear constraints of the discretized
% optimal control problem. This is particularly
% useful to set control and state bounds.
% The function returns the required matrices for
% the linear inequality and equality constraints A
% and Aeq, the corresponding right hand sides b and
% beq as well as the lower and upper bound of the
% control.
% Usage: [A, b, Aeq, beq, lb, ub] = linearconstraints(t, x, u)
% with time t, state x and control u
% system: evaluates the difference equation describing the
% process given time t, state vector x and control
% u.
% The function returns the state vector x at the
% next time instant.
% Usage: [y] = system(t, x, u, T)
% with time t, state x, control u and sampling interval T
% for a given number of NMPC iteration steps (mpciterations). For
% the open loop problem, the horizon is defined by the number of
% time instances N and the sampling time T. Note that the dynamic
% can also be the solution of a differential equation. Moreover, the
% initial time tmeasure, the state measurement xmeasure and a guess of
% the optimal control u0 are required.
%
% Arguments:
% mpciterations: Number of MPC iterations to be performed
% N: Length of optimization horizon
% T: Sampling interval
% tmeasure: Time measurement of initial value
% xmeasure: State measurement of initial value
% u0: Initial guess of open loop control
%
% Optional arguments:
% iprint: = 0 Print closed loop data(default)
% = 1 Print closed loop data and errors of the
% optimization method
% = 2 Print closed loop data and errors and warnings of
% the optimization method
% >= 5 Print closed loop data and errors and warnings of
% the optimization method as well as graphical
% output of closed loop state trajectories
% >=10 Print closed loop data and errors and warnings of
% the optimization method with error and warning
% description
% printHeader: Clarifying header for selective output of closed
% loop data, cf. printClosedloopData
% printClosedloopData: Selective output of closed loop data
% plotTrajectories: Graphical output of the trajectories, requires
% iprint >= 4
% tol_opt: Tolerance of the optimization method
% opt_option: = 0: Active-set method used for optimization (default)
% = 1: Interior-point method used for optimization
% = 2: Trust-region reflective method used for
% optimization
% type: Type of dynamic, either difference equation or
% differential equation can be used
% atol_ode_real: Absolute tolerance of the ODE solver for the
% simulated process
% rtol_ode_real: Relative tolerance of the ODE solver for the
% simulated process
% atol_ode_sim: Absolute tolerance of the ODE solver for the
% simulated NMPC prediction
% rtol_ode_sim: Relative tolerance of the ODE solver for the
% simulated NMPC prediction
%
% Internal Functions:
% measureInitialValue: measures the new initial values for t0
% and x0 by adopting values computed by
% method applyControl.
% The function returns new initial state
% vector x0 at sampling instant t0.
% applyControl: applies the first control element of u to
% the simulated process for one sampling
% interval T.
% The function returns closed loop state
% vector xapplied at sampling instant
% tapplied.
% shiftHorizon: applies the shift method to the open loop
% control in order to ease the restart.
% The function returns a new initial guess
% u0 of the control.
% solveOptimalControlProblem: solves the optimal control problem of the
% horizon N with sampling length T for the
% given initial values t0 and x0 and the
% initial guess u0 using the specified
% algorithm.
% The function returns the computed optimal
% control u, the corresponding value of the
% cost function V as well as possible exit
% flags and additional output of the
% optimization method.
% costfunction: evaluates the cost function of the
%
评论1