crane_ws.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 int main( ){
40 
42 
43 
44  // INTRODUCE THE VARIABLES:
45  // -------------------------
46  DifferentialState x , dx ; // the position of the mounting point and its velocity
47  DifferentialState L , dL ; // the length of the cable and its velocity
48  DifferentialState phi, dphi; // the angle phi and its velocity
49  DifferentialState P0,P1,P2 ; // the variance-covariance states
50 
51  Control ddx, ddL ; // the accelarations
52  Parameter T ; // duration of the maneuver
53  Parameter gamma ; // the confidence level
54 
55  double const g = 9.81; // the gravitational constant
56  double const m = 10.0; // the mass at the end of the crane
57  double const b = 0.1 ; // a frictional constant
58 
59  DifferentialEquation f(0.0,T);
60 
61  const double F2 = 50.0;
62 
63 
64  // DEFINE A DIFFERENTIAL EQUATION:
65  // -------------------------------
66  f << dot(x ) == dx + 0.000001*gamma; // small regularization term
67  f << dot(dx ) == ddx ;
68  f << dot(L ) == dL ;
69  f << dot(dL ) == ddL ;
70  f << dot(phi ) == dphi;
71  f << dot(dphi) == -(g/L)*phi - ( b + 2.0*dL/L )*dphi - ddx/L;
72 
73  f << dot(P0) == 2.0*P1;
74  f << dot(P1) == -(g/L)*P0 - ( b + 2.0*dL/L )*P1 + P2;
75  f << dot(P2) == -2.0*(g/L)*P1 - 2.0*( b + 2.0*dL/L )*P2 + F2/(m*m*L*L);
76 
77 
78  // DEFINE AN OPTIMAL CONTROL PROBLEM:
79  // ----------------------------------
80  OCP ocp( 0.0, T, 20 );
81  ocp.minimizeMayerTerm( 0, T );
82  ocp.minimizeMayerTerm( 1, -gamma );
83 
84  ocp.subjectTo( f );
85 
86  ocp.subjectTo( AT_START, x == 0.0 );
87  ocp.subjectTo( AT_START, dx == 0.0 );
88  ocp.subjectTo( AT_START, L == 70.0 );
89  ocp.subjectTo( AT_START, dL == 0.0 );
90  ocp.subjectTo( AT_START, phi == 0.0 );
91  ocp.subjectTo( AT_START, dphi == 0.0 );
92 
93  ocp.subjectTo( AT_START, P0 == 0.0 );
94  ocp.subjectTo( AT_START, P1 == 0.0 );
95  ocp.subjectTo( AT_START, P2 == 0.0 );
96 
97  ocp.subjectTo( AT_END , x == 10.0 );
98  ocp.subjectTo( AT_END , dx == 0.0 );
99  ocp.subjectTo( AT_END , L == 70.0 );
100  ocp.subjectTo( AT_END , dL == 0.0 );
101 
102  ocp.subjectTo( AT_END , -0.075 <= phi - gamma*sqrt(P0) );
103  ocp.subjectTo( AT_END , phi + gamma*sqrt(P0) <= 0.075 );
104 
105  ocp.subjectTo( gamma >= 0.0 );
106 
107  ocp.subjectTo( 5.0 <= T <= 17.0 );
108 
109  ocp.subjectTo( -0.3 <= ddx <= 0.3 );
110  ocp.subjectTo( -1.0 <= ddL <= 1.0 );
111 
112  ocp.subjectTo( -10.0 <= x <= 50.0 );
113  ocp.subjectTo( -20.0 <= dx <= 20.0 );
114  ocp.subjectTo( 30.0 <= L <= 75.0 );
115  ocp.subjectTo( -20.0 <= dL <= 20.0 );
116 
117 
118  // DEFINE A MULTI-OBJECTIVE ALGORITHM AND SOLVE THE OCP:
119  // -----------------------------------------------------
120  MultiObjectiveAlgorithm algorithm(ocp);
121 
122  algorithm.set( PARETO_FRONT_DISCRETIZATION, 31 );
124  //algorithm.set( DISCRETIZATION_TYPE , SINGLE_SHOOTING );
125  //algorithm.set( PARETO_FRONT_HOTSTART , BT_FALSE );
126 
127  // Generate Pareto set
128  algorithm.solve();
129 
130  algorithm.getWeights("crane_ws_weights.txt");
131  algorithm.getAllDifferentialStates("crane_ws_states.txt");
132  algorithm.getAllControls("crane_ws_controls.txt");
133  algorithm.getAllParameters("crane_ws_parameters.txt");
134 
135 
136  // GET THE RESULT FOR THE PARETO FRONT AND PLOT IT:
137  // ------------------------------------------------
138  VariablesGrid paretoFront;
139  algorithm.getParetoFront( paretoFront );
140 
141  GnuplotWindow window1;
142  window1.addSubplot( paretoFront, "Pareto Front (robustness versus time)", "TIME","ROBUSTNESS", PM_POINTS );
143  window1.plot( );
144 
145 
146  // PRINT INFORMATION ABOUT THE ALGORITHM:
147  // --------------------------------------
148  algorithm.printInfo();
149 
150 
151  // SAVE INFORMATION:
152  // -----------------
153  paretoFront.print( "crane_ws_pareto.txt" );
154 
155  return 0;
156 }
157 /* <<< end tutorial code <<< */
158 
returnValue print(std::ostream &stream=std::cout, const char *const name=DEFAULT_LABEL, const char *const startString=DEFAULT_START_STRING, const char *const endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const char *const colSeparator=DEFAULT_COL_SEPARATOR, const char *const rowSeparator=DEFAULT_ROW_SEPARATOR) const
IntermediateState sqrt(const Expression &arg)
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
DMatrix getWeights() const
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue printInfo()
int main()
Definition: crane_ws.cpp:39
returnValue subjectTo(const DifferentialEquation &differentialEquation_)
Definition: ocp.cpp:153
returnValue minimizeMayerTerm(const Expression &arg)
Definition: ocp.cpp:238
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue getAllControls(const char *fileName) const
returnValue getParetoFront(VariablesGrid &paretoFront) const
Data class for defining optimal control problems.
Definition: ocp.hpp:89
Expression dot(const Expression &arg)
#define L
User-interface to formulate and solve optimal control problems with multiple objectives.
returnValue getAllDifferentialStates(const char *fileName) const
Provides an interface to Gnuplot for plotting algorithmic outputs.
returnValue getAllParameters(const char *fileName) const
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:34:31