Add constraints to an OCP. Link differential equation to an OCP. Usage: * ocp.subjectTo(acado.DifferentialEquation) OCP w.r.t. a differential equation. This line should always be added in the OCP formulation! All other subjectto's are optional. >> ocp.subjectTo(f) * ocp.subjectTo(acado.DifferentialEquation, n) OCP w.r.t. a differential equation. "n" is the number of control intervals (use this in a multi stage OCP) >> ocp.subjectTo(f, 10) * ocp.subjectTo( 'AT_START', expression ); Add an Initial constraint for expression. This constraint should only be satisfied in the beginning (eg fix initial values) >> ocp.subjectTo( 'AT_START', x == 1.0 ); >> ocp.subjectTo( 'AT_START', x+y == sin(pi) ); * ocp.subjectTo( 'AT_END', expression ); Add a terminal constraint for expression. This constraint should only be satisfied at the end (eg fix a terminal value) >> ocp.subjectTo( 'AT_END', x == 10.0 ); * ocp.subjectTo( expression ); Add a path constraint (should always be satisfield). >> ocp.subjectTo( 0.1 <= p <= 2.0 ); (P should be between certain bounds) >> ocp.subjectTo( 0.1 == p ); (P should always be fixed to 0.1 over the entire interval. Use this to fix for example a parameters) >> ocp.subjectTo( 0.1 == (p + cos(m))/2 ); (More difficult expresssions are also allowed) >> ocp.subjectTo( p == MATRIX ) (Matrix contains as first column time points and as second column reference values for p on these specific time points. Use this to set a trajectory for values over time. You can for example use this for time varying paramters. When you have a certain input trajectory which is fixed, define a control and use this notation to fix the input) * ocp.subjectTo( 0.0, r , -r , 0.0 ); Adds a constraint of the form lb_ <= arg1(0) + arg_2(T) <= ub with constant lower and upper bounds. Licence: This file is part of ACADO Toolkit - (http://www.acadotoolkit.org/) ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization. Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven. Developed within the Optimization in Engineering Center (OPTEC) under supervision of Moritz Diehl. All rights reserved. ACADO Toolkit is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ACADO Toolkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with ACADO Toolkit; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Author: David Ariens Date: 2009-2010
0001 function subjectTo(obj, varargin) 0002 %Add constraints to an OCP. Link differential equation to an OCP. 0003 % 0004 % Usage: 0005 % * ocp.subjectTo(acado.DifferentialEquation) 0006 % OCP w.r.t. a differential equation. This line should always be added 0007 % in the OCP formulation! All other subjectto's are optional. 0008 % >> ocp.subjectTo(f) 0009 % 0010 % * ocp.subjectTo(acado.DifferentialEquation, n) 0011 % OCP w.r.t. a differential equation. "n" is the number of control 0012 % intervals (use this in a multi stage OCP) 0013 % >> ocp.subjectTo(f, 10) 0014 % 0015 % * ocp.subjectTo( 'AT_START', expression ); 0016 % Add an Initial constraint for expression. This constraint should 0017 % only be satisfied in the beginning (eg fix initial values) 0018 % >> ocp.subjectTo( 'AT_START', x == 1.0 ); 0019 % >> ocp.subjectTo( 'AT_START', x+y == sin(pi) ); 0020 % 0021 % * ocp.subjectTo( 'AT_END', expression ); 0022 % Add a terminal constraint for expression. This constraint should 0023 % only be satisfied at the end (eg fix a terminal value) 0024 % >> ocp.subjectTo( 'AT_END', x == 10.0 ); 0025 % 0026 % * ocp.subjectTo( expression ); 0027 % Add a path constraint (should always be satisfield). 0028 % >> ocp.subjectTo( 0.1 <= p <= 2.0 ); 0029 % (P should be between certain bounds) 0030 % >> ocp.subjectTo( 0.1 == p ); 0031 % (P should always be fixed to 0.1 over the entire interval. Use 0032 % this to fix for example a parameters) 0033 % >> ocp.subjectTo( 0.1 == (p + cos(m))/2 ); 0034 % (More difficult expresssions are also allowed) 0035 % >> ocp.subjectTo( p == MATRIX ) 0036 % (Matrix contains as first column time points and as second column 0037 % reference values for p on these specific time points. Use this to 0038 % set a trajectory for values over time. You can for example use 0039 % this for time varying paramters. When you have a certain input 0040 % trajectory which is fixed, define a control and use this notation 0041 % to fix the input) 0042 % 0043 % * ocp.subjectTo( 0.0, r , -r , 0.0 ); 0044 % Adds a constraint of the form lb_ <= arg1(0) + arg_2(T) <= ub with 0045 % constant lower and upper bounds. 0046 % 0047 % 0048 % Licence: 0049 % This file is part of ACADO Toolkit - (http://www.acadotoolkit.org/) 0050 % 0051 % ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization. 0052 % Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven. 0053 % Developed within the Optimization in Engineering Center (OPTEC) under 0054 % supervision of Moritz Diehl. All rights reserved. 0055 % 0056 % ACADO Toolkit is free software; you can redistribute it and/or 0057 % modify it under the terms of the GNU Lesser General Public 0058 % License as published by the Free Software Foundation; either 0059 % version 3 of the License, or (at your option) any later version. 0060 % 0061 % ACADO Toolkit is distributed in the hope that it will be useful, 0062 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0063 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0064 % Lesser General Public License for more details. 0065 % 0066 % You should have received a copy of the GNU Lesser General Public 0067 % License along with ACADO Toolkit; if not, write to the Free Software 0068 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0069 % 0070 % Author: David Ariens 0071 % Date: 2009-2010 0072 % 0073 0074 if (nargin == 2 && isa(varargin{1}, 'acado.DifferentialEquation')) 0075 % ocp.subjectTo( f ); 0076 obj.subjectoItems{end+1} = sprintf('%s', varargin{1}.name); 0077 0078 elseif (nargin == 3 && isa(varargin{1}, 'acado.DifferentialEquation') && isa(varargin{2}, 'numeric')) 0079 % ocp.subjectTo( f, 10 ); 0080 double1 = acado.DoubleConstant(varargin{2}); 0081 obj.subjectoItems{end+1} = sprintf('%s, %s', varargin{1}.name, double1.toString()); 0082 0083 elseif(nargin == 3 && isa(varargin{1}, 'char') && isa(varargin{2}, 'acado.Expression')) 0084 % ocp.subjectTo( 'AT_START', x == 1.0 ); 0085 % ocp.subjectTo( 'AT_END', x == 1.0 ); 0086 obj.subjectoItems{end+1} = sprintf('%s, %s', varargin{1}, varargin{2}.toString()); 0087 0088 elseif(nargin == 2 && isa(varargin{1}, 'acado.Expression')) 0089 % ocp.subjectTo( 0.1 <= p <= 2.0 ); 0090 % ocp.subjectTo( 0.1 == p ); 0091 obj.subjectoItems{end+1} = varargin{1}.toString(); 0092 0093 elseif(nargin == 5 && isa(varargin{1}, 'numeric') && isa(varargin{2}, 'acado.Expression') && isa(varargin{3}, 'acado.Expression') && isa(varargin{4}, 'numeric')) 0094 % ocp.subjectTo( 0.0, r , -r , 0.0 ); 0095 0096 double1 = acado.DoubleConstant(varargin{1}); 0097 double2 = acado.DoubleConstant(varargin{4}); 0098 0099 obj.subjectoItems{end+1} = sprintf('%s, %s, %s, %s',double1.toString(), varargin{2}.toString(), varargin{3}.toString(), double2.toString()); 0100 0101 else 0102 error('ERROR: Invalid subjectTo. <a href="matlab: help acado.OCP.subjectTo">help acado.OCP.subjectTo</a>'); 0103 0104 end 0105 0106 end