examples/process/getting_started.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 
36 #include <acado_toolkit.hpp>
37 #include <acado_gnuplot.hpp>
38 
39 
40 int main( )
41 {
43 
44 
45  // INTRODUCE THE VARIABLES:
46  // -------------------------
51 
52  Disturbance R;
53  Control F;
54 
55  Parameter mB;
56  double mW = 50.0;
57  double kS = 20000.0;
58  double kT = 200000.0;
59 
60 
61  // DEFINE THE DYNAMIC SYSTEM:
62  // --------------------------
64 
65  f << dot(xB) == vB;
66  f << dot(xW) == vW;
67  f << dot(vB) == ( -kS*xB + kS*xW + F ) / mB;
68  f << dot(vW) == ( kS*xB - (kT+kS)*xW + kT*R - F ) / mW;
69 
70  OutputFcn g;
71  g << xB;
72  g << 500.0*vB + F;
73 
74  DynamicSystem dynSys( f,g );
75 
76 
77  // SETUP THE PROCESS:
78  // ------------------
79  Process myProcess;
80 
81  myProcess.setDynamicSystem( dynSys,INT_RK45 );
82  myProcess.set( ABSOLUTE_TOLERANCE,1.0e-8 );
83 
84  DVector x0( 4 );
85  x0.setZero( );
86  x0( 0 ) = 0.01;
87 
88  myProcess.initializeStartValues( x0 );
89  myProcess.setProcessDisturbance( "road.txt" );
90 
91  myProcess.set( PLOT_RESOLUTION,HIGH );
92 
93  GnuplotWindow window;
94  window.addSubplot( xB, "Body Position [m]" );
95  window.addSubplot( xW, "Wheel Position [m]" );
96  window.addSubplot( vB, "Body Velocity [m/s]" );
97  window.addSubplot( vW, "Wheel Velocity [m/s]" );
98 
99  window.addSubplot( F,"Damping Force [N]" );
100  window.addSubplot( mB,"Body Mass [kg]" );
101  window.addSubplot( R, "Road Disturbance" );
102  window.addSubplot( g(0),"Output 1" );
103  window.addSubplot( g(1),"Output 2" );
104 
105  myProcess << window;
106 
107 
108  // SIMULATE AND GET THE RESULTS:
109  // -----------------------------
110  VariablesGrid u( 1,0.0,1.0,6 );
111 
112  u( 0,0 ) = 10.0;
113  u( 1,0 ) = -200.0;
114  u( 2,0 ) = 200.0;
115  u( 3,0 ) = 0.0;
116  u( 4,0 ) = 0.0;
117  u( 5,0 ) = 0.0;
118 
119  DVector p( 1 );
120  p(0) = 350.0;
121 
122  myProcess.init( 0.0 );
123  myProcess.run( u,p );
124 
125 
126  VariablesGrid xSim, ySim;
127 
128  myProcess.getLast( LOG_SIMULATED_DIFFERENTIAL_STATES,xSim );
129  xSim.print( "Simulated Differential States" );
130 
131  myProcess.getLast( LOG_PROCESS_OUTPUT,ySim );
132  ySim.print( "Process Output" );
133 
134 
135  return 0;
136 }
137 
138 
139 
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
Allows to setup and evaluate output functions based on SymbolicExpressions.
Definition: output_fcn.hpp:55
Stores a DifferentialEquation together with an OutputFcn.
#define USING_NAMESPACE_ACADO
Provides a time grid consisting of vector-valued optimization variables at each grid point...
returnValue addSubplot(PlotWindowSubplot &_subplot)
returnValue initializeStartValues(const DVector &_xStart, const DVector &_xaStart=emptyConstVector)
Definition: process.cpp:330
returnValue set(OptionsName name, int value)
Definition: options.cpp:126
returnValue getLast(LogName _name, DMatrix &lastValue) const
Derived & setZero(Index size)
Expression dot(const Expression &arg)
virtual returnValue run(const VariablesGrid &_u, const VariablesGrid &_p=emptyVariablesGrid)
Definition: process.cpp:632
returnValue setProcessDisturbance(const Curve &_processDisturbance)
Definition: process.cpp:289
Simulates the process to be controlled based on a dynamic model.
Definition: process.hpp:71
Provides an interface to Gnuplot for plotting algorithmic outputs.
returnValue setDynamicSystem(const DynamicSystem &_dynamicSystem, IntegratorType _integratorType=INT_UNKNOWN)
Definition: process.cpp:204
#define R
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
virtual returnValue init(double _startTime=0.0, const DVector &_xStart=emptyConstVector, const DVector &_uStart=emptyConstVector, const DVector &_pStart=emptyConstVector)
Definition: process.cpp:353


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