rocket_c.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
35 #include <acado_gnuplot.hpp>
36 
37 
38 /* >>> start tutorial code >>> */
39 
40 
41 // -------------------------------------------------------------------------
42 // C-STYLE DEFINITION OF THE PROBLEM DIMENSIONS:
43 // -------------------------------------------------------------------------
44 
45 
46 #define NJ 1 // number of objective functions
47 #define NX 4 // number of differential states
48 #define NI 4 // number of initial value constraints
49 #define NE 2 // number of end-point / terminal constraints
50 #define NH 1 // number of inequality path constraints
51 
52 
53 // -----------------------------------------------------------------------------
54 // UGLY C-STYLE DEFINITION OF THE OBJECTIVE, MODEL AND CONSTRAINT FUNCTIONS:
55 // -----------------------------------------------------------------------------
56 
57 
58 void myDifferentialEquation( double *x, double *f, void *user_data ){
59 
60  f[0] = x[0];
61  f[1] = (x[2]-0.02*x[0]*x[0])/(1.0+x[1]);
62  f[2] = -0.01*x[2]*x[2];
63  f[3] = x[2]*x[2];
64 }
65 
66 void myObjectiveFunction( double *x, double *f, void *user_data ){
67 
68  f[0] = x[3];
69 }
70 
71 
72 void myInitialValueConstraint( double *x, double *f, void *user_data ){
73 
74  f[0] = x[4];
75  f[1] = x[0];
76  f[2] = x[1];
77  f[3] = x[3];
78 }
79 
80 
81 void myEndPointConstraint( double *x, double *f, void *user_data ){
82 
83  f[0] = x[4] - 10.0;
84  f[1] = x[0];
85 }
86 
87 
88 void myInequalityPathConstraint( double *x, double *f, void *user_data ){
89 
90  f[0] = x[0];
91 }
92 
93 
94 // -------------------------------------------------------------------------
95 // USE THE ACADO TOOLKIT TO SOLVE THE PROBLEM:
96 // -------------------------------------------------------------------------
97 
98 
100 
101 
102 int main( ){
103 
104 
105  // INTRODUCE THE VARIABLES:
106  // --------------------------------------------------
107  DifferentialState s,v,m,L;
108  Control u ;
110 
111 
112  // DEFINE THE DIMENSIONS OF THE C-FUNCTIONS:
113  // --------------------------------------------------
119 
120 
121  // DEFINE THE OPTIMIZATION VARIABLES:
122  // --------------------------------------------------
123 
124  IntermediateState x(5);
125 
126  x(0) = v; x(1) = m; x(2) = u; x(3) = L; x(4) = s;
127 
128 
129  // DEFINE AN OPTIMAL CONTROL PROBLEM:
130  // ----------------------------------
131  OCP ocp( 0.0, 10.0 );
132 
133  ocp.minimizeMayerTerm( M(x) );
134 
135  ocp.subjectTo( f << F(x) );
136 
137  ocp.subjectTo( AT_START, I(x) == 0.0 );
138  ocp.subjectTo( AT_END , E(x) == 0.0 );
139  ocp.subjectTo( H(x) <= 1.3 );
140 
141 
142  // VISUALIZE THE RESULTS IN A GNUPLOT WINDOW:
143  // ------------------------------------------
144  GnuplotWindow window1;
145  window1.addSubplot( s,"DifferentialState s" );
146  window1.addSubplot( v,"DifferentialState v" );
147  window1.addSubplot( m,"DifferentialState m" );
148  window1.addSubplot( u,"Control u" );
149 
150 
151  // DEFINE AN OPTIMIZATION ALGORITHM AND SOLVE THE OCP:
152  // ---------------------------------------------------
153  OptimizationAlgorithm algorithm(ocp);
154  algorithm.set( INTEGRATOR_TOLERANCE, 1e-6 );
155  algorithm.set( KKT_TOLERANCE, 1e-3 );
156  algorithm << window1;
157  algorithm.solve();
158 
159 
160  return 0;
161 }
162 /* <<< end tutorial code <<< */
#define NJ
Definition: rocket_c.cpp:46
User-interface to formulate and solve optimal control problems and static NLPs.
#define USING_NAMESPACE_ACADO
void myInitialValueConstraint(double *x, double *f, void *user_data)
Definition: rocket_c.cpp:72
void myObjectiveFunction(double *x, double *f, void *user_data)
Definition: rocket_c.cpp:66
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
#define NI
Definition: rocket_c.cpp:48
returnValue minimizeMayerTerm(const Expression &arg)
Definition: ocp.cpp:238
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
#define E
#define NX
Definition: rocket_c.cpp:47
Data class for defining optimal control problems.
Definition: ocp.hpp:89
#define v
void myInequalityPathConstraint(double *x, double *f, void *user_data)
Definition: rocket_c.cpp:88
#define L
USING_NAMESPACE_ACADO int main()
Definition: rocket_c.cpp:102
void myEndPointConstraint(double *x, double *f, void *user_data)
Definition: rocket_c.cpp:81
(no description yet)
Definition: c_function.hpp:54
void myDifferentialEquation(double *x, double *f, void *user_data)
Definition: rocket_c.cpp:58
#define NH
Definition: rocket_c.cpp:50
Provides an interface to Gnuplot for plotting algorithmic outputs.
#define NE
Definition: rocket_c.cpp:49
virtual returnValue solve()
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:03